babylon.viewer.max.js 3.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842
  1. (function universalModuleDefinition(root, factory) {
  2. var amdDependencies = [];
  3. if(typeof exports === 'object' && typeof module === 'object') {
  4. module.exports = factory();
  5. } else if(typeof define === 'function' && define.amd) {
  6. define("babylonjs-viewer", amdDependencies, factory);
  7. } else if(typeof exports === 'object') {
  8. exports["babylonjs-viewer"] = factory();
  9. } else {
  10. root["BabylonViewer"] = factory();
  11. }
  12. })(this, function() {
  13. var BabylonViewer =
  14. /******/ (function(modules) { // webpackBootstrap
  15. /******/ // The module cache
  16. /******/ var installedModules = {};
  17. /******/
  18. /******/ // The require function
  19. /******/ function __webpack_require__(moduleId) {
  20. /******/
  21. /******/ // Check if module is in cache
  22. /******/ if(installedModules[moduleId]) {
  23. /******/ return installedModules[moduleId].exports;
  24. /******/ }
  25. /******/ // Create a new module (and put it into the cache)
  26. /******/ var module = installedModules[moduleId] = {
  27. /******/ i: moduleId,
  28. /******/ l: false,
  29. /******/ exports: {}
  30. /******/ };
  31. /******/
  32. /******/ // Execute the module function
  33. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  34. /******/
  35. /******/ // Flag the module as loaded
  36. /******/ module.l = true;
  37. /******/
  38. /******/ // Return the exports of the module
  39. /******/ return module.exports;
  40. /******/ }
  41. /******/
  42. /******/
  43. /******/ // expose the modules object (__webpack_modules__)
  44. /******/ __webpack_require__.m = modules;
  45. /******/
  46. /******/ // expose the module cache
  47. /******/ __webpack_require__.c = installedModules;
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function(exports, name, getter) {
  51. /******/ if(!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/ });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = function(module) {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ function getDefault() { return module['default']; } :
  64. /******/ function getModuleExports() { return module; };
  65. /******/ __webpack_require__.d(getter, 'a', getter);
  66. /******/ return getter;
  67. /******/ };
  68. /******/
  69. /******/ // Object.prototype.hasOwnProperty.call
  70. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  71. /******/
  72. /******/ // __webpack_public_path__
  73. /******/ __webpack_require__.p = "";
  74. /******/
  75. /******/ // Load entry module and return exports
  76. /******/ return __webpack_require__(__webpack_require__.s = 15);
  77. /******/ })
  78. /************************************************************************/
  79. /******/ ([
  80. /* 0 */
  81. /***/ (function(module, exports, __webpack_require__) {
  82. /* WEBPACK VAR INJECTION */(function(global) {
  83. (function universalModuleDefinition(root, factory) {
  84. var amdDependencies = [];
  85. var CANNON = root.CANNON || this.CANNON;
  86. var OIMO = root.OIMO || this.OIMO;
  87. var earcut = root.earcut || this.earcut;
  88. if(true) {
  89. try { CANNON = CANNON || __webpack_require__(18); } catch(e) {}
  90. try { OIMO = OIMO || __webpack_require__(19); } catch(e) {}
  91. try { earcut = earcut || __webpack_require__(20); } catch(e) {}
  92. module.exports = factory(CANNON,OIMO,earcut);
  93. } else if(typeof define === 'function' && define.amd) {
  94. if(require.specified && require.specified("cannon")) amdDependencies.push("cannon");
  95. if(require.specified && require.specified("oimo")) amdDependencies.push("oimo");
  96. if(require.specified && require.specified("earcut")) amdDependencies.push("earcut");
  97. define("babylonjs", amdDependencies, factory);
  98. } else if(typeof exports === 'object') {
  99. try { CANNON = CANNON || require("cannon"); } catch(e) {}
  100. try { OIMO = OIMO || require("oimo"); } catch(e) {}
  101. try { earcut = earcut || require("earcut"); } catch(e) {}
  102. exports["babylonjs"] = factory(CANNON,OIMO,earcut);
  103. } else {
  104. root["BABYLON"] = factory(CANNON,OIMO,earcut);
  105. }
  106. })(this, function(CANNON,OIMO,earcut) {
  107. CANNON = CANNON || this.CANNON;
  108. OIMO = OIMO || this.OIMO;
  109. earcut = earcut || this.earcut;
  110. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  111. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  112. var BABYLON;
  113. (function (BABYLON) {
  114. /**
  115. * EffectFallbacks can be used to add fallbacks (properties to disable) to certain properties when desired to improve performance.
  116. * (Eg. Start at high quality with reflection and fog, if fps is low, remove reflection, if still low remove fog)
  117. */
  118. var EffectFallbacks = /** @class */ (function () {
  119. function EffectFallbacks() {
  120. this._defines = {};
  121. this._currentRank = 32;
  122. this._maxRank = -1;
  123. }
  124. /**
  125. * Removes the fallback from the bound mesh.
  126. */
  127. EffectFallbacks.prototype.unBindMesh = function () {
  128. this._mesh = null;
  129. };
  130. /**
  131. * Adds a fallback on the specified property.
  132. * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)
  133. * @param define The name of the define in the shader
  134. */
  135. EffectFallbacks.prototype.addFallback = function (rank, define) {
  136. if (!this._defines[rank]) {
  137. if (rank < this._currentRank) {
  138. this._currentRank = rank;
  139. }
  140. if (rank > this._maxRank) {
  141. this._maxRank = rank;
  142. }
  143. this._defines[rank] = new Array();
  144. }
  145. this._defines[rank].push(define);
  146. };
  147. /**
  148. * Sets the mesh to use CPU skinning when needing to fallback.
  149. * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)
  150. * @param mesh The mesh to use the fallbacks.
  151. */
  152. EffectFallbacks.prototype.addCPUSkinningFallback = function (rank, mesh) {
  153. this._mesh = mesh;
  154. if (rank < this._currentRank) {
  155. this._currentRank = rank;
  156. }
  157. if (rank > this._maxRank) {
  158. this._maxRank = rank;
  159. }
  160. };
  161. Object.defineProperty(EffectFallbacks.prototype, "isMoreFallbacks", {
  162. /**
  163. * Checks to see if more fallbacks are still availible.
  164. */
  165. get: function () {
  166. return this._currentRank <= this._maxRank;
  167. },
  168. enumerable: true,
  169. configurable: true
  170. });
  171. /**
  172. * Removes the defines that shoould be removed when falling back.
  173. * @param currentDefines defines the current define statements for the shader.
  174. * @param effect defines the current effect we try to compile
  175. * @returns The resulting defines with defines of the current rank removed.
  176. */
  177. EffectFallbacks.prototype.reduce = function (currentDefines, effect) {
  178. // First we try to switch to CPU skinning
  179. if (this._mesh && this._mesh.computeBonesUsingShaders && this._mesh.numBoneInfluencers > 0 && this._mesh.material) {
  180. this._mesh.computeBonesUsingShaders = false;
  181. currentDefines = currentDefines.replace("#define NUM_BONE_INFLUENCERS " + this._mesh.numBoneInfluencers, "#define NUM_BONE_INFLUENCERS 0");
  182. effect._bonesComputationForcedToCPU = true;
  183. var scene = this._mesh.getScene();
  184. for (var index = 0; index < scene.meshes.length; index++) {
  185. var otherMesh = scene.meshes[index];
  186. if (!otherMesh.material) {
  187. continue;
  188. }
  189. if (!otherMesh.computeBonesUsingShaders || otherMesh.numBoneInfluencers === 0) {
  190. continue;
  191. }
  192. if (otherMesh.material.getEffect() === effect) {
  193. otherMesh.computeBonesUsingShaders = false;
  194. }
  195. else if (otherMesh.subMeshes) {
  196. for (var _i = 0, _a = otherMesh.subMeshes; _i < _a.length; _i++) {
  197. var subMesh = _a[_i];
  198. var subMeshEffect = subMesh.effect;
  199. if (subMeshEffect === effect) {
  200. otherMesh.computeBonesUsingShaders = false;
  201. break;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. else {
  208. var currentFallbacks = this._defines[this._currentRank];
  209. if (currentFallbacks) {
  210. for (var index = 0; index < currentFallbacks.length; index++) {
  211. currentDefines = currentDefines.replace("#define " + currentFallbacks[index], "");
  212. }
  213. }
  214. this._currentRank++;
  215. }
  216. return currentDefines;
  217. };
  218. return EffectFallbacks;
  219. }());
  220. BABYLON.EffectFallbacks = EffectFallbacks;
  221. /**
  222. * Options to be used when creating an effect.
  223. */
  224. var EffectCreationOptions = /** @class */ (function () {
  225. function EffectCreationOptions() {
  226. }
  227. return EffectCreationOptions;
  228. }());
  229. BABYLON.EffectCreationOptions = EffectCreationOptions;
  230. /**
  231. * Effect containing vertex and fragment shader that can be executed on an object.
  232. */
  233. var Effect = /** @class */ (function () {
  234. /**
  235. * Instantiates an effect.
  236. * An effect can be used to create/manage/execute vertex and fragment shaders.
  237. * @param baseName Name of the effect.
  238. * @param attributesNamesOrOptions List of attribute names that will be passed to the shader or set of all options to create the effect.
  239. * @param uniformsNamesOrEngine List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.
  240. * @param samplers List of sampler variables that will be passed to the shader.
  241. * @param engine Engine to be used to render the effect
  242. * @param defines Define statements to be added to the shader.
  243. * @param fallbacks Possible fallbacks for this effect to improve performance when needed.
  244. * @param onCompiled Callback that will be called when the shader is compiled.
  245. * @param onError Callback that will be called if an error occurs during shader compilation.
  246. * @param indexParameters Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})
  247. */
  248. function Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, engine, defines, fallbacks, onCompiled, onError, indexParameters) {
  249. if (samplers === void 0) { samplers = null; }
  250. if (defines === void 0) { defines = null; }
  251. if (fallbacks === void 0) { fallbacks = null; }
  252. if (onCompiled === void 0) { onCompiled = null; }
  253. if (onError === void 0) { onError = null; }
  254. var _this = this;
  255. /**
  256. * Unique ID of the effect.
  257. */
  258. this.uniqueId = 0;
  259. /**
  260. * Observable that will be called when the shader is compiled.
  261. */
  262. this.onCompileObservable = new BABYLON.Observable();
  263. /**
  264. * Observable that will be called if an error occurs during shader compilation.
  265. */
  266. this.onErrorObservable = new BABYLON.Observable();
  267. /**
  268. * Observable that will be called when effect is bound.
  269. */
  270. this.onBindObservable = new BABYLON.Observable();
  271. /** @hidden */
  272. this._bonesComputationForcedToCPU = false;
  273. this._uniformBuffersNames = {};
  274. this._isReady = false;
  275. this._compilationError = "";
  276. this.name = baseName;
  277. if (attributesNamesOrOptions.attributes) {
  278. var options = attributesNamesOrOptions;
  279. this._engine = uniformsNamesOrEngine;
  280. this._attributesNames = options.attributes;
  281. this._uniformsNames = options.uniformsNames.concat(options.samplers);
  282. this._samplers = options.samplers.slice();
  283. this.defines = options.defines;
  284. this.onError = options.onError;
  285. this.onCompiled = options.onCompiled;
  286. this._fallbacks = options.fallbacks;
  287. this._indexParameters = options.indexParameters;
  288. this._transformFeedbackVaryings = options.transformFeedbackVaryings;
  289. if (options.uniformBuffersNames) {
  290. for (var i = 0; i < options.uniformBuffersNames.length; i++) {
  291. this._uniformBuffersNames[options.uniformBuffersNames[i]] = i;
  292. }
  293. }
  294. }
  295. else {
  296. this._engine = engine;
  297. this.defines = defines;
  298. this._uniformsNames = uniformsNamesOrEngine.concat(samplers);
  299. this._samplers = samplers ? samplers.slice() : [];
  300. this._attributesNames = attributesNamesOrOptions;
  301. this.onError = onError;
  302. this.onCompiled = onCompiled;
  303. this._indexParameters = indexParameters;
  304. this._fallbacks = fallbacks;
  305. }
  306. this.uniqueId = Effect._uniqueIdSeed++;
  307. var vertexSource;
  308. var fragmentSource;
  309. if (baseName.vertexElement) {
  310. vertexSource = document.getElementById(baseName.vertexElement);
  311. if (!vertexSource) {
  312. vertexSource = baseName.vertexElement;
  313. }
  314. }
  315. else {
  316. vertexSource = baseName.vertex || baseName;
  317. }
  318. if (baseName.fragmentElement) {
  319. fragmentSource = document.getElementById(baseName.fragmentElement);
  320. if (!fragmentSource) {
  321. fragmentSource = baseName.fragmentElement;
  322. }
  323. }
  324. else {
  325. fragmentSource = baseName.fragment || baseName;
  326. }
  327. this._loadVertexShader(vertexSource, function (vertexCode) {
  328. _this._processIncludes(vertexCode, function (vertexCodeWithIncludes) {
  329. _this._processShaderConversion(vertexCodeWithIncludes, false, function (migratedVertexCode) {
  330. _this._loadFragmentShader(fragmentSource, function (fragmentCode) {
  331. _this._processIncludes(fragmentCode, function (fragmentCodeWithIncludes) {
  332. _this._processShaderConversion(fragmentCodeWithIncludes, true, function (migratedFragmentCode) {
  333. if (baseName) {
  334. var vertex = baseName.vertexElement || baseName.vertex || baseName;
  335. var fragment = baseName.fragmentElement || baseName.fragment || baseName;
  336. _this._vertexSourceCode = "#define SHADER_NAME vertex:" + vertex + "\n" + migratedVertexCode;
  337. _this._fragmentSourceCode = "#define SHADER_NAME fragment:" + fragment + "\n" + migratedFragmentCode;
  338. }
  339. else {
  340. _this._vertexSourceCode = migratedVertexCode;
  341. _this._fragmentSourceCode = migratedFragmentCode;
  342. }
  343. _this._prepareEffect();
  344. });
  345. });
  346. });
  347. });
  348. });
  349. });
  350. }
  351. Object.defineProperty(Effect.prototype, "key", {
  352. /**
  353. * Unique key for this effect
  354. */
  355. get: function () {
  356. return this._key;
  357. },
  358. enumerable: true,
  359. configurable: true
  360. });
  361. /**
  362. * If the effect has been compiled and prepared.
  363. * @returns if the effect is compiled and prepared.
  364. */
  365. Effect.prototype.isReady = function () {
  366. return this._isReady;
  367. };
  368. /**
  369. * The engine the effect was initialized with.
  370. * @returns the engine.
  371. */
  372. Effect.prototype.getEngine = function () {
  373. return this._engine;
  374. };
  375. /**
  376. * The compiled webGL program for the effect
  377. * @returns the webGL program.
  378. */
  379. Effect.prototype.getProgram = function () {
  380. return this._program;
  381. };
  382. /**
  383. * The set of names of attribute variables for the shader.
  384. * @returns An array of attribute names.
  385. */
  386. Effect.prototype.getAttributesNames = function () {
  387. return this._attributesNames;
  388. };
  389. /**
  390. * Returns the attribute at the given index.
  391. * @param index The index of the attribute.
  392. * @returns The location of the attribute.
  393. */
  394. Effect.prototype.getAttributeLocation = function (index) {
  395. return this._attributes[index];
  396. };
  397. /**
  398. * Returns the attribute based on the name of the variable.
  399. * @param name of the attribute to look up.
  400. * @returns the attribute location.
  401. */
  402. Effect.prototype.getAttributeLocationByName = function (name) {
  403. var index = this._attributesNames.indexOf(name);
  404. return this._attributes[index];
  405. };
  406. /**
  407. * The number of attributes.
  408. * @returns the numnber of attributes.
  409. */
  410. Effect.prototype.getAttributesCount = function () {
  411. return this._attributes.length;
  412. };
  413. /**
  414. * Gets the index of a uniform variable.
  415. * @param uniformName of the uniform to look up.
  416. * @returns the index.
  417. */
  418. Effect.prototype.getUniformIndex = function (uniformName) {
  419. return this._uniformsNames.indexOf(uniformName);
  420. };
  421. /**
  422. * Returns the attribute based on the name of the variable.
  423. * @param uniformName of the uniform to look up.
  424. * @returns the location of the uniform.
  425. */
  426. Effect.prototype.getUniform = function (uniformName) {
  427. return this._uniforms[this._uniformsNames.indexOf(uniformName)];
  428. };
  429. /**
  430. * Returns an array of sampler variable names
  431. * @returns The array of sampler variable neames.
  432. */
  433. Effect.prototype.getSamplers = function () {
  434. return this._samplers;
  435. };
  436. /**
  437. * The error from the last compilation.
  438. * @returns the error string.
  439. */
  440. Effect.prototype.getCompilationError = function () {
  441. return this._compilationError;
  442. };
  443. /**
  444. * Adds a callback to the onCompiled observable and call the callback imediatly if already ready.
  445. * @param func The callback to be used.
  446. */
  447. Effect.prototype.executeWhenCompiled = function (func) {
  448. if (this.isReady()) {
  449. func(this);
  450. return;
  451. }
  452. this.onCompileObservable.add(function (effect) {
  453. func(effect);
  454. });
  455. };
  456. /** @hidden */
  457. Effect.prototype._loadVertexShader = function (vertex, callback) {
  458. if (BABYLON.Tools.IsWindowObjectExist()) {
  459. // DOM element ?
  460. if (vertex instanceof HTMLElement) {
  461. var vertexCode = BABYLON.Tools.GetDOMTextContent(vertex);
  462. callback(vertexCode);
  463. return;
  464. }
  465. }
  466. // Base64 encoded ?
  467. if (vertex.substr(0, 7) === "base64:") {
  468. var vertexBinary = window.atob(vertex.substr(7));
  469. callback(vertexBinary);
  470. return;
  471. }
  472. // Is in local store ?
  473. if (Effect.ShadersStore[vertex + "VertexShader"]) {
  474. callback(Effect.ShadersStore[vertex + "VertexShader"]);
  475. return;
  476. }
  477. var vertexShaderUrl;
  478. if (vertex[0] === "." || vertex[0] === "/" || vertex.indexOf("http") > -1) {
  479. vertexShaderUrl = vertex;
  480. }
  481. else {
  482. vertexShaderUrl = BABYLON.Engine.ShadersRepository + vertex;
  483. }
  484. // Vertex shader
  485. this._engine._loadFile(vertexShaderUrl + ".vertex.fx", callback);
  486. };
  487. /** @hidden */
  488. Effect.prototype._loadFragmentShader = function (fragment, callback) {
  489. if (BABYLON.Tools.IsWindowObjectExist()) {
  490. // DOM element ?
  491. if (fragment instanceof HTMLElement) {
  492. var fragmentCode = BABYLON.Tools.GetDOMTextContent(fragment);
  493. callback(fragmentCode);
  494. return;
  495. }
  496. }
  497. // Base64 encoded ?
  498. if (fragment.substr(0, 7) === "base64:") {
  499. var fragmentBinary = window.atob(fragment.substr(7));
  500. callback(fragmentBinary);
  501. return;
  502. }
  503. // Is in local store ?
  504. if (Effect.ShadersStore[fragment + "PixelShader"]) {
  505. callback(Effect.ShadersStore[fragment + "PixelShader"]);
  506. return;
  507. }
  508. if (Effect.ShadersStore[fragment + "FragmentShader"]) {
  509. callback(Effect.ShadersStore[fragment + "FragmentShader"]);
  510. return;
  511. }
  512. var fragmentShaderUrl;
  513. if (fragment[0] === "." || fragment[0] === "/" || fragment.indexOf("http") > -1) {
  514. fragmentShaderUrl = fragment;
  515. }
  516. else {
  517. fragmentShaderUrl = BABYLON.Engine.ShadersRepository + fragment;
  518. }
  519. // Fragment shader
  520. this._engine._loadFile(fragmentShaderUrl + ".fragment.fx", callback);
  521. };
  522. Effect.prototype._dumpShadersSource = function (vertexCode, fragmentCode, defines) {
  523. // Rebuild shaders source code
  524. var shaderVersion = (this._engine.webGLVersion > 1) ? "#version 300 es\n#define WEBGL2 \n" : "";
  525. var prefix = shaderVersion + (defines ? defines + "\n" : "");
  526. vertexCode = prefix + vertexCode;
  527. fragmentCode = prefix + fragmentCode;
  528. // Number lines of shaders source code
  529. var i = 2;
  530. var regex = /\n/gm;
  531. var formattedVertexCode = "\n1\t" + vertexCode.replace(regex, function () { return "\n" + (i++) + "\t"; });
  532. i = 2;
  533. var formattedFragmentCode = "\n1\t" + fragmentCode.replace(regex, function () { return "\n" + (i++) + "\t"; });
  534. // Dump shaders name and formatted source code
  535. if (this.name.vertexElement) {
  536. BABYLON.Tools.Error("Vertex shader: " + this.name.vertexElement + formattedVertexCode);
  537. BABYLON.Tools.Error("Fragment shader: " + this.name.fragmentElement + formattedFragmentCode);
  538. }
  539. else if (this.name.vertex) {
  540. BABYLON.Tools.Error("Vertex shader: " + this.name.vertex + formattedVertexCode);
  541. BABYLON.Tools.Error("Fragment shader: " + this.name.fragment + formattedFragmentCode);
  542. }
  543. else {
  544. BABYLON.Tools.Error("Vertex shader: " + this.name + formattedVertexCode);
  545. BABYLON.Tools.Error("Fragment shader: " + this.name + formattedFragmentCode);
  546. }
  547. };
  548. ;
  549. Effect.prototype._processShaderConversion = function (sourceCode, isFragment, callback) {
  550. var preparedSourceCode = this._processPrecision(sourceCode);
  551. if (this._engine.webGLVersion == 1) {
  552. callback(preparedSourceCode);
  553. return;
  554. }
  555. // Already converted
  556. if (preparedSourceCode.indexOf("#version 3") !== -1) {
  557. callback(preparedSourceCode.replace("#version 300 es", ""));
  558. return;
  559. }
  560. var hasDrawBuffersExtension = preparedSourceCode.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;
  561. // Remove extensions
  562. // #extension GL_OES_standard_derivatives : enable
  563. // #extension GL_EXT_shader_texture_lod : enable
  564. // #extension GL_EXT_frag_depth : enable
  565. // #extension GL_EXT_draw_buffers : require
  566. var regex = /#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
  567. var result = preparedSourceCode.replace(regex, "");
  568. // Migrate to GLSL v300
  569. result = result.replace(/varying(?![\n\r])\s/g, isFragment ? "in " : "out ");
  570. result = result.replace(/attribute[ \t]/g, "in ");
  571. result = result.replace(/[ \t]attribute/g, " in");
  572. if (isFragment) {
  573. result = result.replace(/texture2DLodEXT\s*\(/g, "textureLod(");
  574. result = result.replace(/textureCubeLodEXT\s*\(/g, "textureLod(");
  575. result = result.replace(/texture2D\s*\(/g, "texture(");
  576. result = result.replace(/textureCube\s*\(/g, "texture(");
  577. result = result.replace(/gl_FragDepthEXT/g, "gl_FragDepth");
  578. result = result.replace(/gl_FragColor/g, "glFragColor");
  579. result = result.replace(/gl_FragData/g, "glFragData");
  580. result = result.replace(/void\s+?main\s*\(/g, (hasDrawBuffersExtension ? "" : "out vec4 glFragColor;\n") + "void main(");
  581. }
  582. callback(result);
  583. };
  584. Effect.prototype._processIncludes = function (sourceCode, callback) {
  585. var _this = this;
  586. var regex = /#include<(.+)>(\((.*)\))*(\[(.*)\])*/g;
  587. var match = regex.exec(sourceCode);
  588. var returnValue = new String(sourceCode);
  589. while (match != null) {
  590. var includeFile = match[1];
  591. // Uniform declaration
  592. if (includeFile.indexOf("__decl__") !== -1) {
  593. includeFile = includeFile.replace(/__decl__/, "");
  594. if (this._engine.supportsUniformBuffers) {
  595. includeFile = includeFile.replace(/Vertex/, "Ubo");
  596. includeFile = includeFile.replace(/Fragment/, "Ubo");
  597. }
  598. includeFile = includeFile + "Declaration";
  599. }
  600. if (Effect.IncludesShadersStore[includeFile]) {
  601. // Substitution
  602. var includeContent = Effect.IncludesShadersStore[includeFile];
  603. if (match[2]) {
  604. var splits = match[3].split(",");
  605. for (var index = 0; index < splits.length; index += 2) {
  606. var source = new RegExp(splits[index], "g");
  607. var dest = splits[index + 1];
  608. includeContent = includeContent.replace(source, dest);
  609. }
  610. }
  611. if (match[4]) {
  612. var indexString = match[5];
  613. if (indexString.indexOf("..") !== -1) {
  614. var indexSplits = indexString.split("..");
  615. var minIndex = parseInt(indexSplits[0]);
  616. var maxIndex = parseInt(indexSplits[1]);
  617. var sourceIncludeContent = includeContent.slice(0);
  618. includeContent = "";
  619. if (isNaN(maxIndex)) {
  620. maxIndex = this._indexParameters[indexSplits[1]];
  621. }
  622. for (var i = minIndex; i < maxIndex; i++) {
  623. if (!this._engine.supportsUniformBuffers) {
  624. // Ubo replacement
  625. sourceIncludeContent = sourceIncludeContent.replace(/light\{X\}.(\w*)/g, function (str, p1) {
  626. return p1 + "{X}";
  627. });
  628. }
  629. includeContent += sourceIncludeContent.replace(/\{X\}/g, i.toString()) + "\n";
  630. }
  631. }
  632. else {
  633. if (!this._engine.supportsUniformBuffers) {
  634. // Ubo replacement
  635. includeContent = includeContent.replace(/light\{X\}.(\w*)/g, function (str, p1) {
  636. return p1 + "{X}";
  637. });
  638. }
  639. includeContent = includeContent.replace(/\{X\}/g, indexString);
  640. }
  641. }
  642. // Replace
  643. returnValue = returnValue.replace(match[0], includeContent);
  644. }
  645. else {
  646. var includeShaderUrl = BABYLON.Engine.ShadersRepository + "ShadersInclude/" + includeFile + ".fx";
  647. this._engine._loadFile(includeShaderUrl, function (fileContent) {
  648. Effect.IncludesShadersStore[includeFile] = fileContent;
  649. _this._processIncludes(returnValue, callback);
  650. });
  651. return;
  652. }
  653. match = regex.exec(sourceCode);
  654. }
  655. callback(returnValue);
  656. };
  657. Effect.prototype._processPrecision = function (source) {
  658. if (source.indexOf("precision highp float") === -1) {
  659. if (!this._engine.getCaps().highPrecisionShaderSupported) {
  660. source = "precision mediump float;\n" + source;
  661. }
  662. else {
  663. source = "precision highp float;\n" + source;
  664. }
  665. }
  666. else {
  667. if (!this._engine.getCaps().highPrecisionShaderSupported) { // Moving highp to mediump
  668. source = source.replace("precision highp float", "precision mediump float");
  669. }
  670. }
  671. return source;
  672. };
  673. /**
  674. * Recompiles the webGL program
  675. * @param vertexSourceCode The source code for the vertex shader.
  676. * @param fragmentSourceCode The source code for the fragment shader.
  677. * @param onCompiled Callback called when completed.
  678. * @param onError Callback called on error.
  679. */
  680. Effect.prototype._rebuildProgram = function (vertexSourceCode, fragmentSourceCode, onCompiled, onError) {
  681. var _this = this;
  682. this._isReady = false;
  683. this._vertexSourceCodeOverride = vertexSourceCode;
  684. this._fragmentSourceCodeOverride = fragmentSourceCode;
  685. this.onError = function (effect, error) {
  686. if (onError) {
  687. onError(error);
  688. }
  689. };
  690. this.onCompiled = function () {
  691. var scenes = _this.getEngine().scenes;
  692. for (var i = 0; i < scenes.length; i++) {
  693. scenes[i].markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  694. }
  695. if (onCompiled) {
  696. onCompiled(_this._program);
  697. }
  698. };
  699. this._fallbacks = null;
  700. this._prepareEffect();
  701. };
  702. /**
  703. * Gets the uniform locations of the the specified variable names
  704. * @param names THe names of the variables to lookup.
  705. * @returns Array of locations in the same order as variable names.
  706. */
  707. Effect.prototype.getSpecificUniformLocations = function (names) {
  708. var engine = this._engine;
  709. return engine.getUniforms(this._program, names);
  710. };
  711. /**
  712. * Prepares the effect
  713. */
  714. Effect.prototype._prepareEffect = function () {
  715. var attributesNames = this._attributesNames;
  716. var defines = this.defines;
  717. var fallbacks = this._fallbacks;
  718. this._valueCache = {};
  719. var previousProgram = this._program;
  720. try {
  721. var engine = this._engine;
  722. if (this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride) {
  723. this._program = engine.createRawShaderProgram(this._vertexSourceCodeOverride, this._fragmentSourceCodeOverride, undefined, this._transformFeedbackVaryings);
  724. }
  725. else {
  726. this._program = engine.createShaderProgram(this._vertexSourceCode, this._fragmentSourceCode, defines, undefined, this._transformFeedbackVaryings);
  727. }
  728. this._program.__SPECTOR_rebuildProgram = this._rebuildProgram.bind(this);
  729. if (engine.supportsUniformBuffers) {
  730. for (var name in this._uniformBuffersNames) {
  731. this.bindUniformBlock(name, this._uniformBuffersNames[name]);
  732. }
  733. }
  734. this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
  735. this._attributes = engine.getAttributes(this._program, attributesNames);
  736. var index;
  737. for (index = 0; index < this._samplers.length; index++) {
  738. var sampler = this.getUniform(this._samplers[index]);
  739. if (sampler == null) {
  740. this._samplers.splice(index, 1);
  741. index--;
  742. }
  743. }
  744. engine.bindSamplers(this);
  745. this._compilationError = "";
  746. this._isReady = true;
  747. if (this.onCompiled) {
  748. this.onCompiled(this);
  749. }
  750. this.onCompileObservable.notifyObservers(this);
  751. this.onCompileObservable.clear();
  752. // Unbind mesh reference in fallbacks
  753. if (this._fallbacks) {
  754. this._fallbacks.unBindMesh();
  755. }
  756. if (previousProgram) {
  757. this.getEngine()._deleteProgram(previousProgram);
  758. }
  759. }
  760. catch (e) {
  761. this._compilationError = e.message;
  762. // Let's go through fallbacks then
  763. BABYLON.Tools.Error("Unable to compile effect:");
  764. BABYLON.Tools.Error("Uniforms: " + this._uniformsNames.map(function (uniform) {
  765. return " " + uniform;
  766. }));
  767. BABYLON.Tools.Error("Attributes: " + attributesNames.map(function (attribute) {
  768. return " " + attribute;
  769. }));
  770. this._dumpShadersSource(this._vertexSourceCode, this._fragmentSourceCode, defines);
  771. BABYLON.Tools.Error("Error: " + this._compilationError);
  772. if (previousProgram) {
  773. this._program = previousProgram;
  774. this._isReady = true;
  775. if (this.onError) {
  776. this.onError(this, this._compilationError);
  777. }
  778. this.onErrorObservable.notifyObservers(this);
  779. }
  780. if (fallbacks && fallbacks.isMoreFallbacks) {
  781. BABYLON.Tools.Error("Trying next fallback.");
  782. this.defines = fallbacks.reduce(this.defines, this);
  783. this._prepareEffect();
  784. }
  785. else { // Sorry we did everything we can
  786. if (this.onError) {
  787. this.onError(this, this._compilationError);
  788. }
  789. this.onErrorObservable.notifyObservers(this);
  790. this.onErrorObservable.clear();
  791. // Unbind mesh reference in fallbacks
  792. if (this._fallbacks) {
  793. this._fallbacks.unBindMesh();
  794. }
  795. }
  796. }
  797. };
  798. Object.defineProperty(Effect.prototype, "isSupported", {
  799. /**
  800. * Checks if the effect is supported. (Must be called after compilation)
  801. */
  802. get: function () {
  803. return this._compilationError === "";
  804. },
  805. enumerable: true,
  806. configurable: true
  807. });
  808. /**
  809. * Binds a texture to the engine to be used as output of the shader.
  810. * @param channel Name of the output variable.
  811. * @param texture Texture to bind.
  812. */
  813. Effect.prototype._bindTexture = function (channel, texture) {
  814. this._engine._bindTexture(this._samplers.indexOf(channel), texture);
  815. };
  816. /**
  817. * Sets a texture on the engine to be used in the shader.
  818. * @param channel Name of the sampler variable.
  819. * @param texture Texture to set.
  820. */
  821. Effect.prototype.setTexture = function (channel, texture) {
  822. this._engine.setTexture(this._samplers.indexOf(channel), this.getUniform(channel), texture);
  823. };
  824. /**
  825. * Sets a depth stencil texture from a render target on the engine to be used in the shader.
  826. * @param channel Name of the sampler variable.
  827. * @param texture Texture to set.
  828. */
  829. Effect.prototype.setDepthStencilTexture = function (channel, texture) {
  830. this._engine.setDepthStencilTexture(this._samplers.indexOf(channel), this.getUniform(channel), texture);
  831. };
  832. /**
  833. * Sets an array of textures on the engine to be used in the shader.
  834. * @param channel Name of the variable.
  835. * @param textures Textures to set.
  836. */
  837. Effect.prototype.setTextureArray = function (channel, textures) {
  838. if (this._samplers.indexOf(channel + "Ex") === -1) {
  839. var initialPos = this._samplers.indexOf(channel);
  840. for (var index = 1; index < textures.length; index++) {
  841. this._samplers.splice(initialPos + index, 0, channel + "Ex");
  842. }
  843. }
  844. this._engine.setTextureArray(this._samplers.indexOf(channel), this.getUniform(channel), textures);
  845. };
  846. /**
  847. * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)
  848. * @param channel Name of the sampler variable.
  849. * @param postProcess Post process to get the input texture from.
  850. */
  851. Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
  852. this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
  853. };
  854. /**
  855. * (Warning! setTextureFromPostProcessOutput may be desired instead)
  856. * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)
  857. * @param channel Name of the sampler variable.
  858. * @param postProcess Post process to get the output texture from.
  859. */
  860. Effect.prototype.setTextureFromPostProcessOutput = function (channel, postProcess) {
  861. this._engine.setTextureFromPostProcessOutput(this._samplers.indexOf(channel), postProcess);
  862. };
  863. /** @hidden */
  864. Effect.prototype._cacheMatrix = function (uniformName, matrix) {
  865. var cache = this._valueCache[uniformName];
  866. var flag = matrix.updateFlag;
  867. if (cache !== undefined && cache === flag) {
  868. return false;
  869. }
  870. this._valueCache[uniformName] = flag;
  871. return true;
  872. };
  873. /** @hidden */
  874. Effect.prototype._cacheFloat2 = function (uniformName, x, y) {
  875. var cache = this._valueCache[uniformName];
  876. if (!cache) {
  877. cache = [x, y];
  878. this._valueCache[uniformName] = cache;
  879. return true;
  880. }
  881. var changed = false;
  882. if (cache[0] !== x) {
  883. cache[0] = x;
  884. changed = true;
  885. }
  886. if (cache[1] !== y) {
  887. cache[1] = y;
  888. changed = true;
  889. }
  890. return changed;
  891. };
  892. /** @hidden */
  893. Effect.prototype._cacheFloat3 = function (uniformName, x, y, z) {
  894. var cache = this._valueCache[uniformName];
  895. if (!cache) {
  896. cache = [x, y, z];
  897. this._valueCache[uniformName] = cache;
  898. return true;
  899. }
  900. var changed = false;
  901. if (cache[0] !== x) {
  902. cache[0] = x;
  903. changed = true;
  904. }
  905. if (cache[1] !== y) {
  906. cache[1] = y;
  907. changed = true;
  908. }
  909. if (cache[2] !== z) {
  910. cache[2] = z;
  911. changed = true;
  912. }
  913. return changed;
  914. };
  915. /** @hidden */
  916. Effect.prototype._cacheFloat4 = function (uniformName, x, y, z, w) {
  917. var cache = this._valueCache[uniformName];
  918. if (!cache) {
  919. cache = [x, y, z, w];
  920. this._valueCache[uniformName] = cache;
  921. return true;
  922. }
  923. var changed = false;
  924. if (cache[0] !== x) {
  925. cache[0] = x;
  926. changed = true;
  927. }
  928. if (cache[1] !== y) {
  929. cache[1] = y;
  930. changed = true;
  931. }
  932. if (cache[2] !== z) {
  933. cache[2] = z;
  934. changed = true;
  935. }
  936. if (cache[3] !== w) {
  937. cache[3] = w;
  938. changed = true;
  939. }
  940. return changed;
  941. };
  942. /**
  943. * Binds a buffer to a uniform.
  944. * @param buffer Buffer to bind.
  945. * @param name Name of the uniform variable to bind to.
  946. */
  947. Effect.prototype.bindUniformBuffer = function (buffer, name) {
  948. var bufferName = this._uniformBuffersNames[name];
  949. if (bufferName === undefined || Effect._baseCache[bufferName] === buffer) {
  950. return;
  951. }
  952. Effect._baseCache[bufferName] = buffer;
  953. this._engine.bindUniformBufferBase(buffer, bufferName);
  954. };
  955. /**
  956. * Binds block to a uniform.
  957. * @param blockName Name of the block to bind.
  958. * @param index Index to bind.
  959. */
  960. Effect.prototype.bindUniformBlock = function (blockName, index) {
  961. this._engine.bindUniformBlock(this._program, blockName, index);
  962. };
  963. /**
  964. * Sets an interger value on a uniform variable.
  965. * @param uniformName Name of the variable.
  966. * @param value Value to be set.
  967. * @returns this effect.
  968. */
  969. Effect.prototype.setInt = function (uniformName, value) {
  970. var cache = this._valueCache[uniformName];
  971. if (cache !== undefined && cache === value)
  972. return this;
  973. this._valueCache[uniformName] = value;
  974. this._engine.setInt(this.getUniform(uniformName), value);
  975. return this;
  976. };
  977. /**
  978. * Sets an int array on a uniform variable.
  979. * @param uniformName Name of the variable.
  980. * @param array array to be set.
  981. * @returns this effect.
  982. */
  983. Effect.prototype.setIntArray = function (uniformName, array) {
  984. this._valueCache[uniformName] = null;
  985. this._engine.setIntArray(this.getUniform(uniformName), array);
  986. return this;
  987. };
  988. /**
  989. * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  990. * @param uniformName Name of the variable.
  991. * @param array array to be set.
  992. * @returns this effect.
  993. */
  994. Effect.prototype.setIntArray2 = function (uniformName, array) {
  995. this._valueCache[uniformName] = null;
  996. this._engine.setIntArray2(this.getUniform(uniformName), array);
  997. return this;
  998. };
  999. /**
  1000. * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  1001. * @param uniformName Name of the variable.
  1002. * @param array array to be set.
  1003. * @returns this effect.
  1004. */
  1005. Effect.prototype.setIntArray3 = function (uniformName, array) {
  1006. this._valueCache[uniformName] = null;
  1007. this._engine.setIntArray3(this.getUniform(uniformName), array);
  1008. return this;
  1009. };
  1010. /**
  1011. * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  1012. * @param uniformName Name of the variable.
  1013. * @param array array to be set.
  1014. * @returns this effect.
  1015. */
  1016. Effect.prototype.setIntArray4 = function (uniformName, array) {
  1017. this._valueCache[uniformName] = null;
  1018. this._engine.setIntArray4(this.getUniform(uniformName), array);
  1019. return this;
  1020. };
  1021. /**
  1022. * Sets an float array on a uniform variable.
  1023. * @param uniformName Name of the variable.
  1024. * @param array array to be set.
  1025. * @returns this effect.
  1026. */
  1027. Effect.prototype.setFloatArray = function (uniformName, array) {
  1028. this._valueCache[uniformName] = null;
  1029. this._engine.setFloatArray(this.getUniform(uniformName), array);
  1030. return this;
  1031. };
  1032. /**
  1033. * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  1034. * @param uniformName Name of the variable.
  1035. * @param array array to be set.
  1036. * @returns this effect.
  1037. */
  1038. Effect.prototype.setFloatArray2 = function (uniformName, array) {
  1039. this._valueCache[uniformName] = null;
  1040. this._engine.setFloatArray2(this.getUniform(uniformName), array);
  1041. return this;
  1042. };
  1043. /**
  1044. * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  1045. * @param uniformName Name of the variable.
  1046. * @param array array to be set.
  1047. * @returns this effect.
  1048. */
  1049. Effect.prototype.setFloatArray3 = function (uniformName, array) {
  1050. this._valueCache[uniformName] = null;
  1051. this._engine.setFloatArray3(this.getUniform(uniformName), array);
  1052. return this;
  1053. };
  1054. /**
  1055. * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  1056. * @param uniformName Name of the variable.
  1057. * @param array array to be set.
  1058. * @returns this effect.
  1059. */
  1060. Effect.prototype.setFloatArray4 = function (uniformName, array) {
  1061. this._valueCache[uniformName] = null;
  1062. this._engine.setFloatArray4(this.getUniform(uniformName), array);
  1063. return this;
  1064. };
  1065. /**
  1066. * Sets an array on a uniform variable.
  1067. * @param uniformName Name of the variable.
  1068. * @param array array to be set.
  1069. * @returns this effect.
  1070. */
  1071. Effect.prototype.setArray = function (uniformName, array) {
  1072. this._valueCache[uniformName] = null;
  1073. this._engine.setArray(this.getUniform(uniformName), array);
  1074. return this;
  1075. };
  1076. /**
  1077. * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  1078. * @param uniformName Name of the variable.
  1079. * @param array array to be set.
  1080. * @returns this effect.
  1081. */
  1082. Effect.prototype.setArray2 = function (uniformName, array) {
  1083. this._valueCache[uniformName] = null;
  1084. this._engine.setArray2(this.getUniform(uniformName), array);
  1085. return this;
  1086. };
  1087. /**
  1088. * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  1089. * @param uniformName Name of the variable.
  1090. * @param array array to be set.
  1091. * @returns this effect.
  1092. */
  1093. Effect.prototype.setArray3 = function (uniformName, array) {
  1094. this._valueCache[uniformName] = null;
  1095. this._engine.setArray3(this.getUniform(uniformName), array);
  1096. return this;
  1097. };
  1098. /**
  1099. * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  1100. * @param uniformName Name of the variable.
  1101. * @param array array to be set.
  1102. * @returns this effect.
  1103. */
  1104. Effect.prototype.setArray4 = function (uniformName, array) {
  1105. this._valueCache[uniformName] = null;
  1106. this._engine.setArray4(this.getUniform(uniformName), array);
  1107. return this;
  1108. };
  1109. /**
  1110. * Sets matrices on a uniform variable.
  1111. * @param uniformName Name of the variable.
  1112. * @param matrices matrices to be set.
  1113. * @returns this effect.
  1114. */
  1115. Effect.prototype.setMatrices = function (uniformName, matrices) {
  1116. if (!matrices) {
  1117. return this;
  1118. }
  1119. this._valueCache[uniformName] = null;
  1120. this._engine.setMatrices(this.getUniform(uniformName), matrices);
  1121. return this;
  1122. };
  1123. /**
  1124. * Sets matrix on a uniform variable.
  1125. * @param uniformName Name of the variable.
  1126. * @param matrix matrix to be set.
  1127. * @returns this effect.
  1128. */
  1129. Effect.prototype.setMatrix = function (uniformName, matrix) {
  1130. if (this._cacheMatrix(uniformName, matrix)) {
  1131. this._engine.setMatrix(this.getUniform(uniformName), matrix);
  1132. }
  1133. return this;
  1134. };
  1135. /**
  1136. * Sets a 3x3 matrix on a uniform variable. (Speicified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)
  1137. * @param uniformName Name of the variable.
  1138. * @param matrix matrix to be set.
  1139. * @returns this effect.
  1140. */
  1141. Effect.prototype.setMatrix3x3 = function (uniformName, matrix) {
  1142. this._valueCache[uniformName] = null;
  1143. this._engine.setMatrix3x3(this.getUniform(uniformName), matrix);
  1144. return this;
  1145. };
  1146. /**
  1147. * Sets a 2x2 matrix on a uniform variable. (Speicified as [1,2,3,4] will result in [1,2][3,4] matrix)
  1148. * @param uniformName Name of the variable.
  1149. * @param matrix matrix to be set.
  1150. * @returns this effect.
  1151. */
  1152. Effect.prototype.setMatrix2x2 = function (uniformName, matrix) {
  1153. this._valueCache[uniformName] = null;
  1154. this._engine.setMatrix2x2(this.getUniform(uniformName), matrix);
  1155. return this;
  1156. };
  1157. /**
  1158. * Sets a float on a uniform variable.
  1159. * @param uniformName Name of the variable.
  1160. * @param value value to be set.
  1161. * @returns this effect.
  1162. */
  1163. Effect.prototype.setFloat = function (uniformName, value) {
  1164. var cache = this._valueCache[uniformName];
  1165. if (cache !== undefined && cache === value)
  1166. return this;
  1167. this._valueCache[uniformName] = value;
  1168. this._engine.setFloat(this.getUniform(uniformName), value);
  1169. return this;
  1170. };
  1171. /**
  1172. * Sets a boolean on a uniform variable.
  1173. * @param uniformName Name of the variable.
  1174. * @param bool value to be set.
  1175. * @returns this effect.
  1176. */
  1177. Effect.prototype.setBool = function (uniformName, bool) {
  1178. var cache = this._valueCache[uniformName];
  1179. if (cache !== undefined && cache === bool)
  1180. return this;
  1181. this._valueCache[uniformName] = bool;
  1182. this._engine.setBool(this.getUniform(uniformName), bool ? 1 : 0);
  1183. return this;
  1184. };
  1185. /**
  1186. * Sets a Vector2 on a uniform variable.
  1187. * @param uniformName Name of the variable.
  1188. * @param vector2 vector2 to be set.
  1189. * @returns this effect.
  1190. */
  1191. Effect.prototype.setVector2 = function (uniformName, vector2) {
  1192. if (this._cacheFloat2(uniformName, vector2.x, vector2.y)) {
  1193. this._engine.setFloat2(this.getUniform(uniformName), vector2.x, vector2.y);
  1194. }
  1195. return this;
  1196. };
  1197. /**
  1198. * Sets a float2 on a uniform variable.
  1199. * @param uniformName Name of the variable.
  1200. * @param x First float in float2.
  1201. * @param y Second float in float2.
  1202. * @returns this effect.
  1203. */
  1204. Effect.prototype.setFloat2 = function (uniformName, x, y) {
  1205. if (this._cacheFloat2(uniformName, x, y)) {
  1206. this._engine.setFloat2(this.getUniform(uniformName), x, y);
  1207. }
  1208. return this;
  1209. };
  1210. /**
  1211. * Sets a Vector3 on a uniform variable.
  1212. * @param uniformName Name of the variable.
  1213. * @param vector3 Value to be set.
  1214. * @returns this effect.
  1215. */
  1216. Effect.prototype.setVector3 = function (uniformName, vector3) {
  1217. if (this._cacheFloat3(uniformName, vector3.x, vector3.y, vector3.z)) {
  1218. this._engine.setFloat3(this.getUniform(uniformName), vector3.x, vector3.y, vector3.z);
  1219. }
  1220. return this;
  1221. };
  1222. /**
  1223. * Sets a float3 on a uniform variable.
  1224. * @param uniformName Name of the variable.
  1225. * @param x First float in float3.
  1226. * @param y Second float in float3.
  1227. * @param z Third float in float3.
  1228. * @returns this effect.
  1229. */
  1230. Effect.prototype.setFloat3 = function (uniformName, x, y, z) {
  1231. if (this._cacheFloat3(uniformName, x, y, z)) {
  1232. this._engine.setFloat3(this.getUniform(uniformName), x, y, z);
  1233. }
  1234. return this;
  1235. };
  1236. /**
  1237. * Sets a Vector4 on a uniform variable.
  1238. * @param uniformName Name of the variable.
  1239. * @param vector4 Value to be set.
  1240. * @returns this effect.
  1241. */
  1242. Effect.prototype.setVector4 = function (uniformName, vector4) {
  1243. if (this._cacheFloat4(uniformName, vector4.x, vector4.y, vector4.z, vector4.w)) {
  1244. this._engine.setFloat4(this.getUniform(uniformName), vector4.x, vector4.y, vector4.z, vector4.w);
  1245. }
  1246. return this;
  1247. };
  1248. /**
  1249. * Sets a float4 on a uniform variable.
  1250. * @param uniformName Name of the variable.
  1251. * @param x First float in float4.
  1252. * @param y Second float in float4.
  1253. * @param z Third float in float4.
  1254. * @param w Fourth float in float4.
  1255. * @returns this effect.
  1256. */
  1257. Effect.prototype.setFloat4 = function (uniformName, x, y, z, w) {
  1258. if (this._cacheFloat4(uniformName, x, y, z, w)) {
  1259. this._engine.setFloat4(this.getUniform(uniformName), x, y, z, w);
  1260. }
  1261. return this;
  1262. };
  1263. /**
  1264. * Sets a Color3 on a uniform variable.
  1265. * @param uniformName Name of the variable.
  1266. * @param color3 Value to be set.
  1267. * @returns this effect.
  1268. */
  1269. Effect.prototype.setColor3 = function (uniformName, color3) {
  1270. if (this._cacheFloat3(uniformName, color3.r, color3.g, color3.b)) {
  1271. this._engine.setColor3(this.getUniform(uniformName), color3);
  1272. }
  1273. return this;
  1274. };
  1275. /**
  1276. * Sets a Color4 on a uniform variable.
  1277. * @param uniformName Name of the variable.
  1278. * @param color3 Value to be set.
  1279. * @param alpha Alpha value to be set.
  1280. * @returns this effect.
  1281. */
  1282. Effect.prototype.setColor4 = function (uniformName, color3, alpha) {
  1283. if (this._cacheFloat4(uniformName, color3.r, color3.g, color3.b, alpha)) {
  1284. this._engine.setColor4(this.getUniform(uniformName), color3, alpha);
  1285. }
  1286. return this;
  1287. };
  1288. /**
  1289. * Sets a Color4 on a uniform variable
  1290. * @param uniformName defines the name of the variable
  1291. * @param color4 defines the value to be set
  1292. * @returns this effect.
  1293. */
  1294. Effect.prototype.setDirectColor4 = function (uniformName, color4) {
  1295. if (this._cacheFloat4(uniformName, color4.r, color4.g, color4.b, color4.a)) {
  1296. this._engine.setDirectColor4(this.getUniform(uniformName), color4);
  1297. }
  1298. return this;
  1299. };
  1300. /**
  1301. * Resets the cache of effects.
  1302. */
  1303. Effect.ResetCache = function () {
  1304. Effect._baseCache = {};
  1305. };
  1306. Effect._uniqueIdSeed = 0;
  1307. Effect._baseCache = {};
  1308. /**
  1309. * Store of each shader (The can be looked up using effect.key)
  1310. */
  1311. Effect.ShadersStore = {};
  1312. /**
  1313. * Store of each included file for a shader (The can be looked up using effect.key)
  1314. */
  1315. Effect.IncludesShadersStore = {};
  1316. return Effect;
  1317. }());
  1318. BABYLON.Effect = Effect;
  1319. })(BABYLON || (BABYLON = {}));
  1320. //# sourceMappingURL=babylon.effect.js.map
  1321. //# sourceMappingURL=babylon.types.js.map
  1322. var BABYLON;
  1323. (function (BABYLON) {
  1324. var KeyboardEventTypes = /** @class */ (function () {
  1325. function KeyboardEventTypes() {
  1326. }
  1327. Object.defineProperty(KeyboardEventTypes, "KEYDOWN", {
  1328. get: function () {
  1329. return KeyboardEventTypes._KEYDOWN;
  1330. },
  1331. enumerable: true,
  1332. configurable: true
  1333. });
  1334. Object.defineProperty(KeyboardEventTypes, "KEYUP", {
  1335. get: function () {
  1336. return KeyboardEventTypes._KEYUP;
  1337. },
  1338. enumerable: true,
  1339. configurable: true
  1340. });
  1341. KeyboardEventTypes._KEYDOWN = 0x01;
  1342. KeyboardEventTypes._KEYUP = 0x02;
  1343. return KeyboardEventTypes;
  1344. }());
  1345. BABYLON.KeyboardEventTypes = KeyboardEventTypes;
  1346. var KeyboardInfo = /** @class */ (function () {
  1347. function KeyboardInfo(type, event) {
  1348. this.type = type;
  1349. this.event = event;
  1350. }
  1351. return KeyboardInfo;
  1352. }());
  1353. BABYLON.KeyboardInfo = KeyboardInfo;
  1354. /**
  1355. * This class is used to store keyboard related info for the onPreKeyboardObservable event.
  1356. * Set the skipOnKeyboardObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onKeyboardObservable
  1357. */
  1358. var KeyboardInfoPre = /** @class */ (function (_super) {
  1359. __extends(KeyboardInfoPre, _super);
  1360. function KeyboardInfoPre(type, event) {
  1361. var _this = _super.call(this, type, event) || this;
  1362. _this.skipOnPointerObservable = false;
  1363. return _this;
  1364. }
  1365. return KeyboardInfoPre;
  1366. }(KeyboardInfo));
  1367. BABYLON.KeyboardInfoPre = KeyboardInfoPre;
  1368. })(BABYLON || (BABYLON = {}));
  1369. //# sourceMappingURL=babylon.keyboardEvents.js.map
  1370. var BABYLON;
  1371. (function (BABYLON) {
  1372. var PointerEventTypes = /** @class */ (function () {
  1373. function PointerEventTypes() {
  1374. }
  1375. Object.defineProperty(PointerEventTypes, "POINTERDOWN", {
  1376. get: function () {
  1377. return PointerEventTypes._POINTERDOWN;
  1378. },
  1379. enumerable: true,
  1380. configurable: true
  1381. });
  1382. Object.defineProperty(PointerEventTypes, "POINTERUP", {
  1383. get: function () {
  1384. return PointerEventTypes._POINTERUP;
  1385. },
  1386. enumerable: true,
  1387. configurable: true
  1388. });
  1389. Object.defineProperty(PointerEventTypes, "POINTERMOVE", {
  1390. get: function () {
  1391. return PointerEventTypes._POINTERMOVE;
  1392. },
  1393. enumerable: true,
  1394. configurable: true
  1395. });
  1396. Object.defineProperty(PointerEventTypes, "POINTERWHEEL", {
  1397. get: function () {
  1398. return PointerEventTypes._POINTERWHEEL;
  1399. },
  1400. enumerable: true,
  1401. configurable: true
  1402. });
  1403. Object.defineProperty(PointerEventTypes, "POINTERPICK", {
  1404. get: function () {
  1405. return PointerEventTypes._POINTERPICK;
  1406. },
  1407. enumerable: true,
  1408. configurable: true
  1409. });
  1410. Object.defineProperty(PointerEventTypes, "POINTERTAP", {
  1411. get: function () {
  1412. return PointerEventTypes._POINTERTAP;
  1413. },
  1414. enumerable: true,
  1415. configurable: true
  1416. });
  1417. Object.defineProperty(PointerEventTypes, "POINTERDOUBLETAP", {
  1418. get: function () {
  1419. return PointerEventTypes._POINTERDOUBLETAP;
  1420. },
  1421. enumerable: true,
  1422. configurable: true
  1423. });
  1424. PointerEventTypes._POINTERDOWN = 0x01;
  1425. PointerEventTypes._POINTERUP = 0x02;
  1426. PointerEventTypes._POINTERMOVE = 0x04;
  1427. PointerEventTypes._POINTERWHEEL = 0x08;
  1428. PointerEventTypes._POINTERPICK = 0x10;
  1429. PointerEventTypes._POINTERTAP = 0x20;
  1430. PointerEventTypes._POINTERDOUBLETAP = 0x40;
  1431. return PointerEventTypes;
  1432. }());
  1433. BABYLON.PointerEventTypes = PointerEventTypes;
  1434. var PointerInfoBase = /** @class */ (function () {
  1435. function PointerInfoBase(type, event) {
  1436. this.type = type;
  1437. this.event = event;
  1438. }
  1439. return PointerInfoBase;
  1440. }());
  1441. BABYLON.PointerInfoBase = PointerInfoBase;
  1442. /**
  1443. * This class is used to store pointer related info for the onPrePointerObservable event.
  1444. * Set the skipOnPointerObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onPointerObservable
  1445. */
  1446. var PointerInfoPre = /** @class */ (function (_super) {
  1447. __extends(PointerInfoPre, _super);
  1448. function PointerInfoPre(type, event, localX, localY) {
  1449. var _this = _super.call(this, type, event) || this;
  1450. /**
  1451. * Ray from a pointer if availible (eg. 6dof controller)
  1452. */
  1453. _this.ray = null;
  1454. _this.skipOnPointerObservable = false;
  1455. _this.localPosition = new BABYLON.Vector2(localX, localY);
  1456. return _this;
  1457. }
  1458. return PointerInfoPre;
  1459. }(PointerInfoBase));
  1460. BABYLON.PointerInfoPre = PointerInfoPre;
  1461. /**
  1462. * This type contains all the data related to a pointer event in Babylon.js.
  1463. * The event member is an instance of PointerEvent for all types except PointerWheel and is of type MouseWheelEvent when type equals PointerWheel. The different event types can be found in the PointerEventTypes class.
  1464. */
  1465. var PointerInfo = /** @class */ (function (_super) {
  1466. __extends(PointerInfo, _super);
  1467. function PointerInfo(type, event, pickInfo) {
  1468. var _this = _super.call(this, type, event) || this;
  1469. _this.pickInfo = pickInfo;
  1470. return _this;
  1471. }
  1472. return PointerInfo;
  1473. }(PointerInfoBase));
  1474. BABYLON.PointerInfo = PointerInfo;
  1475. })(BABYLON || (BABYLON = {}));
  1476. //# sourceMappingURL=babylon.pointerEvents.js.map
  1477. var BABYLON;
  1478. (function (BABYLON) {
  1479. BABYLON.ToGammaSpace = 1 / 2.2;
  1480. BABYLON.ToLinearSpace = 2.2;
  1481. BABYLON.Epsilon = 0.001;
  1482. /**
  1483. * Class used to hold a RBG color
  1484. */
  1485. var Color3 = /** @class */ (function () {
  1486. /**
  1487. * Creates a new Color3 object from red, green, blue values, all between 0 and 1
  1488. * @param r defines the red component (between 0 and 1, default is 0)
  1489. * @param g defines the green component (between 0 and 1, default is 0)
  1490. * @param b defines the blue component (between 0 and 1, default is 0)
  1491. */
  1492. function Color3(
  1493. /**
  1494. * Defines the red component (between 0 and 1, default is 0)
  1495. */
  1496. r,
  1497. /**
  1498. * Defines the green component (between 0 and 1, default is 0)
  1499. */
  1500. g,
  1501. /**
  1502. * Defines the blue component (between 0 and 1, default is 0)
  1503. */
  1504. b) {
  1505. if (r === void 0) { r = 0; }
  1506. if (g === void 0) { g = 0; }
  1507. if (b === void 0) { b = 0; }
  1508. this.r = r;
  1509. this.g = g;
  1510. this.b = b;
  1511. }
  1512. /**
  1513. * Creates a string with the Color3 current values
  1514. * @returns the string representation of the Color3 object
  1515. */
  1516. Color3.prototype.toString = function () {
  1517. return "{R: " + this.r + " G:" + this.g + " B:" + this.b + "}";
  1518. };
  1519. /**
  1520. * Returns the string "Color3"
  1521. * @returns "Color3"
  1522. */
  1523. Color3.prototype.getClassName = function () {
  1524. return "Color3";
  1525. };
  1526. /**
  1527. * Compute the Color3 hash code
  1528. * @returns an unique number that can be used to hash Color3 objects
  1529. */
  1530. Color3.prototype.getHashCode = function () {
  1531. var hash = this.r || 0;
  1532. hash = (hash * 397) ^ (this.g || 0);
  1533. hash = (hash * 397) ^ (this.b || 0);
  1534. return hash;
  1535. };
  1536. // Operators
  1537. /**
  1538. * Stores in the given array from the given starting index the red, green, blue values as successive elements
  1539. * @param array defines the array where to store the r,g,b components
  1540. * @param index defines an optional index in the target array to define where to start storing values
  1541. * @returns the current Color3 object
  1542. */
  1543. Color3.prototype.toArray = function (array, index) {
  1544. if (index === undefined) {
  1545. index = 0;
  1546. }
  1547. array[index] = this.r;
  1548. array[index + 1] = this.g;
  1549. array[index + 2] = this.b;
  1550. return this;
  1551. };
  1552. /**
  1553. * Returns a new {BABYLON.Color4} object from the current Color3 and the given alpha
  1554. * @param alpha defines the alpha component on the new {BABYLON.Color4} object (default is 1)
  1555. * @returns a new {BABYLON.Color4} object
  1556. */
  1557. Color3.prototype.toColor4 = function (alpha) {
  1558. if (alpha === void 0) { alpha = 1; }
  1559. return new Color4(this.r, this.g, this.b, alpha);
  1560. };
  1561. /**
  1562. * Returns a new array populated with 3 numeric elements : red, green and blue values
  1563. * @returns the new array
  1564. */
  1565. Color3.prototype.asArray = function () {
  1566. var result = new Array();
  1567. this.toArray(result, 0);
  1568. return result;
  1569. };
  1570. /**
  1571. * Returns the luminance value
  1572. * @returns a float value
  1573. */
  1574. Color3.prototype.toLuminance = function () {
  1575. return this.r * 0.3 + this.g * 0.59 + this.b * 0.11;
  1576. };
  1577. /**
  1578. * Multiply each Color3 rgb values by the given Color3 rgb values in a new Color3 object
  1579. * @param otherColor defines the second operand
  1580. * @returns the new Color3 object
  1581. */
  1582. Color3.prototype.multiply = function (otherColor) {
  1583. return new Color3(this.r * otherColor.r, this.g * otherColor.g, this.b * otherColor.b);
  1584. };
  1585. /**
  1586. * Multiply the rgb values of the Color3 and the given Color3 and stores the result in the object "result"
  1587. * @param otherColor defines the second operand
  1588. * @param result defines the Color3 object where to store the result
  1589. * @returns the current Color3
  1590. */
  1591. Color3.prototype.multiplyToRef = function (otherColor, result) {
  1592. result.r = this.r * otherColor.r;
  1593. result.g = this.g * otherColor.g;
  1594. result.b = this.b * otherColor.b;
  1595. return this;
  1596. };
  1597. /**
  1598. * Determines equality between Color3 objects
  1599. * @param otherColor defines the second operand
  1600. * @returns true if the rgb values are equal to the given ones
  1601. */
  1602. Color3.prototype.equals = function (otherColor) {
  1603. return otherColor && this.r === otherColor.r && this.g === otherColor.g && this.b === otherColor.b;
  1604. };
  1605. /**
  1606. * Determines equality between the current Color3 object and a set of r,b,g values
  1607. * @param r defines the red component to check
  1608. * @param g defines the green component to check
  1609. * @param b defines the blue component to check
  1610. * @returns true if the rgb values are equal to the given ones
  1611. */
  1612. Color3.prototype.equalsFloats = function (r, g, b) {
  1613. return this.r === r && this.g === g && this.b === b;
  1614. };
  1615. /**
  1616. * Multiplies in place each rgb value by scale
  1617. * @param scale defines the scaling factor
  1618. * @returns the updated Color3
  1619. */
  1620. Color3.prototype.scale = function (scale) {
  1621. return new Color3(this.r * scale, this.g * scale, this.b * scale);
  1622. };
  1623. /**
  1624. * Multiplies the rgb values by scale and stores the result into "result"
  1625. * @param scale defines the scaling factor
  1626. * @param result defines the Color3 object where to store the result
  1627. * @returns the unmodified current Color3
  1628. */
  1629. Color3.prototype.scaleToRef = function (scale, result) {
  1630. result.r = this.r * scale;
  1631. result.g = this.g * scale;
  1632. result.b = this.b * scale;
  1633. return this;
  1634. };
  1635. /**
  1636. * Scale the current Color3 values by a factor and add the result to a given Color3
  1637. * @param scale defines the scale factor
  1638. * @param result defines color to store the result into
  1639. * @returns the unmodified current Color3
  1640. */
  1641. Color3.prototype.scaleAndAddToRef = function (scale, result) {
  1642. result.r += this.r * scale;
  1643. result.g += this.g * scale;
  1644. result.b += this.b * scale;
  1645. return this;
  1646. };
  1647. /**
  1648. * Clamps the rgb values by the min and max values and stores the result into "result"
  1649. * @param min defines minimum clamping value (default is 0)
  1650. * @param max defines maximum clamping value (default is 1)
  1651. * @param result defines color to store the result into
  1652. * @returns the original Color3
  1653. */
  1654. Color3.prototype.clampToRef = function (min, max, result) {
  1655. if (min === void 0) { min = 0; }
  1656. if (max === void 0) { max = 1; }
  1657. result.r = BABYLON.Scalar.Clamp(this.r, min, max);
  1658. result.g = BABYLON.Scalar.Clamp(this.g, min, max);
  1659. result.b = BABYLON.Scalar.Clamp(this.b, min, max);
  1660. return this;
  1661. };
  1662. /**
  1663. * Creates a new Color3 set with the added values of the current Color3 and of the given one
  1664. * @param otherColor defines the second operand
  1665. * @returns the new Color3
  1666. */
  1667. Color3.prototype.add = function (otherColor) {
  1668. return new Color3(this.r + otherColor.r, this.g + otherColor.g, this.b + otherColor.b);
  1669. };
  1670. /**
  1671. * Stores the result of the addition of the current Color3 and given one rgb values into "result"
  1672. * @param otherColor defines the second operand
  1673. * @param result defines Color3 object to store the result into
  1674. * @returns the unmodified current Color3
  1675. */
  1676. Color3.prototype.addToRef = function (otherColor, result) {
  1677. result.r = this.r + otherColor.r;
  1678. result.g = this.g + otherColor.g;
  1679. result.b = this.b + otherColor.b;
  1680. return this;
  1681. };
  1682. /**
  1683. * Returns a new Color3 set with the subtracted values of the given one from the current Color3
  1684. * @param otherColor defines the second operand
  1685. * @returns the new Color3
  1686. */
  1687. Color3.prototype.subtract = function (otherColor) {
  1688. return new Color3(this.r - otherColor.r, this.g - otherColor.g, this.b - otherColor.b);
  1689. };
  1690. /**
  1691. * Stores the result of the subtraction of given one from the current Color3 rgb values into "result"
  1692. * @param otherColor defines the second operand
  1693. * @param result defines Color3 object to store the result into
  1694. * @returns the unmodified current Color3
  1695. */
  1696. Color3.prototype.subtractToRef = function (otherColor, result) {
  1697. result.r = this.r - otherColor.r;
  1698. result.g = this.g - otherColor.g;
  1699. result.b = this.b - otherColor.b;
  1700. return this;
  1701. };
  1702. /**
  1703. * Copy the current object
  1704. * @returns a new Color3 copied the current one
  1705. */
  1706. Color3.prototype.clone = function () {
  1707. return new Color3(this.r, this.g, this.b);
  1708. };
  1709. /**
  1710. * Copies the rgb values from the source in the current Color3
  1711. * @param source defines the source Color3 object
  1712. * @returns the updated Color3 object
  1713. */
  1714. Color3.prototype.copyFrom = function (source) {
  1715. this.r = source.r;
  1716. this.g = source.g;
  1717. this.b = source.b;
  1718. return this;
  1719. };
  1720. /**
  1721. * Updates the Color3 rgb values from the given floats
  1722. * @param r defines the red component to read from
  1723. * @param g defines the green component to read from
  1724. * @param b defines the blue component to read from
  1725. * @returns the current Color3 object
  1726. */
  1727. Color3.prototype.copyFromFloats = function (r, g, b) {
  1728. this.r = r;
  1729. this.g = g;
  1730. this.b = b;
  1731. return this;
  1732. };
  1733. /**
  1734. * Updates the Color3 rgb values from the given floats
  1735. * @param r defines the red component to read from
  1736. * @param g defines the green component to read from
  1737. * @param b defines the blue component to read from
  1738. * @returns the current Color3 object
  1739. */
  1740. Color3.prototype.set = function (r, g, b) {
  1741. return this.copyFromFloats(r, g, b);
  1742. };
  1743. /**
  1744. * Compute the Color3 hexadecimal code as a string
  1745. * @returns a string containing the hexadecimal representation of the Color3 object
  1746. */
  1747. Color3.prototype.toHexString = function () {
  1748. var intR = (this.r * 255) | 0;
  1749. var intG = (this.g * 255) | 0;
  1750. var intB = (this.b * 255) | 0;
  1751. return "#" + BABYLON.Scalar.ToHex(intR) + BABYLON.Scalar.ToHex(intG) + BABYLON.Scalar.ToHex(intB);
  1752. };
  1753. /**
  1754. * Computes a new Color3 converted from the current one to linear space
  1755. * @returns a new Color3 object
  1756. */
  1757. Color3.prototype.toLinearSpace = function () {
  1758. var convertedColor = new Color3();
  1759. this.toLinearSpaceToRef(convertedColor);
  1760. return convertedColor;
  1761. };
  1762. /**
  1763. * Converts the Color3 values to linear space and stores the result in "convertedColor"
  1764. * @param convertedColor defines the Color3 object where to store the linear space version
  1765. * @returns the unmodified Color3
  1766. */
  1767. Color3.prototype.toLinearSpaceToRef = function (convertedColor) {
  1768. convertedColor.r = Math.pow(this.r, BABYLON.ToLinearSpace);
  1769. convertedColor.g = Math.pow(this.g, BABYLON.ToLinearSpace);
  1770. convertedColor.b = Math.pow(this.b, BABYLON.ToLinearSpace);
  1771. return this;
  1772. };
  1773. /**
  1774. * Computes a new Color3 converted from the current one to gamma space
  1775. * @returns a new Color3 object
  1776. */
  1777. Color3.prototype.toGammaSpace = function () {
  1778. var convertedColor = new Color3();
  1779. this.toGammaSpaceToRef(convertedColor);
  1780. return convertedColor;
  1781. };
  1782. /**
  1783. * Converts the Color3 values to gamma space and stores the result in "convertedColor"
  1784. * @param convertedColor defines the Color3 object where to store the gamma space version
  1785. * @returns the unmodified Color3
  1786. */
  1787. Color3.prototype.toGammaSpaceToRef = function (convertedColor) {
  1788. convertedColor.r = Math.pow(this.r, BABYLON.ToGammaSpace);
  1789. convertedColor.g = Math.pow(this.g, BABYLON.ToGammaSpace);
  1790. convertedColor.b = Math.pow(this.b, BABYLON.ToGammaSpace);
  1791. return this;
  1792. };
  1793. // Statics
  1794. /**
  1795. * Creates a new Color3 from the string containing valid hexadecimal values
  1796. * @param hex defines a string containing valid hexadecimal values
  1797. * @returns a new Color3 object
  1798. */
  1799. Color3.FromHexString = function (hex) {
  1800. if (hex.substring(0, 1) !== "#" || hex.length !== 7) {
  1801. return new Color3(0, 0, 0);
  1802. }
  1803. var r = parseInt(hex.substring(1, 3), 16);
  1804. var g = parseInt(hex.substring(3, 5), 16);
  1805. var b = parseInt(hex.substring(5, 7), 16);
  1806. return Color3.FromInts(r, g, b);
  1807. };
  1808. /**
  1809. * Creates a new Vector3 from the starting index of the given array
  1810. * @param array defines the source array
  1811. * @param offset defines an offset in the source array
  1812. * @returns a new Color3 object
  1813. */
  1814. Color3.FromArray = function (array, offset) {
  1815. if (offset === void 0) { offset = 0; }
  1816. return new Color3(array[offset], array[offset + 1], array[offset + 2]);
  1817. };
  1818. /**
  1819. * Creates a new Color3 from integer values (< 256)
  1820. * @param r defines the red component to read from (value between 0 and 255)
  1821. * @param g defines the green component to read from (value between 0 and 255)
  1822. * @param b defines the blue component to read from (value between 0 and 255)
  1823. * @returns a new Color3 object
  1824. */
  1825. Color3.FromInts = function (r, g, b) {
  1826. return new Color3(r / 255.0, g / 255.0, b / 255.0);
  1827. };
  1828. /**
  1829. * Creates a new Color3 with values linearly interpolated of "amount" between the start Color3 and the end Color3
  1830. * @param start defines the start Color3 value
  1831. * @param end defines the end Color3 value
  1832. * @param amount defines the gradient value between start and end
  1833. * @returns a new Color3 object
  1834. */
  1835. Color3.Lerp = function (start, end, amount) {
  1836. var r = start.r + ((end.r - start.r) * amount);
  1837. var g = start.g + ((end.g - start.g) * amount);
  1838. var b = start.b + ((end.b - start.b) * amount);
  1839. return new Color3(r, g, b);
  1840. };
  1841. /**
  1842. * Returns a Color3 value containing a red color
  1843. * @returns a new Color3 object
  1844. */
  1845. Color3.Red = function () { return new Color3(1, 0, 0); };
  1846. /**
  1847. * Returns a Color3 value containing a green color
  1848. * @returns a new Color3 object
  1849. */
  1850. Color3.Green = function () { return new Color3(0, 1, 0); };
  1851. /**
  1852. * Returns a Color3 value containing a blue color
  1853. * @returns a new Color3 object
  1854. */
  1855. Color3.Blue = function () { return new Color3(0, 0, 1); };
  1856. /**
  1857. * Returns a Color3 value containing a black color
  1858. * @returns a new Color3 object
  1859. */
  1860. Color3.Black = function () { return new Color3(0, 0, 0); };
  1861. /**
  1862. * Returns a Color3 value containing a white color
  1863. * @returns a new Color3 object
  1864. */
  1865. Color3.White = function () { return new Color3(1, 1, 1); };
  1866. /**
  1867. * Returns a Color3 value containing a purple color
  1868. * @returns a new Color3 object
  1869. */
  1870. Color3.Purple = function () { return new Color3(0.5, 0, 0.5); };
  1871. /**
  1872. * Returns a Color3 value containing a magenta color
  1873. * @returns a new Color3 object
  1874. */
  1875. Color3.Magenta = function () { return new Color3(1, 0, 1); };
  1876. /**
  1877. * Returns a Color3 value containing a yellow color
  1878. * @returns a new Color3 object
  1879. */
  1880. Color3.Yellow = function () { return new Color3(1, 1, 0); };
  1881. /**
  1882. * Returns a Color3 value containing a gray color
  1883. * @returns a new Color3 object
  1884. */
  1885. Color3.Gray = function () { return new Color3(0.5, 0.5, 0.5); };
  1886. /**
  1887. * Returns a Color3 value containing a teal color
  1888. * @returns a new Color3 object
  1889. */
  1890. Color3.Teal = function () { return new Color3(0, 1.0, 1.0); };
  1891. /**
  1892. * Returns a Color3 value containing a random color
  1893. * @returns a new Color3 object
  1894. */
  1895. Color3.Random = function () { return new Color3(Math.random(), Math.random(), Math.random()); };
  1896. return Color3;
  1897. }());
  1898. BABYLON.Color3 = Color3;
  1899. /**
  1900. * Class used to hold a RBGA color
  1901. */
  1902. var Color4 = /** @class */ (function () {
  1903. /**
  1904. * Creates a new Color4 object from red, green, blue values, all between 0 and 1
  1905. * @param r defines the red component (between 0 and 1, default is 0)
  1906. * @param g defines the green component (between 0 and 1, default is 0)
  1907. * @param b defines the blue component (between 0 and 1, default is 0)
  1908. * @param a defines the alpha component (between 0 and 1, default is 1)
  1909. */
  1910. function Color4(
  1911. /**
  1912. * Defines the red component (between 0 and 1, default is 0)
  1913. */
  1914. r,
  1915. /**
  1916. * Defines the green component (between 0 and 1, default is 0)
  1917. */
  1918. g,
  1919. /**
  1920. * Defines the blue component (between 0 and 1, default is 0)
  1921. */
  1922. b,
  1923. /**
  1924. * Defines the alpha component (between 0 and 1, default is 1)
  1925. */
  1926. a) {
  1927. if (r === void 0) { r = 0; }
  1928. if (g === void 0) { g = 0; }
  1929. if (b === void 0) { b = 0; }
  1930. if (a === void 0) { a = 1; }
  1931. this.r = r;
  1932. this.g = g;
  1933. this.b = b;
  1934. this.a = a;
  1935. }
  1936. // Operators
  1937. /**
  1938. * Adds in place the given Color4 values to the current Color4 object
  1939. * @param right defines the second operand
  1940. * @returns the current updated Color4 object
  1941. */
  1942. Color4.prototype.addInPlace = function (right) {
  1943. this.r += right.r;
  1944. this.g += right.g;
  1945. this.b += right.b;
  1946. this.a += right.a;
  1947. return this;
  1948. };
  1949. /**
  1950. * Creates a new array populated with 4 numeric elements : red, green, blue, alpha values
  1951. * @returns the new array
  1952. */
  1953. Color4.prototype.asArray = function () {
  1954. var result = new Array();
  1955. this.toArray(result, 0);
  1956. return result;
  1957. };
  1958. /**
  1959. * Stores from the starting index in the given array the Color4 successive values
  1960. * @param array defines the array where to store the r,g,b components
  1961. * @param index defines an optional index in the target array to define where to start storing values
  1962. * @returns the current Color4 object
  1963. */
  1964. Color4.prototype.toArray = function (array, index) {
  1965. if (index === undefined) {
  1966. index = 0;
  1967. }
  1968. array[index] = this.r;
  1969. array[index + 1] = this.g;
  1970. array[index + 2] = this.b;
  1971. array[index + 3] = this.a;
  1972. return this;
  1973. };
  1974. /**
  1975. * Creates a new Color4 set with the added values of the current Color4 and of the given one
  1976. * @param right defines the second operand
  1977. * @returns a new Color4 object
  1978. */
  1979. Color4.prototype.add = function (right) {
  1980. return new Color4(this.r + right.r, this.g + right.g, this.b + right.b, this.a + right.a);
  1981. };
  1982. /**
  1983. * Creates a new Color4 set with the subtracted values of the given one from the current Color4
  1984. * @param right defines the second operand
  1985. * @returns a new Color4 object
  1986. */
  1987. Color4.prototype.subtract = function (right) {
  1988. return new Color4(this.r - right.r, this.g - right.g, this.b - right.b, this.a - right.a);
  1989. };
  1990. /**
  1991. * Subtracts the given ones from the current Color4 values and stores the results in "result"
  1992. * @param right defines the second operand
  1993. * @param result defines the Color4 object where to store the result
  1994. * @returns the current Color4 object
  1995. */
  1996. Color4.prototype.subtractToRef = function (right, result) {
  1997. result.r = this.r - right.r;
  1998. result.g = this.g - right.g;
  1999. result.b = this.b - right.b;
  2000. result.a = this.a - right.a;
  2001. return this;
  2002. };
  2003. /**
  2004. * Creates a new Color4 with the current Color4 values multiplied by scale
  2005. * @param scale defines the scaling factor to apply
  2006. * @returns a new Color4 object
  2007. */
  2008. Color4.prototype.scale = function (scale) {
  2009. return new Color4(this.r * scale, this.g * scale, this.b * scale, this.a * scale);
  2010. };
  2011. /**
  2012. * Multiplies the current Color4 values by scale and stores the result in "result"
  2013. * @param scale defines the scaling factor to apply
  2014. * @param result defines the Color4 object where to store the result
  2015. * @returns the current unmodified Color4
  2016. */
  2017. Color4.prototype.scaleToRef = function (scale, result) {
  2018. result.r = this.r * scale;
  2019. result.g = this.g * scale;
  2020. result.b = this.b * scale;
  2021. result.a = this.a * scale;
  2022. return this;
  2023. };
  2024. /**
  2025. * Scale the current Color4 values by a factor and add the result to a given Color4
  2026. * @param scale defines the scale factor
  2027. * @param result defines the Color4 object where to store the result
  2028. * @returns the unmodified current Color4
  2029. */
  2030. Color4.prototype.scaleAndAddToRef = function (scale, result) {
  2031. result.r += this.r * scale;
  2032. result.g += this.g * scale;
  2033. result.b += this.b * scale;
  2034. result.a += this.a * scale;
  2035. return this;
  2036. };
  2037. /**
  2038. * Clamps the rgb values by the min and max values and stores the result into "result"
  2039. * @param min defines minimum clamping value (default is 0)
  2040. * @param max defines maximum clamping value (default is 1)
  2041. * @param result defines color to store the result into.
  2042. * @returns the cuurent Color4
  2043. */
  2044. Color4.prototype.clampToRef = function (min, max, result) {
  2045. if (min === void 0) { min = 0; }
  2046. if (max === void 0) { max = 1; }
  2047. result.r = BABYLON.Scalar.Clamp(this.r, min, max);
  2048. result.g = BABYLON.Scalar.Clamp(this.g, min, max);
  2049. result.b = BABYLON.Scalar.Clamp(this.b, min, max);
  2050. result.a = BABYLON.Scalar.Clamp(this.a, min, max);
  2051. return this;
  2052. };
  2053. /**
  2054. * Multipy an Color4 value by another and return a new Color4 object
  2055. * @param color defines the Color4 value to multiply by
  2056. * @returns a new Color4 object
  2057. */
  2058. Color4.prototype.multiply = function (color) {
  2059. return new Color4(this.r * color.r, this.g * color.g, this.b * color.b, this.a * color.a);
  2060. };
  2061. /**
  2062. * Multipy a Color4 value by another and push the result in a reference value
  2063. * @param color defines the Color4 value to multiply by
  2064. * @param result defines the Color4 to fill the result in
  2065. * @returns the result Color4
  2066. */
  2067. Color4.prototype.multiplyToRef = function (color, result) {
  2068. result.r = this.r * color.r;
  2069. result.g = this.g * color.g;
  2070. result.b = this.b * color.b;
  2071. result.a = this.a * color.a;
  2072. return result;
  2073. };
  2074. /**
  2075. * Creates a string with the Color4 current values
  2076. * @returns the string representation of the Color4 object
  2077. */
  2078. Color4.prototype.toString = function () {
  2079. return "{R: " + this.r + " G:" + this.g + " B:" + this.b + " A:" + this.a + "}";
  2080. };
  2081. /**
  2082. * Returns the string "Color4"
  2083. * @returns "Color4"
  2084. */
  2085. Color4.prototype.getClassName = function () {
  2086. return "Color4";
  2087. };
  2088. /**
  2089. * Compute the Color4 hash code
  2090. * @returns an unique number that can be used to hash Color4 objects
  2091. */
  2092. Color4.prototype.getHashCode = function () {
  2093. var hash = this.r || 0;
  2094. hash = (hash * 397) ^ (this.g || 0);
  2095. hash = (hash * 397) ^ (this.b || 0);
  2096. hash = (hash * 397) ^ (this.a || 0);
  2097. return hash;
  2098. };
  2099. /**
  2100. * Creates a new Color4 copied from the current one
  2101. * @returns a new Color4 object
  2102. */
  2103. Color4.prototype.clone = function () {
  2104. return new Color4(this.r, this.g, this.b, this.a);
  2105. };
  2106. /**
  2107. * Copies the given Color4 values into the current one
  2108. * @param source defines the source Color4 object
  2109. * @returns the current updated Color4 object
  2110. */
  2111. Color4.prototype.copyFrom = function (source) {
  2112. this.r = source.r;
  2113. this.g = source.g;
  2114. this.b = source.b;
  2115. this.a = source.a;
  2116. return this;
  2117. };
  2118. /**
  2119. * Copies the given float values into the current one
  2120. * @param r defines the red component to read from
  2121. * @param g defines the green component to read from
  2122. * @param b defines the blue component to read from
  2123. * @param a defines the alpha component to read from
  2124. * @returns the current updated Color4 object
  2125. */
  2126. Color4.prototype.copyFromFloats = function (r, g, b, a) {
  2127. this.r = r;
  2128. this.g = g;
  2129. this.b = b;
  2130. this.a = a;
  2131. return this;
  2132. };
  2133. /**
  2134. * Copies the given float values into the current one
  2135. * @param r defines the red component to read from
  2136. * @param g defines the green component to read from
  2137. * @param b defines the blue component to read from
  2138. * @param a defines the alpha component to read from
  2139. * @returns the current updated Color4 object
  2140. */
  2141. Color4.prototype.set = function (r, g, b, a) {
  2142. return this.copyFromFloats(r, g, b, a);
  2143. };
  2144. /**
  2145. * Compute the Color4 hexadecimal code as a string
  2146. * @returns a string containing the hexadecimal representation of the Color4 object
  2147. */
  2148. Color4.prototype.toHexString = function () {
  2149. var intR = (this.r * 255) | 0;
  2150. var intG = (this.g * 255) | 0;
  2151. var intB = (this.b * 255) | 0;
  2152. var intA = (this.a * 255) | 0;
  2153. return "#" + BABYLON.Scalar.ToHex(intR) + BABYLON.Scalar.ToHex(intG) + BABYLON.Scalar.ToHex(intB) + BABYLON.Scalar.ToHex(intA);
  2154. };
  2155. /**
  2156. * Computes a new Color4 converted from the current one to linear space
  2157. * @returns a new Color4 object
  2158. */
  2159. Color4.prototype.toLinearSpace = function () {
  2160. var convertedColor = new Color4();
  2161. this.toLinearSpaceToRef(convertedColor);
  2162. return convertedColor;
  2163. };
  2164. /**
  2165. * Converts the Color4 values to linear space and stores the result in "convertedColor"
  2166. * @param convertedColor defines the Color4 object where to store the linear space version
  2167. * @returns the unmodified Color4
  2168. */
  2169. Color4.prototype.toLinearSpaceToRef = function (convertedColor) {
  2170. convertedColor.r = Math.pow(this.r, BABYLON.ToLinearSpace);
  2171. convertedColor.g = Math.pow(this.g, BABYLON.ToLinearSpace);
  2172. convertedColor.b = Math.pow(this.b, BABYLON.ToLinearSpace);
  2173. convertedColor.a = this.a;
  2174. return this;
  2175. };
  2176. /**
  2177. * Computes a new Color4 converted from the current one to gamma space
  2178. * @returns a new Color4 object
  2179. */
  2180. Color4.prototype.toGammaSpace = function () {
  2181. var convertedColor = new Color4();
  2182. this.toGammaSpaceToRef(convertedColor);
  2183. return convertedColor;
  2184. };
  2185. /**
  2186. * Converts the Color4 values to gamma space and stores the result in "convertedColor"
  2187. * @param convertedColor defines the Color4 object where to store the gamma space version
  2188. * @returns the unmodified Color4
  2189. */
  2190. Color4.prototype.toGammaSpaceToRef = function (convertedColor) {
  2191. convertedColor.r = Math.pow(this.r, BABYLON.ToGammaSpace);
  2192. convertedColor.g = Math.pow(this.g, BABYLON.ToGammaSpace);
  2193. convertedColor.b = Math.pow(this.b, BABYLON.ToGammaSpace);
  2194. convertedColor.a = this.a;
  2195. return this;
  2196. };
  2197. // Statics
  2198. /**
  2199. * Creates a new Color4 from the string containing valid hexadecimal values
  2200. * @param hex defines a string containing valid hexadecimal values
  2201. * @returns a new Color4 object
  2202. */
  2203. Color4.FromHexString = function (hex) {
  2204. if (hex.substring(0, 1) !== "#" || hex.length !== 9) {
  2205. return new Color4(0.0, 0.0, 0.0, 0.0);
  2206. }
  2207. var r = parseInt(hex.substring(1, 3), 16);
  2208. var g = parseInt(hex.substring(3, 5), 16);
  2209. var b = parseInt(hex.substring(5, 7), 16);
  2210. var a = parseInt(hex.substring(7, 9), 16);
  2211. return Color4.FromInts(r, g, b, a);
  2212. };
  2213. /**
  2214. * Creates a new Color4 object set with the linearly interpolated values of "amount" between the left Color4 object and the right Color4 object
  2215. * @param left defines the start value
  2216. * @param right defines the end value
  2217. * @param amount defines the gradient factor
  2218. * @returns a new Color4 object
  2219. */
  2220. Color4.Lerp = function (left, right, amount) {
  2221. var result = new Color4(0.0, 0.0, 0.0, 0.0);
  2222. Color4.LerpToRef(left, right, amount, result);
  2223. return result;
  2224. };
  2225. /**
  2226. * Set the given "result" with the linearly interpolated values of "amount" between the left Color4 object and the right Color4 object
  2227. * @param left defines the start value
  2228. * @param right defines the end value
  2229. * @param amount defines the gradient factor
  2230. * @param result defines the Color4 object where to store data
  2231. */
  2232. Color4.LerpToRef = function (left, right, amount, result) {
  2233. result.r = left.r + (right.r - left.r) * amount;
  2234. result.g = left.g + (right.g - left.g) * amount;
  2235. result.b = left.b + (right.b - left.b) * amount;
  2236. result.a = left.a + (right.a - left.a) * amount;
  2237. };
  2238. /**
  2239. * Creates a new Color4 from the starting index element of the given array
  2240. * @param array defines the source array to read from
  2241. * @param offset defines the offset in the source array
  2242. * @returns a new Color4 object
  2243. */
  2244. Color4.FromArray = function (array, offset) {
  2245. if (offset === void 0) { offset = 0; }
  2246. return new Color4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);
  2247. };
  2248. /**
  2249. * Creates a new Color3 from integer values (< 256)
  2250. * @param r defines the red component to read from (value between 0 and 255)
  2251. * @param g defines the green component to read from (value between 0 and 255)
  2252. * @param b defines the blue component to read from (value between 0 and 255)
  2253. * @param a defines the alpha component to read from (value between 0 and 255)
  2254. * @returns a new Color3 object
  2255. */
  2256. Color4.FromInts = function (r, g, b, a) {
  2257. return new Color4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
  2258. };
  2259. /**
  2260. * Check the content of a given array and convert it to an array containing RGBA data
  2261. * If the original array was already containing count * 4 values then it is returned directly
  2262. * @param colors defines the array to check
  2263. * @param count defines the number of RGBA data to expect
  2264. * @returns an array containing count * 4 values (RGBA)
  2265. */
  2266. Color4.CheckColors4 = function (colors, count) {
  2267. // Check if color3 was used
  2268. if (colors.length === count * 3) {
  2269. var colors4 = [];
  2270. for (var index = 0; index < colors.length; index += 3) {
  2271. var newIndex = (index / 3) * 4;
  2272. colors4[newIndex] = colors[index];
  2273. colors4[newIndex + 1] = colors[index + 1];
  2274. colors4[newIndex + 2] = colors[index + 2];
  2275. colors4[newIndex + 3] = 1.0;
  2276. }
  2277. return colors4;
  2278. }
  2279. return colors;
  2280. };
  2281. return Color4;
  2282. }());
  2283. BABYLON.Color4 = Color4;
  2284. /**
  2285. * Class representing a vector containing 2 coordinates
  2286. */
  2287. var Vector2 = /** @class */ (function () {
  2288. /**
  2289. * Creates a new Vector2 from the given x and y coordinates
  2290. * @param x defines the first coordinate
  2291. * @param y defines the second coordinate
  2292. */
  2293. function Vector2(
  2294. /** defines the first coordinate */
  2295. x,
  2296. /** defines the second coordinate */
  2297. y) {
  2298. this.x = x;
  2299. this.y = y;
  2300. }
  2301. /**
  2302. * Gets a string with the Vector2 coordinates
  2303. * @returns a string with the Vector2 coordinates
  2304. */
  2305. Vector2.prototype.toString = function () {
  2306. return "{X: " + this.x + " Y:" + this.y + "}";
  2307. };
  2308. /**
  2309. * Gets class name
  2310. * @returns the string "Vector2"
  2311. */
  2312. Vector2.prototype.getClassName = function () {
  2313. return "Vector2";
  2314. };
  2315. /**
  2316. * Gets current vector hash code
  2317. * @returns the Vector2 hash code as a number
  2318. */
  2319. Vector2.prototype.getHashCode = function () {
  2320. var hash = this.x || 0;
  2321. hash = (hash * 397) ^ (this.y || 0);
  2322. return hash;
  2323. };
  2324. // Operators
  2325. /**
  2326. * Sets the Vector2 coordinates in the given array or Float32Array from the given index.
  2327. * @param array defines the source array
  2328. * @param index defines the offset in source array
  2329. * @returns the current Vector2
  2330. */
  2331. Vector2.prototype.toArray = function (array, index) {
  2332. if (index === void 0) { index = 0; }
  2333. array[index] = this.x;
  2334. array[index + 1] = this.y;
  2335. return this;
  2336. };
  2337. /**
  2338. * Copy the current vector to an array
  2339. * @returns a new array with 2 elements: the Vector2 coordinates.
  2340. */
  2341. Vector2.prototype.asArray = function () {
  2342. var result = new Array();
  2343. this.toArray(result, 0);
  2344. return result;
  2345. };
  2346. /**
  2347. * Sets the Vector2 coordinates with the given Vector2 coordinates
  2348. * @param source defines the source Vector2
  2349. * @returns the current updated Vector2
  2350. */
  2351. Vector2.prototype.copyFrom = function (source) {
  2352. this.x = source.x;
  2353. this.y = source.y;
  2354. return this;
  2355. };
  2356. /**
  2357. * Sets the Vector2 coordinates with the given floats
  2358. * @param x defines the first coordinate
  2359. * @param y defines the second coordinate
  2360. * @returns the current updated Vector2
  2361. */
  2362. Vector2.prototype.copyFromFloats = function (x, y) {
  2363. this.x = x;
  2364. this.y = y;
  2365. return this;
  2366. };
  2367. /**
  2368. * Sets the Vector2 coordinates with the given floats
  2369. * @param x defines the first coordinate
  2370. * @param y defines the second coordinate
  2371. * @returns the current updated Vector2
  2372. */
  2373. Vector2.prototype.set = function (x, y) {
  2374. return this.copyFromFloats(x, y);
  2375. };
  2376. /**
  2377. * Add another vector with the current one
  2378. * @param otherVector defines the other vector
  2379. * @returns a new Vector2 set with the addition of the current Vector2 and the given one coordinates
  2380. */
  2381. Vector2.prototype.add = function (otherVector) {
  2382. return new Vector2(this.x + otherVector.x, this.y + otherVector.y);
  2383. };
  2384. /**
  2385. * Sets the "result" coordinates with the addition of the current Vector2 and the given one coordinates
  2386. * @param otherVector defines the other vector
  2387. * @param result defines the target vector
  2388. * @returns the unmodified current Vector2
  2389. */
  2390. Vector2.prototype.addToRef = function (otherVector, result) {
  2391. result.x = this.x + otherVector.x;
  2392. result.y = this.y + otherVector.y;
  2393. return this;
  2394. };
  2395. /**
  2396. * Set the Vector2 coordinates by adding the given Vector2 coordinates
  2397. * @param otherVector defines the other vector
  2398. * @returns the current updated Vector2
  2399. */
  2400. Vector2.prototype.addInPlace = function (otherVector) {
  2401. this.x += otherVector.x;
  2402. this.y += otherVector.y;
  2403. return this;
  2404. };
  2405. /**
  2406. * Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates
  2407. * @param otherVector defines the other vector
  2408. * @returns a new Vector2
  2409. */
  2410. Vector2.prototype.addVector3 = function (otherVector) {
  2411. return new Vector2(this.x + otherVector.x, this.y + otherVector.y);
  2412. };
  2413. /**
  2414. * Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2
  2415. * @param otherVector defines the other vector
  2416. * @returns a new Vector2
  2417. */
  2418. Vector2.prototype.subtract = function (otherVector) {
  2419. return new Vector2(this.x - otherVector.x, this.y - otherVector.y);
  2420. };
  2421. /**
  2422. * Sets the "result" coordinates with the subtraction of the given one from the current Vector2 coordinates.
  2423. * @param otherVector defines the other vector
  2424. * @param result defines the target vector
  2425. * @returns the unmodified current Vector2
  2426. */
  2427. Vector2.prototype.subtractToRef = function (otherVector, result) {
  2428. result.x = this.x - otherVector.x;
  2429. result.y = this.y - otherVector.y;
  2430. return this;
  2431. };
  2432. /**
  2433. * Sets the current Vector2 coordinates by subtracting from it the given one coordinates
  2434. * @param otherVector defines the other vector
  2435. * @returns the current updated Vector2
  2436. */
  2437. Vector2.prototype.subtractInPlace = function (otherVector) {
  2438. this.x -= otherVector.x;
  2439. this.y -= otherVector.y;
  2440. return this;
  2441. };
  2442. /**
  2443. * Multiplies in place the current Vector2 coordinates by the given ones
  2444. * @param otherVector defines the other vector
  2445. * @returns the current updated Vector2
  2446. */
  2447. Vector2.prototype.multiplyInPlace = function (otherVector) {
  2448. this.x *= otherVector.x;
  2449. this.y *= otherVector.y;
  2450. return this;
  2451. };
  2452. /**
  2453. * Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates
  2454. * @param otherVector defines the other vector
  2455. * @returns a new Vector2
  2456. */
  2457. Vector2.prototype.multiply = function (otherVector) {
  2458. return new Vector2(this.x * otherVector.x, this.y * otherVector.y);
  2459. };
  2460. /**
  2461. * Sets "result" coordinates with the multiplication of the current Vector2 and the given one coordinates
  2462. * @param otherVector defines the other vector
  2463. * @param result defines the target vector
  2464. * @returns the unmodified current Vector2
  2465. */
  2466. Vector2.prototype.multiplyToRef = function (otherVector, result) {
  2467. result.x = this.x * otherVector.x;
  2468. result.y = this.y * otherVector.y;
  2469. return this;
  2470. };
  2471. /**
  2472. * Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats
  2473. * @param x defines the first coordinate
  2474. * @param y defines the second coordinate
  2475. * @returns a new Vector2
  2476. */
  2477. Vector2.prototype.multiplyByFloats = function (x, y) {
  2478. return new Vector2(this.x * x, this.y * y);
  2479. };
  2480. /**
  2481. * Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates
  2482. * @param otherVector defines the other vector
  2483. * @returns a new Vector2
  2484. */
  2485. Vector2.prototype.divide = function (otherVector) {
  2486. return new Vector2(this.x / otherVector.x, this.y / otherVector.y);
  2487. };
  2488. /**
  2489. * Sets the "result" coordinates with the Vector2 divided by the given one coordinates
  2490. * @param otherVector defines the other vector
  2491. * @param result defines the target vector
  2492. * @returns the unmodified current Vector2
  2493. */
  2494. Vector2.prototype.divideToRef = function (otherVector, result) {
  2495. result.x = this.x / otherVector.x;
  2496. result.y = this.y / otherVector.y;
  2497. return this;
  2498. };
  2499. /**
  2500. * Divides the current Vector3 coordinates by the given ones
  2501. * @param otherVector defines the other vector
  2502. * @returns the current updated Vector2
  2503. */
  2504. Vector2.prototype.divideInPlace = function (otherVector) {
  2505. return this.divideToRef(otherVector, this);
  2506. };
  2507. /**
  2508. * Gets a new Vector2 with current Vector2 negated coordinates
  2509. * @returns a new Vector2
  2510. */
  2511. Vector2.prototype.negate = function () {
  2512. return new Vector2(-this.x, -this.y);
  2513. };
  2514. /**
  2515. * Multiply the Vector2 coordinates by scale
  2516. * @param scale defines the scaling factor
  2517. * @returns the current updated Vector2
  2518. */
  2519. Vector2.prototype.scaleInPlace = function (scale) {
  2520. this.x *= scale;
  2521. this.y *= scale;
  2522. return this;
  2523. };
  2524. /**
  2525. * Returns a new Vector2 scaled by "scale" from the current Vector2
  2526. * @param scale defines the scaling factor
  2527. * @returns a new Vector2
  2528. */
  2529. Vector2.prototype.scale = function (scale) {
  2530. var result = new Vector2(0, 0);
  2531. this.scaleToRef(scale, result);
  2532. return result;
  2533. };
  2534. /**
  2535. * Scale the current Vector2 values by a factor to a given Vector2
  2536. * @param scale defines the scale factor
  2537. * @param result defines the Vector2 object where to store the result
  2538. * @returns the unmodified current Vector2
  2539. */
  2540. Vector2.prototype.scaleToRef = function (scale, result) {
  2541. result.x = this.x * scale;
  2542. result.y = this.y * scale;
  2543. return this;
  2544. };
  2545. /**
  2546. * Scale the current Vector2 values by a factor and add the result to a given Vector2
  2547. * @param scale defines the scale factor
  2548. * @param result defines the Vector2 object where to store the result
  2549. * @returns the unmodified current Vector2
  2550. */
  2551. Vector2.prototype.scaleAndAddToRef = function (scale, result) {
  2552. result.x += this.x * scale;
  2553. result.y += this.y * scale;
  2554. return this;
  2555. };
  2556. /**
  2557. * Gets a boolean if two vectors are equals
  2558. * @param otherVector defines the other vector
  2559. * @returns true if the given vector coordinates strictly equal the current Vector2 ones
  2560. */
  2561. Vector2.prototype.equals = function (otherVector) {
  2562. return otherVector && this.x === otherVector.x && this.y === otherVector.y;
  2563. };
  2564. /**
  2565. * Gets a boolean if two vectors are equals (using an epsilon value)
  2566. * @param otherVector defines the other vector
  2567. * @param epsilon defines the minimal distance to consider equality
  2568. * @returns true if the given vector coordinates are close to the current ones by a distance of epsilon.
  2569. */
  2570. Vector2.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
  2571. if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
  2572. return otherVector && BABYLON.Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) && BABYLON.Scalar.WithinEpsilon(this.y, otherVector.y, epsilon);
  2573. };
  2574. // Properties
  2575. /**
  2576. * Gets the length of the vector
  2577. * @returns the vector length (float)
  2578. */
  2579. Vector2.prototype.length = function () {
  2580. return Math.sqrt(this.x * this.x + this.y * this.y);
  2581. };
  2582. /**
  2583. * Gets the vector squared length
  2584. * @returns the vector squared length (float)
  2585. */
  2586. Vector2.prototype.lengthSquared = function () {
  2587. return (this.x * this.x + this.y * this.y);
  2588. };
  2589. // Methods
  2590. /**
  2591. * Normalize the vector
  2592. * @returns the current updated Vector2
  2593. */
  2594. Vector2.prototype.normalize = function () {
  2595. var len = this.length();
  2596. if (len === 0)
  2597. return this;
  2598. var num = 1.0 / len;
  2599. this.x *= num;
  2600. this.y *= num;
  2601. return this;
  2602. };
  2603. /**
  2604. * Gets a new Vector2 copied from the Vector2
  2605. * @returns a new Vector2
  2606. */
  2607. Vector2.prototype.clone = function () {
  2608. return new Vector2(this.x, this.y);
  2609. };
  2610. // Statics
  2611. /**
  2612. * Gets a new Vector2(0, 0)
  2613. * @returns a new Vector2
  2614. */
  2615. Vector2.Zero = function () {
  2616. return new Vector2(0, 0);
  2617. };
  2618. /**
  2619. * Gets a new Vector2(1, 1)
  2620. * @returns a new Vector2
  2621. */
  2622. Vector2.One = function () {
  2623. return new Vector2(1, 1);
  2624. };
  2625. /**
  2626. * Gets a new Vector2 set from the given index element of the given array
  2627. * @param array defines the data source
  2628. * @param offset defines the offset in the data source
  2629. * @returns a new Vector2
  2630. */
  2631. Vector2.FromArray = function (array, offset) {
  2632. if (offset === void 0) { offset = 0; }
  2633. return new Vector2(array[offset], array[offset + 1]);
  2634. };
  2635. /**
  2636. * Sets "result" from the given index element of the given array
  2637. * @param array defines the data source
  2638. * @param offset defines the offset in the data source
  2639. * @param result defines the target vector
  2640. */
  2641. Vector2.FromArrayToRef = function (array, offset, result) {
  2642. result.x = array[offset];
  2643. result.y = array[offset + 1];
  2644. };
  2645. /**
  2646. * Gets a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the given four Vector2
  2647. * @param value1 defines 1st point of control
  2648. * @param value2 defines 2nd point of control
  2649. * @param value3 defines 3rd point of control
  2650. * @param value4 defines 4th point of control
  2651. * @param amount defines the interpolation factor
  2652. * @returns a new Vector2
  2653. */
  2654. Vector2.CatmullRom = function (value1, value2, value3, value4, amount) {
  2655. var squared = amount * amount;
  2656. var cubed = amount * squared;
  2657. var x = 0.5 * ((((2.0 * value2.x) + ((-value1.x + value3.x) * amount)) +
  2658. (((((2.0 * value1.x) - (5.0 * value2.x)) + (4.0 * value3.x)) - value4.x) * squared)) +
  2659. ((((-value1.x + (3.0 * value2.x)) - (3.0 * value3.x)) + value4.x) * cubed));
  2660. var y = 0.5 * ((((2.0 * value2.y) + ((-value1.y + value3.y) * amount)) +
  2661. (((((2.0 * value1.y) - (5.0 * value2.y)) + (4.0 * value3.y)) - value4.y) * squared)) +
  2662. ((((-value1.y + (3.0 * value2.y)) - (3.0 * value3.y)) + value4.y) * cubed));
  2663. return new Vector2(x, y);
  2664. };
  2665. /**
  2666. * Returns a new Vector2 set with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max".
  2667. * If a coordinate of "value" is lower than "min" coordinates, the returned Vector2 is given this "min" coordinate.
  2668. * If a coordinate of "value" is greater than "max" coordinates, the returned Vector2 is given this "max" coordinate
  2669. * @param value defines the value to clamp
  2670. * @param min defines the lower limit
  2671. * @param max defines the upper limit
  2672. * @returns a new Vector2
  2673. */
  2674. Vector2.Clamp = function (value, min, max) {
  2675. var x = value.x;
  2676. x = (x > max.x) ? max.x : x;
  2677. x = (x < min.x) ? min.x : x;
  2678. var y = value.y;
  2679. y = (y > max.y) ? max.y : y;
  2680. y = (y < min.y) ? min.y : y;
  2681. return new Vector2(x, y);
  2682. };
  2683. /**
  2684. * Returns a new Vector2 located for "amount" (float) on the Hermite spline defined by the vectors "value1", "value3", "tangent1", "tangent2"
  2685. * @param value1 defines the 1st control point
  2686. * @param tangent1 defines the outgoing tangent
  2687. * @param value2 defines the 2nd control point
  2688. * @param tangent2 defines the incoming tangent
  2689. * @param amount defines the interpolation factor
  2690. * @returns a new Vector2
  2691. */
  2692. Vector2.Hermite = function (value1, tangent1, value2, tangent2, amount) {
  2693. var squared = amount * amount;
  2694. var cubed = amount * squared;
  2695. var part1 = ((2.0 * cubed) - (3.0 * squared)) + 1.0;
  2696. var part2 = (-2.0 * cubed) + (3.0 * squared);
  2697. var part3 = (cubed - (2.0 * squared)) + amount;
  2698. var part4 = cubed - squared;
  2699. var x = (((value1.x * part1) + (value2.x * part2)) + (tangent1.x * part3)) + (tangent2.x * part4);
  2700. var y = (((value1.y * part1) + (value2.y * part2)) + (tangent1.y * part3)) + (tangent2.y * part4);
  2701. return new Vector2(x, y);
  2702. };
  2703. /**
  2704. * Returns a new Vector2 located for "amount" (float) on the linear interpolation between the vector "start" adn the vector "end".
  2705. * @param start defines the start vector
  2706. * @param end defines the end vector
  2707. * @param amount defines the interpolation factor
  2708. * @returns a new Vector2
  2709. */
  2710. Vector2.Lerp = function (start, end, amount) {
  2711. var x = start.x + ((end.x - start.x) * amount);
  2712. var y = start.y + ((end.y - start.y) * amount);
  2713. return new Vector2(x, y);
  2714. };
  2715. /**
  2716. * Gets the dot product of the vector "left" and the vector "right"
  2717. * @param left defines first vector
  2718. * @param right defines second vector
  2719. * @returns the dot product (float)
  2720. */
  2721. Vector2.Dot = function (left, right) {
  2722. return left.x * right.x + left.y * right.y;
  2723. };
  2724. /**
  2725. * Returns a new Vector2 equal to the normalized given vector
  2726. * @param vector defines the vector to normalize
  2727. * @returns a new Vector2
  2728. */
  2729. Vector2.Normalize = function (vector) {
  2730. var newVector = vector.clone();
  2731. newVector.normalize();
  2732. return newVector;
  2733. };
  2734. /**
  2735. * Gets a new Vector2 set with the minimal coordinate values from the "left" and "right" vectors
  2736. * @param left defines 1st vector
  2737. * @param right defines 2nd vector
  2738. * @returns a new Vector2
  2739. */
  2740. Vector2.Minimize = function (left, right) {
  2741. var x = (left.x < right.x) ? left.x : right.x;
  2742. var y = (left.y < right.y) ? left.y : right.y;
  2743. return new Vector2(x, y);
  2744. };
  2745. /**
  2746. * Gets a new Vecto2 set with the maximal coordinate values from the "left" and "right" vectors
  2747. * @param left defines 1st vector
  2748. * @param right defines 2nd vector
  2749. * @returns a new Vector2
  2750. */
  2751. Vector2.Maximize = function (left, right) {
  2752. var x = (left.x > right.x) ? left.x : right.x;
  2753. var y = (left.y > right.y) ? left.y : right.y;
  2754. return new Vector2(x, y);
  2755. };
  2756. /**
  2757. * Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix
  2758. * @param vector defines the vector to transform
  2759. * @param transformation defines the matrix to apply
  2760. * @returns a new Vector2
  2761. */
  2762. Vector2.Transform = function (vector, transformation) {
  2763. var r = Vector2.Zero();
  2764. Vector2.TransformToRef(vector, transformation, r);
  2765. return r;
  2766. };
  2767. /**
  2768. * Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector "result" coordinates
  2769. * @param vector defines the vector to transform
  2770. * @param transformation defines the matrix to apply
  2771. * @param result defines the target vector
  2772. */
  2773. Vector2.TransformToRef = function (vector, transformation, result) {
  2774. var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + transformation.m[12];
  2775. var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + transformation.m[13];
  2776. result.x = x;
  2777. result.y = y;
  2778. };
  2779. /**
  2780. * Determines if a given vector is included in a triangle
  2781. * @param p defines the vector to test
  2782. * @param p0 defines 1st triangle point
  2783. * @param p1 defines 2nd triangle point
  2784. * @param p2 defines 3rd triangle point
  2785. * @returns true if the point "p" is in the triangle defined by the vertors "p0", "p1", "p2"
  2786. */
  2787. Vector2.PointInTriangle = function (p, p0, p1, p2) {
  2788. var a = 1 / 2 * (-p1.y * p2.x + p0.y * (-p1.x + p2.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y);
  2789. var sign = a < 0 ? -1 : 1;
  2790. var s = (p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y) * sign;
  2791. var t = (p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y) * sign;
  2792. return s > 0 && t > 0 && (s + t) < 2 * a * sign;
  2793. };
  2794. /**
  2795. * Gets the distance between the vectors "value1" and "value2"
  2796. * @param value1 defines first vector
  2797. * @param value2 defines second vector
  2798. * @returns the distance between vectors
  2799. */
  2800. Vector2.Distance = function (value1, value2) {
  2801. return Math.sqrt(Vector2.DistanceSquared(value1, value2));
  2802. };
  2803. /**
  2804. * Returns the squared distance between the vectors "value1" and "value2"
  2805. * @param value1 defines first vector
  2806. * @param value2 defines second vector
  2807. * @returns the squared distance between vectors
  2808. */
  2809. Vector2.DistanceSquared = function (value1, value2) {
  2810. var x = value1.x - value2.x;
  2811. var y = value1.y - value2.y;
  2812. return (x * x) + (y * y);
  2813. };
  2814. /**
  2815. * Gets a new Vector2 located at the center of the vectors "value1" and "value2"
  2816. * @param value1 defines first vector
  2817. * @param value2 defines second vector
  2818. * @returns a new Vector2
  2819. */
  2820. Vector2.Center = function (value1, value2) {
  2821. var center = value1.add(value2);
  2822. center.scaleInPlace(0.5);
  2823. return center;
  2824. };
  2825. /**
  2826. * Gets the shortest distance (float) between the point "p" and the segment defined by the two points "segA" and "segB".
  2827. * @param p defines the middle point
  2828. * @param segA defines one point of the segment
  2829. * @param segB defines the other point of the segment
  2830. * @returns the shortest distance
  2831. */
  2832. Vector2.DistanceOfPointFromSegment = function (p, segA, segB) {
  2833. var l2 = Vector2.DistanceSquared(segA, segB);
  2834. if (l2 === 0.0) {
  2835. return Vector2.Distance(p, segA);
  2836. }
  2837. var v = segB.subtract(segA);
  2838. var t = Math.max(0, Math.min(1, Vector2.Dot(p.subtract(segA), v) / l2));
  2839. var proj = segA.add(v.multiplyByFloats(t, t));
  2840. return Vector2.Distance(p, proj);
  2841. };
  2842. return Vector2;
  2843. }());
  2844. BABYLON.Vector2 = Vector2;
  2845. /**
  2846. * Classed used to store (x,y,z) vector representation
  2847. * A Vector3 is the main object used in 3D geometry
  2848. * It can represent etiher the coordinates of a point the space, either a direction
  2849. * Reminder: Babylon.js uses a left handed forward facing system
  2850. */
  2851. var Vector3 = /** @class */ (function () {
  2852. /**
  2853. * Creates a new Vector3 object from the given x, y, z (floats) coordinates.
  2854. * @param x defines the first coordinates (on X axis)
  2855. * @param y defines the second coordinates (on Y axis)
  2856. * @param z defines the third coordinates (on Z axis)
  2857. */
  2858. function Vector3(
  2859. /**
  2860. * Defines the first coordinates (on X axis)
  2861. */
  2862. x,
  2863. /**
  2864. * Defines the second coordinates (on Y axis)
  2865. */
  2866. y,
  2867. /**
  2868. * Defines the third coordinates (on Z axis)
  2869. */
  2870. z) {
  2871. this.x = x;
  2872. this.y = y;
  2873. this.z = z;
  2874. }
  2875. /**
  2876. * Creates a string representation of the Vector3
  2877. * @returns a string with the Vector3 coordinates.
  2878. */
  2879. Vector3.prototype.toString = function () {
  2880. return "{X: " + this.x + " Y:" + this.y + " Z:" + this.z + "}";
  2881. };
  2882. /**
  2883. * Gets the class name
  2884. * @returns the string "Vector3"
  2885. */
  2886. Vector3.prototype.getClassName = function () {
  2887. return "Vector3";
  2888. };
  2889. /**
  2890. * Creates the Vector3 hash code
  2891. * @returns a number which tends to be unique between Vector3 instances
  2892. */
  2893. Vector3.prototype.getHashCode = function () {
  2894. var hash = this.x || 0;
  2895. hash = (hash * 397) ^ (this.y || 0);
  2896. hash = (hash * 397) ^ (this.z || 0);
  2897. return hash;
  2898. };
  2899. // Operators
  2900. /**
  2901. * Creates an array containing three elements : the coordinates of the Vector3
  2902. * @returns a new array of numbers
  2903. */
  2904. Vector3.prototype.asArray = function () {
  2905. var result = [];
  2906. this.toArray(result, 0);
  2907. return result;
  2908. };
  2909. /**
  2910. * Populates the given array or Float32Array from the given index with the successive coordinates of the Vector3
  2911. * @param array defines the destination array
  2912. * @param index defines the offset in the destination array
  2913. * @returns the current Vector3
  2914. */
  2915. Vector3.prototype.toArray = function (array, index) {
  2916. if (index === void 0) { index = 0; }
  2917. array[index] = this.x;
  2918. array[index + 1] = this.y;
  2919. array[index + 2] = this.z;
  2920. return this;
  2921. };
  2922. /**
  2923. * Converts the current Vector3 into a quaternion (considering that the Vector3 contains Euler angles representation of a rotation)
  2924. * @returns a new Quaternion object, computed from the Vector3 coordinates
  2925. */
  2926. Vector3.prototype.toQuaternion = function () {
  2927. return BABYLON.Quaternion.RotationYawPitchRoll(this.x, this.y, this.z);
  2928. };
  2929. /**
  2930. * Adds the given vector to the current Vector3
  2931. * @param otherVector defines the second operand
  2932. * @returns the current updated Vector3
  2933. */
  2934. Vector3.prototype.addInPlace = function (otherVector) {
  2935. this.x += otherVector.x;
  2936. this.y += otherVector.y;
  2937. this.z += otherVector.z;
  2938. return this;
  2939. };
  2940. /**
  2941. * Gets a new Vector3, result of the addition the current Vector3 and the given vector
  2942. * @param otherVector defines the second operand
  2943. * @returns the resulting Vector3
  2944. */
  2945. Vector3.prototype.add = function (otherVector) {
  2946. return new Vector3(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z);
  2947. };
  2948. /**
  2949. * Adds the current Vector3 to the given one and stores the result in the vector "result"
  2950. * @param otherVector defines the second operand
  2951. * @param result defines the Vector3 object where to store the result
  2952. * @returns the current Vector3
  2953. */
  2954. Vector3.prototype.addToRef = function (otherVector, result) {
  2955. result.x = this.x + otherVector.x;
  2956. result.y = this.y + otherVector.y;
  2957. result.z = this.z + otherVector.z;
  2958. return this;
  2959. };
  2960. /**
  2961. * Subtract the given vector from the current Vector3
  2962. * @param otherVector defines the second operand
  2963. * @returns the current updated Vector3
  2964. */
  2965. Vector3.prototype.subtractInPlace = function (otherVector) {
  2966. this.x -= otherVector.x;
  2967. this.y -= otherVector.y;
  2968. this.z -= otherVector.z;
  2969. return this;
  2970. };
  2971. /**
  2972. * Returns a new Vector3, result of the subtraction of the given vector from the current Vector3
  2973. * @param otherVector defines the second operand
  2974. * @returns the resulting Vector3
  2975. */
  2976. Vector3.prototype.subtract = function (otherVector) {
  2977. return new Vector3(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z);
  2978. };
  2979. /**
  2980. * Subtracts the given vector from the current Vector3 and stores the result in the vector "result".
  2981. * @param otherVector defines the second operand
  2982. * @param result defines the Vector3 object where to store the result
  2983. * @returns the current Vector3
  2984. */
  2985. Vector3.prototype.subtractToRef = function (otherVector, result) {
  2986. result.x = this.x - otherVector.x;
  2987. result.y = this.y - otherVector.y;
  2988. result.z = this.z - otherVector.z;
  2989. return this;
  2990. };
  2991. /**
  2992. * Returns a new Vector3 set with the subtraction of the given floats from the current Vector3 coordinates
  2993. * @param x defines the x coordinate of the operand
  2994. * @param y defines the y coordinate of the operand
  2995. * @param z defines the z coordinate of the operand
  2996. * @returns the resulting Vector3
  2997. */
  2998. Vector3.prototype.subtractFromFloats = function (x, y, z) {
  2999. return new Vector3(this.x - x, this.y - y, this.z - z);
  3000. };
  3001. /**
  3002. * Subtracts the given floats from the current Vector3 coordinates and set the given vector "result" with this result
  3003. * @param x defines the x coordinate of the operand
  3004. * @param y defines the y coordinate of the operand
  3005. * @param z defines the z coordinate of the operand
  3006. * @param result defines the Vector3 object where to store the result
  3007. * @returns the current Vector3
  3008. */
  3009. Vector3.prototype.subtractFromFloatsToRef = function (x, y, z, result) {
  3010. result.x = this.x - x;
  3011. result.y = this.y - y;
  3012. result.z = this.z - z;
  3013. return this;
  3014. };
  3015. /**
  3016. * Gets a new Vector3 set with the current Vector3 negated coordinates
  3017. * @returns a new Vector3
  3018. */
  3019. Vector3.prototype.negate = function () {
  3020. return new Vector3(-this.x, -this.y, -this.z);
  3021. };
  3022. /**
  3023. * Multiplies the Vector3 coordinates by the float "scale"
  3024. * @param scale defines the multiplier factor
  3025. * @returns the current updated Vector3
  3026. */
  3027. Vector3.prototype.scaleInPlace = function (scale) {
  3028. this.x *= scale;
  3029. this.y *= scale;
  3030. this.z *= scale;
  3031. return this;
  3032. };
  3033. /**
  3034. * Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale"
  3035. * @param scale defines the multiplier factor
  3036. * @returns a new Vector3
  3037. */
  3038. Vector3.prototype.scale = function (scale) {
  3039. return new Vector3(this.x * scale, this.y * scale, this.z * scale);
  3040. };
  3041. /**
  3042. * Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the given vector "result" coordinates
  3043. * @param scale defines the multiplier factor
  3044. * @param result defines the Vector3 object where to store the result
  3045. * @returns the current Vector3
  3046. */
  3047. Vector3.prototype.scaleToRef = function (scale, result) {
  3048. result.x = this.x * scale;
  3049. result.y = this.y * scale;
  3050. result.z = this.z * scale;
  3051. return this;
  3052. };
  3053. /**
  3054. * Scale the current Vector3 values by a factor and add the result to a given Vector3
  3055. * @param scale defines the scale factor
  3056. * @param result defines the Vector3 object where to store the result
  3057. * @returns the unmodified current Vector3
  3058. */
  3059. Vector3.prototype.scaleAndAddToRef = function (scale, result) {
  3060. result.x += this.x * scale;
  3061. result.y += this.y * scale;
  3062. result.z += this.z * scale;
  3063. return this;
  3064. };
  3065. /**
  3066. * Returns true if the current Vector3 and the given vector coordinates are strictly equal
  3067. * @param otherVector defines the second operand
  3068. * @returns true if both vectors are equals
  3069. */
  3070. Vector3.prototype.equals = function (otherVector) {
  3071. return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z;
  3072. };
  3073. /**
  3074. * Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon
  3075. * @param otherVector defines the second operand
  3076. * @param epsilon defines the minimal distance to define values as equals
  3077. * @returns true if both vectors are distant less than epsilon
  3078. */
  3079. Vector3.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
  3080. if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
  3081. return otherVector && BABYLON.Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) && BABYLON.Scalar.WithinEpsilon(this.y, otherVector.y, epsilon) && BABYLON.Scalar.WithinEpsilon(this.z, otherVector.z, epsilon);
  3082. };
  3083. /**
  3084. * Returns true if the current Vector3 coordinates equals the given floats
  3085. * @param x defines the x coordinate of the operand
  3086. * @param y defines the y coordinate of the operand
  3087. * @param z defines the z coordinate of the operand
  3088. * @returns true if both vectors are equals
  3089. */
  3090. Vector3.prototype.equalsToFloats = function (x, y, z) {
  3091. return this.x === x && this.y === y && this.z === z;
  3092. };
  3093. /**
  3094. * Multiplies the current Vector3 coordinates by the given ones
  3095. * @param otherVector defines the second operand
  3096. * @returns the current updated Vector3
  3097. */
  3098. Vector3.prototype.multiplyInPlace = function (otherVector) {
  3099. this.x *= otherVector.x;
  3100. this.y *= otherVector.y;
  3101. this.z *= otherVector.z;
  3102. return this;
  3103. };
  3104. /**
  3105. * Returns a new Vector3, result of the multiplication of the current Vector3 by the given vector
  3106. * @param otherVector defines the second operand
  3107. * @returns the new Vector3
  3108. */
  3109. Vector3.prototype.multiply = function (otherVector) {
  3110. return new Vector3(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z);
  3111. };
  3112. /**
  3113. * Multiplies the current Vector3 by the given one and stores the result in the given vector "result"
  3114. * @param otherVector defines the second operand
  3115. * @param result defines the Vector3 object where to store the result
  3116. * @returns the current Vector3
  3117. */
  3118. Vector3.prototype.multiplyToRef = function (otherVector, result) {
  3119. result.x = this.x * otherVector.x;
  3120. result.y = this.y * otherVector.y;
  3121. result.z = this.z * otherVector.z;
  3122. return this;
  3123. };
  3124. /**
  3125. * Returns a new Vector3 set with the result of the mulliplication of the current Vector3 coordinates by the given floats
  3126. * @param x defines the x coordinate of the operand
  3127. * @param y defines the y coordinate of the operand
  3128. * @param z defines the z coordinate of the operand
  3129. * @returns the new Vector3
  3130. */
  3131. Vector3.prototype.multiplyByFloats = function (x, y, z) {
  3132. return new Vector3(this.x * x, this.y * y, this.z * z);
  3133. };
  3134. /**
  3135. * Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones
  3136. * @param otherVector defines the second operand
  3137. * @returns the new Vector3
  3138. */
  3139. Vector3.prototype.divide = function (otherVector) {
  3140. return new Vector3(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z);
  3141. };
  3142. /**
  3143. * Divides the current Vector3 coordinates by the given ones and stores the result in the given vector "result"
  3144. * @param otherVector defines the second operand
  3145. * @param result defines the Vector3 object where to store the result
  3146. * @returns the current Vector3
  3147. */
  3148. Vector3.prototype.divideToRef = function (otherVector, result) {
  3149. result.x = this.x / otherVector.x;
  3150. result.y = this.y / otherVector.y;
  3151. result.z = this.z / otherVector.z;
  3152. return this;
  3153. };
  3154. /**
  3155. * Divides the current Vector3 coordinates by the given ones.
  3156. * @param otherVector defines the second operand
  3157. * @returns the current updated Vector3
  3158. */
  3159. Vector3.prototype.divideInPlace = function (otherVector) {
  3160. return this.divideToRef(otherVector, this);
  3161. };
  3162. /**
  3163. * Updates the current Vector3 with the minimal coordinate values between its and the given vector ones
  3164. * @param other defines the second operand
  3165. * @returns the current updated Vector3
  3166. */
  3167. Vector3.prototype.minimizeInPlace = function (other) {
  3168. if (other.x < this.x)
  3169. this.x = other.x;
  3170. if (other.y < this.y)
  3171. this.y = other.y;
  3172. if (other.z < this.z)
  3173. this.z = other.z;
  3174. return this;
  3175. };
  3176. /**
  3177. * Updates the current Vector3 with the maximal coordinate values between its and the given vector ones.
  3178. * @param other defines the second operand
  3179. * @returns the current updated Vector3
  3180. */
  3181. Vector3.prototype.maximizeInPlace = function (other) {
  3182. if (other.x > this.x)
  3183. this.x = other.x;
  3184. if (other.y > this.y)
  3185. this.y = other.y;
  3186. if (other.z > this.z)
  3187. this.z = other.z;
  3188. return this;
  3189. };
  3190. Object.defineProperty(Vector3.prototype, "isNonUniform", {
  3191. /**
  3192. * Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same
  3193. */
  3194. get: function () {
  3195. var absX = Math.abs(this.x);
  3196. var absY = Math.abs(this.y);
  3197. if (absX !== absY) {
  3198. return true;
  3199. }
  3200. var absZ = Math.abs(this.z);
  3201. if (absX !== absZ) {
  3202. return true;
  3203. }
  3204. if (absY !== absZ) {
  3205. return true;
  3206. }
  3207. return false;
  3208. },
  3209. enumerable: true,
  3210. configurable: true
  3211. });
  3212. // Properties
  3213. /**
  3214. * Gets the length of the Vector3
  3215. * @returns the length of the Vecto3
  3216. */
  3217. Vector3.prototype.length = function () {
  3218. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3219. };
  3220. /**
  3221. * Gets the squared length of the Vector3
  3222. * @returns squared length of the Vector3
  3223. */
  3224. Vector3.prototype.lengthSquared = function () {
  3225. return (this.x * this.x + this.y * this.y + this.z * this.z);
  3226. };
  3227. /**
  3228. * Normalize the current Vector3.
  3229. * Please note that this is an in place operation.
  3230. * @returns the current updated Vector3
  3231. */
  3232. Vector3.prototype.normalize = function () {
  3233. var len = this.length();
  3234. if (len === 0 || len === 1.0)
  3235. return this;
  3236. var num = 1.0 / len;
  3237. this.x *= num;
  3238. this.y *= num;
  3239. this.z *= num;
  3240. return this;
  3241. };
  3242. /**
  3243. * Normalize the current Vector3 to a new vector
  3244. * @returns the new Vector3
  3245. */
  3246. Vector3.prototype.normalizeToNew = function () {
  3247. var normalized = new Vector3(0, 0, 0);
  3248. this.normalizeToRef(normalized);
  3249. return normalized;
  3250. };
  3251. /**
  3252. * Normalize the current Vector3 to the reference
  3253. * @param reference define the Vector3 to update
  3254. * @returns the updated Vector3
  3255. */
  3256. Vector3.prototype.normalizeToRef = function (reference) {
  3257. var len = this.length();
  3258. if (len === 0 || len === 1.0) {
  3259. reference.set(this.x, this.y, this.z);
  3260. return reference;
  3261. }
  3262. var scale = 1.0 / len;
  3263. this.scaleToRef(scale, reference);
  3264. return reference;
  3265. };
  3266. /**
  3267. * Creates a new Vector3 copied from the current Vector3
  3268. * @returns the new Vector3
  3269. */
  3270. Vector3.prototype.clone = function () {
  3271. return new Vector3(this.x, this.y, this.z);
  3272. };
  3273. /**
  3274. * Copies the given vector coordinates to the current Vector3 ones
  3275. * @param source defines the source Vector3
  3276. * @returns the current updated Vector3
  3277. */
  3278. Vector3.prototype.copyFrom = function (source) {
  3279. this.x = source.x;
  3280. this.y = source.y;
  3281. this.z = source.z;
  3282. return this;
  3283. };
  3284. /**
  3285. * Copies the given floats to the current Vector3 coordinates
  3286. * @param x defines the x coordinate of the operand
  3287. * @param y defines the y coordinate of the operand
  3288. * @param z defines the z coordinate of the operand
  3289. * @returns the current updated Vector3
  3290. */
  3291. Vector3.prototype.copyFromFloats = function (x, y, z) {
  3292. this.x = x;
  3293. this.y = y;
  3294. this.z = z;
  3295. return this;
  3296. };
  3297. /**
  3298. * Copies the given floats to the current Vector3 coordinates
  3299. * @param x defines the x coordinate of the operand
  3300. * @param y defines the y coordinate of the operand
  3301. * @param z defines the z coordinate of the operand
  3302. * @returns the current updated Vector3
  3303. */
  3304. Vector3.prototype.set = function (x, y, z) {
  3305. return this.copyFromFloats(x, y, z);
  3306. };
  3307. // Statics
  3308. /**
  3309. * Get the clip factor between two vectors
  3310. * @param vector0 defines the first operand
  3311. * @param vector1 defines the second operand
  3312. * @param axis defines the axis to use
  3313. * @param size defines the size along the axis
  3314. * @returns the clip factor
  3315. */
  3316. Vector3.GetClipFactor = function (vector0, vector1, axis, size) {
  3317. var d0 = Vector3.Dot(vector0, axis) - size;
  3318. var d1 = Vector3.Dot(vector1, axis) - size;
  3319. var s = d0 / (d0 - d1);
  3320. return s;
  3321. };
  3322. /**
  3323. * Get angle between two vectors
  3324. * @param vector0 angle between vector0 and vector1
  3325. * @param vector1 angle between vector0 and vector1
  3326. * @param normal direction of the normal
  3327. * @return the angle between vector0 and vector1
  3328. */
  3329. Vector3.GetAngleBetweenVectors = function (vector0, vector1, normal) {
  3330. var v0 = vector0.clone().normalize();
  3331. var v1 = vector1.clone().normalize();
  3332. var dot = Vector3.Dot(v0, v1);
  3333. var n = Vector3.Cross(v0, v1);
  3334. if (Vector3.Dot(n, normal) > 0) {
  3335. return Math.acos(dot);
  3336. }
  3337. return -Math.acos(dot);
  3338. };
  3339. /**
  3340. * Returns a new Vector3 set from the index "offset" of the given array
  3341. * @param array defines the source array
  3342. * @param offset defines the offset in the source array
  3343. * @returns the new Vector3
  3344. */
  3345. Vector3.FromArray = function (array, offset) {
  3346. if (!offset) {
  3347. offset = 0;
  3348. }
  3349. return new Vector3(array[offset], array[offset + 1], array[offset + 2]);
  3350. };
  3351. /**
  3352. * Returns a new Vector3 set from the index "offset" of the given Float32Array
  3353. * This function is deprecated. Use FromArray instead
  3354. * @param array defines the source array
  3355. * @param offset defines the offset in the source array
  3356. * @returns the new Vector3
  3357. */
  3358. Vector3.FromFloatArray = function (array, offset) {
  3359. return Vector3.FromArray(array, offset);
  3360. };
  3361. /**
  3362. * Sets the given vector "result" with the element values from the index "offset" of the given array
  3363. * @param array defines the source array
  3364. * @param offset defines the offset in the source array
  3365. * @param result defines the Vector3 where to store the result
  3366. */
  3367. Vector3.FromArrayToRef = function (array, offset, result) {
  3368. result.x = array[offset];
  3369. result.y = array[offset + 1];
  3370. result.z = array[offset + 2];
  3371. };
  3372. /**
  3373. * Sets the given vector "result" with the element values from the index "offset" of the given Float32Array
  3374. * This function is deprecated. Use FromArrayToRef instead.
  3375. * @param array defines the source array
  3376. * @param offset defines the offset in the source array
  3377. * @param result defines the Vector3 where to store the result
  3378. */
  3379. Vector3.FromFloatArrayToRef = function (array, offset, result) {
  3380. return Vector3.FromArrayToRef(array, offset, result);
  3381. };
  3382. /**
  3383. * Sets the given vector "result" with the given floats.
  3384. * @param x defines the x coordinate of the source
  3385. * @param y defines the y coordinate of the source
  3386. * @param z defines the z coordinate of the source
  3387. * @param result defines the Vector3 where to store the result
  3388. */
  3389. Vector3.FromFloatsToRef = function (x, y, z, result) {
  3390. result.x = x;
  3391. result.y = y;
  3392. result.z = z;
  3393. };
  3394. /**
  3395. * Returns a new Vector3 set to (0.0, 0.0, 0.0)
  3396. * @returns a new empty Vector3
  3397. */
  3398. Vector3.Zero = function () {
  3399. return new Vector3(0.0, 0.0, 0.0);
  3400. };
  3401. /**
  3402. * Returns a new Vector3 set to (1.0, 1.0, 1.0)
  3403. * @returns a new unit Vector3
  3404. */
  3405. Vector3.One = function () {
  3406. return new Vector3(1.0, 1.0, 1.0);
  3407. };
  3408. /**
  3409. * Returns a new Vector3 set to (0.0, 1.0, 0.0)
  3410. * @returns a new up Vector3
  3411. */
  3412. Vector3.Up = function () {
  3413. return new Vector3(0.0, 1.0, 0.0);
  3414. };
  3415. /**
  3416. * Returns a new Vector3 set to (0.0, 0.0, 1.0)
  3417. * @returns a new forward Vector3
  3418. */
  3419. Vector3.Forward = function () {
  3420. return new Vector3(0.0, 0.0, 1.0);
  3421. };
  3422. /**
  3423. * Returns a new Vector3 set to (1.0, 0.0, 0.0)
  3424. * @returns a new right Vector3
  3425. */
  3426. Vector3.Right = function () {
  3427. return new Vector3(1.0, 0.0, 0.0);
  3428. };
  3429. /**
  3430. * Returns a new Vector3 set to (-1.0, 0.0, 0.0)
  3431. * @returns a new left Vector3
  3432. */
  3433. Vector3.Left = function () {
  3434. return new Vector3(-1.0, 0.0, 0.0);
  3435. };
  3436. /**
  3437. * Returns a new Vector3 set with the result of the transformation by the given matrix of the given vector.
  3438. * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)
  3439. * @param vector defines the Vector3 to transform
  3440. * @param transformation defines the transformation matrix
  3441. * @returns the transformed Vector3
  3442. */
  3443. Vector3.TransformCoordinates = function (vector, transformation) {
  3444. var result = Vector3.Zero();
  3445. Vector3.TransformCoordinatesToRef(vector, transformation, result);
  3446. return result;
  3447. };
  3448. /**
  3449. * Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given vector
  3450. * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)
  3451. * @param vector defines the Vector3 to transform
  3452. * @param transformation defines the transformation matrix
  3453. * @param result defines the Vector3 where to store the result
  3454. */
  3455. Vector3.TransformCoordinatesToRef = function (vector, transformation, result) {
  3456. var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]) + transformation.m[12];
  3457. var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]) + transformation.m[13];
  3458. var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]) + transformation.m[14];
  3459. var w = (vector.x * transformation.m[3]) + (vector.y * transformation.m[7]) + (vector.z * transformation.m[11]) + transformation.m[15];
  3460. result.x = x / w;
  3461. result.y = y / w;
  3462. result.z = z / w;
  3463. };
  3464. /**
  3465. * Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)
  3466. * This method computes tranformed coordinates only, not transformed direction vectors
  3467. * @param x define the x coordinate of the source vector
  3468. * @param y define the y coordinate of the source vector
  3469. * @param z define the z coordinate of the source vector
  3470. * @param transformation defines the transformation matrix
  3471. * @param result defines the Vector3 where to store the result
  3472. */
  3473. Vector3.TransformCoordinatesFromFloatsToRef = function (x, y, z, transformation, result) {
  3474. var rx = (x * transformation.m[0]) + (y * transformation.m[4]) + (z * transformation.m[8]) + transformation.m[12];
  3475. var ry = (x * transformation.m[1]) + (y * transformation.m[5]) + (z * transformation.m[9]) + transformation.m[13];
  3476. var rz = (x * transformation.m[2]) + (y * transformation.m[6]) + (z * transformation.m[10]) + transformation.m[14];
  3477. var rw = (x * transformation.m[3]) + (y * transformation.m[7]) + (z * transformation.m[11]) + transformation.m[15];
  3478. result.x = rx / rw;
  3479. result.y = ry / rw;
  3480. result.z = rz / rw;
  3481. };
  3482. /**
  3483. * Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector
  3484. * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)
  3485. * @param vector defines the Vector3 to transform
  3486. * @param transformation defines the transformation matrix
  3487. * @returns the new Vector3
  3488. */
  3489. Vector3.TransformNormal = function (vector, transformation) {
  3490. var result = Vector3.Zero();
  3491. Vector3.TransformNormalToRef(vector, transformation, result);
  3492. return result;
  3493. };
  3494. /**
  3495. * Sets the given vector "result" with the result of the normal transformation by the given matrix of the given vector
  3496. * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)
  3497. * @param vector defines the Vector3 to transform
  3498. * @param transformation defines the transformation matrix
  3499. * @param result defines the Vector3 where to store the result
  3500. */
  3501. Vector3.TransformNormalToRef = function (vector, transformation, result) {
  3502. var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]);
  3503. var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]);
  3504. var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]);
  3505. result.x = x;
  3506. result.y = y;
  3507. result.z = z;
  3508. };
  3509. /**
  3510. * Sets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z)
  3511. * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)
  3512. * @param x define the x coordinate of the source vector
  3513. * @param y define the y coordinate of the source vector
  3514. * @param z define the z coordinate of the source vector
  3515. * @param transformation defines the transformation matrix
  3516. * @param result defines the Vector3 where to store the result
  3517. */
  3518. Vector3.TransformNormalFromFloatsToRef = function (x, y, z, transformation, result) {
  3519. result.x = (x * transformation.m[0]) + (y * transformation.m[4]) + (z * transformation.m[8]);
  3520. result.y = (x * transformation.m[1]) + (y * transformation.m[5]) + (z * transformation.m[9]);
  3521. result.z = (x * transformation.m[2]) + (y * transformation.m[6]) + (z * transformation.m[10]);
  3522. };
  3523. /**
  3524. * Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4"
  3525. * @param value1 defines the first control point
  3526. * @param value2 defines the second control point
  3527. * @param value3 defines the third control point
  3528. * @param value4 defines the fourth control point
  3529. * @param amount defines the amount on the spline to use
  3530. * @returns the new Vector3
  3531. */
  3532. Vector3.CatmullRom = function (value1, value2, value3, value4, amount) {
  3533. var squared = amount * amount;
  3534. var cubed = amount * squared;
  3535. var x = 0.5 * ((((2.0 * value2.x) + ((-value1.x + value3.x) * amount)) +
  3536. (((((2.0 * value1.x) - (5.0 * value2.x)) + (4.0 * value3.x)) - value4.x) * squared)) +
  3537. ((((-value1.x + (3.0 * value2.x)) - (3.0 * value3.x)) + value4.x) * cubed));
  3538. var y = 0.5 * ((((2.0 * value2.y) + ((-value1.y + value3.y) * amount)) +
  3539. (((((2.0 * value1.y) - (5.0 * value2.y)) + (4.0 * value3.y)) - value4.y) * squared)) +
  3540. ((((-value1.y + (3.0 * value2.y)) - (3.0 * value3.y)) + value4.y) * cubed));
  3541. var z = 0.5 * ((((2.0 * value2.z) + ((-value1.z + value3.z) * amount)) +
  3542. (((((2.0 * value1.z) - (5.0 * value2.z)) + (4.0 * value3.z)) - value4.z) * squared)) +
  3543. ((((-value1.z + (3.0 * value2.z)) - (3.0 * value3.z)) + value4.z) * cubed));
  3544. return new Vector3(x, y, z);
  3545. };
  3546. /**
  3547. * Returns a new Vector3 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max"
  3548. * If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one
  3549. * If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one
  3550. * @param value defines the current value
  3551. * @param min defines the lower range value
  3552. * @param max defines the upper range value
  3553. * @returns the new Vector3
  3554. */
  3555. Vector3.Clamp = function (value, min, max) {
  3556. var x = value.x;
  3557. x = (x > max.x) ? max.x : x;
  3558. x = (x < min.x) ? min.x : x;
  3559. var y = value.y;
  3560. y = (y > max.y) ? max.y : y;
  3561. y = (y < min.y) ? min.y : y;
  3562. var z = value.z;
  3563. z = (z > max.z) ? max.z : z;
  3564. z = (z < min.z) ? min.z : z;
  3565. return new Vector3(x, y, z);
  3566. };
  3567. /**
  3568. * Returns a new Vector3 located for "amount" (float) on the Hermite interpolation spline defined by the vectors "value1", "tangent1", "value2", "tangent2"
  3569. * @param value1 defines the first control point
  3570. * @param tangent1 defines the first tangent vector
  3571. * @param value2 defines the second control point
  3572. * @param tangent2 defines the second tangent vector
  3573. * @param amount defines the amount on the interpolation spline (between 0 and 1)
  3574. * @returns the new Vector3
  3575. */
  3576. Vector3.Hermite = function (value1, tangent1, value2, tangent2, amount) {
  3577. var squared = amount * amount;
  3578. var cubed = amount * squared;
  3579. var part1 = ((2.0 * cubed) - (3.0 * squared)) + 1.0;
  3580. var part2 = (-2.0 * cubed) + (3.0 * squared);
  3581. var part3 = (cubed - (2.0 * squared)) + amount;
  3582. var part4 = cubed - squared;
  3583. var x = (((value1.x * part1) + (value2.x * part2)) + (tangent1.x * part3)) + (tangent2.x * part4);
  3584. var y = (((value1.y * part1) + (value2.y * part2)) + (tangent1.y * part3)) + (tangent2.y * part4);
  3585. var z = (((value1.z * part1) + (value2.z * part2)) + (tangent1.z * part3)) + (tangent2.z * part4);
  3586. return new Vector3(x, y, z);
  3587. };
  3588. /**
  3589. * Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end"
  3590. * @param start defines the start value
  3591. * @param end defines the end value
  3592. * @param amount max defines amount between both (between 0 and 1)
  3593. * @returns the new Vector3
  3594. */
  3595. Vector3.Lerp = function (start, end, amount) {
  3596. var result = new Vector3(0, 0, 0);
  3597. Vector3.LerpToRef(start, end, amount, result);
  3598. return result;
  3599. };
  3600. /**
  3601. * Sets the given vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end"
  3602. * @param start defines the start value
  3603. * @param end defines the end value
  3604. * @param amount max defines amount between both (between 0 and 1)
  3605. * @param result defines the Vector3 where to store the result
  3606. */
  3607. Vector3.LerpToRef = function (start, end, amount, result) {
  3608. result.x = start.x + ((end.x - start.x) * amount);
  3609. result.y = start.y + ((end.y - start.y) * amount);
  3610. result.z = start.z + ((end.z - start.z) * amount);
  3611. };
  3612. /**
  3613. * Returns the dot product (float) between the vectors "left" and "right"
  3614. * @param left defines the left operand
  3615. * @param right defines the right operand
  3616. * @returns the dot product
  3617. */
  3618. Vector3.Dot = function (left, right) {
  3619. return (left.x * right.x + left.y * right.y + left.z * right.z);
  3620. };
  3621. /**
  3622. * Returns a new Vector3 as the cross product of the vectors "left" and "right"
  3623. * The cross product is then orthogonal to both "left" and "right"
  3624. * @param left defines the left operand
  3625. * @param right defines the right operand
  3626. * @returns the cross product
  3627. */
  3628. Vector3.Cross = function (left, right) {
  3629. var result = Vector3.Zero();
  3630. Vector3.CrossToRef(left, right, result);
  3631. return result;
  3632. };
  3633. /**
  3634. * Sets the given vector "result" with the cross product of "left" and "right"
  3635. * The cross product is then orthogonal to both "left" and "right"
  3636. * @param left defines the left operand
  3637. * @param right defines the right operand
  3638. * @param result defines the Vector3 where to store the result
  3639. */
  3640. Vector3.CrossToRef = function (left, right, result) {
  3641. MathTmp.Vector3[0].x = left.y * right.z - left.z * right.y;
  3642. MathTmp.Vector3[0].y = left.z * right.x - left.x * right.z;
  3643. MathTmp.Vector3[0].z = left.x * right.y - left.y * right.x;
  3644. result.copyFrom(MathTmp.Vector3[0]);
  3645. };
  3646. /**
  3647. * Returns a new Vector3 as the normalization of the given vector
  3648. * @param vector defines the Vector3 to normalize
  3649. * @returns the new Vector3
  3650. */
  3651. Vector3.Normalize = function (vector) {
  3652. var result = Vector3.Zero();
  3653. Vector3.NormalizeToRef(vector, result);
  3654. return result;
  3655. };
  3656. /**
  3657. * Sets the given vector "result" with the normalization of the given first vector
  3658. * @param vector defines the Vector3 to normalize
  3659. * @param result defines the Vector3 where to store the result
  3660. */
  3661. Vector3.NormalizeToRef = function (vector, result) {
  3662. result.copyFrom(vector);
  3663. result.normalize();
  3664. };
  3665. /**
  3666. * Project a Vector3 onto screen space
  3667. * @param vector defines the Vector3 to project
  3668. * @param world defines the world matrix to use
  3669. * @param transform defines the transform (view x projection) matrix to use
  3670. * @param viewport defines the screen viewport to use
  3671. * @returns the new Vector3
  3672. */
  3673. Vector3.Project = function (vector, world, transform, viewport) {
  3674. var cw = viewport.width;
  3675. var ch = viewport.height;
  3676. var cx = viewport.x;
  3677. var cy = viewport.y;
  3678. var viewportMatrix = Vector3._viewportMatrixCache ? Vector3._viewportMatrixCache : (Vector3._viewportMatrixCache = new Matrix());
  3679. Matrix.FromValuesToRef(cw / 2.0, 0, 0, 0, 0, -ch / 2.0, 0, 0, 0, 0, 0.5, 0, cx + cw / 2.0, ch / 2.0 + cy, 0.5, 1, viewportMatrix);
  3680. var matrix = MathTmp.Matrix[0];
  3681. world.multiplyToRef(transform, matrix);
  3682. matrix.multiplyToRef(viewportMatrix, matrix);
  3683. return Vector3.TransformCoordinates(vector, matrix);
  3684. };
  3685. /**
  3686. * Unproject from screen space to object space
  3687. * @param source defines the screen space Vector3 to use
  3688. * @param viewportWidth defines the current width of the viewport
  3689. * @param viewportHeight defines the current height of the viewport
  3690. * @param world defines the world matrix to use (can be set to Identity to go to world space)
  3691. * @param transform defines the transform (view x projection) matrix to use
  3692. * @returns the new Vector3
  3693. */
  3694. Vector3.UnprojectFromTransform = function (source, viewportWidth, viewportHeight, world, transform) {
  3695. var matrix = MathTmp.Matrix[0];
  3696. world.multiplyToRef(transform, matrix);
  3697. matrix.invert();
  3698. source.x = source.x / viewportWidth * 2 - 1;
  3699. source.y = -(source.y / viewportHeight * 2 - 1);
  3700. var vector = Vector3.TransformCoordinates(source, matrix);
  3701. var num = source.x * matrix.m[3] + source.y * matrix.m[7] + source.z * matrix.m[11] + matrix.m[15];
  3702. if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
  3703. vector = vector.scale(1.0 / num);
  3704. }
  3705. return vector;
  3706. };
  3707. /**
  3708. * Unproject from screen space to object space
  3709. * @param source defines the screen space Vector3 to use
  3710. * @param viewportWidth defines the current width of the viewport
  3711. * @param viewportHeight defines the current height of the viewport
  3712. * @param world defines the world matrix to use (can be set to Identity to go to world space)
  3713. * @param view defines the view matrix to use
  3714. * @param projection defines the projection matrix to use
  3715. * @returns the new Vector3
  3716. */
  3717. Vector3.Unproject = function (source, viewportWidth, viewportHeight, world, view, projection) {
  3718. var result = Vector3.Zero();
  3719. Vector3.UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result);
  3720. return result;
  3721. };
  3722. /**
  3723. * Unproject from screen space to object space
  3724. * @param source defines the screen space Vector3 to use
  3725. * @param viewportWidth defines the current width of the viewport
  3726. * @param viewportHeight defines the current height of the viewport
  3727. * @param world defines the world matrix to use (can be set to Identity to go to world space)
  3728. * @param view defines the view matrix to use
  3729. * @param projection defines the projection matrix to use
  3730. * @param result defines the Vector3 where to store the result
  3731. */
  3732. Vector3.UnprojectToRef = function (source, viewportWidth, viewportHeight, world, view, projection, result) {
  3733. Vector3.UnprojectFloatsToRef(source.x, source.y, source.z, viewportWidth, viewportHeight, world, view, projection, result);
  3734. };
  3735. /**
  3736. * Unproject from screen space to object space
  3737. * @param sourceX defines the screen space x coordinate to use
  3738. * @param sourceY defines the screen space y coordinate to use
  3739. * @param sourceZ defines the screen space z coordinate to use
  3740. * @param viewportWidth defines the current width of the viewport
  3741. * @param viewportHeight defines the current height of the viewport
  3742. * @param world defines the world matrix to use (can be set to Identity to go to world space)
  3743. * @param view defines the view matrix to use
  3744. * @param projection defines the projection matrix to use
  3745. * @param result defines the Vector3 where to store the result
  3746. */
  3747. Vector3.UnprojectFloatsToRef = function (sourceX, sourceY, sourceZ, viewportWidth, viewportHeight, world, view, projection, result) {
  3748. var matrix = MathTmp.Matrix[0];
  3749. world.multiplyToRef(view, matrix);
  3750. matrix.multiplyToRef(projection, matrix);
  3751. matrix.invert();
  3752. var screenSource = MathTmp.Vector3[0];
  3753. screenSource.x = sourceX / viewportWidth * 2 - 1;
  3754. screenSource.y = -(sourceY / viewportHeight * 2 - 1);
  3755. screenSource.z = 2 * sourceZ - 1.0;
  3756. Vector3.TransformCoordinatesToRef(screenSource, matrix, result);
  3757. var num = screenSource.x * matrix.m[3] + screenSource.y * matrix.m[7] + screenSource.z * matrix.m[11] + matrix.m[15];
  3758. if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
  3759. result.scaleInPlace(1.0 / num);
  3760. }
  3761. };
  3762. /**
  3763. * Gets the minimal coordinate values between two Vector3
  3764. * @param left defines the first operand
  3765. * @param right defines the second operand
  3766. * @returns the new Vector3
  3767. */
  3768. Vector3.Minimize = function (left, right) {
  3769. var min = left.clone();
  3770. min.minimizeInPlace(right);
  3771. return min;
  3772. };
  3773. /**
  3774. * Gets the maximal coordinate values between two Vector3
  3775. * @param left defines the first operand
  3776. * @param right defines the second operand
  3777. * @returns the new Vector3
  3778. */
  3779. Vector3.Maximize = function (left, right) {
  3780. var max = left.clone();
  3781. max.maximizeInPlace(right);
  3782. return max;
  3783. };
  3784. /**
  3785. * Returns the distance between the vectors "value1" and "value2"
  3786. * @param value1 defines the first operand
  3787. * @param value2 defines the second operand
  3788. * @returns the distance
  3789. */
  3790. Vector3.Distance = function (value1, value2) {
  3791. return Math.sqrt(Vector3.DistanceSquared(value1, value2));
  3792. };
  3793. /**
  3794. * Returns the squared distance between the vectors "value1" and "value2"
  3795. * @param value1 defines the first operand
  3796. * @param value2 defines the second operand
  3797. * @returns the squared distance
  3798. */
  3799. Vector3.DistanceSquared = function (value1, value2) {
  3800. var x = value1.x - value2.x;
  3801. var y = value1.y - value2.y;
  3802. var z = value1.z - value2.z;
  3803. return (x * x) + (y * y) + (z * z);
  3804. };
  3805. /**
  3806. * Returns a new Vector3 located at the center between "value1" and "value2"
  3807. * @param value1 defines the first operand
  3808. * @param value2 defines the second operand
  3809. * @returns the new Vector3
  3810. */
  3811. Vector3.Center = function (value1, value2) {
  3812. var center = value1.add(value2);
  3813. center.scaleInPlace(0.5);
  3814. return center;
  3815. };
  3816. /**
  3817. * Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system),
  3818. * RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply
  3819. * to something in order to rotate it from its local system to the given target system
  3820. * Note: axis1, axis2 and axis3 are normalized during this operation
  3821. * @param axis1 defines the first axis
  3822. * @param axis2 defines the second axis
  3823. * @param axis3 defines the third axis
  3824. * @returns a new Vector3
  3825. */
  3826. Vector3.RotationFromAxis = function (axis1, axis2, axis3) {
  3827. var rotation = Vector3.Zero();
  3828. Vector3.RotationFromAxisToRef(axis1, axis2, axis3, rotation);
  3829. return rotation;
  3830. };
  3831. /**
  3832. * The same than RotationFromAxis but updates the given ref Vector3 parameter instead of returning a new Vector3
  3833. * @param axis1 defines the first axis
  3834. * @param axis2 defines the second axis
  3835. * @param axis3 defines the third axis
  3836. * @param ref defines the Vector3 where to store the result
  3837. */
  3838. Vector3.RotationFromAxisToRef = function (axis1, axis2, axis3, ref) {
  3839. var quat = MathTmp.Quaternion[0];
  3840. Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);
  3841. quat.toEulerAnglesToRef(ref);
  3842. };
  3843. return Vector3;
  3844. }());
  3845. BABYLON.Vector3 = Vector3;
  3846. //Vector4 class created for EulerAngle class conversion to Quaternion
  3847. var Vector4 = /** @class */ (function () {
  3848. /**
  3849. * Creates a Vector4 object from the given floats.
  3850. */
  3851. function Vector4(x, y, z, w) {
  3852. this.x = x;
  3853. this.y = y;
  3854. this.z = z;
  3855. this.w = w;
  3856. }
  3857. /**
  3858. * Returns the string with the Vector4 coordinates.
  3859. */
  3860. Vector4.prototype.toString = function () {
  3861. return "{X: " + this.x + " Y:" + this.y + " Z:" + this.z + " W:" + this.w + "}";
  3862. };
  3863. /**
  3864. * Returns the string "Vector4".
  3865. */
  3866. Vector4.prototype.getClassName = function () {
  3867. return "Vector4";
  3868. };
  3869. /**
  3870. * Returns the Vector4 hash code.
  3871. */
  3872. Vector4.prototype.getHashCode = function () {
  3873. var hash = this.x || 0;
  3874. hash = (hash * 397) ^ (this.y || 0);
  3875. hash = (hash * 397) ^ (this.z || 0);
  3876. hash = (hash * 397) ^ (this.w || 0);
  3877. return hash;
  3878. };
  3879. // Operators
  3880. /**
  3881. * Returns a new array populated with 4 elements : the Vector4 coordinates.
  3882. */
  3883. Vector4.prototype.asArray = function () {
  3884. var result = new Array();
  3885. this.toArray(result, 0);
  3886. return result;
  3887. };
  3888. /**
  3889. * Populates the given array from the given index with the Vector4 coordinates.
  3890. * Returns the Vector4.
  3891. */
  3892. Vector4.prototype.toArray = function (array, index) {
  3893. if (index === undefined) {
  3894. index = 0;
  3895. }
  3896. array[index] = this.x;
  3897. array[index + 1] = this.y;
  3898. array[index + 2] = this.z;
  3899. array[index + 3] = this.w;
  3900. return this;
  3901. };
  3902. /**
  3903. * Adds the given vector to the current Vector4.
  3904. * Returns the updated Vector4.
  3905. */
  3906. Vector4.prototype.addInPlace = function (otherVector) {
  3907. this.x += otherVector.x;
  3908. this.y += otherVector.y;
  3909. this.z += otherVector.z;
  3910. this.w += otherVector.w;
  3911. return this;
  3912. };
  3913. /**
  3914. * Returns a new Vector4 as the result of the addition of the current Vector4 and the given one.
  3915. */
  3916. Vector4.prototype.add = function (otherVector) {
  3917. return new Vector4(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);
  3918. };
  3919. /**
  3920. * Updates the given vector "result" with the result of the addition of the current Vector4 and the given one.
  3921. * Returns the current Vector4.
  3922. */
  3923. Vector4.prototype.addToRef = function (otherVector, result) {
  3924. result.x = this.x + otherVector.x;
  3925. result.y = this.y + otherVector.y;
  3926. result.z = this.z + otherVector.z;
  3927. result.w = this.w + otherVector.w;
  3928. return this;
  3929. };
  3930. /**
  3931. * Subtract in place the given vector from the current Vector4.
  3932. * Returns the updated Vector4.
  3933. */
  3934. Vector4.prototype.subtractInPlace = function (otherVector) {
  3935. this.x -= otherVector.x;
  3936. this.y -= otherVector.y;
  3937. this.z -= otherVector.z;
  3938. this.w -= otherVector.w;
  3939. return this;
  3940. };
  3941. /**
  3942. * Returns a new Vector4 with the result of the subtraction of the given vector from the current Vector4.
  3943. */
  3944. Vector4.prototype.subtract = function (otherVector) {
  3945. return new Vector4(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);
  3946. };
  3947. /**
  3948. * Sets the given vector "result" with the result of the subtraction of the given vector from the current Vector4.
  3949. * Returns the current Vector4.
  3950. */
  3951. Vector4.prototype.subtractToRef = function (otherVector, result) {
  3952. result.x = this.x - otherVector.x;
  3953. result.y = this.y - otherVector.y;
  3954. result.z = this.z - otherVector.z;
  3955. result.w = this.w - otherVector.w;
  3956. return this;
  3957. };
  3958. /**
  3959. * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.
  3960. */
  3961. Vector4.prototype.subtractFromFloats = function (x, y, z, w) {
  3962. return new Vector4(this.x - x, this.y - y, this.z - z, this.w - w);
  3963. };
  3964. /**
  3965. * Sets the given vector "result" set with the result of the subtraction of the given floats from the current Vector4 coordinates.
  3966. * Returns the current Vector4.
  3967. */
  3968. Vector4.prototype.subtractFromFloatsToRef = function (x, y, z, w, result) {
  3969. result.x = this.x - x;
  3970. result.y = this.y - y;
  3971. result.z = this.z - z;
  3972. result.w = this.w - w;
  3973. return this;
  3974. };
  3975. /**
  3976. * Returns a new Vector4 set with the current Vector4 negated coordinates.
  3977. */
  3978. Vector4.prototype.negate = function () {
  3979. return new Vector4(-this.x, -this.y, -this.z, -this.w);
  3980. };
  3981. /**
  3982. * Multiplies the current Vector4 coordinates by scale (float).
  3983. * Returns the updated Vector4.
  3984. */
  3985. Vector4.prototype.scaleInPlace = function (scale) {
  3986. this.x *= scale;
  3987. this.y *= scale;
  3988. this.z *= scale;
  3989. this.w *= scale;
  3990. return this;
  3991. };
  3992. /**
  3993. * Returns a new Vector4 set with the current Vector4 coordinates multiplied by scale (float).
  3994. */
  3995. Vector4.prototype.scale = function (scale) {
  3996. return new Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
  3997. };
  3998. /**
  3999. * Sets the given vector "result" with the current Vector4 coordinates multiplied by scale (float).
  4000. * Returns the current Vector4.
  4001. */
  4002. Vector4.prototype.scaleToRef = function (scale, result) {
  4003. result.x = this.x * scale;
  4004. result.y = this.y * scale;
  4005. result.z = this.z * scale;
  4006. result.w = this.w * scale;
  4007. return this;
  4008. };
  4009. /**
  4010. * Scale the current Vector4 values by a factor and add the result to a given Vector4
  4011. * @param scale defines the scale factor
  4012. * @param result defines the Vector4 object where to store the result
  4013. * @returns the unmodified current Vector4
  4014. */
  4015. Vector4.prototype.scaleAndAddToRef = function (scale, result) {
  4016. result.x += this.x * scale;
  4017. result.y += this.y * scale;
  4018. result.z += this.z * scale;
  4019. result.w += this.w * scale;
  4020. return this;
  4021. };
  4022. /**
  4023. * Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.
  4024. */
  4025. Vector4.prototype.equals = function (otherVector) {
  4026. return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z && this.w === otherVector.w;
  4027. };
  4028. /**
  4029. * Boolean : True if the current Vector4 coordinates are each beneath the distance "epsilon" from the given vector ones.
  4030. */
  4031. Vector4.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
  4032. if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
  4033. return otherVector
  4034. && BABYLON.Scalar.WithinEpsilon(this.x, otherVector.x, epsilon)
  4035. && BABYLON.Scalar.WithinEpsilon(this.y, otherVector.y, epsilon)
  4036. && BABYLON.Scalar.WithinEpsilon(this.z, otherVector.z, epsilon)
  4037. && BABYLON.Scalar.WithinEpsilon(this.w, otherVector.w, epsilon);
  4038. };
  4039. /**
  4040. * Boolean : True if the given floats are strictly equal to the current Vector4 coordinates.
  4041. */
  4042. Vector4.prototype.equalsToFloats = function (x, y, z, w) {
  4043. return this.x === x && this.y === y && this.z === z && this.w === w;
  4044. };
  4045. /**
  4046. * Multiplies in place the current Vector4 by the given one.
  4047. * Returns the updated Vector4.
  4048. */
  4049. Vector4.prototype.multiplyInPlace = function (otherVector) {
  4050. this.x *= otherVector.x;
  4051. this.y *= otherVector.y;
  4052. this.z *= otherVector.z;
  4053. this.w *= otherVector.w;
  4054. return this;
  4055. };
  4056. /**
  4057. * Returns a new Vector4 set with the multiplication result of the current Vector4 and the given one.
  4058. */
  4059. Vector4.prototype.multiply = function (otherVector) {
  4060. return new Vector4(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);
  4061. };
  4062. /**
  4063. * Updates the given vector "result" with the multiplication result of the current Vector4 and the given one.
  4064. * Returns the current Vector4.
  4065. */
  4066. Vector4.prototype.multiplyToRef = function (otherVector, result) {
  4067. result.x = this.x * otherVector.x;
  4068. result.y = this.y * otherVector.y;
  4069. result.z = this.z * otherVector.z;
  4070. result.w = this.w * otherVector.w;
  4071. return this;
  4072. };
  4073. /**
  4074. * Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.
  4075. */
  4076. Vector4.prototype.multiplyByFloats = function (x, y, z, w) {
  4077. return new Vector4(this.x * x, this.y * y, this.z * z, this.w * w);
  4078. };
  4079. /**
  4080. * Returns a new Vector4 set with the division result of the current Vector4 by the given one.
  4081. */
  4082. Vector4.prototype.divide = function (otherVector) {
  4083. return new Vector4(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);
  4084. };
  4085. /**
  4086. * Updates the given vector "result" with the division result of the current Vector4 by the given one.
  4087. * Returns the current Vector4.
  4088. */
  4089. Vector4.prototype.divideToRef = function (otherVector, result) {
  4090. result.x = this.x / otherVector.x;
  4091. result.y = this.y / otherVector.y;
  4092. result.z = this.z / otherVector.z;
  4093. result.w = this.w / otherVector.w;
  4094. return this;
  4095. };
  4096. /**
  4097. * Divides the current Vector3 coordinates by the given ones.
  4098. * @returns the updated Vector3.
  4099. */
  4100. Vector4.prototype.divideInPlace = function (otherVector) {
  4101. return this.divideToRef(otherVector, this);
  4102. };
  4103. /**
  4104. * Updates the Vector4 coordinates with the minimum values between its own and the given vector ones
  4105. * @param other defines the second operand
  4106. * @returns the current updated Vector4
  4107. */
  4108. Vector4.prototype.minimizeInPlace = function (other) {
  4109. if (other.x < this.x)
  4110. this.x = other.x;
  4111. if (other.y < this.y)
  4112. this.y = other.y;
  4113. if (other.z < this.z)
  4114. this.z = other.z;
  4115. if (other.w < this.w)
  4116. this.w = other.w;
  4117. return this;
  4118. };
  4119. /**
  4120. * Updates the Vector4 coordinates with the maximum values between its own and the given vector ones
  4121. * @param other defines the second operand
  4122. * @returns the current updated Vector4
  4123. */
  4124. Vector4.prototype.maximizeInPlace = function (other) {
  4125. if (other.x > this.x)
  4126. this.x = other.x;
  4127. if (other.y > this.y)
  4128. this.y = other.y;
  4129. if (other.z > this.z)
  4130. this.z = other.z;
  4131. if (other.w > this.w)
  4132. this.w = other.w;
  4133. return this;
  4134. };
  4135. // Properties
  4136. /**
  4137. * Returns the Vector4 length (float).
  4138. */
  4139. Vector4.prototype.length = function () {
  4140. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  4141. };
  4142. /**
  4143. * Returns the Vector4 squared length (float).
  4144. */
  4145. Vector4.prototype.lengthSquared = function () {
  4146. return (this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  4147. };
  4148. // Methods
  4149. /**
  4150. * Normalizes in place the Vector4.
  4151. * Returns the updated Vector4.
  4152. */
  4153. Vector4.prototype.normalize = function () {
  4154. var len = this.length();
  4155. if (len === 0)
  4156. return this;
  4157. var num = 1.0 / len;
  4158. this.x *= num;
  4159. this.y *= num;
  4160. this.z *= num;
  4161. this.w *= num;
  4162. return this;
  4163. };
  4164. /**
  4165. * Returns a new Vector3 from the Vector4 (x, y, z) coordinates.
  4166. */
  4167. Vector4.prototype.toVector3 = function () {
  4168. return new Vector3(this.x, this.y, this.z);
  4169. };
  4170. /**
  4171. * Returns a new Vector4 copied from the current one.
  4172. */
  4173. Vector4.prototype.clone = function () {
  4174. return new Vector4(this.x, this.y, this.z, this.w);
  4175. };
  4176. /**
  4177. * Updates the current Vector4 with the given one coordinates.
  4178. * Returns the updated Vector4.
  4179. */
  4180. Vector4.prototype.copyFrom = function (source) {
  4181. this.x = source.x;
  4182. this.y = source.y;
  4183. this.z = source.z;
  4184. this.w = source.w;
  4185. return this;
  4186. };
  4187. /**
  4188. * Updates the current Vector4 coordinates with the given floats.
  4189. * Returns the updated Vector4.
  4190. */
  4191. Vector4.prototype.copyFromFloats = function (x, y, z, w) {
  4192. this.x = x;
  4193. this.y = y;
  4194. this.z = z;
  4195. this.w = w;
  4196. return this;
  4197. };
  4198. /**
  4199. * Updates the current Vector4 coordinates with the given floats.
  4200. * Returns the updated Vector4.
  4201. */
  4202. Vector4.prototype.set = function (x, y, z, w) {
  4203. return this.copyFromFloats(x, y, z, w);
  4204. };
  4205. // Statics
  4206. /**
  4207. * Returns a new Vector4 set from the starting index of the given array.
  4208. */
  4209. Vector4.FromArray = function (array, offset) {
  4210. if (!offset) {
  4211. offset = 0;
  4212. }
  4213. return new Vector4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);
  4214. };
  4215. /**
  4216. * Updates the given vector "result" from the starting index of the given array.
  4217. */
  4218. Vector4.FromArrayToRef = function (array, offset, result) {
  4219. result.x = array[offset];
  4220. result.y = array[offset + 1];
  4221. result.z = array[offset + 2];
  4222. result.w = array[offset + 3];
  4223. };
  4224. /**
  4225. * Updates the given vector "result" from the starting index of the given Float32Array.
  4226. */
  4227. Vector4.FromFloatArrayToRef = function (array, offset, result) {
  4228. Vector4.FromArrayToRef(array, offset, result);
  4229. };
  4230. /**
  4231. * Updates the given vector "result" coordinates from the given floats.
  4232. */
  4233. Vector4.FromFloatsToRef = function (x, y, z, w, result) {
  4234. result.x = x;
  4235. result.y = y;
  4236. result.z = z;
  4237. result.w = w;
  4238. };
  4239. /**
  4240. * Returns a new Vector4 set to (0.0, 0.0, 0.0, 0.0)
  4241. */
  4242. Vector4.Zero = function () {
  4243. return new Vector4(0.0, 0.0, 0.0, 0.0);
  4244. };
  4245. /**
  4246. * Returns a new Vector4 set to (1.0, 1.0, 1.0, 1.0)
  4247. */
  4248. Vector4.One = function () {
  4249. return new Vector4(1.0, 1.0, 1.0, 1.0);
  4250. };
  4251. /**
  4252. * Returns a new normalized Vector4 from the given one.
  4253. */
  4254. Vector4.Normalize = function (vector) {
  4255. var result = Vector4.Zero();
  4256. Vector4.NormalizeToRef(vector, result);
  4257. return result;
  4258. };
  4259. /**
  4260. * Updates the given vector "result" from the normalization of the given one.
  4261. */
  4262. Vector4.NormalizeToRef = function (vector, result) {
  4263. result.copyFrom(vector);
  4264. result.normalize();
  4265. };
  4266. Vector4.Minimize = function (left, right) {
  4267. var min = left.clone();
  4268. min.minimizeInPlace(right);
  4269. return min;
  4270. };
  4271. Vector4.Maximize = function (left, right) {
  4272. var max = left.clone();
  4273. max.maximizeInPlace(right);
  4274. return max;
  4275. };
  4276. /**
  4277. * Returns the distance (float) between the vectors "value1" and "value2".
  4278. */
  4279. Vector4.Distance = function (value1, value2) {
  4280. return Math.sqrt(Vector4.DistanceSquared(value1, value2));
  4281. };
  4282. /**
  4283. * Returns the squared distance (float) between the vectors "value1" and "value2".
  4284. */
  4285. Vector4.DistanceSquared = function (value1, value2) {
  4286. var x = value1.x - value2.x;
  4287. var y = value1.y - value2.y;
  4288. var z = value1.z - value2.z;
  4289. var w = value1.w - value2.w;
  4290. return (x * x) + (y * y) + (z * z) + (w * w);
  4291. };
  4292. /**
  4293. * Returns a new Vector4 located at the center between the vectors "value1" and "value2".
  4294. */
  4295. Vector4.Center = function (value1, value2) {
  4296. var center = value1.add(value2);
  4297. center.scaleInPlace(0.5);
  4298. return center;
  4299. };
  4300. /**
  4301. * Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector.
  4302. * This methods computes transformed normalized direction vectors only.
  4303. */
  4304. Vector4.TransformNormal = function (vector, transformation) {
  4305. var result = Vector4.Zero();
  4306. Vector4.TransformNormalToRef(vector, transformation, result);
  4307. return result;
  4308. };
  4309. /**
  4310. * Sets the given vector "result" with the result of the normal transformation by the given matrix of the given vector.
  4311. * This methods computes transformed normalized direction vectors only.
  4312. */
  4313. Vector4.TransformNormalToRef = function (vector, transformation, result) {
  4314. var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]);
  4315. var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]);
  4316. var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]);
  4317. result.x = x;
  4318. result.y = y;
  4319. result.z = z;
  4320. result.w = vector.w;
  4321. };
  4322. /**
  4323. * Sets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z, w).
  4324. * This methods computes transformed normalized direction vectors only.
  4325. */
  4326. Vector4.TransformNormalFromFloatsToRef = function (x, y, z, w, transformation, result) {
  4327. result.x = (x * transformation.m[0]) + (y * transformation.m[4]) + (z * transformation.m[8]);
  4328. result.y = (x * transformation.m[1]) + (y * transformation.m[5]) + (z * transformation.m[9]);
  4329. result.z = (x * transformation.m[2]) + (y * transformation.m[6]) + (z * transformation.m[10]);
  4330. result.w = w;
  4331. };
  4332. return Vector4;
  4333. }());
  4334. BABYLON.Vector4 = Vector4;
  4335. var Size = /** @class */ (function () {
  4336. /**
  4337. * Creates a Size object from the given width and height (floats).
  4338. */
  4339. function Size(width, height) {
  4340. this.width = width;
  4341. this.height = height;
  4342. }
  4343. // Returns a string with the Size width and height.
  4344. Size.prototype.toString = function () {
  4345. return "{W: " + this.width + ", H: " + this.height + "}";
  4346. };
  4347. /**
  4348. * Returns the string "Size"
  4349. */
  4350. Size.prototype.getClassName = function () {
  4351. return "Size";
  4352. };
  4353. /**
  4354. * Returns the Size hash code.
  4355. */
  4356. Size.prototype.getHashCode = function () {
  4357. var hash = this.width || 0;
  4358. hash = (hash * 397) ^ (this.height || 0);
  4359. return hash;
  4360. };
  4361. /**
  4362. * Updates the current size from the given one.
  4363. * Returns the updated Size.
  4364. */
  4365. Size.prototype.copyFrom = function (src) {
  4366. this.width = src.width;
  4367. this.height = src.height;
  4368. };
  4369. /**
  4370. * Updates in place the current Size from the given floats.
  4371. * Returns the updated Size.
  4372. */
  4373. Size.prototype.copyFromFloats = function (width, height) {
  4374. this.width = width;
  4375. this.height = height;
  4376. return this;
  4377. };
  4378. /**
  4379. * Updates in place the current Size from the given floats.
  4380. * Returns the updated Size.
  4381. */
  4382. Size.prototype.set = function (width, height) {
  4383. return this.copyFromFloats(width, height);
  4384. };
  4385. /**
  4386. * Returns a new Size set with the multiplication result of the current Size and the given floats.
  4387. */
  4388. Size.prototype.multiplyByFloats = function (w, h) {
  4389. return new Size(this.width * w, this.height * h);
  4390. };
  4391. /**
  4392. * Returns a new Size copied from the given one.
  4393. */
  4394. Size.prototype.clone = function () {
  4395. return new Size(this.width, this.height);
  4396. };
  4397. /**
  4398. * Boolean : True if the current Size and the given one width and height are strictly equal.
  4399. */
  4400. Size.prototype.equals = function (other) {
  4401. if (!other) {
  4402. return false;
  4403. }
  4404. return (this.width === other.width) && (this.height === other.height);
  4405. };
  4406. Object.defineProperty(Size.prototype, "surface", {
  4407. /**
  4408. * Returns the surface of the Size : width * height (float).
  4409. */
  4410. get: function () {
  4411. return this.width * this.height;
  4412. },
  4413. enumerable: true,
  4414. configurable: true
  4415. });
  4416. /**
  4417. * Returns a new Size set to (0.0, 0.0)
  4418. */
  4419. Size.Zero = function () {
  4420. return new Size(0.0, 0.0);
  4421. };
  4422. /**
  4423. * Returns a new Size set as the addition result of the current Size and the given one.
  4424. */
  4425. Size.prototype.add = function (otherSize) {
  4426. var r = new Size(this.width + otherSize.width, this.height + otherSize.height);
  4427. return r;
  4428. };
  4429. /**
  4430. * Returns a new Size set as the subtraction result of the given one from the current Size.
  4431. */
  4432. Size.prototype.subtract = function (otherSize) {
  4433. var r = new Size(this.width - otherSize.width, this.height - otherSize.height);
  4434. return r;
  4435. };
  4436. /**
  4437. * Returns a new Size set at the linear interpolation "amount" between "start" and "end".
  4438. */
  4439. Size.Lerp = function (start, end, amount) {
  4440. var w = start.width + ((end.width - start.width) * amount);
  4441. var h = start.height + ((end.height - start.height) * amount);
  4442. return new Size(w, h);
  4443. };
  4444. return Size;
  4445. }());
  4446. BABYLON.Size = Size;
  4447. /**
  4448. * Class used to store quaternion data
  4449. * @see https://en.wikipedia.org/wiki/Quaternion
  4450. * @see http://doc.babylonjs.com/features/position,_rotation,_scaling
  4451. */
  4452. var Quaternion = /** @class */ (function () {
  4453. /**
  4454. * Creates a new Quaternion from the given floats
  4455. * @param x defines the first component (0 by default)
  4456. * @param y defines the second component (0 by default)
  4457. * @param z defines the third component (0 by default)
  4458. * @param w defines the fourth component (1.0 by default)
  4459. */
  4460. function Quaternion(
  4461. /** defines the first component (0 by default) */
  4462. x,
  4463. /** defines the second component (0 by default) */
  4464. y,
  4465. /** defines the third component (0 by default) */
  4466. z,
  4467. /** defines the fourth component (1.0 by default) */
  4468. w) {
  4469. if (x === void 0) { x = 0.0; }
  4470. if (y === void 0) { y = 0.0; }
  4471. if (z === void 0) { z = 0.0; }
  4472. if (w === void 0) { w = 1.0; }
  4473. this.x = x;
  4474. this.y = y;
  4475. this.z = z;
  4476. this.w = w;
  4477. }
  4478. /**
  4479. * Gets a string representation for the current quaternion
  4480. * @returns a string with the Quaternion coordinates
  4481. */
  4482. Quaternion.prototype.toString = function () {
  4483. return "{X: " + this.x + " Y:" + this.y + " Z:" + this.z + " W:" + this.w + "}";
  4484. };
  4485. /**
  4486. * Gets the class name of the quaternion
  4487. * @returns the string "Quaternion"
  4488. */
  4489. Quaternion.prototype.getClassName = function () {
  4490. return "Quaternion";
  4491. };
  4492. /**
  4493. * Gets a hash code for this quaternion
  4494. * @returns the quaternion hash code
  4495. */
  4496. Quaternion.prototype.getHashCode = function () {
  4497. var hash = this.x || 0;
  4498. hash = (hash * 397) ^ (this.y || 0);
  4499. hash = (hash * 397) ^ (this.z || 0);
  4500. hash = (hash * 397) ^ (this.w || 0);
  4501. return hash;
  4502. };
  4503. /**
  4504. * Copy the quaternion to an array
  4505. * @returns a new array populated with 4 elements from the quaternion coordinates
  4506. */
  4507. Quaternion.prototype.asArray = function () {
  4508. return [this.x, this.y, this.z, this.w];
  4509. };
  4510. /**
  4511. * Check if two quaternions are equals
  4512. * @param otherQuaternion defines the second operand
  4513. * @return true if the current quaternion and the given one coordinates are strictly equals
  4514. */
  4515. Quaternion.prototype.equals = function (otherQuaternion) {
  4516. return otherQuaternion && this.x === otherQuaternion.x && this.y === otherQuaternion.y && this.z === otherQuaternion.z && this.w === otherQuaternion.w;
  4517. };
  4518. /**
  4519. * Clone the current quaternion
  4520. * @returns a new quaternion copied from the current one
  4521. */
  4522. Quaternion.prototype.clone = function () {
  4523. return new Quaternion(this.x, this.y, this.z, this.w);
  4524. };
  4525. /**
  4526. * Copy a quaternion to the current one
  4527. * @param other defines the other quaternion
  4528. * @returns the updated current quaternion
  4529. */
  4530. Quaternion.prototype.copyFrom = function (other) {
  4531. this.x = other.x;
  4532. this.y = other.y;
  4533. this.z = other.z;
  4534. this.w = other.w;
  4535. return this;
  4536. };
  4537. /**
  4538. * Updates the current quaternion with the given float coordinates
  4539. * @param x defines the x coordinate
  4540. * @param y defines the y coordinate
  4541. * @param z defines the z coordinate
  4542. * @param w defines the w coordinate
  4543. * @returns the updated current quaternion
  4544. */
  4545. Quaternion.prototype.copyFromFloats = function (x, y, z, w) {
  4546. this.x = x;
  4547. this.y = y;
  4548. this.z = z;
  4549. this.w = w;
  4550. return this;
  4551. };
  4552. /**
  4553. * Updates the current quaternion from the given float coordinates
  4554. * @param x defines the x coordinate
  4555. * @param y defines the y coordinate
  4556. * @param z defines the z coordinate
  4557. * @param w defines the w coordinate
  4558. * @returns the updated current quaternion
  4559. */
  4560. Quaternion.prototype.set = function (x, y, z, w) {
  4561. return this.copyFromFloats(x, y, z, w);
  4562. };
  4563. /**
  4564. * Adds two quaternions
  4565. * @param other defines the second operand
  4566. * @returns a new quaternion as the addition result of the given one and the current quaternion
  4567. */
  4568. Quaternion.prototype.add = function (other) {
  4569. return new Quaternion(this.x + other.x, this.y + other.y, this.z + other.z, this.w + other.w);
  4570. };
  4571. /**
  4572. * Add a quaternion to the current one
  4573. * @param other defines the quaternion to add
  4574. * @returns the current quaternion
  4575. */
  4576. Quaternion.prototype.addInPlace = function (other) {
  4577. this.x += other.x;
  4578. this.y += other.y;
  4579. this.z += other.z;
  4580. this.w += other.w;
  4581. return this;
  4582. };
  4583. /**
  4584. * Subtract two quaternions
  4585. * @param other defines the second operand
  4586. * @returns a new quaternion as the subtraction result of the given one from the current one
  4587. */
  4588. Quaternion.prototype.subtract = function (other) {
  4589. return new Quaternion(this.x - other.x, this.y - other.y, this.z - other.z, this.w - other.w);
  4590. };
  4591. /**
  4592. * Multiplies the current quaternion by a scale factor
  4593. * @param value defines the scale factor
  4594. * @returns a new quaternion set by multiplying the current quaternion coordinates by the float "scale"
  4595. */
  4596. Quaternion.prototype.scale = function (value) {
  4597. return new Quaternion(this.x * value, this.y * value, this.z * value, this.w * value);
  4598. };
  4599. /**
  4600. * Scale the current quaternion values by a factor and stores the result to a given quaternion
  4601. * @param scale defines the scale factor
  4602. * @param result defines the Quaternion object where to store the result
  4603. * @returns the unmodified current quaternion
  4604. */
  4605. Quaternion.prototype.scaleToRef = function (scale, result) {
  4606. result.x = this.x * scale;
  4607. result.y = this.y * scale;
  4608. result.z = this.z * scale;
  4609. result.w = this.w * scale;
  4610. return this;
  4611. };
  4612. /**
  4613. * Multiplies in place the current quaternion by a scale factor
  4614. * @param value defines the scale factor
  4615. * @returns the current modified quaternion
  4616. */
  4617. Quaternion.prototype.scaleInPlace = function (value) {
  4618. this.x *= value;
  4619. this.y *= value;
  4620. this.z *= value;
  4621. this.w *= value;
  4622. return this;
  4623. };
  4624. /**
  4625. * Scale the current quaternion values by a factor and add the result to a given quaternion
  4626. * @param scale defines the scale factor
  4627. * @param result defines the Quaternion object where to store the result
  4628. * @returns the unmodified current quaternion
  4629. */
  4630. Quaternion.prototype.scaleAndAddToRef = function (scale, result) {
  4631. result.x += this.x * scale;
  4632. result.y += this.y * scale;
  4633. result.z += this.z * scale;
  4634. result.w += this.w * scale;
  4635. return this;
  4636. };
  4637. /**
  4638. * Multiplies two quaternions
  4639. * @param q1 defines the second operand
  4640. * @returns a new quaternion set as the multiplication result of the current one with the given one "q1"
  4641. */
  4642. Quaternion.prototype.multiply = function (q1) {
  4643. var result = new Quaternion(0, 0, 0, 1.0);
  4644. this.multiplyToRef(q1, result);
  4645. return result;
  4646. };
  4647. /**
  4648. * Sets the given "result" as the the multiplication result of the current one with the given one "q1"
  4649. * @param q1 defines the second operand
  4650. * @param result defines the target quaternion
  4651. * @returns the current quaternion
  4652. */
  4653. Quaternion.prototype.multiplyToRef = function (q1, result) {
  4654. var x = this.x * q1.w + this.y * q1.z - this.z * q1.y + this.w * q1.x;
  4655. var y = -this.x * q1.z + this.y * q1.w + this.z * q1.x + this.w * q1.y;
  4656. var z = this.x * q1.y - this.y * q1.x + this.z * q1.w + this.w * q1.z;
  4657. var w = -this.x * q1.x - this.y * q1.y - this.z * q1.z + this.w * q1.w;
  4658. result.copyFromFloats(x, y, z, w);
  4659. return this;
  4660. };
  4661. /**
  4662. * Updates the current quaternion with the multiplication of itself with the given one "q1"
  4663. * @param q1 defines the second operand
  4664. * @returns the currentupdated quaternion
  4665. */
  4666. Quaternion.prototype.multiplyInPlace = function (q1) {
  4667. this.multiplyToRef(q1, this);
  4668. return this;
  4669. };
  4670. /**
  4671. * Conjugates (1-q) the current quaternion and stores the result in the given quaternion
  4672. * @param ref defines the target quaternion
  4673. * @returns the current quaternion
  4674. */
  4675. Quaternion.prototype.conjugateToRef = function (ref) {
  4676. ref.copyFromFloats(-this.x, -this.y, -this.z, this.w);
  4677. return this;
  4678. };
  4679. /**
  4680. * Conjugates in place (1-q) the current quaternion
  4681. * @returns the current updated quaternion
  4682. */
  4683. Quaternion.prototype.conjugateInPlace = function () {
  4684. this.x *= -1;
  4685. this.y *= -1;
  4686. this.z *= -1;
  4687. return this;
  4688. };
  4689. /**
  4690. * Conjugates in place (1-q) the current quaternion
  4691. * @returns a new quaternion
  4692. */
  4693. Quaternion.prototype.conjugate = function () {
  4694. var result = new Quaternion(-this.x, -this.y, -this.z, this.w);
  4695. return result;
  4696. };
  4697. /**
  4698. * Gets length of current quaternion
  4699. * @returns the quaternion length (float)
  4700. */
  4701. Quaternion.prototype.length = function () {
  4702. return Math.sqrt((this.x * this.x) + (this.y * this.y) + (this.z * this.z) + (this.w * this.w));
  4703. };
  4704. /**
  4705. * Normalize in place the current quaternion
  4706. * @returns the current updated quaternion
  4707. */
  4708. Quaternion.prototype.normalize = function () {
  4709. var length = 1.0 / this.length();
  4710. this.x *= length;
  4711. this.y *= length;
  4712. this.z *= length;
  4713. this.w *= length;
  4714. return this;
  4715. };
  4716. /**
  4717. * Returns a new Vector3 set with the Euler angles translated from the current quaternion
  4718. * @param order is a reserved parameter and is ignore for now
  4719. * @returns a new Vector3 containing the Euler angles
  4720. */
  4721. Quaternion.prototype.toEulerAngles = function (order) {
  4722. if (order === void 0) { order = "YZX"; }
  4723. var result = Vector3.Zero();
  4724. this.toEulerAnglesToRef(result, order);
  4725. return result;
  4726. };
  4727. /**
  4728. * Sets the given vector3 "result" with the Euler angles translated from the current quaternion
  4729. * @param result defines the vector which will be filled with the Euler angles
  4730. * @param order is a reserved parameter and is ignore for now
  4731. * @returns the current unchanged quaternion
  4732. */
  4733. Quaternion.prototype.toEulerAnglesToRef = function (result, order) {
  4734. if (order === void 0) { order = "YZX"; }
  4735. var qz = this.z;
  4736. var qx = this.x;
  4737. var qy = this.y;
  4738. var qw = this.w;
  4739. var sqw = qw * qw;
  4740. var sqz = qz * qz;
  4741. var sqx = qx * qx;
  4742. var sqy = qy * qy;
  4743. var zAxisY = qy * qz - qx * qw;
  4744. var limit = .4999999;
  4745. if (zAxisY < -limit) {
  4746. result.y = 2 * Math.atan2(qy, qw);
  4747. result.x = Math.PI / 2;
  4748. result.z = 0;
  4749. }
  4750. else if (zAxisY > limit) {
  4751. result.y = 2 * Math.atan2(qy, qw);
  4752. result.x = -Math.PI / 2;
  4753. result.z = 0;
  4754. }
  4755. else {
  4756. result.z = Math.atan2(2.0 * (qx * qy + qz * qw), (-sqz - sqx + sqy + sqw));
  4757. result.x = Math.asin(-2.0 * (qz * qy - qx * qw));
  4758. result.y = Math.atan2(2.0 * (qz * qx + qy * qw), (sqz - sqx - sqy + sqw));
  4759. }
  4760. return this;
  4761. };
  4762. /**
  4763. * Updates the given rotation matrix with the current quaternion values
  4764. * @param result defines the target matrix
  4765. * @returns the current unchanged quaternion
  4766. */
  4767. Quaternion.prototype.toRotationMatrix = function (result) {
  4768. var xx = this.x * this.x;
  4769. var yy = this.y * this.y;
  4770. var zz = this.z * this.z;
  4771. var xy = this.x * this.y;
  4772. var zw = this.z * this.w;
  4773. var zx = this.z * this.x;
  4774. var yw = this.y * this.w;
  4775. var yz = this.y * this.z;
  4776. var xw = this.x * this.w;
  4777. result.m[0] = 1.0 - (2.0 * (yy + zz));
  4778. result.m[1] = 2.0 * (xy + zw);
  4779. result.m[2] = 2.0 * (zx - yw);
  4780. result.m[3] = 0;
  4781. result.m[4] = 2.0 * (xy - zw);
  4782. result.m[5] = 1.0 - (2.0 * (zz + xx));
  4783. result.m[6] = 2.0 * (yz + xw);
  4784. result.m[7] = 0;
  4785. result.m[8] = 2.0 * (zx + yw);
  4786. result.m[9] = 2.0 * (yz - xw);
  4787. result.m[10] = 1.0 - (2.0 * (yy + xx));
  4788. result.m[11] = 0;
  4789. result.m[12] = 0;
  4790. result.m[13] = 0;
  4791. result.m[14] = 0;
  4792. result.m[15] = 1.0;
  4793. result._markAsUpdated();
  4794. return this;
  4795. };
  4796. /**
  4797. * Updates the current quaternion from the given rotation matrix values
  4798. * @param matrix defines the source matrix
  4799. * @returns the current updated quaternion
  4800. */
  4801. Quaternion.prototype.fromRotationMatrix = function (matrix) {
  4802. Quaternion.FromRotationMatrixToRef(matrix, this);
  4803. return this;
  4804. };
  4805. // Statics
  4806. /**
  4807. * Creates a new quaternion from a rotation matrix
  4808. * @param matrix defines the source matrix
  4809. * @returns a new quaternion created from the given rotation matrix values
  4810. */
  4811. Quaternion.FromRotationMatrix = function (matrix) {
  4812. var result = new Quaternion();
  4813. Quaternion.FromRotationMatrixToRef(matrix, result);
  4814. return result;
  4815. };
  4816. /**
  4817. * Updates the given quaternion with the given rotation matrix values
  4818. * @param matrix defines the source matrix
  4819. * @param result defines the target quaternion
  4820. */
  4821. Quaternion.FromRotationMatrixToRef = function (matrix, result) {
  4822. var data = matrix.m;
  4823. var m11 = data[0], m12 = data[4], m13 = data[8];
  4824. var m21 = data[1], m22 = data[5], m23 = data[9];
  4825. var m31 = data[2], m32 = data[6], m33 = data[10];
  4826. var trace = m11 + m22 + m33;
  4827. var s;
  4828. if (trace > 0) {
  4829. s = 0.5 / Math.sqrt(trace + 1.0);
  4830. result.w = 0.25 / s;
  4831. result.x = (m32 - m23) * s;
  4832. result.y = (m13 - m31) * s;
  4833. result.z = (m21 - m12) * s;
  4834. }
  4835. else if (m11 > m22 && m11 > m33) {
  4836. s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  4837. result.w = (m32 - m23) / s;
  4838. result.x = 0.25 * s;
  4839. result.y = (m12 + m21) / s;
  4840. result.z = (m13 + m31) / s;
  4841. }
  4842. else if (m22 > m33) {
  4843. s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  4844. result.w = (m13 - m31) / s;
  4845. result.x = (m12 + m21) / s;
  4846. result.y = 0.25 * s;
  4847. result.z = (m23 + m32) / s;
  4848. }
  4849. else {
  4850. s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  4851. result.w = (m21 - m12) / s;
  4852. result.x = (m13 + m31) / s;
  4853. result.y = (m23 + m32) / s;
  4854. result.z = 0.25 * s;
  4855. }
  4856. };
  4857. /**
  4858. * Returns the dot product (float) between the quaternions "left" and "right"
  4859. * @param left defines the left operand
  4860. * @param right defines the right operand
  4861. * @returns the dot product
  4862. */
  4863. Quaternion.Dot = function (left, right) {
  4864. return (left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w);
  4865. };
  4866. /**
  4867. * Checks if the two quaternions are close to each other
  4868. * @param quat0 defines the first quaternion to check
  4869. * @param quat1 defines the second quaternion to check
  4870. * @returns true if the two quaternions are close to each other
  4871. */
  4872. Quaternion.AreClose = function (quat0, quat1) {
  4873. var dot = Quaternion.Dot(quat0, quat1);
  4874. return dot >= 0;
  4875. };
  4876. /**
  4877. * Creates an empty quaternion
  4878. * @returns a new quaternion set to (0.0, 0.0, 0.0)
  4879. */
  4880. Quaternion.Zero = function () {
  4881. return new Quaternion(0.0, 0.0, 0.0, 0.0);
  4882. };
  4883. /**
  4884. * Inverse a given quaternion
  4885. * @param q defines the source quaternion
  4886. * @returns a new quaternion as the inverted current quaternion
  4887. */
  4888. Quaternion.Inverse = function (q) {
  4889. return new Quaternion(-q.x, -q.y, -q.z, q.w);
  4890. };
  4891. /**
  4892. * Creates an identity quaternion
  4893. * @returns the identity quaternion
  4894. */
  4895. Quaternion.Identity = function () {
  4896. return new Quaternion(0.0, 0.0, 0.0, 1.0);
  4897. };
  4898. /**
  4899. * Gets a boolean indicating if the given quaternion is identity
  4900. * @param quaternion defines the quaternion to check
  4901. * @returns true if the quaternion is identity
  4902. */
  4903. Quaternion.IsIdentity = function (quaternion) {
  4904. return quaternion && quaternion.x === 0 && quaternion.y === 0 && quaternion.z === 0 && quaternion.w === 1;
  4905. };
  4906. /**
  4907. * Creates a quaternion from a rotation around an axis
  4908. * @param axis defines the axis to use
  4909. * @param angle defines the angle to use
  4910. * @returns a new quaternion created from the given axis (Vector3) and angle in radians (float)
  4911. */
  4912. Quaternion.RotationAxis = function (axis, angle) {
  4913. return Quaternion.RotationAxisToRef(axis, angle, new Quaternion());
  4914. };
  4915. /**
  4916. * Creates a rotation around an axis and stores it into the given quaternion
  4917. * @param axis defines the axis to use
  4918. * @param angle defines the angle to use
  4919. * @param result defines the target quaternion
  4920. * @returns the target quaternion
  4921. */
  4922. Quaternion.RotationAxisToRef = function (axis, angle, result) {
  4923. var sin = Math.sin(angle / 2);
  4924. axis.normalize();
  4925. result.w = Math.cos(angle / 2);
  4926. result.x = axis.x * sin;
  4927. result.y = axis.y * sin;
  4928. result.z = axis.z * sin;
  4929. return result;
  4930. };
  4931. /**
  4932. * Creates a new quaternion from data stored into an array
  4933. * @param array defines the data source
  4934. * @param offset defines the offset in the source array where the data starts
  4935. * @returns a new quaternion
  4936. */
  4937. Quaternion.FromArray = function (array, offset) {
  4938. if (!offset) {
  4939. offset = 0;
  4940. }
  4941. return new Quaternion(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);
  4942. };
  4943. /**
  4944. * Creates a new quaternion from the given Euler float angles (y, x, z)
  4945. * @param yaw defines the rotation around Y axis
  4946. * @param pitch defines the rotation around X axis
  4947. * @param roll defines the rotation around Z axis
  4948. * @returns the new quaternion
  4949. */
  4950. Quaternion.RotationYawPitchRoll = function (yaw, pitch, roll) {
  4951. var q = new Quaternion();
  4952. Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, q);
  4953. return q;
  4954. };
  4955. /**
  4956. * Creates a new rotation from the given Euler float angles (y, x, z) and stores it in the target quaternion
  4957. * @param yaw defines the rotation around Y axis
  4958. * @param pitch defines the rotation around X axis
  4959. * @param roll defines the rotation around Z axis
  4960. * @param result defines the target quaternion
  4961. */
  4962. Quaternion.RotationYawPitchRollToRef = function (yaw, pitch, roll, result) {
  4963. // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)
  4964. var halfRoll = roll * 0.5;
  4965. var halfPitch = pitch * 0.5;
  4966. var halfYaw = yaw * 0.5;
  4967. var sinRoll = Math.sin(halfRoll);
  4968. var cosRoll = Math.cos(halfRoll);
  4969. var sinPitch = Math.sin(halfPitch);
  4970. var cosPitch = Math.cos(halfPitch);
  4971. var sinYaw = Math.sin(halfYaw);
  4972. var cosYaw = Math.cos(halfYaw);
  4973. result.x = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
  4974. result.y = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);
  4975. result.z = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
  4976. result.w = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);
  4977. };
  4978. /**
  4979. * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation
  4980. * @param alpha defines the rotation around first axis
  4981. * @param beta defines the rotation around second axis
  4982. * @param gamma defines the rotation around third axis
  4983. * @returns the new quaternion
  4984. */
  4985. Quaternion.RotationAlphaBetaGamma = function (alpha, beta, gamma) {
  4986. var result = new Quaternion();
  4987. Quaternion.RotationAlphaBetaGammaToRef(alpha, beta, gamma, result);
  4988. return result;
  4989. };
  4990. /**
  4991. * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation and stores it in the target quaternion
  4992. * @param alpha defines the rotation around first axis
  4993. * @param beta defines the rotation around second axis
  4994. * @param gamma defines the rotation around third axis
  4995. * @param result defines the target quaternion
  4996. */
  4997. Quaternion.RotationAlphaBetaGammaToRef = function (alpha, beta, gamma, result) {
  4998. // Produces a quaternion from Euler angles in the z-x-z orientation
  4999. var halfGammaPlusAlpha = (gamma + alpha) * 0.5;
  5000. var halfGammaMinusAlpha = (gamma - alpha) * 0.5;
  5001. var halfBeta = beta * 0.5;
  5002. result.x = Math.cos(halfGammaMinusAlpha) * Math.sin(halfBeta);
  5003. result.y = Math.sin(halfGammaMinusAlpha) * Math.sin(halfBeta);
  5004. result.z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);
  5005. result.w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);
  5006. };
  5007. /**
  5008. * Creates a new quaternion containing the rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation)
  5009. * @param axis1 defines the first axis
  5010. * @param axis2 defines the second axis
  5011. * @param axis3 defines the third axis
  5012. * @returns the new quaternion
  5013. */
  5014. Quaternion.RotationQuaternionFromAxis = function (axis1, axis2, axis3) {
  5015. var quat = new Quaternion(0.0, 0.0, 0.0, 0.0);
  5016. Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);
  5017. return quat;
  5018. };
  5019. /**
  5020. * Creates a rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) and stores it in the target quaternion
  5021. * @param axis1 defines the first axis
  5022. * @param axis2 defines the second axis
  5023. * @param axis3 defines the third axis
  5024. * @param ref defines the target quaternion
  5025. */
  5026. Quaternion.RotationQuaternionFromAxisToRef = function (axis1, axis2, axis3, ref) {
  5027. var rotMat = MathTmp.Matrix[0];
  5028. Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);
  5029. Quaternion.FromRotationMatrixToRef(rotMat, ref);
  5030. };
  5031. /**
  5032. * Interpolates between two quaternions
  5033. * @param left defines first quaternion
  5034. * @param right defines second quaternion
  5035. * @param amount defines the gradient to use
  5036. * @returns the new interpolated quaternion
  5037. */
  5038. Quaternion.Slerp = function (left, right, amount) {
  5039. var result = Quaternion.Identity();
  5040. Quaternion.SlerpToRef(left, right, amount, result);
  5041. return result;
  5042. };
  5043. /**
  5044. * Interpolates between two quaternions and stores it into a target quaternion
  5045. * @param left defines first quaternion
  5046. * @param right defines second quaternion
  5047. * @param amount defines the gradient to use
  5048. * @param result defines the target quaternion
  5049. */
  5050. Quaternion.SlerpToRef = function (left, right, amount, result) {
  5051. var num2;
  5052. var num3;
  5053. var num4 = (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)) + (left.w * right.w);
  5054. var flag = false;
  5055. if (num4 < 0) {
  5056. flag = true;
  5057. num4 = -num4;
  5058. }
  5059. if (num4 > 0.999999) {
  5060. num3 = 1 - amount;
  5061. num2 = flag ? -amount : amount;
  5062. }
  5063. else {
  5064. var num5 = Math.acos(num4);
  5065. var num6 = (1.0 / Math.sin(num5));
  5066. num3 = (Math.sin((1.0 - amount) * num5)) * num6;
  5067. num2 = flag ? ((-Math.sin(amount * num5)) * num6) : ((Math.sin(amount * num5)) * num6);
  5068. }
  5069. result.x = (num3 * left.x) + (num2 * right.x);
  5070. result.y = (num3 * left.y) + (num2 * right.y);
  5071. result.z = (num3 * left.z) + (num2 * right.z);
  5072. result.w = (num3 * left.w) + (num2 * right.w);
  5073. };
  5074. /**
  5075. * Interpolate between two quaternions using Hermite interpolation
  5076. * @param value1 defines first quaternion
  5077. * @param tangent1 defines the incoming tangent
  5078. * @param value2 defines second quaternion
  5079. * @param tangent2 defines the outgoing tangent
  5080. * @param amount defines the target quaternion
  5081. * @returns the new interpolated quaternion
  5082. */
  5083. Quaternion.Hermite = function (value1, tangent1, value2, tangent2, amount) {
  5084. var squared = amount * amount;
  5085. var cubed = amount * squared;
  5086. var part1 = ((2.0 * cubed) - (3.0 * squared)) + 1.0;
  5087. var part2 = (-2.0 * cubed) + (3.0 * squared);
  5088. var part3 = (cubed - (2.0 * squared)) + amount;
  5089. var part4 = cubed - squared;
  5090. var x = (((value1.x * part1) + (value2.x * part2)) + (tangent1.x * part3)) + (tangent2.x * part4);
  5091. var y = (((value1.y * part1) + (value2.y * part2)) + (tangent1.y * part3)) + (tangent2.y * part4);
  5092. var z = (((value1.z * part1) + (value2.z * part2)) + (tangent1.z * part3)) + (tangent2.z * part4);
  5093. var w = (((value1.w * part1) + (value2.w * part2)) + (tangent1.w * part3)) + (tangent2.w * part4);
  5094. return new Quaternion(x, y, z, w);
  5095. };
  5096. return Quaternion;
  5097. }());
  5098. BABYLON.Quaternion = Quaternion;
  5099. /**
  5100. * Class used to store matrix data (4x4)
  5101. */
  5102. var Matrix = /** @class */ (function () {
  5103. /**
  5104. * Creates an empty matrix (filled with zeros)
  5105. */
  5106. function Matrix() {
  5107. this._isIdentity = false;
  5108. this._isIdentityDirty = true;
  5109. /**
  5110. * Gets or sets the internal data of the matrix
  5111. */
  5112. this.m = new Float32Array(16);
  5113. this._markAsUpdated();
  5114. }
  5115. /** @hidden */
  5116. Matrix.prototype._markAsUpdated = function () {
  5117. this.updateFlag = Matrix._updateFlagSeed++;
  5118. this._isIdentityDirty = true;
  5119. };
  5120. // Properties
  5121. /**
  5122. * Check if the current matrix is indentity
  5123. * @param considerAsTextureMatrix defines if the current matrix must be considered as a texture matrix (3x2)
  5124. * @returns true is the matrix is the identity matrix
  5125. */
  5126. Matrix.prototype.isIdentity = function (considerAsTextureMatrix) {
  5127. if (considerAsTextureMatrix === void 0) { considerAsTextureMatrix = false; }
  5128. if (this._isIdentityDirty) {
  5129. this._isIdentityDirty = false;
  5130. if (this.m[0] !== 1.0 || this.m[5] !== 1.0 || this.m[15] !== 1.0) {
  5131. this._isIdentity = false;
  5132. }
  5133. else if (this.m[1] !== 0.0 || this.m[2] !== 0.0 || this.m[3] !== 0.0 ||
  5134. this.m[4] !== 0.0 || this.m[6] !== 0.0 || this.m[7] !== 0.0 ||
  5135. this.m[8] !== 0.0 || this.m[9] !== 0.0 || this.m[11] !== 0.0 ||
  5136. this.m[12] !== 0.0 || this.m[13] !== 0.0 || this.m[14] !== 0.0) {
  5137. this._isIdentity = false;
  5138. }
  5139. else {
  5140. this._isIdentity = true;
  5141. }
  5142. if (!considerAsTextureMatrix && this.m[10] !== 1.0) {
  5143. this._isIdentity = false;
  5144. }
  5145. }
  5146. return this._isIdentity;
  5147. };
  5148. /**
  5149. * Gets the determinant of the matrix
  5150. * @returns the matrix determinant
  5151. */
  5152. Matrix.prototype.determinant = function () {
  5153. var temp1 = (this.m[10] * this.m[15]) - (this.m[11] * this.m[14]);
  5154. var temp2 = (this.m[9] * this.m[15]) - (this.m[11] * this.m[13]);
  5155. var temp3 = (this.m[9] * this.m[14]) - (this.m[10] * this.m[13]);
  5156. var temp4 = (this.m[8] * this.m[15]) - (this.m[11] * this.m[12]);
  5157. var temp5 = (this.m[8] * this.m[14]) - (this.m[10] * this.m[12]);
  5158. var temp6 = (this.m[8] * this.m[13]) - (this.m[9] * this.m[12]);
  5159. return ((((this.m[0] * (((this.m[5] * temp1) - (this.m[6] * temp2)) + (this.m[7] * temp3))) - (this.m[1] * (((this.m[4] * temp1) -
  5160. (this.m[6] * temp4)) + (this.m[7] * temp5)))) + (this.m[2] * (((this.m[4] * temp2) - (this.m[5] * temp4)) + (this.m[7] * temp6)))) -
  5161. (this.m[3] * (((this.m[4] * temp3) - (this.m[5] * temp5)) + (this.m[6] * temp6))));
  5162. };
  5163. // Methods
  5164. /**
  5165. * Returns the matrix as a Float32Array
  5166. * @returns the matrix underlying array
  5167. */
  5168. Matrix.prototype.toArray = function () {
  5169. return this.m;
  5170. };
  5171. /**
  5172. * Returns the matrix as a Float32Array
  5173. * @returns the matrix underlying array.
  5174. */
  5175. Matrix.prototype.asArray = function () {
  5176. return this.toArray();
  5177. };
  5178. /**
  5179. * Inverts the current matrix in place
  5180. * @returns the current inverted matrix
  5181. */
  5182. Matrix.prototype.invert = function () {
  5183. this.invertToRef(this);
  5184. return this;
  5185. };
  5186. /**
  5187. * Sets all the matrix elements to zero
  5188. * @returns the current matrix
  5189. */
  5190. Matrix.prototype.reset = function () {
  5191. for (var index = 0; index < 16; index++) {
  5192. this.m[index] = 0.0;
  5193. }
  5194. this._markAsUpdated();
  5195. return this;
  5196. };
  5197. /**
  5198. * Adds the current matrix with a second one
  5199. * @param other defines the matrix to add
  5200. * @returns a new matrix as the addition of the current matrix and the given one
  5201. */
  5202. Matrix.prototype.add = function (other) {
  5203. var result = new Matrix();
  5204. this.addToRef(other, result);
  5205. return result;
  5206. };
  5207. /**
  5208. * Sets the given matrix "result" to the addition of the current matrix and the given one
  5209. * @param other defines the matrix to add
  5210. * @param result defines the target matrix
  5211. * @returns the current matrix
  5212. */
  5213. Matrix.prototype.addToRef = function (other, result) {
  5214. for (var index = 0; index < 16; index++) {
  5215. result.m[index] = this.m[index] + other.m[index];
  5216. }
  5217. result._markAsUpdated();
  5218. return this;
  5219. };
  5220. /**
  5221. * Adds in place the given matrix to the current matrix
  5222. * @param other defines the second operand
  5223. * @returns the current updated matrix
  5224. */
  5225. Matrix.prototype.addToSelf = function (other) {
  5226. for (var index = 0; index < 16; index++) {
  5227. this.m[index] += other.m[index];
  5228. }
  5229. this._markAsUpdated();
  5230. return this;
  5231. };
  5232. /**
  5233. * Sets the given matrix to the current inverted Matrix
  5234. * @param other defines the target matrix
  5235. * @returns the unmodified current matrix
  5236. */
  5237. Matrix.prototype.invertToRef = function (other) {
  5238. var l1 = this.m[0];
  5239. var l2 = this.m[1];
  5240. var l3 = this.m[2];
  5241. var l4 = this.m[3];
  5242. var l5 = this.m[4];
  5243. var l6 = this.m[5];
  5244. var l7 = this.m[6];
  5245. var l8 = this.m[7];
  5246. var l9 = this.m[8];
  5247. var l10 = this.m[9];
  5248. var l11 = this.m[10];
  5249. var l12 = this.m[11];
  5250. var l13 = this.m[12];
  5251. var l14 = this.m[13];
  5252. var l15 = this.m[14];
  5253. var l16 = this.m[15];
  5254. var l17 = (l11 * l16) - (l12 * l15);
  5255. var l18 = (l10 * l16) - (l12 * l14);
  5256. var l19 = (l10 * l15) - (l11 * l14);
  5257. var l20 = (l9 * l16) - (l12 * l13);
  5258. var l21 = (l9 * l15) - (l11 * l13);
  5259. var l22 = (l9 * l14) - (l10 * l13);
  5260. var l23 = ((l6 * l17) - (l7 * l18)) + (l8 * l19);
  5261. var l24 = -(((l5 * l17) - (l7 * l20)) + (l8 * l21));
  5262. var l25 = ((l5 * l18) - (l6 * l20)) + (l8 * l22);
  5263. var l26 = -(((l5 * l19) - (l6 * l21)) + (l7 * l22));
  5264. var l27 = 1.0 / ((((l1 * l23) + (l2 * l24)) + (l3 * l25)) + (l4 * l26));
  5265. var l28 = (l7 * l16) - (l8 * l15);
  5266. var l29 = (l6 * l16) - (l8 * l14);
  5267. var l30 = (l6 * l15) - (l7 * l14);
  5268. var l31 = (l5 * l16) - (l8 * l13);
  5269. var l32 = (l5 * l15) - (l7 * l13);
  5270. var l33 = (l5 * l14) - (l6 * l13);
  5271. var l34 = (l7 * l12) - (l8 * l11);
  5272. var l35 = (l6 * l12) - (l8 * l10);
  5273. var l36 = (l6 * l11) - (l7 * l10);
  5274. var l37 = (l5 * l12) - (l8 * l9);
  5275. var l38 = (l5 * l11) - (l7 * l9);
  5276. var l39 = (l5 * l10) - (l6 * l9);
  5277. other.m[0] = l23 * l27;
  5278. other.m[4] = l24 * l27;
  5279. other.m[8] = l25 * l27;
  5280. other.m[12] = l26 * l27;
  5281. other.m[1] = -(((l2 * l17) - (l3 * l18)) + (l4 * l19)) * l27;
  5282. other.m[5] = (((l1 * l17) - (l3 * l20)) + (l4 * l21)) * l27;
  5283. other.m[9] = -(((l1 * l18) - (l2 * l20)) + (l4 * l22)) * l27;
  5284. other.m[13] = (((l1 * l19) - (l2 * l21)) + (l3 * l22)) * l27;
  5285. other.m[2] = (((l2 * l28) - (l3 * l29)) + (l4 * l30)) * l27;
  5286. other.m[6] = -(((l1 * l28) - (l3 * l31)) + (l4 * l32)) * l27;
  5287. other.m[10] = (((l1 * l29) - (l2 * l31)) + (l4 * l33)) * l27;
  5288. other.m[14] = -(((l1 * l30) - (l2 * l32)) + (l3 * l33)) * l27;
  5289. other.m[3] = -(((l2 * l34) - (l3 * l35)) + (l4 * l36)) * l27;
  5290. other.m[7] = (((l1 * l34) - (l3 * l37)) + (l4 * l38)) * l27;
  5291. other.m[11] = -(((l1 * l35) - (l2 * l37)) + (l4 * l39)) * l27;
  5292. other.m[15] = (((l1 * l36) - (l2 * l38)) + (l3 * l39)) * l27;
  5293. other._markAsUpdated();
  5294. return this;
  5295. };
  5296. /**
  5297. * Inserts the translation vector (using 3 floats) in the current matrix
  5298. * @param x defines the 1st component of the translation
  5299. * @param y defines the 2nd component of the translation
  5300. * @param z defines the 3rd component of the translation
  5301. * @returns the current updated matrix
  5302. */
  5303. Matrix.prototype.setTranslationFromFloats = function (x, y, z) {
  5304. this.m[12] = x;
  5305. this.m[13] = y;
  5306. this.m[14] = z;
  5307. this._markAsUpdated();
  5308. return this;
  5309. };
  5310. /**
  5311. * Inserts the translation vector in the current matrix
  5312. * @param vector3 defines the translation to insert
  5313. * @returns the current updated matrix
  5314. */
  5315. Matrix.prototype.setTranslation = function (vector3) {
  5316. this.m[12] = vector3.x;
  5317. this.m[13] = vector3.y;
  5318. this.m[14] = vector3.z;
  5319. this._markAsUpdated();
  5320. return this;
  5321. };
  5322. /**
  5323. * Gets the translation value of the current matrix
  5324. * @returns a new Vector3 as the extracted translation from the matrix
  5325. */
  5326. Matrix.prototype.getTranslation = function () {
  5327. return new Vector3(this.m[12], this.m[13], this.m[14]);
  5328. };
  5329. /**
  5330. * Fill a Vector3 with the extracted translation from the matrix
  5331. * @param result defines the Vector3 where to store the translation
  5332. * @returns the current matrix
  5333. */
  5334. Matrix.prototype.getTranslationToRef = function (result) {
  5335. result.x = this.m[12];
  5336. result.y = this.m[13];
  5337. result.z = this.m[14];
  5338. return this;
  5339. };
  5340. /**
  5341. * Remove rotation and scaling part from the matrix
  5342. * @returns the updated matrix
  5343. */
  5344. Matrix.prototype.removeRotationAndScaling = function () {
  5345. this.setRowFromFloats(0, 1, 0, 0, 0);
  5346. this.setRowFromFloats(1, 0, 1, 0, 0);
  5347. this.setRowFromFloats(2, 0, 0, 1, 0);
  5348. return this;
  5349. };
  5350. /**
  5351. * Multiply two matrices
  5352. * @param other defines the second operand
  5353. * @returns a new matrix set with the multiplication result of the current Matrix and the given one
  5354. */
  5355. Matrix.prototype.multiply = function (other) {
  5356. var result = new Matrix();
  5357. this.multiplyToRef(other, result);
  5358. return result;
  5359. };
  5360. /**
  5361. * Copy the current matrix from the given one
  5362. * @param other defines the source matrix
  5363. * @returns the current updated matrix
  5364. */
  5365. Matrix.prototype.copyFrom = function (other) {
  5366. for (var index = 0; index < 16; index++) {
  5367. this.m[index] = other.m[index];
  5368. }
  5369. this._markAsUpdated();
  5370. return this;
  5371. };
  5372. /**
  5373. * Populates the given array from the starting index with the current matrix values
  5374. * @param array defines the target array
  5375. * @param offset defines the offset in the target array where to start storing values
  5376. * @returns the current matrix
  5377. */
  5378. Matrix.prototype.copyToArray = function (array, offset) {
  5379. if (offset === void 0) { offset = 0; }
  5380. for (var index = 0; index < 16; index++) {
  5381. array[offset + index] = this.m[index];
  5382. }
  5383. return this;
  5384. };
  5385. /**
  5386. * Sets the given matrix "result" with the multiplication result of the current Matrix and the given one
  5387. * @param other defines the second operand
  5388. * @param result defines the matrix where to store the multiplication
  5389. * @returns the current matrix
  5390. */
  5391. Matrix.prototype.multiplyToRef = function (other, result) {
  5392. this.multiplyToArray(other, result.m, 0);
  5393. result._markAsUpdated();
  5394. return this;
  5395. };
  5396. /**
  5397. * Sets the Float32Array "result" from the given index "offset" with the multiplication of the current matrix and the given one
  5398. * @param other defines the second operand
  5399. * @param result defines the array where to store the multiplication
  5400. * @param offset defines the offset in the target array where to start storing values
  5401. * @returns the current matrix
  5402. */
  5403. Matrix.prototype.multiplyToArray = function (other, result, offset) {
  5404. var tm0 = this.m[0];
  5405. var tm1 = this.m[1];
  5406. var tm2 = this.m[2];
  5407. var tm3 = this.m[3];
  5408. var tm4 = this.m[4];
  5409. var tm5 = this.m[5];
  5410. var tm6 = this.m[6];
  5411. var tm7 = this.m[7];
  5412. var tm8 = this.m[8];
  5413. var tm9 = this.m[9];
  5414. var tm10 = this.m[10];
  5415. var tm11 = this.m[11];
  5416. var tm12 = this.m[12];
  5417. var tm13 = this.m[13];
  5418. var tm14 = this.m[14];
  5419. var tm15 = this.m[15];
  5420. var om0 = other.m[0];
  5421. var om1 = other.m[1];
  5422. var om2 = other.m[2];
  5423. var om3 = other.m[3];
  5424. var om4 = other.m[4];
  5425. var om5 = other.m[5];
  5426. var om6 = other.m[6];
  5427. var om7 = other.m[7];
  5428. var om8 = other.m[8];
  5429. var om9 = other.m[9];
  5430. var om10 = other.m[10];
  5431. var om11 = other.m[11];
  5432. var om12 = other.m[12];
  5433. var om13 = other.m[13];
  5434. var om14 = other.m[14];
  5435. var om15 = other.m[15];
  5436. result[offset] = tm0 * om0 + tm1 * om4 + tm2 * om8 + tm3 * om12;
  5437. result[offset + 1] = tm0 * om1 + tm1 * om5 + tm2 * om9 + tm3 * om13;
  5438. result[offset + 2] = tm0 * om2 + tm1 * om6 + tm2 * om10 + tm3 * om14;
  5439. result[offset + 3] = tm0 * om3 + tm1 * om7 + tm2 * om11 + tm3 * om15;
  5440. result[offset + 4] = tm4 * om0 + tm5 * om4 + tm6 * om8 + tm7 * om12;
  5441. result[offset + 5] = tm4 * om1 + tm5 * om5 + tm6 * om9 + tm7 * om13;
  5442. result[offset + 6] = tm4 * om2 + tm5 * om6 + tm6 * om10 + tm7 * om14;
  5443. result[offset + 7] = tm4 * om3 + tm5 * om7 + tm6 * om11 + tm7 * om15;
  5444. result[offset + 8] = tm8 * om0 + tm9 * om4 + tm10 * om8 + tm11 * om12;
  5445. result[offset + 9] = tm8 * om1 + tm9 * om5 + tm10 * om9 + tm11 * om13;
  5446. result[offset + 10] = tm8 * om2 + tm9 * om6 + tm10 * om10 + tm11 * om14;
  5447. result[offset + 11] = tm8 * om3 + tm9 * om7 + tm10 * om11 + tm11 * om15;
  5448. result[offset + 12] = tm12 * om0 + tm13 * om4 + tm14 * om8 + tm15 * om12;
  5449. result[offset + 13] = tm12 * om1 + tm13 * om5 + tm14 * om9 + tm15 * om13;
  5450. result[offset + 14] = tm12 * om2 + tm13 * om6 + tm14 * om10 + tm15 * om14;
  5451. result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;
  5452. return this;
  5453. };
  5454. /**
  5455. * Check equality between this matrix and a second one
  5456. * @param value defines the second matrix to compare
  5457. * @returns true is the current matrix and the given one values are strictly equal
  5458. */
  5459. Matrix.prototype.equals = function (value) {
  5460. return value &&
  5461. (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] &&
  5462. this.m[4] === value.m[4] && this.m[5] === value.m[5] && this.m[6] === value.m[6] && this.m[7] === value.m[7] &&
  5463. this.m[8] === value.m[8] && this.m[9] === value.m[9] && this.m[10] === value.m[10] && this.m[11] === value.m[11] &&
  5464. this.m[12] === value.m[12] && this.m[13] === value.m[13] && this.m[14] === value.m[14] && this.m[15] === value.m[15]);
  5465. };
  5466. /**
  5467. * Clone the current matrix
  5468. * @returns a new matrix from the current matrix
  5469. */
  5470. Matrix.prototype.clone = function () {
  5471. return Matrix.FromValues(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5], this.m[6], this.m[7], this.m[8], this.m[9], this.m[10], this.m[11], this.m[12], this.m[13], this.m[14], this.m[15]);
  5472. };
  5473. /**
  5474. * Returns the name of the current matrix class
  5475. * @returns the string "Matrix"
  5476. */
  5477. Matrix.prototype.getClassName = function () {
  5478. return "Matrix";
  5479. };
  5480. /**
  5481. * Gets the hash code of the current matrix
  5482. * @returns the hash code
  5483. */
  5484. Matrix.prototype.getHashCode = function () {
  5485. var hash = this.m[0] || 0;
  5486. for (var i = 1; i < 16; i++) {
  5487. hash = (hash * 397) ^ (this.m[i] || 0);
  5488. }
  5489. return hash;
  5490. };
  5491. /**
  5492. * Decomposes the current Matrix into a translation, rotation and scaling components
  5493. * @param scale defines the scale vector3 given as a reference to update
  5494. * @param rotation defines the rotation quaternion given as a reference to update
  5495. * @param translation defines the translation vector3 given as a reference to update
  5496. * @returns true if operation was successful
  5497. */
  5498. Matrix.prototype.decompose = function (scale, rotation, translation) {
  5499. if (translation) {
  5500. translation.x = this.m[12];
  5501. translation.y = this.m[13];
  5502. translation.z = this.m[14];
  5503. }
  5504. scale = scale || MathTmp.Vector3[0];
  5505. scale.x = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1] + this.m[2] * this.m[2]);
  5506. scale.y = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5] + this.m[6] * this.m[6]);
  5507. scale.z = Math.sqrt(this.m[8] * this.m[8] + this.m[9] * this.m[9] + this.m[10] * this.m[10]);
  5508. if (this.determinant() <= 0) {
  5509. scale.y *= -1;
  5510. }
  5511. if (scale.x === 0 || scale.y === 0 || scale.z === 0) {
  5512. if (rotation) {
  5513. rotation.x = 0;
  5514. rotation.y = 0;
  5515. rotation.z = 0;
  5516. rotation.w = 1;
  5517. }
  5518. return false;
  5519. }
  5520. if (rotation) {
  5521. Matrix.FromValuesToRef(this.m[0] / scale.x, this.m[1] / scale.x, this.m[2] / scale.x, 0, this.m[4] / scale.y, this.m[5] / scale.y, this.m[6] / scale.y, 0, this.m[8] / scale.z, this.m[9] / scale.z, this.m[10] / scale.z, 0, 0, 0, 0, 1, MathTmp.Matrix[0]);
  5522. Quaternion.FromRotationMatrixToRef(MathTmp.Matrix[0], rotation);
  5523. }
  5524. return true;
  5525. };
  5526. /**
  5527. * Gets specific row of the matrix
  5528. * @param index defines the number of the row to get
  5529. * @returns the index-th row of the current matrix as a new Vector4
  5530. */
  5531. Matrix.prototype.getRow = function (index) {
  5532. if (index < 0 || index > 3) {
  5533. return null;
  5534. }
  5535. var i = index * 4;
  5536. return new Vector4(this.m[i + 0], this.m[i + 1], this.m[i + 2], this.m[i + 3]);
  5537. };
  5538. /**
  5539. * Sets the index-th row of the current matrix to the vector4 values
  5540. * @param index defines the number of the row to set
  5541. * @param row defines the target vector4
  5542. * @returns the updated current matrix
  5543. */
  5544. Matrix.prototype.setRow = function (index, row) {
  5545. if (index < 0 || index > 3) {
  5546. return this;
  5547. }
  5548. var i = index * 4;
  5549. this.m[i + 0] = row.x;
  5550. this.m[i + 1] = row.y;
  5551. this.m[i + 2] = row.z;
  5552. this.m[i + 3] = row.w;
  5553. this._markAsUpdated();
  5554. return this;
  5555. };
  5556. /**
  5557. * Compute the transpose of the matrix
  5558. * @returns the new transposed matrix
  5559. */
  5560. Matrix.prototype.transpose = function () {
  5561. return Matrix.Transpose(this);
  5562. };
  5563. /**
  5564. * Compute the transpose of the matrix and store it in a given matrix
  5565. * @param result defines the target matrix
  5566. * @returns the current matrix
  5567. */
  5568. Matrix.prototype.transposeToRef = function (result) {
  5569. Matrix.TransposeToRef(this, result);
  5570. return this;
  5571. };
  5572. /**
  5573. * Sets the index-th row of the current matrix with the given 4 x float values
  5574. * @param index defines the row index
  5575. * @param x defines the x component to set
  5576. * @param y defines the y component to set
  5577. * @param z defines the z component to set
  5578. * @param w defines the w component to set
  5579. * @returns the updated current matrix
  5580. */
  5581. Matrix.prototype.setRowFromFloats = function (index, x, y, z, w) {
  5582. if (index < 0 || index > 3) {
  5583. return this;
  5584. }
  5585. var i = index * 4;
  5586. this.m[i + 0] = x;
  5587. this.m[i + 1] = y;
  5588. this.m[i + 2] = z;
  5589. this.m[i + 3] = w;
  5590. this._markAsUpdated();
  5591. return this;
  5592. };
  5593. /**
  5594. * Compute a new matrix set with the current matrix values multiplied by scale (float)
  5595. * @param scale defines the scale factor
  5596. * @returns a new matrix
  5597. */
  5598. Matrix.prototype.scale = function (scale) {
  5599. var result = new Matrix();
  5600. this.scaleToRef(scale, result);
  5601. return result;
  5602. };
  5603. /**
  5604. * Scale the current matrix values by a factor to a given result matrix
  5605. * @param scale defines the scale factor
  5606. * @param result defines the matrix to store the result
  5607. * @returns the current matrix
  5608. */
  5609. Matrix.prototype.scaleToRef = function (scale, result) {
  5610. for (var index = 0; index < 16; index++) {
  5611. result.m[index] = this.m[index] * scale;
  5612. }
  5613. result._markAsUpdated();
  5614. return this;
  5615. };
  5616. /**
  5617. * Scale the current matrix values by a factor and add the result to a given matrix
  5618. * @param scale defines the scale factor
  5619. * @param result defines the Matrix to store the result
  5620. * @returns the current matrix
  5621. */
  5622. Matrix.prototype.scaleAndAddToRef = function (scale, result) {
  5623. for (var index = 0; index < 16; index++) {
  5624. result.m[index] += this.m[index] * scale;
  5625. }
  5626. result._markAsUpdated();
  5627. return this;
  5628. };
  5629. /**
  5630. * Writes to the given matrix a normal matrix, computed from this one (using values from identity matrix for fourth row and column).
  5631. * @param ref matrix to store the result
  5632. */
  5633. Matrix.prototype.toNormalMatrix = function (ref) {
  5634. this.invertToRef(ref);
  5635. ref.transpose();
  5636. var m = ref.m;
  5637. Matrix.FromValuesToRef(m[0], m[1], m[2], 0, m[4], m[5], m[6], 0, m[8], m[9], m[10], 0, 0, 0, 0, 1, ref);
  5638. };
  5639. /**
  5640. * Gets only rotation part of the current matrix
  5641. * @returns a new matrix sets to the extracted rotation matrix from the current one
  5642. */
  5643. Matrix.prototype.getRotationMatrix = function () {
  5644. var result = Matrix.Identity();
  5645. this.getRotationMatrixToRef(result);
  5646. return result;
  5647. };
  5648. /**
  5649. * Extracts the rotation matrix from the current one and sets it as the given "result"
  5650. * @param result defines the target matrix to store data to
  5651. * @returns the current matrix
  5652. */
  5653. Matrix.prototype.getRotationMatrixToRef = function (result) {
  5654. var m = this.m;
  5655. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]);
  5656. var sy = Math.sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]);
  5657. var sz = Math.sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]);
  5658. if (this.determinant() <= 0) {
  5659. sy *= -1;
  5660. }
  5661. if (sx === 0 || sy === 0 || sz === 0) {
  5662. Matrix.IdentityToRef(result);
  5663. }
  5664. else {
  5665. Matrix.FromValuesToRef(m[0] / sx, m[1] / sx, m[2] / sx, 0, m[4] / sy, m[5] / sy, m[6] / sy, 0, m[8] / sz, m[9] / sz, m[10] / sz, 0, 0, 0, 0, 1, result);
  5666. }
  5667. return this;
  5668. };
  5669. // Statics
  5670. /**
  5671. * Creates a matrix from an array
  5672. * @param array defines the source array
  5673. * @param offset defines an offset in the source array
  5674. * @returns a new Matrix set from the starting index of the given array
  5675. */
  5676. Matrix.FromArray = function (array, offset) {
  5677. var result = new Matrix();
  5678. if (!offset) {
  5679. offset = 0;
  5680. }
  5681. Matrix.FromArrayToRef(array, offset, result);
  5682. return result;
  5683. };
  5684. /**
  5685. * Copy the content of an array into a given matrix
  5686. * @param array defines the source array
  5687. * @param offset defines an offset in the source array
  5688. * @param result defines the target matrix
  5689. */
  5690. Matrix.FromArrayToRef = function (array, offset, result) {
  5691. for (var index = 0; index < 16; index++) {
  5692. result.m[index] = array[index + offset];
  5693. }
  5694. result._markAsUpdated();
  5695. };
  5696. /**
  5697. * Stores an array into a matrix after having multiplied each component by a given factor
  5698. * @param array defines the source array
  5699. * @param offset defines the offset in the source array
  5700. * @param scale defines the scaling factor
  5701. * @param result defines the target matrix
  5702. */
  5703. Matrix.FromFloat32ArrayToRefScaled = function (array, offset, scale, result) {
  5704. for (var index = 0; index < 16; index++) {
  5705. result.m[index] = array[index + offset] * scale;
  5706. }
  5707. result._markAsUpdated();
  5708. };
  5709. /**
  5710. * Stores a list of values (16) inside a given matrix
  5711. * @param initialM11 defines 1st value of 1st row
  5712. * @param initialM12 defines 2nd value of 1st row
  5713. * @param initialM13 defines 3rd value of 1st row
  5714. * @param initialM14 defines 4th value of 1st row
  5715. * @param initialM21 defines 1st value of 2nd row
  5716. * @param initialM22 defines 2nd value of 2nd row
  5717. * @param initialM23 defines 3rd value of 2nd row
  5718. * @param initialM24 defines 4th value of 2nd row
  5719. * @param initialM31 defines 1st value of 3rd row
  5720. * @param initialM32 defines 2nd value of 3rd row
  5721. * @param initialM33 defines 3rd value of 3rd row
  5722. * @param initialM34 defines 4th value of 3rd row
  5723. * @param initialM41 defines 1st value of 4th row
  5724. * @param initialM42 defines 2nd value of 4th row
  5725. * @param initialM43 defines 3rd value of 4th row
  5726. * @param initialM44 defines 4th value of 4th row
  5727. * @param result defines the target matrix
  5728. */
  5729. Matrix.FromValuesToRef = function (initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44, result) {
  5730. result.m[0] = initialM11;
  5731. result.m[1] = initialM12;
  5732. result.m[2] = initialM13;
  5733. result.m[3] = initialM14;
  5734. result.m[4] = initialM21;
  5735. result.m[5] = initialM22;
  5736. result.m[6] = initialM23;
  5737. result.m[7] = initialM24;
  5738. result.m[8] = initialM31;
  5739. result.m[9] = initialM32;
  5740. result.m[10] = initialM33;
  5741. result.m[11] = initialM34;
  5742. result.m[12] = initialM41;
  5743. result.m[13] = initialM42;
  5744. result.m[14] = initialM43;
  5745. result.m[15] = initialM44;
  5746. result._markAsUpdated();
  5747. };
  5748. Object.defineProperty(Matrix, "IdentityReadOnly", {
  5749. /**
  5750. * Gets an identity matrix that must not be updated
  5751. */
  5752. get: function () {
  5753. return Matrix._identityReadOnly;
  5754. },
  5755. enumerable: true,
  5756. configurable: true
  5757. });
  5758. /**
  5759. * Creates new matrix from a list of values (16)
  5760. * @param initialM11 defines 1st value of 1st row
  5761. * @param initialM12 defines 2nd value of 1st row
  5762. * @param initialM13 defines 3rd value of 1st row
  5763. * @param initialM14 defines 4th value of 1st row
  5764. * @param initialM21 defines 1st value of 2nd row
  5765. * @param initialM22 defines 2nd value of 2nd row
  5766. * @param initialM23 defines 3rd value of 2nd row
  5767. * @param initialM24 defines 4th value of 2nd row
  5768. * @param initialM31 defines 1st value of 3rd row
  5769. * @param initialM32 defines 2nd value of 3rd row
  5770. * @param initialM33 defines 3rd value of 3rd row
  5771. * @param initialM34 defines 4th value of 3rd row
  5772. * @param initialM41 defines 1st value of 4th row
  5773. * @param initialM42 defines 2nd value of 4th row
  5774. * @param initialM43 defines 3rd value of 4th row
  5775. * @param initialM44 defines 4th value of 4th row
  5776. * @returns the new matrix
  5777. */
  5778. Matrix.FromValues = function (initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44) {
  5779. var result = new Matrix();
  5780. result.m[0] = initialM11;
  5781. result.m[1] = initialM12;
  5782. result.m[2] = initialM13;
  5783. result.m[3] = initialM14;
  5784. result.m[4] = initialM21;
  5785. result.m[5] = initialM22;
  5786. result.m[6] = initialM23;
  5787. result.m[7] = initialM24;
  5788. result.m[8] = initialM31;
  5789. result.m[9] = initialM32;
  5790. result.m[10] = initialM33;
  5791. result.m[11] = initialM34;
  5792. result.m[12] = initialM41;
  5793. result.m[13] = initialM42;
  5794. result.m[14] = initialM43;
  5795. result.m[15] = initialM44;
  5796. return result;
  5797. };
  5798. /**
  5799. * Creates a new matrix composed by merging scale (vector3), rotation (quaternion) and translation (vector3)
  5800. * @param scale defines the scale vector3
  5801. * @param rotation defines the rotation quaternion
  5802. * @param translation defines the translation vector3
  5803. * @returns a new matrix
  5804. */
  5805. Matrix.Compose = function (scale, rotation, translation) {
  5806. var result = Matrix.Identity();
  5807. Matrix.ComposeToRef(scale, rotation, translation, result);
  5808. return result;
  5809. };
  5810. /**
  5811. * Sets a matrix to a value composed by merging scale (vector3), rotation (quaternion) and translation (vector3)
  5812. * @param scale defines the scale vector3
  5813. * @param rotation defines the rotation quaternion
  5814. * @param translation defines the translation vector3
  5815. * @param result defines the target matrix
  5816. */
  5817. Matrix.ComposeToRef = function (scale, rotation, translation, result) {
  5818. Matrix.FromValuesToRef(scale.x, 0, 0, 0, 0, scale.y, 0, 0, 0, 0, scale.z, 0, 0, 0, 0, 1, MathTmp.Matrix[1]);
  5819. rotation.toRotationMatrix(MathTmp.Matrix[0]);
  5820. MathTmp.Matrix[1].multiplyToRef(MathTmp.Matrix[0], result);
  5821. result.setTranslation(translation);
  5822. };
  5823. /**
  5824. * Creates a new identity matrix
  5825. * @returns a new identity matrix
  5826. */
  5827. Matrix.Identity = function () {
  5828. return Matrix.FromValues(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
  5829. };
  5830. /**
  5831. * Creates a new identity matrix and stores the result in a given matrix
  5832. * @param result defines the target matrix
  5833. */
  5834. Matrix.IdentityToRef = function (result) {
  5835. Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);
  5836. };
  5837. /**
  5838. * Creates a new zero matrix
  5839. * @returns a new zero matrix
  5840. */
  5841. Matrix.Zero = function () {
  5842. return Matrix.FromValues(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  5843. };
  5844. /**
  5845. * Creates a new rotation matrix for "angle" radians around the X axis
  5846. * @param angle defines the angle (in radians) to use
  5847. * @return the new matrix
  5848. */
  5849. Matrix.RotationX = function (angle) {
  5850. var result = new Matrix();
  5851. Matrix.RotationXToRef(angle, result);
  5852. return result;
  5853. };
  5854. /**
  5855. * Creates a new matrix as the invert of a given matrix
  5856. * @param source defines the source matrix
  5857. * @returns the new matrix
  5858. */
  5859. Matrix.Invert = function (source) {
  5860. var result = new Matrix();
  5861. source.invertToRef(result);
  5862. return result;
  5863. };
  5864. /**
  5865. * Creates a new rotation matrix for "angle" radians around the X axis and stores it in a given matrix
  5866. * @param angle defines the angle (in radians) to use
  5867. * @param result defines the target matrix
  5868. */
  5869. Matrix.RotationXToRef = function (angle, result) {
  5870. var s = Math.sin(angle);
  5871. var c = Math.cos(angle);
  5872. result.m[0] = 1.0;
  5873. result.m[15] = 1.0;
  5874. result.m[5] = c;
  5875. result.m[10] = c;
  5876. result.m[9] = -s;
  5877. result.m[6] = s;
  5878. result.m[1] = 0.0;
  5879. result.m[2] = 0.0;
  5880. result.m[3] = 0.0;
  5881. result.m[4] = 0.0;
  5882. result.m[7] = 0.0;
  5883. result.m[8] = 0.0;
  5884. result.m[11] = 0.0;
  5885. result.m[12] = 0.0;
  5886. result.m[13] = 0.0;
  5887. result.m[14] = 0.0;
  5888. result._markAsUpdated();
  5889. };
  5890. /**
  5891. * Creates a new rotation matrix for "angle" radians around the Y axis
  5892. * @param angle defines the angle (in radians) to use
  5893. * @return the new matrix
  5894. */
  5895. Matrix.RotationY = function (angle) {
  5896. var result = new Matrix();
  5897. Matrix.RotationYToRef(angle, result);
  5898. return result;
  5899. };
  5900. /**
  5901. * Creates a new rotation matrix for "angle" radians around the Y axis and stores it in a given matrix
  5902. * @param angle defines the angle (in radians) to use
  5903. * @param result defines the target matrix
  5904. */
  5905. Matrix.RotationYToRef = function (angle, result) {
  5906. var s = Math.sin(angle);
  5907. var c = Math.cos(angle);
  5908. result.m[5] = 1.0;
  5909. result.m[15] = 1.0;
  5910. result.m[0] = c;
  5911. result.m[2] = -s;
  5912. result.m[8] = s;
  5913. result.m[10] = c;
  5914. result.m[1] = 0.0;
  5915. result.m[3] = 0.0;
  5916. result.m[4] = 0.0;
  5917. result.m[6] = 0.0;
  5918. result.m[7] = 0.0;
  5919. result.m[9] = 0.0;
  5920. result.m[11] = 0.0;
  5921. result.m[12] = 0.0;
  5922. result.m[13] = 0.0;
  5923. result.m[14] = 0.0;
  5924. result._markAsUpdated();
  5925. };
  5926. /**
  5927. * Creates a new rotation matrix for "angle" radians around the Z axis
  5928. * @param angle defines the angle (in radians) to use
  5929. * @return the new matrix
  5930. */
  5931. Matrix.RotationZ = function (angle) {
  5932. var result = new Matrix();
  5933. Matrix.RotationZToRef(angle, result);
  5934. return result;
  5935. };
  5936. /**
  5937. * Creates a new rotation matrix for "angle" radians around the Z axis and stores it in a given matrix
  5938. * @param angle defines the angle (in radians) to use
  5939. * @param result defines the target matrix
  5940. */
  5941. Matrix.RotationZToRef = function (angle, result) {
  5942. var s = Math.sin(angle);
  5943. var c = Math.cos(angle);
  5944. result.m[10] = 1.0;
  5945. result.m[15] = 1.0;
  5946. result.m[0] = c;
  5947. result.m[1] = s;
  5948. result.m[4] = -s;
  5949. result.m[5] = c;
  5950. result.m[2] = 0.0;
  5951. result.m[3] = 0.0;
  5952. result.m[6] = 0.0;
  5953. result.m[7] = 0.0;
  5954. result.m[8] = 0.0;
  5955. result.m[9] = 0.0;
  5956. result.m[11] = 0.0;
  5957. result.m[12] = 0.0;
  5958. result.m[13] = 0.0;
  5959. result.m[14] = 0.0;
  5960. result._markAsUpdated();
  5961. };
  5962. /**
  5963. * Creates a new rotation matrix for "angle" radians around the given axis
  5964. * @param axis defines the axis to use
  5965. * @param angle defines the angle (in radians) to use
  5966. * @return the new matrix
  5967. */
  5968. Matrix.RotationAxis = function (axis, angle) {
  5969. var result = Matrix.Zero();
  5970. Matrix.RotationAxisToRef(axis, angle, result);
  5971. return result;
  5972. };
  5973. /**
  5974. * Creates a new rotation matrix for "angle" radians around the given axis and stores it in a given matrix
  5975. * @param axis defines the axis to use
  5976. * @param angle defines the angle (in radians) to use
  5977. * @param result defines the target matrix
  5978. */
  5979. Matrix.RotationAxisToRef = function (axis, angle, result) {
  5980. var s = Math.sin(-angle);
  5981. var c = Math.cos(-angle);
  5982. var c1 = 1 - c;
  5983. axis.normalize();
  5984. result.m[0] = (axis.x * axis.x) * c1 + c;
  5985. result.m[1] = (axis.x * axis.y) * c1 - (axis.z * s);
  5986. result.m[2] = (axis.x * axis.z) * c1 + (axis.y * s);
  5987. result.m[3] = 0.0;
  5988. result.m[4] = (axis.y * axis.x) * c1 + (axis.z * s);
  5989. result.m[5] = (axis.y * axis.y) * c1 + c;
  5990. result.m[6] = (axis.y * axis.z) * c1 - (axis.x * s);
  5991. result.m[7] = 0.0;
  5992. result.m[8] = (axis.z * axis.x) * c1 - (axis.y * s);
  5993. result.m[9] = (axis.z * axis.y) * c1 + (axis.x * s);
  5994. result.m[10] = (axis.z * axis.z) * c1 + c;
  5995. result.m[11] = 0.0;
  5996. result.m[15] = 1.0;
  5997. result._markAsUpdated();
  5998. };
  5999. /**
  6000. * Creates a rotation matrix
  6001. * @param yaw defines the yaw angle in radians (Y axis)
  6002. * @param pitch defines the pitch angle in radians (X axis)
  6003. * @param roll defines the roll angle in radians (X axis)
  6004. * @returns the new rotation matrix
  6005. */
  6006. Matrix.RotationYawPitchRoll = function (yaw, pitch, roll) {
  6007. var result = new Matrix();
  6008. Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, result);
  6009. return result;
  6010. };
  6011. /**
  6012. * Creates a rotation matrix and stores it in a given matrix
  6013. * @param yaw defines the yaw angle in radians (Y axis)
  6014. * @param pitch defines the pitch angle in radians (X axis)
  6015. * @param roll defines the roll angle in radians (X axis)
  6016. * @param result defines the target matrix
  6017. */
  6018. Matrix.RotationYawPitchRollToRef = function (yaw, pitch, roll, result) {
  6019. Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, this._tempQuaternion);
  6020. this._tempQuaternion.toRotationMatrix(result);
  6021. };
  6022. /**
  6023. * Creates a scaling matrix
  6024. * @param x defines the scale factor on X axis
  6025. * @param y defines the scale factor on Y axis
  6026. * @param z defines the scale factor on Z axis
  6027. * @returns the new matrix
  6028. */
  6029. Matrix.Scaling = function (x, y, z) {
  6030. var result = Matrix.Zero();
  6031. Matrix.ScalingToRef(x, y, z, result);
  6032. return result;
  6033. };
  6034. /**
  6035. * Creates a scaling matrix and stores it in a given matrix
  6036. * @param x defines the scale factor on X axis
  6037. * @param y defines the scale factor on Y axis
  6038. * @param z defines the scale factor on Z axis
  6039. * @param result defines the target matrix
  6040. */
  6041. Matrix.ScalingToRef = function (x, y, z, result) {
  6042. result.m[0] = x;
  6043. result.m[1] = 0.0;
  6044. result.m[2] = 0.0;
  6045. result.m[3] = 0.0;
  6046. result.m[4] = 0.0;
  6047. result.m[5] = y;
  6048. result.m[6] = 0.0;
  6049. result.m[7] = 0.0;
  6050. result.m[8] = 0.0;
  6051. result.m[9] = 0.0;
  6052. result.m[10] = z;
  6053. result.m[11] = 0.0;
  6054. result.m[12] = 0.0;
  6055. result.m[13] = 0.0;
  6056. result.m[14] = 0.0;
  6057. result.m[15] = 1.0;
  6058. result._markAsUpdated();
  6059. };
  6060. /**
  6061. * Creates a translation matrix
  6062. * @param x defines the translation on X axis
  6063. * @param y defines the translation on Y axis
  6064. * @param z defines the translationon Z axis
  6065. * @returns the new matrix
  6066. */
  6067. Matrix.Translation = function (x, y, z) {
  6068. var result = Matrix.Identity();
  6069. Matrix.TranslationToRef(x, y, z, result);
  6070. return result;
  6071. };
  6072. /**
  6073. * Creates a translation matrix and stores it in a given matrix
  6074. * @param x defines the translation on X axis
  6075. * @param y defines the translation on Y axis
  6076. * @param z defines the translationon Z axis
  6077. * @param result defines the target matrix
  6078. */
  6079. Matrix.TranslationToRef = function (x, y, z, result) {
  6080. Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0, result);
  6081. };
  6082. /**
  6083. * Returns a new Matrix whose values are the interpolated values for "gradient" (float) between the ones of the matrices "startValue" and "endValue".
  6084. * @param startValue defines the start value
  6085. * @param endValue defines the end value
  6086. * @param gradient defines the gradient factor
  6087. * @returns the new matrix
  6088. */
  6089. Matrix.Lerp = function (startValue, endValue, gradient) {
  6090. var result = Matrix.Zero();
  6091. Matrix.LerpToRef(startValue, endValue, gradient, result);
  6092. return result;
  6093. };
  6094. /**
  6095. * Set the given matrix "result" as the interpolated values for "gradient" (float) between the ones of the matrices "startValue" and "endValue".
  6096. * @param startValue defines the start value
  6097. * @param endValue defines the end value
  6098. * @param gradient defines the gradient factor
  6099. * @param result defines the Matrix object where to store data
  6100. */
  6101. Matrix.LerpToRef = function (startValue, endValue, gradient, result) {
  6102. for (var index = 0; index < 16; index++) {
  6103. result.m[index] = startValue.m[index] * (1.0 - gradient) + endValue.m[index] * gradient;
  6104. }
  6105. result._markAsUpdated();
  6106. };
  6107. /**
  6108. * Builds a new matrix whose values are computed by:
  6109. * * decomposing the the "startValue" and "endValue" matrices into their respective scale, rotation and translation matrices
  6110. * * interpolating for "gradient" (float) the values between each of these decomposed matrices between the start and the end
  6111. * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices
  6112. * @param startValue defines the first matrix
  6113. * @param endValue defines the second matrix
  6114. * @param gradient defines the gradient between the two matrices
  6115. * @returns the new matrix
  6116. */
  6117. Matrix.DecomposeLerp = function (startValue, endValue, gradient) {
  6118. var result = Matrix.Zero();
  6119. Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);
  6120. return result;
  6121. };
  6122. /**
  6123. * Update a matrix to values which are computed by:
  6124. * * decomposing the the "startValue" and "endValue" matrices into their respective scale, rotation and translation matrices
  6125. * * interpolating for "gradient" (float) the values between each of these decomposed matrices between the start and the end
  6126. * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices
  6127. * @param startValue defines the first matrix
  6128. * @param endValue defines the second matrix
  6129. * @param gradient defines the gradient between the two matrices
  6130. * @param result defines the target matrix
  6131. */
  6132. Matrix.DecomposeLerpToRef = function (startValue, endValue, gradient, result) {
  6133. var startScale = MathTmp.Vector3[0];
  6134. var startRotation = MathTmp.Quaternion[0];
  6135. var startTranslation = MathTmp.Vector3[1];
  6136. startValue.decompose(startScale, startRotation, startTranslation);
  6137. var endScale = MathTmp.Vector3[2];
  6138. var endRotation = MathTmp.Quaternion[1];
  6139. var endTranslation = MathTmp.Vector3[3];
  6140. endValue.decompose(endScale, endRotation, endTranslation);
  6141. var resultScale = MathTmp.Vector3[4];
  6142. Vector3.LerpToRef(startScale, endScale, gradient, resultScale);
  6143. var resultRotation = MathTmp.Quaternion[2];
  6144. Quaternion.SlerpToRef(startRotation, endRotation, gradient, resultRotation);
  6145. var resultTranslation = MathTmp.Vector3[5];
  6146. Vector3.LerpToRef(startTranslation, endTranslation, gradient, resultTranslation);
  6147. Matrix.ComposeToRef(resultScale, resultRotation, resultTranslation, result);
  6148. };
  6149. /**
  6150. * Gets a new rotation matrix used to rotate an entity so as it looks at the target vector3, from the eye vector3 position, the up vector3 being oriented like "up"
  6151. * This function works in left handed mode
  6152. * @param eye defines the final position of the entity
  6153. * @param target defines where the entity should look at
  6154. * @param up defines the up vector for the entity
  6155. * @returns the new matrix
  6156. */
  6157. Matrix.LookAtLH = function (eye, target, up) {
  6158. var result = Matrix.Zero();
  6159. Matrix.LookAtLHToRef(eye, target, up, result);
  6160. return result;
  6161. };
  6162. /**
  6163. * Sets the given "result" Matrix to a rotation matrix used to rotate an entity so that it looks at the target vector3, from the eye vector3 position, the up vector3 being oriented like "up".
  6164. * This function works in left handed mode
  6165. * @param eye defines the final position of the entity
  6166. * @param target defines where the entity should look at
  6167. * @param up defines the up vector for the entity
  6168. * @param result defines the target matrix
  6169. */
  6170. Matrix.LookAtLHToRef = function (eye, target, up, result) {
  6171. // Z axis
  6172. target.subtractToRef(eye, this._zAxis);
  6173. this._zAxis.normalize();
  6174. // X axis
  6175. Vector3.CrossToRef(up, this._zAxis, this._xAxis);
  6176. if (this._xAxis.lengthSquared() === 0) {
  6177. this._xAxis.x = 1.0;
  6178. }
  6179. else {
  6180. this._xAxis.normalize();
  6181. }
  6182. // Y axis
  6183. Vector3.CrossToRef(this._zAxis, this._xAxis, this._yAxis);
  6184. this._yAxis.normalize();
  6185. // Eye angles
  6186. var ex = -Vector3.Dot(this._xAxis, eye);
  6187. var ey = -Vector3.Dot(this._yAxis, eye);
  6188. var ez = -Vector3.Dot(this._zAxis, eye);
  6189. return Matrix.FromValuesToRef(this._xAxis.x, this._yAxis.x, this._zAxis.x, 0, this._xAxis.y, this._yAxis.y, this._zAxis.y, 0, this._xAxis.z, this._yAxis.z, this._zAxis.z, 0, ex, ey, ez, 1, result);
  6190. };
  6191. /**
  6192. * Gets a new rotation matrix used to rotate an entity so as it looks at the target vector3, from the eye vector3 position, the up vector3 being oriented like "up"
  6193. * This function works in right handed mode
  6194. * @param eye defines the final position of the entity
  6195. * @param target defines where the entity should look at
  6196. * @param up defines the up vector for the entity
  6197. * @returns the new matrix
  6198. */
  6199. Matrix.LookAtRH = function (eye, target, up) {
  6200. var result = Matrix.Zero();
  6201. Matrix.LookAtRHToRef(eye, target, up, result);
  6202. return result;
  6203. };
  6204. /**
  6205. * Sets the given "result" Matrix to a rotation matrix used to rotate an entity so that it looks at the target vector3, from the eye vector3 position, the up vector3 being oriented like "up".
  6206. * This function works in right handed mode
  6207. * @param eye defines the final position of the entity
  6208. * @param target defines where the entity should look at
  6209. * @param up defines the up vector for the entity
  6210. * @param result defines the target matrix
  6211. */
  6212. Matrix.LookAtRHToRef = function (eye, target, up, result) {
  6213. // Z axis
  6214. eye.subtractToRef(target, this._zAxis);
  6215. this._zAxis.normalize();
  6216. // X axis
  6217. Vector3.CrossToRef(up, this._zAxis, this._xAxis);
  6218. if (this._xAxis.lengthSquared() === 0) {
  6219. this._xAxis.x = 1.0;
  6220. }
  6221. else {
  6222. this._xAxis.normalize();
  6223. }
  6224. // Y axis
  6225. Vector3.CrossToRef(this._zAxis, this._xAxis, this._yAxis);
  6226. this._yAxis.normalize();
  6227. // Eye angles
  6228. var ex = -Vector3.Dot(this._xAxis, eye);
  6229. var ey = -Vector3.Dot(this._yAxis, eye);
  6230. var ez = -Vector3.Dot(this._zAxis, eye);
  6231. return Matrix.FromValuesToRef(this._xAxis.x, this._yAxis.x, this._zAxis.x, 0, this._xAxis.y, this._yAxis.y, this._zAxis.y, 0, this._xAxis.z, this._yAxis.z, this._zAxis.z, 0, ex, ey, ez, 1, result);
  6232. };
  6233. /**
  6234. * Create a left-handed orthographic projection matrix
  6235. * @param width defines the viewport width
  6236. * @param height defines the viewport height
  6237. * @param znear defines the near clip plane
  6238. * @param zfar defines the far clip plane
  6239. * @returns a new matrix as a left-handed orthographic projection matrix
  6240. */
  6241. Matrix.OrthoLH = function (width, height, znear, zfar) {
  6242. var matrix = Matrix.Zero();
  6243. Matrix.OrthoLHToRef(width, height, znear, zfar, matrix);
  6244. return matrix;
  6245. };
  6246. /**
  6247. * Store a left-handed orthographic projection to a given matrix
  6248. * @param width defines the viewport width
  6249. * @param height defines the viewport height
  6250. * @param znear defines the near clip plane
  6251. * @param zfar defines the far clip plane
  6252. * @param result defines the target matrix
  6253. */
  6254. Matrix.OrthoLHToRef = function (width, height, znear, zfar, result) {
  6255. var n = znear;
  6256. var f = zfar;
  6257. var a = 2.0 / width;
  6258. var b = 2.0 / height;
  6259. var c = 2.0 / (f - n);
  6260. var d = -(f + n) / (f - n);
  6261. Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, 0.0, 0.0, d, 1.0, result);
  6262. };
  6263. /**
  6264. * Create a left-handed orthographic projection matrix
  6265. * @param left defines the viewport left coordinate
  6266. * @param right defines the viewport right coordinate
  6267. * @param bottom defines the viewport bottom coordinate
  6268. * @param top defines the viewport top coordinate
  6269. * @param znear defines the near clip plane
  6270. * @param zfar defines the far clip plane
  6271. * @returns a new matrix as a left-handed orthographic projection matrix
  6272. */
  6273. Matrix.OrthoOffCenterLH = function (left, right, bottom, top, znear, zfar) {
  6274. var matrix = Matrix.Zero();
  6275. Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, matrix);
  6276. return matrix;
  6277. };
  6278. /**
  6279. * Stores a left-handed orthographic projection into a given matrix
  6280. * @param left defines the viewport left coordinate
  6281. * @param right defines the viewport right coordinate
  6282. * @param bottom defines the viewport bottom coordinate
  6283. * @param top defines the viewport top coordinate
  6284. * @param znear defines the near clip plane
  6285. * @param zfar defines the far clip plane
  6286. * @param result defines the target matrix
  6287. */
  6288. Matrix.OrthoOffCenterLHToRef = function (left, right, bottom, top, znear, zfar, result) {
  6289. var n = znear;
  6290. var f = zfar;
  6291. var a = 2.0 / (right - left);
  6292. var b = 2.0 / (top - bottom);
  6293. var c = 2.0 / (f - n);
  6294. var d = -(f + n) / (f - n);
  6295. var i0 = (left + right) / (left - right);
  6296. var i1 = (top + bottom) / (bottom - top);
  6297. Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, i0, i1, d, 1.0, result);
  6298. };
  6299. /**
  6300. * Creates a right-handed orthographic projection matrix
  6301. * @param left defines the viewport left coordinate
  6302. * @param right defines the viewport right coordinate
  6303. * @param bottom defines the viewport bottom coordinate
  6304. * @param top defines the viewport top coordinate
  6305. * @param znear defines the near clip plane
  6306. * @param zfar defines the far clip plane
  6307. * @returns a new matrix as a right-handed orthographic projection matrix
  6308. */
  6309. Matrix.OrthoOffCenterRH = function (left, right, bottom, top, znear, zfar) {
  6310. var matrix = Matrix.Zero();
  6311. Matrix.OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, matrix);
  6312. return matrix;
  6313. };
  6314. /**
  6315. * Stores a right-handed orthographic projection into a given matrix
  6316. * @param left defines the viewport left coordinate
  6317. * @param right defines the viewport right coordinate
  6318. * @param bottom defines the viewport bottom coordinate
  6319. * @param top defines the viewport top coordinate
  6320. * @param znear defines the near clip plane
  6321. * @param zfar defines the far clip plane
  6322. * @param result defines the target matrix
  6323. */
  6324. Matrix.OrthoOffCenterRHToRef = function (left, right, bottom, top, znear, zfar, result) {
  6325. Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result);
  6326. result.m[10] *= -1.0;
  6327. };
  6328. /**
  6329. * Creates a left-handed perspective projection matrix
  6330. * @param width defines the viewport width
  6331. * @param height defines the viewport height
  6332. * @param znear defines the near clip plane
  6333. * @param zfar defines the far clip plane
  6334. * @returns a new matrix as a left-handed perspective projection matrix
  6335. */
  6336. Matrix.PerspectiveLH = function (width, height, znear, zfar) {
  6337. var matrix = Matrix.Zero();
  6338. var n = znear;
  6339. var f = zfar;
  6340. var a = 2.0 * n / width;
  6341. var b = 2.0 * n / height;
  6342. var c = (f + n) / (f - n);
  6343. var d = -2.0 * f * n / (f - n);
  6344. Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, matrix);
  6345. return matrix;
  6346. };
  6347. /**
  6348. * Creates a left-handed perspective projection matrix
  6349. * @param fov defines the horizontal field of view
  6350. * @param aspect defines the aspect ratio
  6351. * @param znear defines the near clip plane
  6352. * @param zfar defines the far clip plane
  6353. * @returns a new matrix as a left-handed perspective projection matrix
  6354. */
  6355. Matrix.PerspectiveFovLH = function (fov, aspect, znear, zfar) {
  6356. var matrix = Matrix.Zero();
  6357. Matrix.PerspectiveFovLHToRef(fov, aspect, znear, zfar, matrix);
  6358. return matrix;
  6359. };
  6360. /**
  6361. * Stores a left-handed perspective projection into a given matrix
  6362. * @param fov defines the horizontal field of view
  6363. * @param aspect defines the aspect ratio
  6364. * @param znear defines the near clip plane
  6365. * @param zfar defines the far clip plane
  6366. * @param result defines the target matrix
  6367. * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
  6368. */
  6369. Matrix.PerspectiveFovLHToRef = function (fov, aspect, znear, zfar, result, isVerticalFovFixed) {
  6370. if (isVerticalFovFixed === void 0) { isVerticalFovFixed = true; }
  6371. var n = znear;
  6372. var f = zfar;
  6373. var t = 1.0 / (Math.tan(fov * 0.5));
  6374. var a = isVerticalFovFixed ? (t / aspect) : t;
  6375. var b = isVerticalFovFixed ? t : (t * aspect);
  6376. var c = (f + n) / (f - n);
  6377. var d = -2.0 * f * n / (f - n);
  6378. Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, result);
  6379. };
  6380. /**
  6381. * Creates a right-handed perspective projection matrix
  6382. * @param fov defines the horizontal field of view
  6383. * @param aspect defines the aspect ratio
  6384. * @param znear defines the near clip plane
  6385. * @param zfar defines the far clip plane
  6386. * @returns a new matrix as a right-handed perspective projection matrix
  6387. */
  6388. Matrix.PerspectiveFovRH = function (fov, aspect, znear, zfar) {
  6389. var matrix = Matrix.Zero();
  6390. Matrix.PerspectiveFovRHToRef(fov, aspect, znear, zfar, matrix);
  6391. return matrix;
  6392. };
  6393. /**
  6394. * Stores a right-handed perspective projection into a given matrix
  6395. * @param fov defines the horizontal field of view
  6396. * @param aspect defines the aspect ratio
  6397. * @param znear defines the near clip plane
  6398. * @param zfar defines the far clip plane
  6399. * @param result defines the target matrix
  6400. * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
  6401. */
  6402. Matrix.PerspectiveFovRHToRef = function (fov, aspect, znear, zfar, result, isVerticalFovFixed) {
  6403. //alternatively this could be expressed as:
  6404. // m = PerspectiveFovLHToRef
  6405. // m[10] *= -1.0;
  6406. // m[11] *= -1.0;
  6407. if (isVerticalFovFixed === void 0) { isVerticalFovFixed = true; }
  6408. var n = znear;
  6409. var f = zfar;
  6410. var t = 1.0 / (Math.tan(fov * 0.5));
  6411. var a = isVerticalFovFixed ? (t / aspect) : t;
  6412. var b = isVerticalFovFixed ? t : (t * aspect);
  6413. var c = -(f + n) / (f - n);
  6414. var d = -2 * f * n / (f - n);
  6415. Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, -1.0, 0.0, 0.0, d, 0.0, result);
  6416. };
  6417. /**
  6418. * Stores a perspective projection for WebVR info a given matrix
  6419. * @param fov defines the field of view
  6420. * @param znear defines the near clip plane
  6421. * @param zfar defines the far clip plane
  6422. * @param result defines the target matrix
  6423. * @param rightHanded defines if the matrix must be in right-handed mode (false by default)
  6424. */
  6425. Matrix.PerspectiveFovWebVRToRef = function (fov, znear, zfar, result, rightHanded) {
  6426. if (rightHanded === void 0) { rightHanded = false; }
  6427. var rightHandedFactor = rightHanded ? -1 : 1;
  6428. var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
  6429. var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
  6430. var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
  6431. var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);
  6432. var xScale = 2.0 / (leftTan + rightTan);
  6433. var yScale = 2.0 / (upTan + downTan);
  6434. result.m[0] = xScale;
  6435. result.m[1] = result.m[2] = result.m[3] = result.m[4] = 0.0;
  6436. result.m[5] = yScale;
  6437. result.m[6] = result.m[7] = 0.0;
  6438. result.m[8] = ((leftTan - rightTan) * xScale * 0.5);
  6439. result.m[9] = -((upTan - downTan) * yScale * 0.5);
  6440. result.m[10] = -zfar / (znear - zfar);
  6441. result.m[11] = 1.0 * rightHandedFactor;
  6442. result.m[12] = result.m[13] = result.m[15] = 0.0;
  6443. result.m[14] = -(2.0 * zfar * znear) / (zfar - znear);
  6444. result._markAsUpdated();
  6445. };
  6446. /**
  6447. * Computes a complete transformation matrix
  6448. * @param viewport defines the viewport to use
  6449. * @param world defines the world matrix
  6450. * @param view defines the view matrix
  6451. * @param projection defines the projection matrix
  6452. * @param zmin defines the near clip plane
  6453. * @param zmax defines the far clip plane
  6454. * @returns the transformation matrix
  6455. */
  6456. Matrix.GetFinalMatrix = function (viewport, world, view, projection, zmin, zmax) {
  6457. var cw = viewport.width;
  6458. var ch = viewport.height;
  6459. var cx = viewport.x;
  6460. var cy = viewport.y;
  6461. var viewportMatrix = Matrix.FromValues(cw / 2.0, 0.0, 0.0, 0.0, 0.0, -ch / 2.0, 0.0, 0.0, 0.0, 0.0, zmax - zmin, 0.0, cx + cw / 2.0, ch / 2.0 + cy, zmin, 1);
  6462. return world.multiply(view).multiply(projection).multiply(viewportMatrix);
  6463. };
  6464. /**
  6465. * Extracts a 2x2 matrix from a given matrix and store the result in a Float32Array
  6466. * @param matrix defines the matrix to use
  6467. * @returns a new Float32Array array with 4 elements : the 2x2 matrix extracted from the given matrix
  6468. */
  6469. Matrix.GetAsMatrix2x2 = function (matrix) {
  6470. return new Float32Array([
  6471. matrix.m[0], matrix.m[1],
  6472. matrix.m[4], matrix.m[5]
  6473. ]);
  6474. };
  6475. /**
  6476. * Extracts a 3x3 matrix from a given matrix and store the result in a Float32Array
  6477. * @param matrix defines the matrix to use
  6478. * @returns a new Float32Array array with 9 elements : the 3x3 matrix extracted from the given matrix
  6479. */
  6480. Matrix.GetAsMatrix3x3 = function (matrix) {
  6481. return new Float32Array([
  6482. matrix.m[0], matrix.m[1], matrix.m[2],
  6483. matrix.m[4], matrix.m[5], matrix.m[6],
  6484. matrix.m[8], matrix.m[9], matrix.m[10]
  6485. ]);
  6486. };
  6487. /**
  6488. * Compute the transpose of a given matrix
  6489. * @param matrix defines the matrix to transpose
  6490. * @returns the new matrix
  6491. */
  6492. Matrix.Transpose = function (matrix) {
  6493. var result = new Matrix();
  6494. Matrix.TransposeToRef(matrix, result);
  6495. return result;
  6496. };
  6497. /**
  6498. * Compute the transpose of a matrix and store it in a target matrix
  6499. * @param matrix defines the matrix to transpose
  6500. * @param result defines the target matrix
  6501. */
  6502. Matrix.TransposeToRef = function (matrix, result) {
  6503. result.m[0] = matrix.m[0];
  6504. result.m[1] = matrix.m[4];
  6505. result.m[2] = matrix.m[8];
  6506. result.m[3] = matrix.m[12];
  6507. result.m[4] = matrix.m[1];
  6508. result.m[5] = matrix.m[5];
  6509. result.m[6] = matrix.m[9];
  6510. result.m[7] = matrix.m[13];
  6511. result.m[8] = matrix.m[2];
  6512. result.m[9] = matrix.m[6];
  6513. result.m[10] = matrix.m[10];
  6514. result.m[11] = matrix.m[14];
  6515. result.m[12] = matrix.m[3];
  6516. result.m[13] = matrix.m[7];
  6517. result.m[14] = matrix.m[11];
  6518. result.m[15] = matrix.m[15];
  6519. };
  6520. /**
  6521. * Computes a reflection matrix from a plane
  6522. * @param plane defines the reflection plane
  6523. * @returns a new matrix
  6524. */
  6525. Matrix.Reflection = function (plane) {
  6526. var matrix = new Matrix();
  6527. Matrix.ReflectionToRef(plane, matrix);
  6528. return matrix;
  6529. };
  6530. /**
  6531. * Computes a reflection matrix from a plane
  6532. * @param plane defines the reflection plane
  6533. * @param result defines the target matrix
  6534. */
  6535. Matrix.ReflectionToRef = function (plane, result) {
  6536. plane.normalize();
  6537. var x = plane.normal.x;
  6538. var y = plane.normal.y;
  6539. var z = plane.normal.z;
  6540. var temp = -2 * x;
  6541. var temp2 = -2 * y;
  6542. var temp3 = -2 * z;
  6543. result.m[0] = (temp * x) + 1;
  6544. result.m[1] = temp2 * x;
  6545. result.m[2] = temp3 * x;
  6546. result.m[3] = 0.0;
  6547. result.m[4] = temp * y;
  6548. result.m[5] = (temp2 * y) + 1;
  6549. result.m[6] = temp3 * y;
  6550. result.m[7] = 0.0;
  6551. result.m[8] = temp * z;
  6552. result.m[9] = temp2 * z;
  6553. result.m[10] = (temp3 * z) + 1;
  6554. result.m[11] = 0.0;
  6555. result.m[12] = temp * plane.d;
  6556. result.m[13] = temp2 * plane.d;
  6557. result.m[14] = temp3 * plane.d;
  6558. result.m[15] = 1.0;
  6559. result._markAsUpdated();
  6560. };
  6561. /**
  6562. * Sets the given matrix as a rotation matrix composed from the 3 left handed axes
  6563. * @param xaxis defines the value of the 1st axis
  6564. * @param yaxis defines the value of the 2nd axis
  6565. * @param zaxis defines the value of the 3rd axis
  6566. * @param result defines the target matrix
  6567. */
  6568. Matrix.FromXYZAxesToRef = function (xaxis, yaxis, zaxis, result) {
  6569. result.m[0] = xaxis.x;
  6570. result.m[1] = xaxis.y;
  6571. result.m[2] = xaxis.z;
  6572. result.m[3] = 0.0;
  6573. result.m[4] = yaxis.x;
  6574. result.m[5] = yaxis.y;
  6575. result.m[6] = yaxis.z;
  6576. result.m[7] = 0.0;
  6577. result.m[8] = zaxis.x;
  6578. result.m[9] = zaxis.y;
  6579. result.m[10] = zaxis.z;
  6580. result.m[11] = 0.0;
  6581. result.m[12] = 0.0;
  6582. result.m[13] = 0.0;
  6583. result.m[14] = 0.0;
  6584. result.m[15] = 1.0;
  6585. result._markAsUpdated();
  6586. };
  6587. /**
  6588. * Creates a rotation matrix from a quaternion and stores it in a target matrix
  6589. * @param quat defines the quaternion to use
  6590. * @param result defines the target matrix
  6591. */
  6592. Matrix.FromQuaternionToRef = function (quat, result) {
  6593. var xx = quat.x * quat.x;
  6594. var yy = quat.y * quat.y;
  6595. var zz = quat.z * quat.z;
  6596. var xy = quat.x * quat.y;
  6597. var zw = quat.z * quat.w;
  6598. var zx = quat.z * quat.x;
  6599. var yw = quat.y * quat.w;
  6600. var yz = quat.y * quat.z;
  6601. var xw = quat.x * quat.w;
  6602. result.m[0] = 1.0 - (2.0 * (yy + zz));
  6603. result.m[1] = 2.0 * (xy + zw);
  6604. result.m[2] = 2.0 * (zx - yw);
  6605. result.m[3] = 0.0;
  6606. result.m[4] = 2.0 * (xy - zw);
  6607. result.m[5] = 1.0 - (2.0 * (zz + xx));
  6608. result.m[6] = 2.0 * (yz + xw);
  6609. result.m[7] = 0.0;
  6610. result.m[8] = 2.0 * (zx + yw);
  6611. result.m[9] = 2.0 * (yz - xw);
  6612. result.m[10] = 1.0 - (2.0 * (yy + xx));
  6613. result.m[11] = 0.0;
  6614. result.m[12] = 0.0;
  6615. result.m[13] = 0.0;
  6616. result.m[14] = 0.0;
  6617. result.m[15] = 1.0;
  6618. result._markAsUpdated();
  6619. };
  6620. Matrix._tempQuaternion = new Quaternion();
  6621. Matrix._xAxis = Vector3.Zero();
  6622. Matrix._yAxis = Vector3.Zero();
  6623. Matrix._zAxis = Vector3.Zero();
  6624. Matrix._updateFlagSeed = 0;
  6625. Matrix._identityReadOnly = Matrix.Identity();
  6626. return Matrix;
  6627. }());
  6628. BABYLON.Matrix = Matrix;
  6629. var Plane = /** @class */ (function () {
  6630. /**
  6631. * Creates a Plane object according to the given floats a, b, c, d and the plane equation : ax + by + cz + d = 0
  6632. */
  6633. function Plane(a, b, c, d) {
  6634. this.normal = new Vector3(a, b, c);
  6635. this.d = d;
  6636. }
  6637. /**
  6638. * Returns the plane coordinates as a new array of 4 elements [a, b, c, d].
  6639. */
  6640. Plane.prototype.asArray = function () {
  6641. return [this.normal.x, this.normal.y, this.normal.z, this.d];
  6642. };
  6643. // Methods
  6644. /**
  6645. * Returns a new plane copied from the current Plane.
  6646. */
  6647. Plane.prototype.clone = function () {
  6648. return new Plane(this.normal.x, this.normal.y, this.normal.z, this.d);
  6649. };
  6650. /**
  6651. * Returns the string "Plane".
  6652. */
  6653. Plane.prototype.getClassName = function () {
  6654. return "Plane";
  6655. };
  6656. /**
  6657. * Returns the Plane hash code.
  6658. */
  6659. Plane.prototype.getHashCode = function () {
  6660. var hash = this.normal.getHashCode();
  6661. hash = (hash * 397) ^ (this.d || 0);
  6662. return hash;
  6663. };
  6664. /**
  6665. * Normalize the current Plane in place.
  6666. * Returns the updated Plane.
  6667. */
  6668. Plane.prototype.normalize = function () {
  6669. var norm = (Math.sqrt((this.normal.x * this.normal.x) + (this.normal.y * this.normal.y) + (this.normal.z * this.normal.z)));
  6670. var magnitude = 0.0;
  6671. if (norm !== 0) {
  6672. magnitude = 1.0 / norm;
  6673. }
  6674. this.normal.x *= magnitude;
  6675. this.normal.y *= magnitude;
  6676. this.normal.z *= magnitude;
  6677. this.d *= magnitude;
  6678. return this;
  6679. };
  6680. /**
  6681. * Returns a new Plane as the result of the transformation of the current Plane by the given matrix.
  6682. */
  6683. Plane.prototype.transform = function (transformation) {
  6684. var transposedMatrix = Matrix.Transpose(transformation);
  6685. var x = this.normal.x;
  6686. var y = this.normal.y;
  6687. var z = this.normal.z;
  6688. var d = this.d;
  6689. var normalX = (((x * transposedMatrix.m[0]) + (y * transposedMatrix.m[1])) + (z * transposedMatrix.m[2])) + (d * transposedMatrix.m[3]);
  6690. var normalY = (((x * transposedMatrix.m[4]) + (y * transposedMatrix.m[5])) + (z * transposedMatrix.m[6])) + (d * transposedMatrix.m[7]);
  6691. var normalZ = (((x * transposedMatrix.m[8]) + (y * transposedMatrix.m[9])) + (z * transposedMatrix.m[10])) + (d * transposedMatrix.m[11]);
  6692. var finalD = (((x * transposedMatrix.m[12]) + (y * transposedMatrix.m[13])) + (z * transposedMatrix.m[14])) + (d * transposedMatrix.m[15]);
  6693. return new Plane(normalX, normalY, normalZ, finalD);
  6694. };
  6695. /**
  6696. * Returns the dot product (float) of the point coordinates and the plane normal.
  6697. */
  6698. Plane.prototype.dotCoordinate = function (point) {
  6699. return ((((this.normal.x * point.x) + (this.normal.y * point.y)) + (this.normal.z * point.z)) + this.d);
  6700. };
  6701. /**
  6702. * Updates the current Plane from the plane defined by the three given points.
  6703. * Returns the updated Plane.
  6704. */
  6705. Plane.prototype.copyFromPoints = function (point1, point2, point3) {
  6706. var x1 = point2.x - point1.x;
  6707. var y1 = point2.y - point1.y;
  6708. var z1 = point2.z - point1.z;
  6709. var x2 = point3.x - point1.x;
  6710. var y2 = point3.y - point1.y;
  6711. var z2 = point3.z - point1.z;
  6712. var yz = (y1 * z2) - (z1 * y2);
  6713. var xz = (z1 * x2) - (x1 * z2);
  6714. var xy = (x1 * y2) - (y1 * x2);
  6715. var pyth = (Math.sqrt((yz * yz) + (xz * xz) + (xy * xy)));
  6716. var invPyth;
  6717. if (pyth !== 0) {
  6718. invPyth = 1.0 / pyth;
  6719. }
  6720. else {
  6721. invPyth = 0.0;
  6722. }
  6723. this.normal.x = yz * invPyth;
  6724. this.normal.y = xz * invPyth;
  6725. this.normal.z = xy * invPyth;
  6726. this.d = -((this.normal.x * point1.x) + (this.normal.y * point1.y) + (this.normal.z * point1.z));
  6727. return this;
  6728. };
  6729. /**
  6730. * Boolean : True is the vector "direction" is the same side than the plane normal.
  6731. */
  6732. Plane.prototype.isFrontFacingTo = function (direction, epsilon) {
  6733. var dot = Vector3.Dot(this.normal, direction);
  6734. return (dot <= epsilon);
  6735. };
  6736. /**
  6737. * Returns the signed distance (float) from the given point to the Plane.
  6738. */
  6739. Plane.prototype.signedDistanceTo = function (point) {
  6740. return Vector3.Dot(point, this.normal) + this.d;
  6741. };
  6742. // Statics
  6743. /**
  6744. * Returns a new Plane from the given array.
  6745. */
  6746. Plane.FromArray = function (array) {
  6747. return new Plane(array[0], array[1], array[2], array[3]);
  6748. };
  6749. /**
  6750. * Returns a new Plane defined by the three given points.
  6751. */
  6752. Plane.FromPoints = function (point1, point2, point3) {
  6753. var result = new Plane(0.0, 0.0, 0.0, 0.0);
  6754. result.copyFromPoints(point1, point2, point3);
  6755. return result;
  6756. };
  6757. /**
  6758. * Returns a new Plane the normal vector to this plane at the given origin point.
  6759. * Note : the vector "normal" is updated because normalized.
  6760. */
  6761. Plane.FromPositionAndNormal = function (origin, normal) {
  6762. var result = new Plane(0.0, 0.0, 0.0, 0.0);
  6763. normal.normalize();
  6764. result.normal = normal;
  6765. result.d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
  6766. return result;
  6767. };
  6768. /**
  6769. * Returns the signed distance between the plane defined by the normal vector at the "origin"" point and the given other point.
  6770. */
  6771. Plane.SignedDistanceToPlaneFromPositionAndNormal = function (origin, normal, point) {
  6772. var d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
  6773. return Vector3.Dot(point, normal) + d;
  6774. };
  6775. return Plane;
  6776. }());
  6777. BABYLON.Plane = Plane;
  6778. var Viewport = /** @class */ (function () {
  6779. /**
  6780. * Creates a Viewport object located at (x, y) and sized (width, height).
  6781. */
  6782. function Viewport(x, y, width, height) {
  6783. this.x = x;
  6784. this.y = y;
  6785. this.width = width;
  6786. this.height = height;
  6787. }
  6788. Viewport.prototype.toGlobal = function (renderWidthOrEngine, renderHeight) {
  6789. if (renderWidthOrEngine.getRenderWidth) {
  6790. var engine = renderWidthOrEngine;
  6791. return this.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  6792. }
  6793. var renderWidth = renderWidthOrEngine;
  6794. return new Viewport(this.x * renderWidth, this.y * renderHeight, this.width * renderWidth, this.height * renderHeight);
  6795. };
  6796. /**
  6797. * Returns a new Viewport copied from the current one.
  6798. */
  6799. Viewport.prototype.clone = function () {
  6800. return new Viewport(this.x, this.y, this.width, this.height);
  6801. };
  6802. return Viewport;
  6803. }());
  6804. BABYLON.Viewport = Viewport;
  6805. var Frustum = /** @class */ (function () {
  6806. function Frustum() {
  6807. }
  6808. /**
  6809. * Returns a new array of 6 Frustum planes computed by the given transformation matrix.
  6810. */
  6811. Frustum.GetPlanes = function (transform) {
  6812. var frustumPlanes = [];
  6813. for (var index = 0; index < 6; index++) {
  6814. frustumPlanes.push(new Plane(0.0, 0.0, 0.0, 0.0));
  6815. }
  6816. Frustum.GetPlanesToRef(transform, frustumPlanes);
  6817. return frustumPlanes;
  6818. };
  6819. Frustum.GetNearPlaneToRef = function (transform, frustumPlane) {
  6820. frustumPlane.normal.x = transform.m[3] + transform.m[2];
  6821. frustumPlane.normal.y = transform.m[7] + transform.m[6];
  6822. frustumPlane.normal.z = transform.m[11] + transform.m[10];
  6823. frustumPlane.d = transform.m[15] + transform.m[14];
  6824. frustumPlane.normalize();
  6825. };
  6826. Frustum.GetFarPlaneToRef = function (transform, frustumPlane) {
  6827. frustumPlane.normal.x = transform.m[3] - transform.m[2];
  6828. frustumPlane.normal.y = transform.m[7] - transform.m[6];
  6829. frustumPlane.normal.z = transform.m[11] - transform.m[10];
  6830. frustumPlane.d = transform.m[15] - transform.m[14];
  6831. frustumPlane.normalize();
  6832. };
  6833. Frustum.GetLeftPlaneToRef = function (transform, frustumPlane) {
  6834. frustumPlane.normal.x = transform.m[3] + transform.m[0];
  6835. frustumPlane.normal.y = transform.m[7] + transform.m[4];
  6836. frustumPlane.normal.z = transform.m[11] + transform.m[8];
  6837. frustumPlane.d = transform.m[15] + transform.m[12];
  6838. frustumPlane.normalize();
  6839. };
  6840. Frustum.GetRightPlaneToRef = function (transform, frustumPlane) {
  6841. frustumPlane.normal.x = transform.m[3] - transform.m[0];
  6842. frustumPlane.normal.y = transform.m[7] - transform.m[4];
  6843. frustumPlane.normal.z = transform.m[11] - transform.m[8];
  6844. frustumPlane.d = transform.m[15] - transform.m[12];
  6845. frustumPlane.normalize();
  6846. };
  6847. Frustum.GetTopPlaneToRef = function (transform, frustumPlane) {
  6848. frustumPlane.normal.x = transform.m[3] - transform.m[1];
  6849. frustumPlane.normal.y = transform.m[7] - transform.m[5];
  6850. frustumPlane.normal.z = transform.m[11] - transform.m[9];
  6851. frustumPlane.d = transform.m[15] - transform.m[13];
  6852. frustumPlane.normalize();
  6853. };
  6854. Frustum.GetBottomPlaneToRef = function (transform, frustumPlane) {
  6855. frustumPlane.normal.x = transform.m[3] + transform.m[1];
  6856. frustumPlane.normal.y = transform.m[7] + transform.m[5];
  6857. frustumPlane.normal.z = transform.m[11] + transform.m[9];
  6858. frustumPlane.d = transform.m[15] + transform.m[13];
  6859. frustumPlane.normalize();
  6860. };
  6861. /**
  6862. * Sets the given array "frustumPlanes" with the 6 Frustum planes computed by the given transformation matrix.
  6863. */
  6864. Frustum.GetPlanesToRef = function (transform, frustumPlanes) {
  6865. // Near
  6866. Frustum.GetNearPlaneToRef(transform, frustumPlanes[0]);
  6867. // Far
  6868. Frustum.GetFarPlaneToRef(transform, frustumPlanes[1]);
  6869. // Left
  6870. Frustum.GetLeftPlaneToRef(transform, frustumPlanes[2]);
  6871. // Right
  6872. Frustum.GetRightPlaneToRef(transform, frustumPlanes[3]);
  6873. // Top
  6874. Frustum.GetTopPlaneToRef(transform, frustumPlanes[4]);
  6875. // Bottom
  6876. Frustum.GetBottomPlaneToRef(transform, frustumPlanes[5]);
  6877. };
  6878. return Frustum;
  6879. }());
  6880. BABYLON.Frustum = Frustum;
  6881. /** Defines supported spaces */
  6882. var Space;
  6883. (function (Space) {
  6884. /** Local (object) space */
  6885. Space[Space["LOCAL"] = 0] = "LOCAL";
  6886. /** World space */
  6887. Space[Space["WORLD"] = 1] = "WORLD";
  6888. /** Bone space */
  6889. Space[Space["BONE"] = 2] = "BONE";
  6890. })(Space = BABYLON.Space || (BABYLON.Space = {}));
  6891. /** Defines the 3 main axes */
  6892. var Axis = /** @class */ (function () {
  6893. function Axis() {
  6894. }
  6895. /** X axis */
  6896. Axis.X = new Vector3(1.0, 0.0, 0.0);
  6897. /** Y axis */
  6898. Axis.Y = new Vector3(0.0, 1.0, 0.0);
  6899. /** Z axis */
  6900. Axis.Z = new Vector3(0.0, 0.0, 1.0);
  6901. return Axis;
  6902. }());
  6903. BABYLON.Axis = Axis;
  6904. ;
  6905. var BezierCurve = /** @class */ (function () {
  6906. function BezierCurve() {
  6907. }
  6908. /**
  6909. * Returns the cubic Bezier interpolated value (float) at "t" (float) from the given x1, y1, x2, y2 floats.
  6910. */
  6911. BezierCurve.interpolate = function (t, x1, y1, x2, y2) {
  6912. // Extract X (which is equal to time here)
  6913. var f0 = 1 - 3 * x2 + 3 * x1;
  6914. var f1 = 3 * x2 - 6 * x1;
  6915. var f2 = 3 * x1;
  6916. var refinedT = t;
  6917. for (var i = 0; i < 5; i++) {
  6918. var refinedT2 = refinedT * refinedT;
  6919. var refinedT3 = refinedT2 * refinedT;
  6920. var x = f0 * refinedT3 + f1 * refinedT2 + f2 * refinedT;
  6921. var slope = 1.0 / (3.0 * f0 * refinedT2 + 2.0 * f1 * refinedT + f2);
  6922. refinedT -= (x - t) * slope;
  6923. refinedT = Math.min(1, Math.max(0, refinedT));
  6924. }
  6925. // Resolve cubic bezier for the given x
  6926. return 3 * Math.pow(1 - refinedT, 2) * refinedT * y1 +
  6927. 3 * (1 - refinedT) * Math.pow(refinedT, 2) * y2 +
  6928. Math.pow(refinedT, 3);
  6929. };
  6930. return BezierCurve;
  6931. }());
  6932. BABYLON.BezierCurve = BezierCurve;
  6933. /**
  6934. * Defines potential orientation for back face culling
  6935. */
  6936. var Orientation;
  6937. (function (Orientation) {
  6938. /**
  6939. * Clockwise
  6940. */
  6941. Orientation[Orientation["CW"] = 0] = "CW";
  6942. /** Counter clockwise */
  6943. Orientation[Orientation["CCW"] = 1] = "CCW";
  6944. })(Orientation = BABYLON.Orientation || (BABYLON.Orientation = {}));
  6945. /**
  6946. * Defines angle representation
  6947. */
  6948. var Angle = /** @class */ (function () {
  6949. /**
  6950. * Creates an Angle object of "radians" radians (float).
  6951. */
  6952. function Angle(radians) {
  6953. this._radians = radians;
  6954. if (this._radians < 0.0)
  6955. this._radians += (2.0 * Math.PI);
  6956. }
  6957. /**
  6958. * Get value in degrees
  6959. * @returns the Angle value in degrees (float)
  6960. */
  6961. Angle.prototype.degrees = function () {
  6962. return this._radians * 180.0 / Math.PI;
  6963. };
  6964. /**
  6965. * Get value in radians
  6966. * @returns the Angle value in radians (float)
  6967. */
  6968. Angle.prototype.radians = function () {
  6969. return this._radians;
  6970. };
  6971. /**
  6972. * Gets a new Angle object valued with the angle value in radians between the two given vectors
  6973. * @param a defines first vector
  6974. * @param b defines second vector
  6975. * @returns a new Angle
  6976. */
  6977. Angle.BetweenTwoPoints = function (a, b) {
  6978. var delta = b.subtract(a);
  6979. var theta = Math.atan2(delta.y, delta.x);
  6980. return new Angle(theta);
  6981. };
  6982. /**
  6983. * Gets a new Angle object from the given float in radians
  6984. * @param radians defines the angle value in radians
  6985. * @returns a new Angle
  6986. */
  6987. Angle.FromRadians = function (radians) {
  6988. return new Angle(radians);
  6989. };
  6990. /**
  6991. * Gets a new Angle object from the given float in degrees
  6992. * @param degrees defines the angle value in degrees
  6993. * @returns a new Angle
  6994. */
  6995. Angle.FromDegrees = function (degrees) {
  6996. return new Angle(degrees * Math.PI / 180.0);
  6997. };
  6998. return Angle;
  6999. }());
  7000. BABYLON.Angle = Angle;
  7001. var Arc2 = /** @class */ (function () {
  7002. /**
  7003. * Creates an Arc object from the three given points : start, middle and end.
  7004. */
  7005. function Arc2(startPoint, midPoint, endPoint) {
  7006. this.startPoint = startPoint;
  7007. this.midPoint = midPoint;
  7008. this.endPoint = endPoint;
  7009. var temp = Math.pow(midPoint.x, 2) + Math.pow(midPoint.y, 2);
  7010. var startToMid = (Math.pow(startPoint.x, 2) + Math.pow(startPoint.y, 2) - temp) / 2.;
  7011. var midToEnd = (temp - Math.pow(endPoint.x, 2) - Math.pow(endPoint.y, 2)) / 2.;
  7012. var det = (startPoint.x - midPoint.x) * (midPoint.y - endPoint.y) - (midPoint.x - endPoint.x) * (startPoint.y - midPoint.y);
  7013. this.centerPoint = new Vector2((startToMid * (midPoint.y - endPoint.y) - midToEnd * (startPoint.y - midPoint.y)) / det, ((startPoint.x - midPoint.x) * midToEnd - (midPoint.x - endPoint.x) * startToMid) / det);
  7014. this.radius = this.centerPoint.subtract(this.startPoint).length();
  7015. this.startAngle = Angle.BetweenTwoPoints(this.centerPoint, this.startPoint);
  7016. var a1 = this.startAngle.degrees();
  7017. var a2 = Angle.BetweenTwoPoints(this.centerPoint, this.midPoint).degrees();
  7018. var a3 = Angle.BetweenTwoPoints(this.centerPoint, this.endPoint).degrees();
  7019. // angles correction
  7020. if (a2 - a1 > +180.0)
  7021. a2 -= 360.0;
  7022. if (a2 - a1 < -180.0)
  7023. a2 += 360.0;
  7024. if (a3 - a2 > +180.0)
  7025. a3 -= 360.0;
  7026. if (a3 - a2 < -180.0)
  7027. a3 += 360.0;
  7028. this.orientation = (a2 - a1) < 0 ? Orientation.CW : Orientation.CCW;
  7029. this.angle = Angle.FromDegrees(this.orientation === Orientation.CW ? a1 - a3 : a3 - a1);
  7030. }
  7031. return Arc2;
  7032. }());
  7033. BABYLON.Arc2 = Arc2;
  7034. var Path2 = /** @class */ (function () {
  7035. /**
  7036. * Creates a Path2 object from the starting 2D coordinates x and y.
  7037. */
  7038. function Path2(x, y) {
  7039. this._points = new Array();
  7040. this._length = 0.0;
  7041. this.closed = false;
  7042. this._points.push(new Vector2(x, y));
  7043. }
  7044. /**
  7045. * Adds a new segment until the given coordinates (x, y) to the current Path2.
  7046. * Returns the updated Path2.
  7047. */
  7048. Path2.prototype.addLineTo = function (x, y) {
  7049. if (this.closed) {
  7050. return this;
  7051. }
  7052. var newPoint = new Vector2(x, y);
  7053. var previousPoint = this._points[this._points.length - 1];
  7054. this._points.push(newPoint);
  7055. this._length += newPoint.subtract(previousPoint).length();
  7056. return this;
  7057. };
  7058. /**
  7059. * Adds _numberOfSegments_ segments according to the arc definition (middle point coordinates, end point coordinates, the arc start point being the current Path2 last point) to the current Path2.
  7060. * Returns the updated Path2.
  7061. */
  7062. Path2.prototype.addArcTo = function (midX, midY, endX, endY, numberOfSegments) {
  7063. if (numberOfSegments === void 0) { numberOfSegments = 36; }
  7064. if (this.closed) {
  7065. return this;
  7066. }
  7067. var startPoint = this._points[this._points.length - 1];
  7068. var midPoint = new Vector2(midX, midY);
  7069. var endPoint = new Vector2(endX, endY);
  7070. var arc = new Arc2(startPoint, midPoint, endPoint);
  7071. var increment = arc.angle.radians() / numberOfSegments;
  7072. if (arc.orientation === Orientation.CW)
  7073. increment *= -1;
  7074. var currentAngle = arc.startAngle.radians() + increment;
  7075. for (var i = 0; i < numberOfSegments; i++) {
  7076. var x = Math.cos(currentAngle) * arc.radius + arc.centerPoint.x;
  7077. var y = Math.sin(currentAngle) * arc.radius + arc.centerPoint.y;
  7078. this.addLineTo(x, y);
  7079. currentAngle += increment;
  7080. }
  7081. return this;
  7082. };
  7083. /**
  7084. * Closes the Path2.
  7085. * Returns the Path2.
  7086. */
  7087. Path2.prototype.close = function () {
  7088. this.closed = true;
  7089. return this;
  7090. };
  7091. /**
  7092. * Returns the Path2 total length (float).
  7093. */
  7094. Path2.prototype.length = function () {
  7095. var result = this._length;
  7096. if (!this.closed) {
  7097. var lastPoint = this._points[this._points.length - 1];
  7098. var firstPoint = this._points[0];
  7099. result += (firstPoint.subtract(lastPoint).length());
  7100. }
  7101. return result;
  7102. };
  7103. /**
  7104. * Returns the Path2 internal array of points.
  7105. */
  7106. Path2.prototype.getPoints = function () {
  7107. return this._points;
  7108. };
  7109. /**
  7110. * Returns a new Vector2 located at a percentage of the Path2 total length on this path.
  7111. */
  7112. Path2.prototype.getPointAtLengthPosition = function (normalizedLengthPosition) {
  7113. if (normalizedLengthPosition < 0 || normalizedLengthPosition > 1) {
  7114. return Vector2.Zero();
  7115. }
  7116. var lengthPosition = normalizedLengthPosition * this.length();
  7117. var previousOffset = 0;
  7118. for (var i = 0; i < this._points.length; i++) {
  7119. var j = (i + 1) % this._points.length;
  7120. var a = this._points[i];
  7121. var b = this._points[j];
  7122. var bToA = b.subtract(a);
  7123. var nextOffset = (bToA.length() + previousOffset);
  7124. if (lengthPosition >= previousOffset && lengthPosition <= nextOffset) {
  7125. var dir = bToA.normalize();
  7126. var localOffset = lengthPosition - previousOffset;
  7127. return new Vector2(a.x + (dir.x * localOffset), a.y + (dir.y * localOffset));
  7128. }
  7129. previousOffset = nextOffset;
  7130. }
  7131. return Vector2.Zero();
  7132. };
  7133. /**
  7134. * Returns a new Path2 starting at the coordinates (x, y).
  7135. */
  7136. Path2.StartingAt = function (x, y) {
  7137. return new Path2(x, y);
  7138. };
  7139. return Path2;
  7140. }());
  7141. BABYLON.Path2 = Path2;
  7142. var Path3D = /** @class */ (function () {
  7143. /**
  7144. * new Path3D(path, normal, raw)
  7145. * Creates a Path3D. A Path3D is a logical math object, so not a mesh.
  7146. * please read the description in the tutorial : http://doc.babylonjs.com/tutorials/How_to_use_Path3D
  7147. * path : an array of Vector3, the curve axis of the Path3D
  7148. * normal (optional) : Vector3, the first wanted normal to the curve. Ex (0, 1, 0) for a vertical normal.
  7149. * raw (optional, default false) : boolean, if true the returned Path3D isn't normalized. Useful to depict path acceleration or speed.
  7150. */
  7151. function Path3D(path, firstNormal, raw) {
  7152. if (firstNormal === void 0) { firstNormal = null; }
  7153. this.path = path;
  7154. this._curve = new Array();
  7155. this._distances = new Array();
  7156. this._tangents = new Array();
  7157. this._normals = new Array();
  7158. this._binormals = new Array();
  7159. for (var p = 0; p < path.length; p++) {
  7160. this._curve[p] = path[p].clone(); // hard copy
  7161. }
  7162. this._raw = raw || false;
  7163. this._compute(firstNormal);
  7164. }
  7165. /**
  7166. * Returns the Path3D array of successive Vector3 designing its curve.
  7167. */
  7168. Path3D.prototype.getCurve = function () {
  7169. return this._curve;
  7170. };
  7171. /**
  7172. * Returns an array populated with tangent vectors on each Path3D curve point.
  7173. */
  7174. Path3D.prototype.getTangents = function () {
  7175. return this._tangents;
  7176. };
  7177. /**
  7178. * Returns an array populated with normal vectors on each Path3D curve point.
  7179. */
  7180. Path3D.prototype.getNormals = function () {
  7181. return this._normals;
  7182. };
  7183. /**
  7184. * Returns an array populated with binormal vectors on each Path3D curve point.
  7185. */
  7186. Path3D.prototype.getBinormals = function () {
  7187. return this._binormals;
  7188. };
  7189. /**
  7190. * Returns an array populated with distances (float) of the i-th point from the first curve point.
  7191. */
  7192. Path3D.prototype.getDistances = function () {
  7193. return this._distances;
  7194. };
  7195. /**
  7196. * Forces the Path3D tangent, normal, binormal and distance recomputation.
  7197. * Returns the same object updated.
  7198. */
  7199. Path3D.prototype.update = function (path, firstNormal) {
  7200. if (firstNormal === void 0) { firstNormal = null; }
  7201. for (var p = 0; p < path.length; p++) {
  7202. this._curve[p].x = path[p].x;
  7203. this._curve[p].y = path[p].y;
  7204. this._curve[p].z = path[p].z;
  7205. }
  7206. this._compute(firstNormal);
  7207. return this;
  7208. };
  7209. // private function compute() : computes tangents, normals and binormals
  7210. Path3D.prototype._compute = function (firstNormal) {
  7211. var l = this._curve.length;
  7212. // first and last tangents
  7213. this._tangents[0] = this._getFirstNonNullVector(0);
  7214. if (!this._raw) {
  7215. this._tangents[0].normalize();
  7216. }
  7217. this._tangents[l - 1] = this._curve[l - 1].subtract(this._curve[l - 2]);
  7218. if (!this._raw) {
  7219. this._tangents[l - 1].normalize();
  7220. }
  7221. // normals and binormals at first point : arbitrary vector with _normalVector()
  7222. var tg0 = this._tangents[0];
  7223. var pp0 = this._normalVector(this._curve[0], tg0, firstNormal);
  7224. this._normals[0] = pp0;
  7225. if (!this._raw) {
  7226. this._normals[0].normalize();
  7227. }
  7228. this._binormals[0] = Vector3.Cross(tg0, this._normals[0]);
  7229. if (!this._raw) {
  7230. this._binormals[0].normalize();
  7231. }
  7232. this._distances[0] = 0.0;
  7233. // normals and binormals : next points
  7234. var prev; // previous vector (segment)
  7235. var cur; // current vector (segment)
  7236. var curTang; // current tangent
  7237. // previous normal
  7238. var prevBinor; // previous binormal
  7239. for (var i = 1; i < l; i++) {
  7240. // tangents
  7241. prev = this._getLastNonNullVector(i);
  7242. if (i < l - 1) {
  7243. cur = this._getFirstNonNullVector(i);
  7244. this._tangents[i] = prev.add(cur);
  7245. this._tangents[i].normalize();
  7246. }
  7247. this._distances[i] = this._distances[i - 1] + prev.length();
  7248. // normals and binormals
  7249. // http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html
  7250. curTang = this._tangents[i];
  7251. prevBinor = this._binormals[i - 1];
  7252. this._normals[i] = Vector3.Cross(prevBinor, curTang);
  7253. if (!this._raw) {
  7254. this._normals[i].normalize();
  7255. }
  7256. this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);
  7257. if (!this._raw) {
  7258. this._binormals[i].normalize();
  7259. }
  7260. }
  7261. };
  7262. // private function getFirstNonNullVector(index)
  7263. // returns the first non null vector from index : curve[index + N].subtract(curve[index])
  7264. Path3D.prototype._getFirstNonNullVector = function (index) {
  7265. var i = 1;
  7266. var nNVector = this._curve[index + i].subtract(this._curve[index]);
  7267. while (nNVector.length() === 0 && index + i + 1 < this._curve.length) {
  7268. i++;
  7269. nNVector = this._curve[index + i].subtract(this._curve[index]);
  7270. }
  7271. return nNVector;
  7272. };
  7273. // private function getLastNonNullVector(index)
  7274. // returns the last non null vector from index : curve[index].subtract(curve[index - N])
  7275. Path3D.prototype._getLastNonNullVector = function (index) {
  7276. var i = 1;
  7277. var nLVector = this._curve[index].subtract(this._curve[index - i]);
  7278. while (nLVector.length() === 0 && index > i + 1) {
  7279. i++;
  7280. nLVector = this._curve[index].subtract(this._curve[index - i]);
  7281. }
  7282. return nLVector;
  7283. };
  7284. // private function normalVector(v0, vt, va) :
  7285. // returns an arbitrary point in the plane defined by the point v0 and the vector vt orthogonal to this plane
  7286. // if va is passed, it returns the va projection on the plane orthogonal to vt at the point v0
  7287. Path3D.prototype._normalVector = function (v0, vt, va) {
  7288. var normal0;
  7289. var tgl = vt.length();
  7290. if (tgl === 0.0) {
  7291. tgl = 1.0;
  7292. }
  7293. if (va === undefined || va === null) {
  7294. var point;
  7295. if (!BABYLON.Scalar.WithinEpsilon(Math.abs(vt.y) / tgl, 1.0, BABYLON.Epsilon)) { // search for a point in the plane
  7296. point = new Vector3(0.0, -1.0, 0.0);
  7297. }
  7298. else if (!BABYLON.Scalar.WithinEpsilon(Math.abs(vt.x) / tgl, 1.0, BABYLON.Epsilon)) {
  7299. point = new Vector3(1.0, 0.0, 0.0);
  7300. }
  7301. else if (!BABYLON.Scalar.WithinEpsilon(Math.abs(vt.z) / tgl, 1.0, BABYLON.Epsilon)) {
  7302. point = new Vector3(0.0, 0.0, 1.0);
  7303. }
  7304. else {
  7305. point = Vector3.Zero();
  7306. }
  7307. normal0 = Vector3.Cross(vt, point);
  7308. }
  7309. else {
  7310. normal0 = Vector3.Cross(vt, va);
  7311. Vector3.CrossToRef(normal0, vt, normal0);
  7312. }
  7313. normal0.normalize();
  7314. return normal0;
  7315. };
  7316. return Path3D;
  7317. }());
  7318. BABYLON.Path3D = Path3D;
  7319. var Curve3 = /** @class */ (function () {
  7320. /**
  7321. * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.
  7322. * A Curve3 is designed from a series of successive Vector3.
  7323. * Tuto : http://doc.babylonjs.com/tutorials/How_to_use_Curve3#curve3-object
  7324. */
  7325. function Curve3(points) {
  7326. this._length = 0.0;
  7327. this._points = points;
  7328. this._length = this._computeLength(points);
  7329. }
  7330. /**
  7331. * Returns a Curve3 object along a Quadratic Bezier curve : http://doc.babylonjs.com/tutorials/How_to_use_Curve3#quadratic-bezier-curve
  7332. * @param v0 (Vector3) the origin point of the Quadratic Bezier
  7333. * @param v1 (Vector3) the control point
  7334. * @param v2 (Vector3) the end point of the Quadratic Bezier
  7335. * @param nbPoints (integer) the wanted number of points in the curve
  7336. */
  7337. Curve3.CreateQuadraticBezier = function (v0, v1, v2, nbPoints) {
  7338. nbPoints = nbPoints > 2 ? nbPoints : 3;
  7339. var bez = new Array();
  7340. var equation = function (t, val0, val1, val2) {
  7341. var res = (1.0 - t) * (1.0 - t) * val0 + 2.0 * t * (1.0 - t) * val1 + t * t * val2;
  7342. return res;
  7343. };
  7344. for (var i = 0; i <= nbPoints; i++) {
  7345. bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x), equation(i / nbPoints, v0.y, v1.y, v2.y), equation(i / nbPoints, v0.z, v1.z, v2.z)));
  7346. }
  7347. return new Curve3(bez);
  7348. };
  7349. /**
  7350. * Returns a Curve3 object along a Cubic Bezier curve : http://doc.babylonjs.com/tutorials/How_to_use_Curve3#cubic-bezier-curve
  7351. * @param v0 (Vector3) the origin point of the Cubic Bezier
  7352. * @param v1 (Vector3) the first control point
  7353. * @param v2 (Vector3) the second control point
  7354. * @param v3 (Vector3) the end point of the Cubic Bezier
  7355. * @param nbPoints (integer) the wanted number of points in the curve
  7356. */
  7357. Curve3.CreateCubicBezier = function (v0, v1, v2, v3, nbPoints) {
  7358. nbPoints = nbPoints > 3 ? nbPoints : 4;
  7359. var bez = new Array();
  7360. var equation = function (t, val0, val1, val2, val3) {
  7361. var res = (1.0 - t) * (1.0 - t) * (1.0 - t) * val0 + 3.0 * t * (1.0 - t) * (1.0 - t) * val1 + 3.0 * t * t * (1.0 - t) * val2 + t * t * t * val3;
  7362. return res;
  7363. };
  7364. for (var i = 0; i <= nbPoints; i++) {
  7365. bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x, v3.x), equation(i / nbPoints, v0.y, v1.y, v2.y, v3.y), equation(i / nbPoints, v0.z, v1.z, v2.z, v3.z)));
  7366. }
  7367. return new Curve3(bez);
  7368. };
  7369. /**
  7370. * Returns a Curve3 object along a Hermite Spline curve : http://doc.babylonjs.com/tutorials/How_to_use_Curve3#hermite-spline
  7371. * @param p1 (Vector3) the origin point of the Hermite Spline
  7372. * @param t1 (Vector3) the tangent vector at the origin point
  7373. * @param p2 (Vector3) the end point of the Hermite Spline
  7374. * @param t2 (Vector3) the tangent vector at the end point
  7375. * @param nbPoints (integer) the wanted number of points in the curve
  7376. */
  7377. Curve3.CreateHermiteSpline = function (p1, t1, p2, t2, nbPoints) {
  7378. var hermite = new Array();
  7379. var step = 1.0 / nbPoints;
  7380. for (var i = 0; i <= nbPoints; i++) {
  7381. hermite.push(Vector3.Hermite(p1, t1, p2, t2, i * step));
  7382. }
  7383. return new Curve3(hermite);
  7384. };
  7385. /**
  7386. * Returns a Curve3 object along a CatmullRom Spline curve :
  7387. * @param points (array of Vector3) the points the spline must pass through. At least, four points required
  7388. * @param nbPoints (integer) the wanted number of points between each curve control points
  7389. * @param closed (boolean) optional with default false, when true forms a closed loop from the points
  7390. */
  7391. Curve3.CreateCatmullRomSpline = function (points, nbPoints, closed) {
  7392. var catmullRom = new Array();
  7393. var step = 1.0 / nbPoints;
  7394. var amount = 0.0;
  7395. if (closed) {
  7396. var pointsCount = points.length;
  7397. for (var i = 0; i < pointsCount; i++) {
  7398. amount = 0;
  7399. for (var c = 0; c < nbPoints; c++) {
  7400. catmullRom.push(Vector3.CatmullRom(points[i % pointsCount], points[(i + 1) % pointsCount], points[(i + 2) % pointsCount], points[(i + 3) % pointsCount], amount));
  7401. amount += step;
  7402. }
  7403. }
  7404. catmullRom.push(catmullRom[0]);
  7405. }
  7406. else {
  7407. var totalPoints = new Array();
  7408. totalPoints.push(points[0].clone());
  7409. Array.prototype.push.apply(totalPoints, points);
  7410. totalPoints.push(points[points.length - 1].clone());
  7411. for (var i = 0; i < totalPoints.length - 3; i++) {
  7412. amount = 0;
  7413. for (var c = 0; c < nbPoints; c++) {
  7414. catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));
  7415. amount += step;
  7416. }
  7417. }
  7418. i--;
  7419. catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));
  7420. }
  7421. return new Curve3(catmullRom);
  7422. };
  7423. /**
  7424. * Returns the Curve3 stored array of successive Vector3
  7425. */
  7426. Curve3.prototype.getPoints = function () {
  7427. return this._points;
  7428. };
  7429. /**
  7430. * Returns the computed length (float) of the curve.
  7431. */
  7432. Curve3.prototype.length = function () {
  7433. return this._length;
  7434. };
  7435. /**
  7436. * Returns a new instance of Curve3 object : var curve = curveA.continue(curveB);
  7437. * This new Curve3 is built by translating and sticking the curveB at the end of the curveA.
  7438. * curveA and curveB keep unchanged.
  7439. */
  7440. Curve3.prototype.continue = function (curve) {
  7441. var lastPoint = this._points[this._points.length - 1];
  7442. var continuedPoints = this._points.slice();
  7443. var curvePoints = curve.getPoints();
  7444. for (var i = 1; i < curvePoints.length; i++) {
  7445. continuedPoints.push(curvePoints[i].subtract(curvePoints[0]).add(lastPoint));
  7446. }
  7447. var continuedCurve = new Curve3(continuedPoints);
  7448. return continuedCurve;
  7449. };
  7450. Curve3.prototype._computeLength = function (path) {
  7451. var l = 0;
  7452. for (var i = 1; i < path.length; i++) {
  7453. l += (path[i].subtract(path[i - 1])).length();
  7454. }
  7455. return l;
  7456. };
  7457. return Curve3;
  7458. }());
  7459. BABYLON.Curve3 = Curve3;
  7460. // Vertex formats
  7461. var PositionNormalVertex = /** @class */ (function () {
  7462. function PositionNormalVertex(position, normal) {
  7463. if (position === void 0) { position = Vector3.Zero(); }
  7464. if (normal === void 0) { normal = Vector3.Up(); }
  7465. this.position = position;
  7466. this.normal = normal;
  7467. }
  7468. PositionNormalVertex.prototype.clone = function () {
  7469. return new PositionNormalVertex(this.position.clone(), this.normal.clone());
  7470. };
  7471. return PositionNormalVertex;
  7472. }());
  7473. BABYLON.PositionNormalVertex = PositionNormalVertex;
  7474. var PositionNormalTextureVertex = /** @class */ (function () {
  7475. function PositionNormalTextureVertex(position, normal, uv) {
  7476. if (position === void 0) { position = Vector3.Zero(); }
  7477. if (normal === void 0) { normal = Vector3.Up(); }
  7478. if (uv === void 0) { uv = Vector2.Zero(); }
  7479. this.position = position;
  7480. this.normal = normal;
  7481. this.uv = uv;
  7482. }
  7483. PositionNormalTextureVertex.prototype.clone = function () {
  7484. return new PositionNormalTextureVertex(this.position.clone(), this.normal.clone(), this.uv.clone());
  7485. };
  7486. return PositionNormalTextureVertex;
  7487. }());
  7488. BABYLON.PositionNormalTextureVertex = PositionNormalTextureVertex;
  7489. // Temporary pre-allocated objects for engine internal use
  7490. // usage in any internal function :
  7491. // var tmp = Tmp.Vector3[0]; <= gets access to the first pre-created Vector3
  7492. // There's a Tmp array per object type : int, float, Vector2, Vector3, Vector4, Quaternion, Matrix
  7493. var Tmp = /** @class */ (function () {
  7494. function Tmp() {
  7495. }
  7496. Tmp.Color3 = [Color3.Black(), Color3.Black(), Color3.Black()];
  7497. Tmp.Vector2 = [Vector2.Zero(), Vector2.Zero(), Vector2.Zero()]; // 3 temp Vector2 at once should be enough
  7498. Tmp.Vector3 = [Vector3.Zero(), Vector3.Zero(), Vector3.Zero(),
  7499. Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero()]; // 9 temp Vector3 at once should be enough
  7500. Tmp.Vector4 = [Vector4.Zero(), Vector4.Zero(), Vector4.Zero()]; // 3 temp Vector4 at once should be enough
  7501. Tmp.Quaternion = [Quaternion.Zero(), Quaternion.Zero()]; // 2 temp Quaternion at once should be enough
  7502. Tmp.Matrix = [Matrix.Zero(), Matrix.Zero(),
  7503. Matrix.Zero(), Matrix.Zero(),
  7504. Matrix.Zero(), Matrix.Zero(),
  7505. Matrix.Zero(), Matrix.Zero()]; // 6 temp Matrices at once should be enough
  7506. return Tmp;
  7507. }());
  7508. BABYLON.Tmp = Tmp;
  7509. // Same as Tmp but not exported to keep it only for math functions to avoid conflicts
  7510. var MathTmp = /** @class */ (function () {
  7511. function MathTmp() {
  7512. }
  7513. MathTmp.Vector3 = [Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero()];
  7514. MathTmp.Matrix = [Matrix.Zero(), Matrix.Zero()];
  7515. MathTmp.Quaternion = [Quaternion.Zero(), Quaternion.Zero(), Quaternion.Zero()];
  7516. return MathTmp;
  7517. }());
  7518. })(BABYLON || (BABYLON = {}));
  7519. //# sourceMappingURL=babylon.math.js.map
  7520. var BABYLON;
  7521. (function (BABYLON) {
  7522. var Scalar = /** @class */ (function () {
  7523. function Scalar() {
  7524. }
  7525. /**
  7526. * Boolean : true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)
  7527. */
  7528. Scalar.WithinEpsilon = function (a, b, epsilon) {
  7529. if (epsilon === void 0) { epsilon = 1.401298E-45; }
  7530. var num = a - b;
  7531. return -epsilon <= num && num <= epsilon;
  7532. };
  7533. /**
  7534. * Returns a string : the upper case translation of the number i to hexadecimal.
  7535. */
  7536. Scalar.ToHex = function (i) {
  7537. var str = i.toString(16);
  7538. if (i <= 15) {
  7539. return ("0" + str).toUpperCase();
  7540. }
  7541. return str.toUpperCase();
  7542. };
  7543. /**
  7544. * Returns -1 if value is negative and +1 is value is positive.
  7545. * Returns the value itself if it's equal to zero.
  7546. */
  7547. Scalar.Sign = function (value) {
  7548. value = +value; // convert to a number
  7549. if (value === 0 || isNaN(value))
  7550. return value;
  7551. return value > 0 ? 1 : -1;
  7552. };
  7553. /**
  7554. * Returns the value itself if it's between min and max.
  7555. * Returns min if the value is lower than min.
  7556. * Returns max if the value is greater than max.
  7557. */
  7558. Scalar.Clamp = function (value, min, max) {
  7559. if (min === void 0) { min = 0; }
  7560. if (max === void 0) { max = 1; }
  7561. return Math.min(max, Math.max(min, value));
  7562. };
  7563. /**
  7564. * Returns the log2 of value.
  7565. */
  7566. Scalar.Log2 = function (value) {
  7567. return Math.log(value) * Math.LOG2E;
  7568. };
  7569. /**
  7570. * Loops the value, so that it is never larger than length and never smaller than 0.
  7571. *
  7572. * This is similar to the modulo operator but it works with floating point numbers.
  7573. * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
  7574. * With t = 5 and length = 2.5, the result would be 0.0.
  7575. * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
  7576. */
  7577. Scalar.Repeat = function (value, length) {
  7578. return value - Math.floor(value / length) * length;
  7579. };
  7580. /**
  7581. * Normalize the value between 0.0 and 1.0 using min and max values
  7582. */
  7583. Scalar.Normalize = function (value, min, max) {
  7584. return (value - min) / (max - min);
  7585. };
  7586. /**
  7587. * Denormalize the value from 0.0 and 1.0 using min and max values
  7588. */
  7589. Scalar.Denormalize = function (normalized, min, max) {
  7590. return (normalized * (max - min) + min);
  7591. };
  7592. /**
  7593. * Calculates the shortest difference between two given angles given in degrees.
  7594. */
  7595. Scalar.DeltaAngle = function (current, target) {
  7596. var num = Scalar.Repeat(target - current, 360.0);
  7597. if (num > 180.0) {
  7598. num -= 360.0;
  7599. }
  7600. return num;
  7601. };
  7602. /**
  7603. * PingPongs the value t, so that it is never larger than length and never smaller than 0.
  7604. *
  7605. * The returned value will move back and forth between 0 and length
  7606. */
  7607. Scalar.PingPong = function (tx, length) {
  7608. var t = Scalar.Repeat(tx, length * 2.0);
  7609. return length - Math.abs(t - length);
  7610. };
  7611. /**
  7612. * Interpolates between min and max with smoothing at the limits.
  7613. *
  7614. * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up
  7615. * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.
  7616. */
  7617. Scalar.SmoothStep = function (from, to, tx) {
  7618. var t = Scalar.Clamp(tx);
  7619. t = -2.0 * t * t * t + 3.0 * t * t;
  7620. return to * t + from * (1.0 - t);
  7621. };
  7622. /**
  7623. * Moves a value current towards target.
  7624. *
  7625. * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.
  7626. * Negative values of maxDelta pushes the value away from target.
  7627. */
  7628. Scalar.MoveTowards = function (current, target, maxDelta) {
  7629. var result = 0;
  7630. if (Math.abs(target - current) <= maxDelta) {
  7631. result = target;
  7632. }
  7633. else {
  7634. result = current + Scalar.Sign(target - current) * maxDelta;
  7635. }
  7636. return result;
  7637. };
  7638. /**
  7639. * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
  7640. *
  7641. * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta
  7642. * are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.
  7643. */
  7644. Scalar.MoveTowardsAngle = function (current, target, maxDelta) {
  7645. var num = Scalar.DeltaAngle(current, target);
  7646. var result = 0;
  7647. if (-maxDelta < num && num < maxDelta) {
  7648. result = target;
  7649. }
  7650. else {
  7651. target = current + num;
  7652. result = Scalar.MoveTowards(current, target, maxDelta);
  7653. }
  7654. return result;
  7655. };
  7656. /**
  7657. * Creates a new scalar with values linearly interpolated of "amount" between the start scalar and the end scalar.
  7658. */
  7659. Scalar.Lerp = function (start, end, amount) {
  7660. return start + ((end - start) * amount);
  7661. };
  7662. /**
  7663. * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
  7664. * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.
  7665. */
  7666. Scalar.LerpAngle = function (start, end, amount) {
  7667. var num = Scalar.Repeat(end - start, 360.0);
  7668. if (num > 180.0) {
  7669. num -= 360.0;
  7670. }
  7671. return start + num * Scalar.Clamp(amount);
  7672. };
  7673. /**
  7674. * Calculates the linear parameter t that produces the interpolant value within the range [a, b].
  7675. */
  7676. Scalar.InverseLerp = function (a, b, value) {
  7677. var result = 0;
  7678. if (a != b) {
  7679. result = Scalar.Clamp((value - a) / (b - a));
  7680. }
  7681. else {
  7682. result = 0.0;
  7683. }
  7684. return result;
  7685. };
  7686. /**
  7687. * Returns a new scalar located for "amount" (float) on the Hermite spline defined by the scalars "value1", "value3", "tangent1", "tangent2".
  7688. */
  7689. Scalar.Hermite = function (value1, tangent1, value2, tangent2, amount) {
  7690. var squared = amount * amount;
  7691. var cubed = amount * squared;
  7692. var part1 = ((2.0 * cubed) - (3.0 * squared)) + 1.0;
  7693. var part2 = (-2.0 * cubed) + (3.0 * squared);
  7694. var part3 = (cubed - (2.0 * squared)) + amount;
  7695. var part4 = cubed - squared;
  7696. return (((value1 * part1) + (value2 * part2)) + (tangent1 * part3)) + (tangent2 * part4);
  7697. };
  7698. /**
  7699. * Returns a random float number between and min and max values
  7700. */
  7701. Scalar.RandomRange = function (min, max) {
  7702. if (min === max)
  7703. return min;
  7704. return ((Math.random() * (max - min)) + min);
  7705. };
  7706. /**
  7707. * This function returns percentage of a number in a given range.
  7708. *
  7709. * RangeToPercent(40,20,60) will return 0.5 (50%)
  7710. * RangeToPercent(34,0,100) will return 0.34 (34%)
  7711. */
  7712. Scalar.RangeToPercent = function (number, min, max) {
  7713. return ((number - min) / (max - min));
  7714. };
  7715. /**
  7716. * This function returns number that corresponds to the percentage in a given range.
  7717. *
  7718. * PercentToRange(0.34,0,100) will return 34.
  7719. */
  7720. Scalar.PercentToRange = function (percent, min, max) {
  7721. return ((max - min) * percent + min);
  7722. };
  7723. /**
  7724. * Returns the angle converted to equivalent value between -Math.PI and Math.PI radians.
  7725. * @param angle The angle to normalize in radian.
  7726. * @return The converted angle.
  7727. */
  7728. Scalar.NormalizeRadians = function (angle) {
  7729. // More precise but slower version kept for reference.
  7730. // angle = angle % Tools.TwoPi;
  7731. // angle = (angle + Tools.TwoPi) % Tools.TwoPi;
  7732. //if (angle > Math.PI) {
  7733. // angle -= Tools.TwoPi;
  7734. //}
  7735. angle -= (Scalar.TwoPi * Math.floor((angle + Math.PI) / Scalar.TwoPi));
  7736. return angle;
  7737. };
  7738. /**
  7739. * Two pi constants convenient for computation.
  7740. */
  7741. Scalar.TwoPi = Math.PI * 2;
  7742. return Scalar;
  7743. }());
  7744. BABYLON.Scalar = Scalar;
  7745. })(BABYLON || (BABYLON = {}));
  7746. //# sourceMappingURL=babylon.math.scalar.js.map
  7747. //# sourceMappingURL=babylon.mixins.js.map
  7748. // Type definitions for WebGL 2, Editor's Draft Fri Feb 24 16:10:18 2017 -0800
  7749. // Project: https://www.khronos.org/registry/webgl/specs/latest/2.0/
  7750. // Definitions by: Nico Kemnitz <https://github.com/nkemnitz/>
  7751. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  7752. //# sourceMappingURL=babylon.webgl2.js.map
  7753. var BABYLON;
  7754. (function (BABYLON) {
  7755. var __decoratorInitialStore = {};
  7756. var __mergedStore = {};
  7757. var _copySource = function (creationFunction, source, instanciate) {
  7758. var destination = creationFunction();
  7759. // Tags
  7760. if (BABYLON.Tags) {
  7761. BABYLON.Tags.AddTagsTo(destination, source.tags);
  7762. }
  7763. var classStore = getMergedStore(destination);
  7764. // Properties
  7765. for (var property in classStore) {
  7766. var propertyDescriptor = classStore[property];
  7767. var sourceProperty = source[property];
  7768. var propertyType = propertyDescriptor.type;
  7769. if (sourceProperty !== undefined && sourceProperty !== null) {
  7770. switch (propertyType) {
  7771. case 0: // Value
  7772. case 6: // Mesh reference
  7773. case 11: // Camera reference
  7774. destination[property] = sourceProperty;
  7775. break;
  7776. case 1: // Texture
  7777. destination[property] = (instanciate || sourceProperty.isRenderTarget) ? sourceProperty : sourceProperty.clone();
  7778. break;
  7779. case 2: // Color3
  7780. case 3: // FresnelParameters
  7781. case 4: // Vector2
  7782. case 5: // Vector3
  7783. case 7: // Color Curves
  7784. case 10: // Quaternion
  7785. destination[property] = instanciate ? sourceProperty : sourceProperty.clone();
  7786. break;
  7787. }
  7788. }
  7789. }
  7790. return destination;
  7791. };
  7792. function getDirectStore(target) {
  7793. var classKey = target.getClassName();
  7794. if (!__decoratorInitialStore[classKey]) {
  7795. __decoratorInitialStore[classKey] = {};
  7796. }
  7797. return __decoratorInitialStore[classKey];
  7798. }
  7799. /**
  7800. * Return the list of properties flagged as serializable
  7801. * @param target: host object
  7802. */
  7803. function getMergedStore(target) {
  7804. var classKey = target.getClassName();
  7805. if (__mergedStore[classKey]) {
  7806. return __mergedStore[classKey];
  7807. }
  7808. __mergedStore[classKey] = {};
  7809. var store = __mergedStore[classKey];
  7810. var currentTarget = target;
  7811. var currentKey = classKey;
  7812. while (currentKey) {
  7813. var initialStore = __decoratorInitialStore[currentKey];
  7814. for (var property in initialStore) {
  7815. store[property] = initialStore[property];
  7816. }
  7817. var parent_1 = void 0;
  7818. var done = false;
  7819. do {
  7820. parent_1 = Object.getPrototypeOf(currentTarget);
  7821. if (!parent_1.getClassName) {
  7822. done = true;
  7823. break;
  7824. }
  7825. if (parent_1.getClassName() !== currentKey) {
  7826. break;
  7827. }
  7828. currentTarget = parent_1;
  7829. } while (parent_1);
  7830. if (done) {
  7831. break;
  7832. }
  7833. currentKey = parent_1.getClassName();
  7834. currentTarget = parent_1;
  7835. }
  7836. return store;
  7837. }
  7838. function generateSerializableMember(type, sourceName) {
  7839. return function (target, propertyKey) {
  7840. var classStore = getDirectStore(target);
  7841. if (!classStore[propertyKey]) {
  7842. classStore[propertyKey] = { type: type, sourceName: sourceName };
  7843. }
  7844. };
  7845. }
  7846. function generateExpandMember(setCallback, targetKey) {
  7847. if (targetKey === void 0) { targetKey = null; }
  7848. return function (target, propertyKey) {
  7849. var key = targetKey || ("_" + propertyKey);
  7850. Object.defineProperty(target, propertyKey, {
  7851. get: function () {
  7852. return this[key];
  7853. },
  7854. set: function (value) {
  7855. if (this[key] === value) {
  7856. return;
  7857. }
  7858. this[key] = value;
  7859. target[setCallback].apply(this);
  7860. },
  7861. enumerable: true,
  7862. configurable: true
  7863. });
  7864. };
  7865. }
  7866. function expandToProperty(callback, targetKey) {
  7867. if (targetKey === void 0) { targetKey = null; }
  7868. return generateExpandMember(callback, targetKey);
  7869. }
  7870. BABYLON.expandToProperty = expandToProperty;
  7871. function serialize(sourceName) {
  7872. return generateSerializableMember(0, sourceName); // value member
  7873. }
  7874. BABYLON.serialize = serialize;
  7875. function serializeAsTexture(sourceName) {
  7876. return generateSerializableMember(1, sourceName); // texture member
  7877. }
  7878. BABYLON.serializeAsTexture = serializeAsTexture;
  7879. function serializeAsColor3(sourceName) {
  7880. return generateSerializableMember(2, sourceName); // color3 member
  7881. }
  7882. BABYLON.serializeAsColor3 = serializeAsColor3;
  7883. function serializeAsFresnelParameters(sourceName) {
  7884. return generateSerializableMember(3, sourceName); // fresnel parameters member
  7885. }
  7886. BABYLON.serializeAsFresnelParameters = serializeAsFresnelParameters;
  7887. function serializeAsVector2(sourceName) {
  7888. return generateSerializableMember(4, sourceName); // vector2 member
  7889. }
  7890. BABYLON.serializeAsVector2 = serializeAsVector2;
  7891. function serializeAsVector3(sourceName) {
  7892. return generateSerializableMember(5, sourceName); // vector3 member
  7893. }
  7894. BABYLON.serializeAsVector3 = serializeAsVector3;
  7895. function serializeAsMeshReference(sourceName) {
  7896. return generateSerializableMember(6, sourceName); // mesh reference member
  7897. }
  7898. BABYLON.serializeAsMeshReference = serializeAsMeshReference;
  7899. function serializeAsColorCurves(sourceName) {
  7900. return generateSerializableMember(7, sourceName); // color curves
  7901. }
  7902. BABYLON.serializeAsColorCurves = serializeAsColorCurves;
  7903. function serializeAsColor4(sourceName) {
  7904. return generateSerializableMember(8, sourceName); // color 4
  7905. }
  7906. BABYLON.serializeAsColor4 = serializeAsColor4;
  7907. function serializeAsImageProcessingConfiguration(sourceName) {
  7908. return generateSerializableMember(9, sourceName); // image processing
  7909. }
  7910. BABYLON.serializeAsImageProcessingConfiguration = serializeAsImageProcessingConfiguration;
  7911. function serializeAsQuaternion(sourceName) {
  7912. return generateSerializableMember(10, sourceName); // quaternion member
  7913. }
  7914. BABYLON.serializeAsQuaternion = serializeAsQuaternion;
  7915. /**
  7916. * Decorator used to define property that can be serialized as reference to a camera
  7917. * @param sourceName defines the name of the property to decorate
  7918. */
  7919. function serializeAsCameraReference(sourceName) {
  7920. return generateSerializableMember(11, sourceName); // camera reference member
  7921. }
  7922. BABYLON.serializeAsCameraReference = serializeAsCameraReference;
  7923. var SerializationHelper = /** @class */ (function () {
  7924. function SerializationHelper() {
  7925. }
  7926. SerializationHelper.Serialize = function (entity, serializationObject) {
  7927. if (!serializationObject) {
  7928. serializationObject = {};
  7929. }
  7930. // Tags
  7931. if (BABYLON.Tags) {
  7932. serializationObject.tags = BABYLON.Tags.GetTags(entity);
  7933. }
  7934. var serializedProperties = getMergedStore(entity);
  7935. // Properties
  7936. for (var property in serializedProperties) {
  7937. var propertyDescriptor = serializedProperties[property];
  7938. var targetPropertyName = propertyDescriptor.sourceName || property;
  7939. var propertyType = propertyDescriptor.type;
  7940. var sourceProperty = entity[property];
  7941. if (sourceProperty !== undefined && sourceProperty !== null) {
  7942. switch (propertyType) {
  7943. case 0: // Value
  7944. serializationObject[targetPropertyName] = sourceProperty;
  7945. break;
  7946. case 1: // Texture
  7947. serializationObject[targetPropertyName] = sourceProperty.serialize();
  7948. break;
  7949. case 2: // Color3
  7950. serializationObject[targetPropertyName] = sourceProperty.asArray();
  7951. break;
  7952. case 3: // FresnelParameters
  7953. serializationObject[targetPropertyName] = sourceProperty.serialize();
  7954. break;
  7955. case 4: // Vector2
  7956. serializationObject[targetPropertyName] = sourceProperty.asArray();
  7957. break;
  7958. case 5: // Vector3
  7959. serializationObject[targetPropertyName] = sourceProperty.asArray();
  7960. break;
  7961. case 6: // Mesh reference
  7962. serializationObject[targetPropertyName] = sourceProperty.id;
  7963. break;
  7964. case 7: // Color Curves
  7965. serializationObject[targetPropertyName] = sourceProperty.serialize();
  7966. break;
  7967. case 8: // Color 4
  7968. serializationObject[targetPropertyName] = sourceProperty.asArray();
  7969. break;
  7970. case 9: // Image Processing
  7971. serializationObject[targetPropertyName] = sourceProperty.serialize();
  7972. break;
  7973. case 10: // Quaternion
  7974. serializationObject[targetPropertyName] = sourceProperty.asArray();
  7975. break;
  7976. case 11: // Camera reference
  7977. serializationObject[targetPropertyName] = sourceProperty.id;
  7978. break;
  7979. }
  7980. }
  7981. }
  7982. return serializationObject;
  7983. };
  7984. SerializationHelper.Parse = function (creationFunction, source, scene, rootUrl) {
  7985. if (rootUrl === void 0) { rootUrl = null; }
  7986. var destination = creationFunction();
  7987. if (!rootUrl) {
  7988. rootUrl = "";
  7989. }
  7990. // Tags
  7991. if (BABYLON.Tags) {
  7992. BABYLON.Tags.AddTagsTo(destination, source.tags);
  7993. }
  7994. var classStore = getMergedStore(destination);
  7995. // Properties
  7996. for (var property in classStore) {
  7997. var propertyDescriptor = classStore[property];
  7998. var sourceProperty = source[propertyDescriptor.sourceName || property];
  7999. var propertyType = propertyDescriptor.type;
  8000. if (sourceProperty !== undefined && sourceProperty !== null) {
  8001. var dest = destination;
  8002. switch (propertyType) {
  8003. case 0: // Value
  8004. dest[property] = sourceProperty;
  8005. break;
  8006. case 1: // Texture
  8007. if (scene) {
  8008. dest[property] = BABYLON.Texture.Parse(sourceProperty, scene, rootUrl);
  8009. }
  8010. break;
  8011. case 2: // Color3
  8012. dest[property] = BABYLON.Color3.FromArray(sourceProperty);
  8013. break;
  8014. case 3: // FresnelParameters
  8015. dest[property] = BABYLON.FresnelParameters.Parse(sourceProperty);
  8016. break;
  8017. case 4: // Vector2
  8018. dest[property] = BABYLON.Vector2.FromArray(sourceProperty);
  8019. break;
  8020. case 5: // Vector3
  8021. dest[property] = BABYLON.Vector3.FromArray(sourceProperty);
  8022. break;
  8023. case 6: // Mesh reference
  8024. if (scene) {
  8025. dest[property] = scene.getLastMeshByID(sourceProperty);
  8026. }
  8027. break;
  8028. case 7: // Color Curves
  8029. dest[property] = BABYLON.ColorCurves.Parse(sourceProperty);
  8030. break;
  8031. case 8: // Color 4
  8032. dest[property] = BABYLON.Color4.FromArray(sourceProperty);
  8033. break;
  8034. case 9: // Image Processing
  8035. dest[property] = BABYLON.ImageProcessingConfiguration.Parse(sourceProperty);
  8036. break;
  8037. case 10: // Quaternion
  8038. dest[property] = BABYLON.Quaternion.FromArray(sourceProperty);
  8039. break;
  8040. case 11: // Camera reference
  8041. if (scene) {
  8042. dest[property] = scene.getCameraByID(sourceProperty);
  8043. }
  8044. break;
  8045. }
  8046. }
  8047. }
  8048. return destination;
  8049. };
  8050. SerializationHelper.Clone = function (creationFunction, source) {
  8051. return _copySource(creationFunction, source, false);
  8052. };
  8053. SerializationHelper.Instanciate = function (creationFunction, source) {
  8054. return _copySource(creationFunction, source, true);
  8055. };
  8056. return SerializationHelper;
  8057. }());
  8058. BABYLON.SerializationHelper = SerializationHelper;
  8059. })(BABYLON || (BABYLON = {}));
  8060. //# sourceMappingURL=babylon.decorators.js.map
  8061. var BABYLON;
  8062. (function (BABYLON) {
  8063. /**
  8064. * Wrapper class for promise with external resolve and reject.
  8065. */
  8066. var Deferred = /** @class */ (function () {
  8067. /**
  8068. * Constructor for this deferred object.
  8069. */
  8070. function Deferred() {
  8071. var _this = this;
  8072. this.promise = new Promise(function (resolve, reject) {
  8073. _this._resolve = resolve;
  8074. _this._reject = reject;
  8075. });
  8076. }
  8077. Object.defineProperty(Deferred.prototype, "resolve", {
  8078. /**
  8079. * The resolve method of the promise associated with this deferred object.
  8080. */
  8081. get: function () {
  8082. return this._resolve;
  8083. },
  8084. enumerable: true,
  8085. configurable: true
  8086. });
  8087. Object.defineProperty(Deferred.prototype, "reject", {
  8088. /**
  8089. * The reject method of the promise associated with this deferred object.
  8090. */
  8091. get: function () {
  8092. return this._reject;
  8093. },
  8094. enumerable: true,
  8095. configurable: true
  8096. });
  8097. return Deferred;
  8098. }());
  8099. BABYLON.Deferred = Deferred;
  8100. })(BABYLON || (BABYLON = {}));
  8101. //# sourceMappingURL=babylon.deferred.js.map
  8102. var BABYLON;
  8103. (function (BABYLON) {
  8104. /**
  8105. * A class serves as a medium between the observable and its observers
  8106. */
  8107. var EventState = /** @class */ (function () {
  8108. /**
  8109. * Create a new EventState
  8110. * @param mask defines the mask associated with this state
  8111. * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
  8112. * @param target defines the original target of the state
  8113. * @param currentTarget defines the current target of the state
  8114. */
  8115. function EventState(mask, skipNextObservers, target, currentTarget) {
  8116. if (skipNextObservers === void 0) { skipNextObservers = false; }
  8117. this.initalize(mask, skipNextObservers, target, currentTarget);
  8118. }
  8119. /**
  8120. * Initialize the current event state
  8121. * @param mask defines the mask associated with this state
  8122. * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
  8123. * @param target defines the original target of the state
  8124. * @param currentTarget defines the current target of the state
  8125. * @returns the current event state
  8126. */
  8127. EventState.prototype.initalize = function (mask, skipNextObservers, target, currentTarget) {
  8128. if (skipNextObservers === void 0) { skipNextObservers = false; }
  8129. this.mask = mask;
  8130. this.skipNextObservers = skipNextObservers;
  8131. this.target = target;
  8132. this.currentTarget = currentTarget;
  8133. return this;
  8134. };
  8135. return EventState;
  8136. }());
  8137. BABYLON.EventState = EventState;
  8138. /**
  8139. * Represent an Observer registered to a given Observable object.
  8140. */
  8141. var Observer = /** @class */ (function () {
  8142. /**
  8143. * Creates a new observer
  8144. * @param callback defines the callback to call when the observer is notified
  8145. * @param mask defines the mask of the observer (used to filter notifications)
  8146. * @param scope defines the current scope used to restore the JS context
  8147. */
  8148. function Observer(
  8149. /**
  8150. * Defines the callback to call when the observer is notified
  8151. */
  8152. callback,
  8153. /**
  8154. * Defines the mask of the observer (used to filter notifications)
  8155. */
  8156. mask,
  8157. /**
  8158. * Defines the current scope used to restore the JS context
  8159. */
  8160. scope) {
  8161. if (scope === void 0) { scope = null; }
  8162. this.callback = callback;
  8163. this.mask = mask;
  8164. this.scope = scope;
  8165. /** @hidden */
  8166. this._willBeUnregistered = false;
  8167. /**
  8168. * Gets or sets a property defining that the observer as to be unregistered after the next notification
  8169. */
  8170. this.unregisterOnNextCall = false;
  8171. }
  8172. return Observer;
  8173. }());
  8174. BABYLON.Observer = Observer;
  8175. /**
  8176. * Represent a list of observers registered to multiple Observables object.
  8177. */
  8178. var MultiObserver = /** @class */ (function () {
  8179. function MultiObserver() {
  8180. }
  8181. /**
  8182. * Release associated resources
  8183. */
  8184. MultiObserver.prototype.dispose = function () {
  8185. if (this._observers && this._observables) {
  8186. for (var index = 0; index < this._observers.length; index++) {
  8187. this._observables[index].remove(this._observers[index]);
  8188. }
  8189. }
  8190. this._observers = null;
  8191. this._observables = null;
  8192. };
  8193. /**
  8194. * Raise a callback when one of the observable will notify
  8195. * @param observables defines a list of observables to watch
  8196. * @param callback defines the callback to call on notification
  8197. * @param mask defines the mask used to filter notifications
  8198. * @param scope defines the current scope used to restore the JS context
  8199. * @returns the new MultiObserver
  8200. */
  8201. MultiObserver.Watch = function (observables, callback, mask, scope) {
  8202. if (mask === void 0) { mask = -1; }
  8203. if (scope === void 0) { scope = null; }
  8204. var result = new MultiObserver();
  8205. result._observers = new Array();
  8206. result._observables = observables;
  8207. for (var _i = 0, observables_1 = observables; _i < observables_1.length; _i++) {
  8208. var observable = observables_1[_i];
  8209. var observer = observable.add(callback, mask, false, scope);
  8210. if (observer) {
  8211. result._observers.push(observer);
  8212. }
  8213. }
  8214. return result;
  8215. };
  8216. return MultiObserver;
  8217. }());
  8218. BABYLON.MultiObserver = MultiObserver;
  8219. /**
  8220. * The Observable class is a simple implementation of the Observable pattern.
  8221. *
  8222. * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.
  8223. * This enable a more fine grained execution without having to rely on multiple different Observable objects.
  8224. * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).
  8225. * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
  8226. */
  8227. var Observable = /** @class */ (function () {
  8228. /**
  8229. * Creates a new observable
  8230. * @param onObserverAdded defines a callback to call when a new observer is added
  8231. */
  8232. function Observable(onObserverAdded) {
  8233. this._observers = new Array();
  8234. this._eventState = new EventState(0);
  8235. if (onObserverAdded) {
  8236. this._onObserverAdded = onObserverAdded;
  8237. }
  8238. }
  8239. /**
  8240. * Create a new Observer with the specified callback
  8241. * @param callback the callback that will be executed for that Observer
  8242. * @param mask the mask used to filter observers
  8243. * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.
  8244. * @param scope optional scope for the callback to be called from
  8245. * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification
  8246. * @returns the new observer created for the callback
  8247. */
  8248. Observable.prototype.add = function (callback, mask, insertFirst, scope, unregisterOnFirstCall) {
  8249. if (mask === void 0) { mask = -1; }
  8250. if (insertFirst === void 0) { insertFirst = false; }
  8251. if (scope === void 0) { scope = null; }
  8252. if (unregisterOnFirstCall === void 0) { unregisterOnFirstCall = false; }
  8253. if (!callback) {
  8254. return null;
  8255. }
  8256. var observer = new Observer(callback, mask, scope);
  8257. observer.unregisterOnNextCall = unregisterOnFirstCall;
  8258. if (insertFirst) {
  8259. this._observers.unshift(observer);
  8260. }
  8261. else {
  8262. this._observers.push(observer);
  8263. }
  8264. if (this._onObserverAdded) {
  8265. this._onObserverAdded(observer);
  8266. }
  8267. return observer;
  8268. };
  8269. /**
  8270. * Create a new Observer with the specified callback and unregisters after the next notification
  8271. * @param callback the callback that will be executed for that Observer
  8272. * @returns the new observer created for the callback
  8273. */
  8274. Observable.prototype.addOnce = function (callback) {
  8275. return this.add(callback, undefined, undefined, undefined, true);
  8276. };
  8277. /**
  8278. * Remove an Observer from the Observable object
  8279. * @param observer the instance of the Observer to remove
  8280. * @returns false if it doesn't belong to this Observable
  8281. */
  8282. Observable.prototype.remove = function (observer) {
  8283. if (!observer) {
  8284. return false;
  8285. }
  8286. var index = this._observers.indexOf(observer);
  8287. if (index !== -1) {
  8288. this._observers.splice(index, 1);
  8289. return true;
  8290. }
  8291. return false;
  8292. };
  8293. /**
  8294. * Remove a callback from the Observable object
  8295. * @param callback the callback to remove
  8296. * @param scope optional scope. If used only the callbacks with this scope will be removed
  8297. * @returns false if it doesn't belong to this Observable
  8298. */
  8299. Observable.prototype.removeCallback = function (callback, scope) {
  8300. for (var index = 0; index < this._observers.length; index++) {
  8301. if (this._observers[index].callback === callback && (!scope || scope === this._observers[index].scope)) {
  8302. this._observers.splice(index, 1);
  8303. return true;
  8304. }
  8305. }
  8306. return false;
  8307. };
  8308. Observable.prototype._deferUnregister = function (observer) {
  8309. var _this = this;
  8310. observer.unregisterOnNextCall = false;
  8311. observer._willBeUnregistered = true;
  8312. BABYLON.Tools.SetImmediate(function () {
  8313. _this.remove(observer);
  8314. });
  8315. };
  8316. /**
  8317. * Notify all Observers by calling their respective callback with the given data
  8318. * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
  8319. * @param eventData defines the data to send to all observers
  8320. * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)
  8321. * @param target defines the original target of the state
  8322. * @param currentTarget defines the current target of the state
  8323. * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)
  8324. */
  8325. Observable.prototype.notifyObservers = function (eventData, mask, target, currentTarget) {
  8326. if (mask === void 0) { mask = -1; }
  8327. if (!this._observers.length) {
  8328. return true;
  8329. }
  8330. var state = this._eventState;
  8331. state.mask = mask;
  8332. state.target = target;
  8333. state.currentTarget = currentTarget;
  8334. state.skipNextObservers = false;
  8335. state.lastReturnValue = eventData;
  8336. for (var _i = 0, _a = this._observers; _i < _a.length; _i++) {
  8337. var obs = _a[_i];
  8338. if (obs._willBeUnregistered) {
  8339. continue;
  8340. }
  8341. if (obs.mask & mask) {
  8342. if (obs.scope) {
  8343. state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);
  8344. }
  8345. else {
  8346. state.lastReturnValue = obs.callback(eventData, state);
  8347. }
  8348. if (obs.unregisterOnNextCall) {
  8349. this._deferUnregister(obs);
  8350. }
  8351. }
  8352. if (state.skipNextObservers) {
  8353. return false;
  8354. }
  8355. }
  8356. return true;
  8357. };
  8358. /**
  8359. * Calling this will execute each callback, expecting it to be a promise or return a value.
  8360. * If at any point in the chain one function fails, the promise will fail and the execution will not continue.
  8361. * This is useful when a chain of events (sometimes async events) is needed to initialize a certain object
  8362. * and it is crucial that all callbacks will be executed.
  8363. * The order of the callbacks is kept, callbacks are not executed parallel.
  8364. *
  8365. * @param eventData The data to be sent to each callback
  8366. * @param mask is used to filter observers defaults to -1
  8367. * @param target defines the callback target (see EventState)
  8368. * @param currentTarget defines he current object in the bubbling phase
  8369. * @returns {Promise<T>} will return a Promise than resolves when all callbacks executed successfully.
  8370. */
  8371. Observable.prototype.notifyObserversWithPromise = function (eventData, mask, target, currentTarget) {
  8372. var _this = this;
  8373. if (mask === void 0) { mask = -1; }
  8374. // create an empty promise
  8375. var p = Promise.resolve(eventData);
  8376. // no observers? return this promise.
  8377. if (!this._observers.length) {
  8378. return p;
  8379. }
  8380. var state = this._eventState;
  8381. state.mask = mask;
  8382. state.target = target;
  8383. state.currentTarget = currentTarget;
  8384. state.skipNextObservers = false;
  8385. // execute one callback after another (not using Promise.all, the order is important)
  8386. this._observers.forEach(function (obs) {
  8387. if (state.skipNextObservers) {
  8388. return;
  8389. }
  8390. if (obs._willBeUnregistered) {
  8391. return;
  8392. }
  8393. if (obs.mask & mask) {
  8394. if (obs.scope) {
  8395. p = p.then(function (lastReturnedValue) {
  8396. state.lastReturnValue = lastReturnedValue;
  8397. return obs.callback.apply(obs.scope, [eventData, state]);
  8398. });
  8399. }
  8400. else {
  8401. p = p.then(function (lastReturnedValue) {
  8402. state.lastReturnValue = lastReturnedValue;
  8403. return obs.callback(eventData, state);
  8404. });
  8405. }
  8406. if (obs.unregisterOnNextCall) {
  8407. _this._deferUnregister(obs);
  8408. }
  8409. }
  8410. });
  8411. // return the eventData
  8412. return p.then(function () { return eventData; });
  8413. };
  8414. /**
  8415. * Notify a specific observer
  8416. * @param observer defines the observer to notify
  8417. * @param eventData defines the data to be sent to each callback
  8418. * @param mask is used to filter observers defaults to -1
  8419. */
  8420. Observable.prototype.notifyObserver = function (observer, eventData, mask) {
  8421. if (mask === void 0) { mask = -1; }
  8422. var state = this._eventState;
  8423. state.mask = mask;
  8424. state.skipNextObservers = false;
  8425. observer.callback(eventData, state);
  8426. };
  8427. /**
  8428. * Gets a boolean indicating if the observable has at least one observer
  8429. * @returns true is the Observable has at least one Observer registered
  8430. */
  8431. Observable.prototype.hasObservers = function () {
  8432. return this._observers.length > 0;
  8433. };
  8434. /**
  8435. * Clear the list of observers
  8436. */
  8437. Observable.prototype.clear = function () {
  8438. this._observers = new Array();
  8439. this._onObserverAdded = null;
  8440. };
  8441. /**
  8442. * Clone the current observable
  8443. * @returns a new observable
  8444. */
  8445. Observable.prototype.clone = function () {
  8446. var result = new Observable();
  8447. result._observers = this._observers.slice(0);
  8448. return result;
  8449. };
  8450. /**
  8451. * Does this observable handles observer registered with a given mask
  8452. * @param mask defines the mask to be tested
  8453. * @return whether or not one observer registered with the given mask is handeled
  8454. **/
  8455. Observable.prototype.hasSpecificMask = function (mask) {
  8456. if (mask === void 0) { mask = -1; }
  8457. for (var _i = 0, _a = this._observers; _i < _a.length; _i++) {
  8458. var obs = _a[_i];
  8459. if (obs.mask & mask || obs.mask === mask) {
  8460. return true;
  8461. }
  8462. }
  8463. return false;
  8464. };
  8465. return Observable;
  8466. }());
  8467. BABYLON.Observable = Observable;
  8468. })(BABYLON || (BABYLON = {}));
  8469. //# sourceMappingURL=babylon.observable.js.map
  8470. var BABYLON;
  8471. (function (BABYLON) {
  8472. var SmartArray = /** @class */ (function () {
  8473. function SmartArray(capacity) {
  8474. this.length = 0;
  8475. this.data = new Array(capacity);
  8476. this._id = SmartArray._GlobalId++;
  8477. }
  8478. SmartArray.prototype.push = function (value) {
  8479. this.data[this.length++] = value;
  8480. if (this.length > this.data.length) {
  8481. this.data.length *= 2;
  8482. }
  8483. };
  8484. SmartArray.prototype.forEach = function (func) {
  8485. for (var index = 0; index < this.length; index++) {
  8486. func(this.data[index]);
  8487. }
  8488. };
  8489. SmartArray.prototype.sort = function (compareFn) {
  8490. this.data.sort(compareFn);
  8491. };
  8492. SmartArray.prototype.reset = function () {
  8493. this.length = 0;
  8494. };
  8495. SmartArray.prototype.dispose = function () {
  8496. this.reset();
  8497. if (this.data) {
  8498. this.data.length = 0;
  8499. this.data = [];
  8500. }
  8501. };
  8502. SmartArray.prototype.concat = function (array) {
  8503. if (array.length === 0) {
  8504. return;
  8505. }
  8506. if (this.length + array.length > this.data.length) {
  8507. this.data.length = (this.length + array.length) * 2;
  8508. }
  8509. for (var index = 0; index < array.length; index++) {
  8510. this.data[this.length++] = (array.data || array)[index];
  8511. }
  8512. };
  8513. SmartArray.prototype.indexOf = function (value) {
  8514. var position = this.data.indexOf(value);
  8515. if (position >= this.length) {
  8516. return -1;
  8517. }
  8518. return position;
  8519. };
  8520. SmartArray.prototype.contains = function (value) {
  8521. return this.data.indexOf(value) !== -1;
  8522. };
  8523. // Statics
  8524. SmartArray._GlobalId = 0;
  8525. return SmartArray;
  8526. }());
  8527. BABYLON.SmartArray = SmartArray;
  8528. var SmartArrayNoDuplicate = /** @class */ (function (_super) {
  8529. __extends(SmartArrayNoDuplicate, _super);
  8530. function SmartArrayNoDuplicate() {
  8531. var _this = _super !== null && _super.apply(this, arguments) || this;
  8532. _this._duplicateId = 0;
  8533. return _this;
  8534. }
  8535. SmartArrayNoDuplicate.prototype.push = function (value) {
  8536. _super.prototype.push.call(this, value);
  8537. if (!value.__smartArrayFlags) {
  8538. value.__smartArrayFlags = {};
  8539. }
  8540. value.__smartArrayFlags[this._id] = this._duplicateId;
  8541. };
  8542. SmartArrayNoDuplicate.prototype.pushNoDuplicate = function (value) {
  8543. if (value.__smartArrayFlags && value.__smartArrayFlags[this._id] === this._duplicateId) {
  8544. return false;
  8545. }
  8546. this.push(value);
  8547. return true;
  8548. };
  8549. SmartArrayNoDuplicate.prototype.reset = function () {
  8550. _super.prototype.reset.call(this);
  8551. this._duplicateId++;
  8552. };
  8553. SmartArrayNoDuplicate.prototype.concatWithNoDuplicate = function (array) {
  8554. if (array.length === 0) {
  8555. return;
  8556. }
  8557. if (this.length + array.length > this.data.length) {
  8558. this.data.length = (this.length + array.length) * 2;
  8559. }
  8560. for (var index = 0; index < array.length; index++) {
  8561. var item = (array.data || array)[index];
  8562. this.pushNoDuplicate(item);
  8563. }
  8564. };
  8565. return SmartArrayNoDuplicate;
  8566. }(SmartArray));
  8567. BABYLON.SmartArrayNoDuplicate = SmartArrayNoDuplicate;
  8568. })(BABYLON || (BABYLON = {}));
  8569. //# sourceMappingURL=babylon.smartArray.js.map
  8570. var BABYLON;
  8571. (function (BABYLON) {
  8572. // See https://stackoverflow.com/questions/12915412/how-do-i-extend-a-host-object-e-g-error-in-typescript
  8573. // and https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
  8574. var LoadFileError = /** @class */ (function (_super) {
  8575. __extends(LoadFileError, _super);
  8576. function LoadFileError(message, request) {
  8577. var _this = _super.call(this, message) || this;
  8578. _this.request = request;
  8579. _this.name = "LoadFileError";
  8580. LoadFileError._setPrototypeOf(_this, LoadFileError.prototype);
  8581. return _this;
  8582. }
  8583. // Polyfill for Object.setPrototypeOf if necessary.
  8584. LoadFileError._setPrototypeOf = Object.setPrototypeOf || (function (o, proto) { o.__proto__ = proto; return o; });
  8585. return LoadFileError;
  8586. }(Error));
  8587. BABYLON.LoadFileError = LoadFileError;
  8588. var RetryStrategy = /** @class */ (function () {
  8589. function RetryStrategy() {
  8590. }
  8591. RetryStrategy.ExponentialBackoff = function (maxRetries, baseInterval) {
  8592. if (maxRetries === void 0) { maxRetries = 3; }
  8593. if (baseInterval === void 0) { baseInterval = 500; }
  8594. return function (url, request, retryIndex) {
  8595. if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf("file:") !== -1) {
  8596. return -1;
  8597. }
  8598. return Math.pow(2, retryIndex) * baseInterval;
  8599. };
  8600. };
  8601. return RetryStrategy;
  8602. }());
  8603. BABYLON.RetryStrategy = RetryStrategy;
  8604. // Screenshots
  8605. var screenshotCanvas;
  8606. var cloneValue = function (source, destinationObject) {
  8607. if (!source)
  8608. return null;
  8609. if (source instanceof BABYLON.Mesh) {
  8610. return null;
  8611. }
  8612. if (source instanceof BABYLON.SubMesh) {
  8613. return source.clone(destinationObject);
  8614. }
  8615. else if (source.clone) {
  8616. return source.clone();
  8617. }
  8618. return null;
  8619. };
  8620. var Tools = /** @class */ (function () {
  8621. function Tools() {
  8622. }
  8623. /**
  8624. * Interpolates between a and b via alpha
  8625. * @param a The lower value (returned when alpha = 0)
  8626. * @param b The upper value (returned when alpha = 1)
  8627. * @param alpha The interpolation-factor
  8628. * @return The mixed value
  8629. */
  8630. Tools.Mix = function (a, b, alpha) {
  8631. return a * (1 - alpha) + b * alpha;
  8632. };
  8633. Tools.Instantiate = function (className) {
  8634. if (Tools.RegisteredExternalClasses && Tools.RegisteredExternalClasses[className]) {
  8635. return Tools.RegisteredExternalClasses[className];
  8636. }
  8637. var arr = className.split(".");
  8638. var fn = (window || this);
  8639. for (var i = 0, len = arr.length; i < len; i++) {
  8640. fn = fn[arr[i]];
  8641. }
  8642. if (typeof fn !== "function") {
  8643. return null;
  8644. }
  8645. return fn;
  8646. };
  8647. /**
  8648. * Provides a slice function that will work even on IE
  8649. * @param data defines the array to slice
  8650. * @param start defines the start of the data (optional)
  8651. * @param end defines the end of the data (optional)
  8652. * @returns the new sliced array
  8653. */
  8654. Tools.Slice = function (data, start, end) {
  8655. if (data.slice) {
  8656. return data.slice(start, end);
  8657. }
  8658. return Array.prototype.slice.call(data, start, end);
  8659. };
  8660. Tools.SetImmediate = function (action) {
  8661. if (window.setImmediate) {
  8662. window.setImmediate(action);
  8663. }
  8664. else {
  8665. setTimeout(action, 1);
  8666. }
  8667. };
  8668. Tools.IsExponentOfTwo = function (value) {
  8669. var count = 1;
  8670. do {
  8671. count *= 2;
  8672. } while (count < value);
  8673. return count === value;
  8674. };
  8675. /**
  8676. * Returns the nearest 32-bit single precision float representation of a Number
  8677. * @param value A Number. If the parameter is of a different type, it will get converted
  8678. * to a number or to NaN if it cannot be converted
  8679. * @returns number
  8680. */
  8681. Tools.FloatRound = function (value) {
  8682. if (Math.fround) {
  8683. return Math.fround(value);
  8684. }
  8685. return (Tools._tmpFloatArray[0] = value);
  8686. };
  8687. /**
  8688. * Find the next highest power of two.
  8689. * @param x Number to start search from.
  8690. * @return Next highest power of two.
  8691. */
  8692. Tools.CeilingPOT = function (x) {
  8693. x--;
  8694. x |= x >> 1;
  8695. x |= x >> 2;
  8696. x |= x >> 4;
  8697. x |= x >> 8;
  8698. x |= x >> 16;
  8699. x++;
  8700. return x;
  8701. };
  8702. /**
  8703. * Find the next lowest power of two.
  8704. * @param x Number to start search from.
  8705. * @return Next lowest power of two.
  8706. */
  8707. Tools.FloorPOT = function (x) {
  8708. x = x | (x >> 1);
  8709. x = x | (x >> 2);
  8710. x = x | (x >> 4);
  8711. x = x | (x >> 8);
  8712. x = x | (x >> 16);
  8713. return x - (x >> 1);
  8714. };
  8715. /**
  8716. * Find the nearest power of two.
  8717. * @param x Number to start search from.
  8718. * @return Next nearest power of two.
  8719. */
  8720. Tools.NearestPOT = function (x) {
  8721. var c = Tools.CeilingPOT(x);
  8722. var f = Tools.FloorPOT(x);
  8723. return (c - x) > (x - f) ? f : c;
  8724. };
  8725. Tools.GetExponentOfTwo = function (value, max, mode) {
  8726. if (mode === void 0) { mode = BABYLON.Engine.SCALEMODE_NEAREST; }
  8727. var pot;
  8728. switch (mode) {
  8729. case BABYLON.Engine.SCALEMODE_FLOOR:
  8730. pot = Tools.FloorPOT(value);
  8731. break;
  8732. case BABYLON.Engine.SCALEMODE_NEAREST:
  8733. pot = Tools.NearestPOT(value);
  8734. break;
  8735. case BABYLON.Engine.SCALEMODE_CEILING:
  8736. default:
  8737. pot = Tools.CeilingPOT(value);
  8738. break;
  8739. }
  8740. return Math.min(pot, max);
  8741. };
  8742. Tools.GetFilename = function (path) {
  8743. var index = path.lastIndexOf("/");
  8744. if (index < 0)
  8745. return path;
  8746. return path.substring(index + 1);
  8747. };
  8748. /**
  8749. * Extracts the "folder" part of a path (everything before the filename).
  8750. * @param uri The URI to extract the info from
  8751. * @param returnUnchangedIfNoSlash Do not touch the URI if no slashes are present
  8752. * @returns The "folder" part of the path
  8753. */
  8754. Tools.GetFolderPath = function (uri, returnUnchangedIfNoSlash) {
  8755. if (returnUnchangedIfNoSlash === void 0) { returnUnchangedIfNoSlash = false; }
  8756. var index = uri.lastIndexOf("/");
  8757. if (index < 0) {
  8758. if (returnUnchangedIfNoSlash) {
  8759. return uri;
  8760. }
  8761. return "";
  8762. }
  8763. return uri.substring(0, index + 1);
  8764. };
  8765. Tools.GetDOMTextContent = function (element) {
  8766. var result = "";
  8767. var child = element.firstChild;
  8768. while (child) {
  8769. if (child.nodeType === 3) {
  8770. result += child.textContent;
  8771. }
  8772. child = child.nextSibling;
  8773. }
  8774. return result;
  8775. };
  8776. Tools.ToDegrees = function (angle) {
  8777. return angle * 180 / Math.PI;
  8778. };
  8779. Tools.ToRadians = function (angle) {
  8780. return angle * Math.PI / 180;
  8781. };
  8782. Tools.EncodeArrayBufferTobase64 = function (buffer) {
  8783. var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  8784. var output = "";
  8785. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  8786. var i = 0;
  8787. var bytes = new Uint8Array(buffer);
  8788. while (i < bytes.length) {
  8789. chr1 = bytes[i++];
  8790. chr2 = i < bytes.length ? bytes[i++] : Number.NaN; // Not sure if the index
  8791. chr3 = i < bytes.length ? bytes[i++] : Number.NaN; // checks are needed here
  8792. enc1 = chr1 >> 2;
  8793. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  8794. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  8795. enc4 = chr3 & 63;
  8796. if (isNaN(chr2)) {
  8797. enc3 = enc4 = 64;
  8798. }
  8799. else if (isNaN(chr3)) {
  8800. enc4 = 64;
  8801. }
  8802. output += keyStr.charAt(enc1) + keyStr.charAt(enc2) +
  8803. keyStr.charAt(enc3) + keyStr.charAt(enc4);
  8804. }
  8805. return "data:image/png;base64," + output;
  8806. };
  8807. Tools.ExtractMinAndMaxIndexed = function (positions, indices, indexStart, indexCount, bias) {
  8808. if (bias === void 0) { bias = null; }
  8809. var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  8810. var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  8811. for (var index = indexStart; index < indexStart + indexCount; index++) {
  8812. var current = new BABYLON.Vector3(positions[indices[index] * 3], positions[indices[index] * 3 + 1], positions[indices[index] * 3 + 2]);
  8813. minimum = BABYLON.Vector3.Minimize(current, minimum);
  8814. maximum = BABYLON.Vector3.Maximize(current, maximum);
  8815. }
  8816. if (bias) {
  8817. minimum.x -= minimum.x * bias.x + bias.y;
  8818. minimum.y -= minimum.y * bias.x + bias.y;
  8819. minimum.z -= minimum.z * bias.x + bias.y;
  8820. maximum.x += maximum.x * bias.x + bias.y;
  8821. maximum.y += maximum.y * bias.x + bias.y;
  8822. maximum.z += maximum.z * bias.x + bias.y;
  8823. }
  8824. return {
  8825. minimum: minimum,
  8826. maximum: maximum
  8827. };
  8828. };
  8829. Tools.ExtractMinAndMax = function (positions, start, count, bias, stride) {
  8830. if (bias === void 0) { bias = null; }
  8831. var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  8832. var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  8833. if (!stride) {
  8834. stride = 3;
  8835. }
  8836. for (var index = start; index < start + count; index++) {
  8837. var current = new BABYLON.Vector3(positions[index * stride], positions[index * stride + 1], positions[index * stride + 2]);
  8838. minimum = BABYLON.Vector3.Minimize(current, minimum);
  8839. maximum = BABYLON.Vector3.Maximize(current, maximum);
  8840. }
  8841. if (bias) {
  8842. minimum.x -= minimum.x * bias.x + bias.y;
  8843. minimum.y -= minimum.y * bias.x + bias.y;
  8844. minimum.z -= minimum.z * bias.x + bias.y;
  8845. maximum.x += maximum.x * bias.x + bias.y;
  8846. maximum.y += maximum.y * bias.x + bias.y;
  8847. maximum.z += maximum.z * bias.x + bias.y;
  8848. }
  8849. return {
  8850. minimum: minimum,
  8851. maximum: maximum
  8852. };
  8853. };
  8854. Tools.Vector2ArrayFeeder = function (array) {
  8855. return function (index) {
  8856. var isFloatArray = (array.BYTES_PER_ELEMENT !== undefined);
  8857. var length = isFloatArray ? array.length / 2 : array.length;
  8858. if (index >= length) {
  8859. return null;
  8860. }
  8861. if (isFloatArray) {
  8862. var fa = array;
  8863. return new BABYLON.Vector2(fa[index * 2 + 0], fa[index * 2 + 1]);
  8864. }
  8865. var a = array;
  8866. return a[index];
  8867. };
  8868. };
  8869. Tools.ExtractMinAndMaxVector2 = function (feeder, bias) {
  8870. if (bias === void 0) { bias = null; }
  8871. var minimum = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  8872. var maximum = new BABYLON.Vector2(-Number.MAX_VALUE, -Number.MAX_VALUE);
  8873. var i = 0;
  8874. var cur = feeder(i++);
  8875. while (cur) {
  8876. minimum = BABYLON.Vector2.Minimize(cur, minimum);
  8877. maximum = BABYLON.Vector2.Maximize(cur, maximum);
  8878. cur = feeder(i++);
  8879. }
  8880. if (bias) {
  8881. minimum.x -= minimum.x * bias.x + bias.y;
  8882. minimum.y -= minimum.y * bias.x + bias.y;
  8883. maximum.x += maximum.x * bias.x + bias.y;
  8884. maximum.y += maximum.y * bias.x + bias.y;
  8885. }
  8886. return {
  8887. minimum: minimum,
  8888. maximum: maximum
  8889. };
  8890. };
  8891. Tools.MakeArray = function (obj, allowsNullUndefined) {
  8892. if (allowsNullUndefined !== true && (obj === undefined || obj == null))
  8893. return null;
  8894. return Array.isArray(obj) ? obj : [obj];
  8895. };
  8896. // Misc.
  8897. Tools.GetPointerPrefix = function () {
  8898. var eventPrefix = "pointer";
  8899. // Check if pointer events are supported
  8900. if (Tools.IsWindowObjectExist() && !window.PointerEvent && !navigator.pointerEnabled) {
  8901. eventPrefix = "mouse";
  8902. }
  8903. return eventPrefix;
  8904. };
  8905. /**
  8906. * @param func - the function to be called
  8907. * @param requester - the object that will request the next frame. Falls back to window.
  8908. */
  8909. Tools.QueueNewFrame = function (func, requester) {
  8910. if (!Tools.IsWindowObjectExist()) {
  8911. return setTimeout(func, 16);
  8912. }
  8913. if (!requester) {
  8914. requester = window;
  8915. }
  8916. if (requester.requestAnimationFrame) {
  8917. return requester.requestAnimationFrame(func);
  8918. }
  8919. else if (requester.msRequestAnimationFrame) {
  8920. return requester.msRequestAnimationFrame(func);
  8921. }
  8922. else if (requester.webkitRequestAnimationFrame) {
  8923. return requester.webkitRequestAnimationFrame(func);
  8924. }
  8925. else if (requester.mozRequestAnimationFrame) {
  8926. return requester.mozRequestAnimationFrame(func);
  8927. }
  8928. else if (requester.oRequestAnimationFrame) {
  8929. return requester.oRequestAnimationFrame(func);
  8930. }
  8931. else {
  8932. return window.setTimeout(func, 16);
  8933. }
  8934. };
  8935. Tools.RequestFullscreen = function (element) {
  8936. var requestFunction = element.requestFullscreen || element.msRequestFullscreen || element.webkitRequestFullscreen || element.mozRequestFullScreen;
  8937. if (!requestFunction)
  8938. return;
  8939. requestFunction.call(element);
  8940. };
  8941. Tools.ExitFullscreen = function () {
  8942. if (document.exitFullscreen) {
  8943. document.exitFullscreen();
  8944. }
  8945. else if (document.mozCancelFullScreen) {
  8946. document.mozCancelFullScreen();
  8947. }
  8948. else if (document.webkitCancelFullScreen) {
  8949. document.webkitCancelFullScreen();
  8950. }
  8951. else if (document.msCancelFullScreen) {
  8952. document.msCancelFullScreen();
  8953. }
  8954. };
  8955. Tools.SetCorsBehavior = function (url, element) {
  8956. if (url && url.indexOf("data:") === 0) {
  8957. return;
  8958. }
  8959. if (Tools.CorsBehavior) {
  8960. if (typeof (Tools.CorsBehavior) === 'string' || Tools.CorsBehavior instanceof String) {
  8961. element.crossOrigin = Tools.CorsBehavior;
  8962. }
  8963. else {
  8964. var result = Tools.CorsBehavior(url);
  8965. if (result) {
  8966. element.crossOrigin = result;
  8967. }
  8968. }
  8969. }
  8970. };
  8971. // External files
  8972. Tools.CleanUrl = function (url) {
  8973. url = url.replace(/#/mg, "%23");
  8974. return url;
  8975. };
  8976. /**
  8977. * Loads an image as an HTMLImageElement.
  8978. * @param input url string, ArrayBuffer, or Blob to load
  8979. * @param onLoad callback called when the image successfully loads
  8980. * @param onError callback called when the image fails to load
  8981. * @param database database for caching
  8982. * @returns the HTMLImageElement of the loaded image
  8983. */
  8984. Tools.LoadImage = function (input, onLoad, onError, database) {
  8985. var url;
  8986. var usingObjectURL = false;
  8987. if (input instanceof ArrayBuffer) {
  8988. url = URL.createObjectURL(new Blob([input]));
  8989. usingObjectURL = true;
  8990. }
  8991. else if (input instanceof Blob) {
  8992. url = URL.createObjectURL(input);
  8993. usingObjectURL = true;
  8994. }
  8995. else {
  8996. url = Tools.CleanUrl(input);
  8997. url = Tools.PreprocessUrl(input);
  8998. }
  8999. var img = new Image();
  9000. Tools.SetCorsBehavior(url, img);
  9001. var loadHandler = function () {
  9002. if (usingObjectURL && img.src) {
  9003. URL.revokeObjectURL(img.src);
  9004. }
  9005. img.removeEventListener("load", loadHandler);
  9006. img.removeEventListener("error", errorHandler);
  9007. onLoad(img);
  9008. };
  9009. var errorHandler = function (err) {
  9010. if (usingObjectURL && img.src) {
  9011. URL.revokeObjectURL(img.src);
  9012. }
  9013. img.removeEventListener("load", loadHandler);
  9014. img.removeEventListener("error", errorHandler);
  9015. Tools.Error("Error while trying to load image: " + input);
  9016. if (onError) {
  9017. onError("Error while trying to load image: " + input, err);
  9018. }
  9019. };
  9020. img.addEventListener("load", loadHandler);
  9021. img.addEventListener("error", errorHandler);
  9022. var noIndexedDB = function () {
  9023. img.src = url;
  9024. };
  9025. var loadFromIndexedDB = function () {
  9026. if (database) {
  9027. database.loadImageFromDB(url, img);
  9028. }
  9029. };
  9030. //ANY database to do!
  9031. if (url.substr(0, 5) !== "data:" && database && database.enableTexturesOffline && BABYLON.Database.IsUASupportingBlobStorage) {
  9032. database.openAsync(loadFromIndexedDB, noIndexedDB);
  9033. }
  9034. else {
  9035. if (url.indexOf("file:") !== -1) {
  9036. var textureName = decodeURIComponent(url.substring(5).toLowerCase());
  9037. if (BABYLON.FilesInput.FilesToLoad[textureName]) {
  9038. try {
  9039. var blobURL;
  9040. try {
  9041. blobURL = URL.createObjectURL(BABYLON.FilesInput.FilesToLoad[textureName], { oneTimeOnly: true });
  9042. }
  9043. catch (ex) {
  9044. // Chrome doesn't support oneTimeOnly parameter
  9045. blobURL = URL.createObjectURL(BABYLON.FilesInput.FilesToLoad[textureName]);
  9046. }
  9047. img.src = blobURL;
  9048. usingObjectURL = true;
  9049. }
  9050. catch (e) {
  9051. img.src = "";
  9052. }
  9053. return img;
  9054. }
  9055. }
  9056. noIndexedDB();
  9057. }
  9058. return img;
  9059. };
  9060. Tools.LoadFile = function (url, onSuccess, onProgress, database, useArrayBuffer, onError) {
  9061. url = Tools.CleanUrl(url);
  9062. url = Tools.PreprocessUrl(url);
  9063. // If file and file input are set
  9064. if (url.indexOf("file:") !== -1) {
  9065. var fileName = decodeURIComponent(url.substring(5).toLowerCase());
  9066. if (BABYLON.FilesInput.FilesToLoad[fileName]) {
  9067. return Tools.ReadFile(BABYLON.FilesInput.FilesToLoad[fileName], onSuccess, onProgress, useArrayBuffer);
  9068. }
  9069. }
  9070. var loadUrl = Tools.BaseUrl + url;
  9071. var aborted = false;
  9072. var fileRequest = {
  9073. onCompleteObservable: new BABYLON.Observable(),
  9074. abort: function () { return aborted = true; },
  9075. };
  9076. var requestFile = function () {
  9077. var request = new XMLHttpRequest();
  9078. var retryHandle = null;
  9079. fileRequest.abort = function () {
  9080. aborted = true;
  9081. if (request.readyState !== (XMLHttpRequest.DONE || 4)) {
  9082. request.abort();
  9083. }
  9084. if (retryHandle !== null) {
  9085. clearTimeout(retryHandle);
  9086. retryHandle = null;
  9087. }
  9088. };
  9089. var retryLoop = function (retryIndex) {
  9090. request.open('GET', loadUrl, true);
  9091. if (useArrayBuffer) {
  9092. request.responseType = "arraybuffer";
  9093. }
  9094. if (onProgress) {
  9095. request.addEventListener("progress", onProgress);
  9096. }
  9097. var onLoadEnd = function () {
  9098. request.removeEventListener("loadend", onLoadEnd);
  9099. fileRequest.onCompleteObservable.notifyObservers(fileRequest);
  9100. fileRequest.onCompleteObservable.clear();
  9101. };
  9102. request.addEventListener("loadend", onLoadEnd);
  9103. var onReadyStateChange = function () {
  9104. if (aborted) {
  9105. return;
  9106. }
  9107. // In case of undefined state in some browsers.
  9108. if (request.readyState === (XMLHttpRequest.DONE || 4)) {
  9109. // Some browsers have issues where onreadystatechange can be called multiple times with the same value.
  9110. request.removeEventListener("readystatechange", onReadyStateChange);
  9111. if (request.status >= 200 && request.status < 300 || (!Tools.IsWindowObjectExist() && (request.status === 0))) {
  9112. onSuccess(!useArrayBuffer ? request.responseText : request.response, request.responseURL);
  9113. return;
  9114. }
  9115. var retryStrategy = Tools.DefaultRetryStrategy;
  9116. if (retryStrategy) {
  9117. var waitTime = retryStrategy(loadUrl, request, retryIndex);
  9118. if (waitTime !== -1) {
  9119. // Prevent the request from completing for retry.
  9120. request.removeEventListener("loadend", onLoadEnd);
  9121. request = new XMLHttpRequest();
  9122. retryHandle = setTimeout(function () { return retryLoop(retryIndex + 1); }, waitTime);
  9123. return;
  9124. }
  9125. }
  9126. var e = new LoadFileError("Error status: " + request.status + " " + request.statusText + " - Unable to load " + loadUrl, request);
  9127. if (onError) {
  9128. onError(request, e);
  9129. }
  9130. else {
  9131. throw e;
  9132. }
  9133. }
  9134. };
  9135. request.addEventListener("readystatechange", onReadyStateChange);
  9136. request.send();
  9137. };
  9138. retryLoop(0);
  9139. };
  9140. // Caching all files
  9141. if (database && database.enableSceneOffline) {
  9142. var noIndexedDB_1 = function () {
  9143. if (!aborted) {
  9144. requestFile();
  9145. }
  9146. };
  9147. var loadFromIndexedDB = function () {
  9148. // TODO: database needs to support aborting and should return a IFileRequest
  9149. if (aborted) {
  9150. return;
  9151. }
  9152. if (database) {
  9153. database.loadFileFromDB(url, function (data) {
  9154. if (!aborted) {
  9155. onSuccess(data);
  9156. }
  9157. fileRequest.onCompleteObservable.notifyObservers(fileRequest);
  9158. }, onProgress ? function (event) {
  9159. if (!aborted) {
  9160. onProgress(event);
  9161. }
  9162. } : undefined, noIndexedDB_1, useArrayBuffer);
  9163. }
  9164. };
  9165. database.openAsync(loadFromIndexedDB, noIndexedDB_1);
  9166. }
  9167. else {
  9168. requestFile();
  9169. }
  9170. return fileRequest;
  9171. };
  9172. /**
  9173. * Load a script (identified by an url). When the url returns, the
  9174. * content of this file is added into a new script element, attached to the DOM (body element)
  9175. */
  9176. Tools.LoadScript = function (scriptUrl, onSuccess, onError) {
  9177. var head = document.getElementsByTagName('head')[0];
  9178. var script = document.createElement('script');
  9179. script.type = 'text/javascript';
  9180. script.src = scriptUrl;
  9181. script.onload = function () {
  9182. if (onSuccess) {
  9183. onSuccess();
  9184. }
  9185. };
  9186. script.onerror = function (e) {
  9187. if (onError) {
  9188. onError("Unable to load script '" + scriptUrl + "'", e);
  9189. }
  9190. };
  9191. head.appendChild(script);
  9192. };
  9193. Tools.ReadFileAsDataURL = function (fileToLoad, callback, progressCallback) {
  9194. var reader = new FileReader();
  9195. var request = {
  9196. onCompleteObservable: new BABYLON.Observable(),
  9197. abort: function () { return reader.abort(); },
  9198. };
  9199. reader.onloadend = function (e) {
  9200. request.onCompleteObservable.notifyObservers(request);
  9201. };
  9202. reader.onload = function (e) {
  9203. //target doesn't have result from ts 1.3
  9204. callback(e.target['result']);
  9205. };
  9206. reader.onprogress = progressCallback;
  9207. reader.readAsDataURL(fileToLoad);
  9208. return request;
  9209. };
  9210. Tools.ReadFile = function (fileToLoad, callback, progressCallBack, useArrayBuffer) {
  9211. var reader = new FileReader();
  9212. var request = {
  9213. onCompleteObservable: new BABYLON.Observable(),
  9214. abort: function () { return reader.abort(); },
  9215. };
  9216. reader.onloadend = function (e) { return request.onCompleteObservable.notifyObservers(request); };
  9217. reader.onerror = function (e) {
  9218. Tools.Log("Error while reading file: " + fileToLoad.name);
  9219. callback(JSON.stringify({ autoClear: true, clearColor: [1, 0, 0], ambientColor: [0, 0, 0], gravity: [0, -9.807, 0], meshes: [], cameras: [], lights: [] }));
  9220. };
  9221. reader.onload = function (e) {
  9222. //target doesn't have result from ts 1.3
  9223. callback(e.target['result']);
  9224. };
  9225. if (progressCallBack) {
  9226. reader.onprogress = progressCallBack;
  9227. }
  9228. if (!useArrayBuffer) {
  9229. // Asynchronous read
  9230. reader.readAsText(fileToLoad);
  9231. }
  9232. else {
  9233. reader.readAsArrayBuffer(fileToLoad);
  9234. }
  9235. return request;
  9236. };
  9237. //returns a downloadable url to a file content.
  9238. Tools.FileAsURL = function (content) {
  9239. var fileBlob = new Blob([content]);
  9240. var url = window.URL || window.webkitURL;
  9241. var link = url.createObjectURL(fileBlob);
  9242. return link;
  9243. };
  9244. // Misc.
  9245. Tools.Format = function (value, decimals) {
  9246. if (decimals === void 0) { decimals = 2; }
  9247. return value.toFixed(decimals);
  9248. };
  9249. Tools.CheckExtends = function (v, min, max) {
  9250. if (v.x < min.x)
  9251. min.x = v.x;
  9252. if (v.y < min.y)
  9253. min.y = v.y;
  9254. if (v.z < min.z)
  9255. min.z = v.z;
  9256. if (v.x > max.x)
  9257. max.x = v.x;
  9258. if (v.y > max.y)
  9259. max.y = v.y;
  9260. if (v.z > max.z)
  9261. max.z = v.z;
  9262. };
  9263. Tools.DeepCopy = function (source, destination, doNotCopyList, mustCopyList) {
  9264. for (var prop in source) {
  9265. if (prop[0] === "_" && (!mustCopyList || mustCopyList.indexOf(prop) === -1)) {
  9266. continue;
  9267. }
  9268. if (doNotCopyList && doNotCopyList.indexOf(prop) !== -1) {
  9269. continue;
  9270. }
  9271. var sourceValue = source[prop];
  9272. var typeOfSourceValue = typeof sourceValue;
  9273. if (typeOfSourceValue === "function") {
  9274. continue;
  9275. }
  9276. try {
  9277. if (typeOfSourceValue === "object") {
  9278. if (sourceValue instanceof Array) {
  9279. destination[prop] = [];
  9280. if (sourceValue.length > 0) {
  9281. if (typeof sourceValue[0] == "object") {
  9282. for (var index = 0; index < sourceValue.length; index++) {
  9283. var clonedValue = cloneValue(sourceValue[index], destination);
  9284. if (destination[prop].indexOf(clonedValue) === -1) { // Test if auto inject was not done
  9285. destination[prop].push(clonedValue);
  9286. }
  9287. }
  9288. }
  9289. else {
  9290. destination[prop] = sourceValue.slice(0);
  9291. }
  9292. }
  9293. }
  9294. else {
  9295. destination[prop] = cloneValue(sourceValue, destination);
  9296. }
  9297. }
  9298. else {
  9299. destination[prop] = sourceValue;
  9300. }
  9301. }
  9302. catch (e) {
  9303. // Just ignore error (it could be because of a read-only property)
  9304. }
  9305. }
  9306. };
  9307. Tools.IsEmpty = function (obj) {
  9308. for (var i in obj) {
  9309. if (obj.hasOwnProperty(i)) {
  9310. return false;
  9311. }
  9312. }
  9313. return true;
  9314. };
  9315. Tools.RegisterTopRootEvents = function (events) {
  9316. for (var index = 0; index < events.length; index++) {
  9317. var event = events[index];
  9318. window.addEventListener(event.name, event.handler, false);
  9319. try {
  9320. if (window.parent) {
  9321. window.parent.addEventListener(event.name, event.handler, false);
  9322. }
  9323. }
  9324. catch (e) {
  9325. // Silently fails...
  9326. }
  9327. }
  9328. };
  9329. Tools.UnregisterTopRootEvents = function (events) {
  9330. for (var index = 0; index < events.length; index++) {
  9331. var event = events[index];
  9332. window.removeEventListener(event.name, event.handler);
  9333. try {
  9334. if (window.parent) {
  9335. window.parent.removeEventListener(event.name, event.handler);
  9336. }
  9337. }
  9338. catch (e) {
  9339. // Silently fails...
  9340. }
  9341. }
  9342. };
  9343. Tools.DumpFramebuffer = function (width, height, engine, successCallback, mimeType, fileName) {
  9344. if (mimeType === void 0) { mimeType = "image/png"; }
  9345. // Read the contents of the framebuffer
  9346. var numberOfChannelsByLine = width * 4;
  9347. var halfHeight = height / 2;
  9348. //Reading datas from WebGL
  9349. var data = engine.readPixels(0, 0, width, height);
  9350. //To flip image on Y axis.
  9351. for (var i = 0; i < halfHeight; i++) {
  9352. for (var j = 0; j < numberOfChannelsByLine; j++) {
  9353. var currentCell = j + i * numberOfChannelsByLine;
  9354. var targetLine = height - i - 1;
  9355. var targetCell = j + targetLine * numberOfChannelsByLine;
  9356. var temp = data[currentCell];
  9357. data[currentCell] = data[targetCell];
  9358. data[targetCell] = temp;
  9359. }
  9360. }
  9361. // Create a 2D canvas to store the result
  9362. if (!screenshotCanvas) {
  9363. screenshotCanvas = document.createElement('canvas');
  9364. }
  9365. screenshotCanvas.width = width;
  9366. screenshotCanvas.height = height;
  9367. var context = screenshotCanvas.getContext('2d');
  9368. if (context) {
  9369. // Copy the pixels to a 2D canvas
  9370. var imageData = context.createImageData(width, height);
  9371. var castData = (imageData.data);
  9372. castData.set(data);
  9373. context.putImageData(imageData, 0, 0);
  9374. Tools.EncodeScreenshotCanvasData(successCallback, mimeType, fileName);
  9375. }
  9376. };
  9377. Tools.EncodeScreenshotCanvasData = function (successCallback, mimeType, fileName) {
  9378. if (mimeType === void 0) { mimeType = "image/png"; }
  9379. var base64Image = screenshotCanvas.toDataURL(mimeType);
  9380. if (successCallback) {
  9381. successCallback(base64Image);
  9382. }
  9383. else {
  9384. // We need HTMLCanvasElement.toBlob for HD screenshots
  9385. if (!screenshotCanvas.toBlob) {
  9386. // low performance polyfill based on toDataURL (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)
  9387. screenshotCanvas.toBlob = function (callback, type, quality) {
  9388. var _this = this;
  9389. setTimeout(function () {
  9390. var binStr = atob(_this.toDataURL(type, quality).split(',')[1]), len = binStr.length, arr = new Uint8Array(len);
  9391. for (var i = 0; i < len; i++) {
  9392. arr[i] = binStr.charCodeAt(i);
  9393. }
  9394. callback(new Blob([arr], { type: type || 'image/png' }));
  9395. });
  9396. };
  9397. }
  9398. screenshotCanvas.toBlob(function (blob) {
  9399. //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.
  9400. if (("download" in document.createElement("a"))) {
  9401. if (!fileName) {
  9402. var date = new Date();
  9403. var stringDate = (date.getFullYear() + "-" + (date.getMonth() + 1)).slice(2) + "-" + date.getDate() + "_" + date.getHours() + "-" + ('0' + date.getMinutes()).slice(-2);
  9404. fileName = "screenshot_" + stringDate + ".png";
  9405. }
  9406. Tools.Download(blob, fileName);
  9407. }
  9408. else {
  9409. var url = URL.createObjectURL(blob);
  9410. var newWindow = window.open("");
  9411. if (!newWindow)
  9412. return;
  9413. var img = newWindow.document.createElement("img");
  9414. img.onload = function () {
  9415. // no longer need to read the blob so it's revoked
  9416. URL.revokeObjectURL(url);
  9417. };
  9418. img.src = url;
  9419. newWindow.document.body.appendChild(img);
  9420. }
  9421. });
  9422. }
  9423. };
  9424. /**
  9425. * Downloads a blob in the browser
  9426. * @param blob defines the blob to download
  9427. * @param fileName defines the name of the downloaded file
  9428. */
  9429. Tools.Download = function (blob, fileName) {
  9430. var url = window.URL.createObjectURL(blob);
  9431. var a = document.createElement("a");
  9432. document.body.appendChild(a);
  9433. a.style.display = "none";
  9434. a.href = url;
  9435. a.download = fileName;
  9436. a.addEventListener("click", function () {
  9437. if (a.parentElement) {
  9438. a.parentElement.removeChild(a);
  9439. }
  9440. });
  9441. a.click();
  9442. window.URL.revokeObjectURL(url);
  9443. };
  9444. Tools.CreateScreenshot = function (engine, camera, size, successCallback, mimeType) {
  9445. if (mimeType === void 0) { mimeType = "image/png"; }
  9446. var width;
  9447. var height;
  9448. // If a precision value is specified
  9449. if (size.precision) {
  9450. width = Math.round(engine.getRenderWidth() * size.precision);
  9451. height = Math.round(width / engine.getAspectRatio(camera));
  9452. }
  9453. else if (size.width && size.height) {
  9454. width = size.width;
  9455. height = size.height;
  9456. }
  9457. //If passing only width, computing height to keep display canvas ratio.
  9458. else if (size.width && !size.height) {
  9459. width = size.width;
  9460. height = Math.round(width / engine.getAspectRatio(camera));
  9461. }
  9462. //If passing only height, computing width to keep display canvas ratio.
  9463. else if (size.height && !size.width) {
  9464. height = size.height;
  9465. width = Math.round(height * engine.getAspectRatio(camera));
  9466. }
  9467. //Assuming here that "size" parameter is a number
  9468. else if (!isNaN(size)) {
  9469. height = size;
  9470. width = size;
  9471. }
  9472. else {
  9473. Tools.Error("Invalid 'size' parameter !");
  9474. return;
  9475. }
  9476. if (!screenshotCanvas) {
  9477. screenshotCanvas = document.createElement('canvas');
  9478. }
  9479. screenshotCanvas.width = width;
  9480. screenshotCanvas.height = height;
  9481. var renderContext = screenshotCanvas.getContext("2d");
  9482. var ratio = engine.getRenderWidth() / engine.getRenderHeight();
  9483. var newWidth = width;
  9484. var newHeight = newWidth / ratio;
  9485. if (newHeight > height) {
  9486. newHeight = height;
  9487. newWidth = newHeight * ratio;
  9488. }
  9489. var offsetX = Math.max(0, width - newWidth) / 2;
  9490. var offsetY = Math.max(0, height - newHeight) / 2;
  9491. var renderingCanvas = engine.getRenderingCanvas();
  9492. if (renderContext && renderingCanvas) {
  9493. renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);
  9494. }
  9495. Tools.EncodeScreenshotCanvasData(successCallback, mimeType);
  9496. };
  9497. /**
  9498. * Generates an image screenshot from the specified camera.
  9499. *
  9500. * @param engine The engine to use for rendering
  9501. * @param camera The camera to use for rendering
  9502. * @param size This parameter can be set to a single number or to an object with the
  9503. * following (optional) properties: precision, width, height. If a single number is passed,
  9504. * it will be used for both width and height. If an object is passed, the screenshot size
  9505. * will be derived from the parameters. The precision property is a multiplier allowing
  9506. * rendering at a higher or lower resolution.
  9507. * @param successCallback The callback receives a single parameter which contains the
  9508. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  9509. * src parameter of an <img> to display it.
  9510. * @param mimeType The MIME type of the screenshot image (default: image/png).
  9511. * Check your browser for supported MIME types.
  9512. * @param samples Texture samples (default: 1)
  9513. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  9514. * @param fileName A name for for the downloaded file.
  9515. * @constructor
  9516. */
  9517. Tools.CreateScreenshotUsingRenderTarget = function (engine, camera, size, successCallback, mimeType, samples, antialiasing, fileName) {
  9518. if (mimeType === void 0) { mimeType = "image/png"; }
  9519. if (samples === void 0) { samples = 1; }
  9520. if (antialiasing === void 0) { antialiasing = false; }
  9521. var width;
  9522. var height;
  9523. //If a precision value is specified
  9524. if (size.precision) {
  9525. width = Math.round(engine.getRenderWidth() * size.precision);
  9526. height = Math.round(width / engine.getAspectRatio(camera));
  9527. size = { width: width, height: height };
  9528. }
  9529. else if (size.width && size.height) {
  9530. width = size.width;
  9531. height = size.height;
  9532. }
  9533. //If passing only width, computing height to keep display canvas ratio.
  9534. else if (size.width && !size.height) {
  9535. width = size.width;
  9536. height = Math.round(width / engine.getAspectRatio(camera));
  9537. size = { width: width, height: height };
  9538. }
  9539. //If passing only height, computing width to keep display canvas ratio.
  9540. else if (size.height && !size.width) {
  9541. height = size.height;
  9542. width = Math.round(height * engine.getAspectRatio(camera));
  9543. size = { width: width, height: height };
  9544. }
  9545. //Assuming here that "size" parameter is a number
  9546. else if (!isNaN(size)) {
  9547. height = size;
  9548. width = size;
  9549. }
  9550. else {
  9551. Tools.Error("Invalid 'size' parameter !");
  9552. return;
  9553. }
  9554. var scene = camera.getScene();
  9555. var previousCamera = null;
  9556. if (scene.activeCamera !== camera) {
  9557. previousCamera = scene.activeCamera;
  9558. scene.activeCamera = camera;
  9559. }
  9560. //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
  9561. var texture = new BABYLON.RenderTargetTexture("screenShot", size, scene, false, false, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
  9562. texture.renderList = null;
  9563. texture.samples = samples;
  9564. if (antialiasing) {
  9565. texture.addPostProcess(new BABYLON.FxaaPostProcess('antialiasing', 1.0, scene.activeCamera));
  9566. }
  9567. texture.onAfterRenderObservable.add(function () {
  9568. Tools.DumpFramebuffer(width, height, engine, successCallback, mimeType, fileName);
  9569. });
  9570. scene.incrementRenderId();
  9571. scene.resetCachedMaterial();
  9572. texture.render(true);
  9573. texture.dispose();
  9574. if (previousCamera) {
  9575. scene.activeCamera = previousCamera;
  9576. }
  9577. camera.getProjectionMatrix(true); // Force cache refresh;
  9578. };
  9579. // XHR response validator for local file scenario
  9580. Tools.ValidateXHRData = function (xhr, dataType) {
  9581. // 1 for text (.babylon, manifest and shaders), 2 for TGA, 4 for DDS, 7 for all
  9582. if (dataType === void 0) { dataType = 7; }
  9583. try {
  9584. if (dataType & 1) {
  9585. if (xhr.responseText && xhr.responseText.length > 0) {
  9586. return true;
  9587. }
  9588. else if (dataType === 1) {
  9589. return false;
  9590. }
  9591. }
  9592. if (dataType & 2) {
  9593. // Check header width and height since there is no "TGA" magic number
  9594. var tgaHeader = BABYLON.TGATools.GetTGAHeader(xhr.response);
  9595. if (tgaHeader.width && tgaHeader.height && tgaHeader.width > 0 && tgaHeader.height > 0) {
  9596. return true;
  9597. }
  9598. else if (dataType === 2) {
  9599. return false;
  9600. }
  9601. }
  9602. if (dataType & 4) {
  9603. // Check for the "DDS" magic number
  9604. var ddsHeader = new Uint8Array(xhr.response, 0, 3);
  9605. if (ddsHeader[0] === 68 && ddsHeader[1] === 68 && ddsHeader[2] === 83) {
  9606. return true;
  9607. }
  9608. else {
  9609. return false;
  9610. }
  9611. }
  9612. }
  9613. catch (e) {
  9614. // Global protection
  9615. }
  9616. return false;
  9617. };
  9618. /**
  9619. * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  9620. * Be aware Math.random() could cause collisions, but:
  9621. * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"
  9622. */
  9623. Tools.RandomId = function () {
  9624. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  9625. var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
  9626. return v.toString(16);
  9627. });
  9628. };
  9629. /**
  9630. * Test if the given uri is a base64 string.
  9631. * @param uri The uri to test
  9632. * @return True if the uri is a base64 string or false otherwise.
  9633. */
  9634. Tools.IsBase64 = function (uri) {
  9635. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  9636. };
  9637. /**
  9638. * Decode the given base64 uri.
  9639. * @param uri The uri to decode
  9640. * @return The decoded base64 data.
  9641. */
  9642. Tools.DecodeBase64 = function (uri) {
  9643. var decodedString = atob(uri.split(",")[1]);
  9644. var bufferLength = decodedString.length;
  9645. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  9646. for (var i = 0; i < bufferLength; i++) {
  9647. bufferView[i] = decodedString.charCodeAt(i);
  9648. }
  9649. return bufferView.buffer;
  9650. };
  9651. Object.defineProperty(Tools, "NoneLogLevel", {
  9652. get: function () {
  9653. return Tools._NoneLogLevel;
  9654. },
  9655. enumerable: true,
  9656. configurable: true
  9657. });
  9658. Object.defineProperty(Tools, "MessageLogLevel", {
  9659. get: function () {
  9660. return Tools._MessageLogLevel;
  9661. },
  9662. enumerable: true,
  9663. configurable: true
  9664. });
  9665. Object.defineProperty(Tools, "WarningLogLevel", {
  9666. get: function () {
  9667. return Tools._WarningLogLevel;
  9668. },
  9669. enumerable: true,
  9670. configurable: true
  9671. });
  9672. Object.defineProperty(Tools, "ErrorLogLevel", {
  9673. get: function () {
  9674. return Tools._ErrorLogLevel;
  9675. },
  9676. enumerable: true,
  9677. configurable: true
  9678. });
  9679. Object.defineProperty(Tools, "AllLogLevel", {
  9680. get: function () {
  9681. return Tools._MessageLogLevel | Tools._WarningLogLevel | Tools._ErrorLogLevel;
  9682. },
  9683. enumerable: true,
  9684. configurable: true
  9685. });
  9686. Tools._AddLogEntry = function (entry) {
  9687. Tools._LogCache = entry + Tools._LogCache;
  9688. if (Tools.OnNewCacheEntry) {
  9689. Tools.OnNewCacheEntry(entry);
  9690. }
  9691. };
  9692. Tools._FormatMessage = function (message) {
  9693. var padStr = function (i) { return (i < 10) ? "0" + i : "" + i; };
  9694. var date = new Date();
  9695. return "[" + padStr(date.getHours()) + ":" + padStr(date.getMinutes()) + ":" + padStr(date.getSeconds()) + "]: " + message;
  9696. };
  9697. Tools._LogDisabled = function (message) {
  9698. // nothing to do
  9699. };
  9700. Tools._LogEnabled = function (message) {
  9701. var formattedMessage = Tools._FormatMessage(message);
  9702. console.log("BJS - " + formattedMessage);
  9703. var entry = "<div style='color:white'>" + formattedMessage + "</div><br>";
  9704. Tools._AddLogEntry(entry);
  9705. };
  9706. Tools._WarnDisabled = function (message) {
  9707. // nothing to do
  9708. };
  9709. Tools._WarnEnabled = function (message) {
  9710. var formattedMessage = Tools._FormatMessage(message);
  9711. console.warn("BJS - " + formattedMessage);
  9712. var entry = "<div style='color:orange'>" + formattedMessage + "</div><br>";
  9713. Tools._AddLogEntry(entry);
  9714. };
  9715. Tools._ErrorDisabled = function (message) {
  9716. // nothing to do
  9717. };
  9718. Tools._ErrorEnabled = function (message) {
  9719. Tools.errorsCount++;
  9720. var formattedMessage = Tools._FormatMessage(message);
  9721. console.error("BJS - " + formattedMessage);
  9722. var entry = "<div style='color:red'>" + formattedMessage + "</div><br>";
  9723. Tools._AddLogEntry(entry);
  9724. };
  9725. Object.defineProperty(Tools, "LogCache", {
  9726. get: function () {
  9727. return Tools._LogCache;
  9728. },
  9729. enumerable: true,
  9730. configurable: true
  9731. });
  9732. Tools.ClearLogCache = function () {
  9733. Tools._LogCache = "";
  9734. Tools.errorsCount = 0;
  9735. };
  9736. Object.defineProperty(Tools, "LogLevels", {
  9737. set: function (level) {
  9738. if ((level & Tools.MessageLogLevel) === Tools.MessageLogLevel) {
  9739. Tools.Log = Tools._LogEnabled;
  9740. }
  9741. else {
  9742. Tools.Log = Tools._LogDisabled;
  9743. }
  9744. if ((level & Tools.WarningLogLevel) === Tools.WarningLogLevel) {
  9745. Tools.Warn = Tools._WarnEnabled;
  9746. }
  9747. else {
  9748. Tools.Warn = Tools._WarnDisabled;
  9749. }
  9750. if ((level & Tools.ErrorLogLevel) === Tools.ErrorLogLevel) {
  9751. Tools.Error = Tools._ErrorEnabled;
  9752. }
  9753. else {
  9754. Tools.Error = Tools._ErrorDisabled;
  9755. }
  9756. },
  9757. enumerable: true,
  9758. configurable: true
  9759. });
  9760. Tools.IsWindowObjectExist = function () {
  9761. return (typeof window) !== "undefined";
  9762. };
  9763. Object.defineProperty(Tools, "PerformanceNoneLogLevel", {
  9764. get: function () {
  9765. return Tools._PerformanceNoneLogLevel;
  9766. },
  9767. enumerable: true,
  9768. configurable: true
  9769. });
  9770. Object.defineProperty(Tools, "PerformanceUserMarkLogLevel", {
  9771. get: function () {
  9772. return Tools._PerformanceUserMarkLogLevel;
  9773. },
  9774. enumerable: true,
  9775. configurable: true
  9776. });
  9777. Object.defineProperty(Tools, "PerformanceConsoleLogLevel", {
  9778. get: function () {
  9779. return Tools._PerformanceConsoleLogLevel;
  9780. },
  9781. enumerable: true,
  9782. configurable: true
  9783. });
  9784. Object.defineProperty(Tools, "PerformanceLogLevel", {
  9785. set: function (level) {
  9786. if ((level & Tools.PerformanceUserMarkLogLevel) === Tools.PerformanceUserMarkLogLevel) {
  9787. Tools.StartPerformanceCounter = Tools._StartUserMark;
  9788. Tools.EndPerformanceCounter = Tools._EndUserMark;
  9789. return;
  9790. }
  9791. if ((level & Tools.PerformanceConsoleLogLevel) === Tools.PerformanceConsoleLogLevel) {
  9792. Tools.StartPerformanceCounter = Tools._StartPerformanceConsole;
  9793. Tools.EndPerformanceCounter = Tools._EndPerformanceConsole;
  9794. return;
  9795. }
  9796. Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;
  9797. Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;
  9798. },
  9799. enumerable: true,
  9800. configurable: true
  9801. });
  9802. Tools._StartPerformanceCounterDisabled = function (counterName, condition) {
  9803. };
  9804. Tools._EndPerformanceCounterDisabled = function (counterName, condition) {
  9805. };
  9806. Tools._StartUserMark = function (counterName, condition) {
  9807. if (condition === void 0) { condition = true; }
  9808. if (!Tools._performance) {
  9809. if (!Tools.IsWindowObjectExist()) {
  9810. return;
  9811. }
  9812. Tools._performance = window.performance;
  9813. }
  9814. if (!condition || !Tools._performance.mark) {
  9815. return;
  9816. }
  9817. Tools._performance.mark(counterName + "-Begin");
  9818. };
  9819. Tools._EndUserMark = function (counterName, condition) {
  9820. if (condition === void 0) { condition = true; }
  9821. if (!condition || !Tools._performance.mark) {
  9822. return;
  9823. }
  9824. Tools._performance.mark(counterName + "-End");
  9825. Tools._performance.measure(counterName, counterName + "-Begin", counterName + "-End");
  9826. };
  9827. Tools._StartPerformanceConsole = function (counterName, condition) {
  9828. if (condition === void 0) { condition = true; }
  9829. if (!condition) {
  9830. return;
  9831. }
  9832. Tools._StartUserMark(counterName, condition);
  9833. if (console.time) {
  9834. console.time(counterName);
  9835. }
  9836. };
  9837. Tools._EndPerformanceConsole = function (counterName, condition) {
  9838. if (condition === void 0) { condition = true; }
  9839. if (!condition) {
  9840. return;
  9841. }
  9842. Tools._EndUserMark(counterName, condition);
  9843. if (console.time) {
  9844. console.timeEnd(counterName);
  9845. }
  9846. };
  9847. Object.defineProperty(Tools, "Now", {
  9848. get: function () {
  9849. if (Tools.IsWindowObjectExist() && window.performance && window.performance.now) {
  9850. return window.performance.now();
  9851. }
  9852. return Date.now();
  9853. },
  9854. enumerable: true,
  9855. configurable: true
  9856. });
  9857. /**
  9858. * This method will return the name of the class used to create the instance of the given object.
  9859. * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.
  9860. * @param object the object to get the class name from
  9861. * @return the name of the class, will be "object" for a custom data type not using the @className decorator
  9862. */
  9863. Tools.GetClassName = function (object, isType) {
  9864. if (isType === void 0) { isType = false; }
  9865. var name = null;
  9866. if (!isType && object.getClassName) {
  9867. name = object.getClassName();
  9868. }
  9869. else {
  9870. if (object instanceof Object) {
  9871. var classObj = isType ? object : Object.getPrototypeOf(object);
  9872. name = classObj.constructor["__bjsclassName__"];
  9873. }
  9874. if (!name) {
  9875. name = typeof object;
  9876. }
  9877. }
  9878. return name;
  9879. };
  9880. Tools.First = function (array, predicate) {
  9881. for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
  9882. var el = array_1[_i];
  9883. if (predicate(el)) {
  9884. return el;
  9885. }
  9886. }
  9887. return null;
  9888. };
  9889. /**
  9890. * This method will return the name of the full name of the class, including its owning module (if any).
  9891. * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator or implementing a method getClassName():string (in which case the module won't be specified).
  9892. * @param object the object to get the class name from
  9893. * @return a string that can have two forms: "moduleName.className" if module was specified when the class' Name was registered or "className" if there was not module specified.
  9894. */
  9895. Tools.getFullClassName = function (object, isType) {
  9896. if (isType === void 0) { isType = false; }
  9897. var className = null;
  9898. var moduleName = null;
  9899. if (!isType && object.getClassName) {
  9900. className = object.getClassName();
  9901. }
  9902. else {
  9903. if (object instanceof Object) {
  9904. var classObj = isType ? object : Object.getPrototypeOf(object);
  9905. className = classObj.constructor["__bjsclassName__"];
  9906. moduleName = classObj.constructor["__bjsmoduleName__"];
  9907. }
  9908. if (!className) {
  9909. className = typeof object;
  9910. }
  9911. }
  9912. if (!className) {
  9913. return null;
  9914. }
  9915. return ((moduleName != null) ? (moduleName + ".") : "") + className;
  9916. };
  9917. /**
  9918. * This method can be used with hashCodeFromStream when your input is an array of values that are either: number, string, boolean or custom type implementing the getHashCode():number method.
  9919. * @param array
  9920. */
  9921. Tools.arrayOrStringFeeder = function (array) {
  9922. return function (index) {
  9923. if (index >= array.length) {
  9924. return null;
  9925. }
  9926. var val = array.charCodeAt ? array.charCodeAt(index) : array[index];
  9927. if (val && val.getHashCode) {
  9928. val = val.getHashCode();
  9929. }
  9930. if (typeof val === "string") {
  9931. return Tools.hashCodeFromStream(Tools.arrayOrStringFeeder(val));
  9932. }
  9933. return val;
  9934. };
  9935. };
  9936. /**
  9937. * Compute the hashCode of a stream of number
  9938. * To compute the HashCode on a string or an Array of data types implementing the getHashCode() method, use the arrayOrStringFeeder method.
  9939. * @param feeder a callback that will be called until it returns null, each valid returned values will be used to compute the hash code.
  9940. * @return the hash code computed
  9941. */
  9942. Tools.hashCodeFromStream = function (feeder) {
  9943. // Based from here: http://stackoverflow.com/a/7616484/802124
  9944. var hash = 0;
  9945. var index = 0;
  9946. var chr = feeder(index++);
  9947. while (chr != null) {
  9948. hash = ((hash << 5) - hash) + chr;
  9949. hash |= 0; // Convert to 32bit integer
  9950. chr = feeder(index++);
  9951. }
  9952. return hash;
  9953. };
  9954. /**
  9955. * Returns a promise that resolves after the given amount of time.
  9956. * @param delay Number of milliseconds to delay
  9957. * @returns Promise that resolves after the given amount of time
  9958. */
  9959. Tools.DelayAsync = function (delay) {
  9960. return new Promise(function (resolve) {
  9961. setTimeout(function () {
  9962. resolve();
  9963. }, delay);
  9964. });
  9965. };
  9966. Tools.BaseUrl = "";
  9967. Tools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff();
  9968. /**
  9969. * Default behaviour for cors in the application.
  9970. * It can be a string if the expected behavior is identical in the entire app.
  9971. * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)
  9972. */
  9973. Tools.CorsBehavior = "anonymous";
  9974. Tools.UseFallbackTexture = true;
  9975. /**
  9976. * Use this object to register external classes like custom textures or material
  9977. * to allow the laoders to instantiate them
  9978. */
  9979. Tools.RegisteredExternalClasses = {};
  9980. // Used in case of a texture loading problem
  9981. Tools.fallbackTexture = "data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z";
  9982. Tools._tmpFloatArray = new Float32Array(1);
  9983. Tools.PreprocessUrl = function (url) {
  9984. return url;
  9985. };
  9986. // Logs
  9987. Tools._NoneLogLevel = 0;
  9988. Tools._MessageLogLevel = 1;
  9989. Tools._WarningLogLevel = 2;
  9990. Tools._ErrorLogLevel = 4;
  9991. Tools._LogCache = "";
  9992. Tools.errorsCount = 0;
  9993. Tools.Log = Tools._LogEnabled;
  9994. Tools.Warn = Tools._WarnEnabled;
  9995. Tools.Error = Tools._ErrorEnabled;
  9996. // Performances
  9997. Tools._PerformanceNoneLogLevel = 0;
  9998. Tools._PerformanceUserMarkLogLevel = 1;
  9999. Tools._PerformanceConsoleLogLevel = 2;
  10000. Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;
  10001. Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;
  10002. return Tools;
  10003. }());
  10004. BABYLON.Tools = Tools;
  10005. /**
  10006. * This class is used to track a performance counter which is number based.
  10007. * The user has access to many properties which give statistics of different nature
  10008. *
  10009. * The implementer can track two kinds of Performance Counter: time and count
  10010. * For time you can optionally call fetchNewFrame() to notify the start of a new frame to monitor, then call beginMonitoring() to start and endMonitoring() to record the lapsed time. endMonitoring takes a newFrame parameter for you to specify if the monitored time should be set for a new frame or accumulated to the current frame being monitored.
  10011. * For count you first have to call fetchNewFrame() to notify the start of a new frame to monitor, then call addCount() how many time required to increment the count value you monitor.
  10012. */
  10013. var PerfCounter = /** @class */ (function () {
  10014. function PerfCounter() {
  10015. this._startMonitoringTime = 0;
  10016. this._min = 0;
  10017. this._max = 0;
  10018. this._average = 0;
  10019. this._lastSecAverage = 0;
  10020. this._current = 0;
  10021. this._totalValueCount = 0;
  10022. this._totalAccumulated = 0;
  10023. this._lastSecAccumulated = 0;
  10024. this._lastSecTime = 0;
  10025. this._lastSecValueCount = 0;
  10026. }
  10027. Object.defineProperty(PerfCounter.prototype, "min", {
  10028. /**
  10029. * Returns the smallest value ever
  10030. */
  10031. get: function () {
  10032. return this._min;
  10033. },
  10034. enumerable: true,
  10035. configurable: true
  10036. });
  10037. Object.defineProperty(PerfCounter.prototype, "max", {
  10038. /**
  10039. * Returns the biggest value ever
  10040. */
  10041. get: function () {
  10042. return this._max;
  10043. },
  10044. enumerable: true,
  10045. configurable: true
  10046. });
  10047. Object.defineProperty(PerfCounter.prototype, "average", {
  10048. /**
  10049. * Returns the average value since the performance counter is running
  10050. */
  10051. get: function () {
  10052. return this._average;
  10053. },
  10054. enumerable: true,
  10055. configurable: true
  10056. });
  10057. Object.defineProperty(PerfCounter.prototype, "lastSecAverage", {
  10058. /**
  10059. * Returns the average value of the last second the counter was monitored
  10060. */
  10061. get: function () {
  10062. return this._lastSecAverage;
  10063. },
  10064. enumerable: true,
  10065. configurable: true
  10066. });
  10067. Object.defineProperty(PerfCounter.prototype, "current", {
  10068. /**
  10069. * Returns the current value
  10070. */
  10071. get: function () {
  10072. return this._current;
  10073. },
  10074. enumerable: true,
  10075. configurable: true
  10076. });
  10077. Object.defineProperty(PerfCounter.prototype, "total", {
  10078. get: function () {
  10079. return this._totalAccumulated;
  10080. },
  10081. enumerable: true,
  10082. configurable: true
  10083. });
  10084. Object.defineProperty(PerfCounter.prototype, "count", {
  10085. get: function () {
  10086. return this._totalValueCount;
  10087. },
  10088. enumerable: true,
  10089. configurable: true
  10090. });
  10091. /**
  10092. * Call this method to start monitoring a new frame.
  10093. * This scenario is typically used when you accumulate monitoring time many times for a single frame, you call this method at the start of the frame, then beginMonitoring to start recording and endMonitoring(false) to accumulated the recorded time to the PerfCounter or addCount() to accumulate a monitored count.
  10094. */
  10095. PerfCounter.prototype.fetchNewFrame = function () {
  10096. this._totalValueCount++;
  10097. this._current = 0;
  10098. this._lastSecValueCount++;
  10099. };
  10100. /**
  10101. * Call this method to monitor a count of something (e.g. mesh drawn in viewport count)
  10102. * @param newCount the count value to add to the monitored count
  10103. * @param fetchResult true when it's the last time in the frame you add to the counter and you wish to update the statistics properties (min/max/average), false if you only want to update statistics.
  10104. */
  10105. PerfCounter.prototype.addCount = function (newCount, fetchResult) {
  10106. if (!PerfCounter.Enabled) {
  10107. return;
  10108. }
  10109. this._current += newCount;
  10110. if (fetchResult) {
  10111. this._fetchResult();
  10112. }
  10113. };
  10114. /**
  10115. * Start monitoring this performance counter
  10116. */
  10117. PerfCounter.prototype.beginMonitoring = function () {
  10118. if (!PerfCounter.Enabled) {
  10119. return;
  10120. }
  10121. this._startMonitoringTime = Tools.Now;
  10122. };
  10123. /**
  10124. * Compute the time lapsed since the previous beginMonitoring() call.
  10125. * @param newFrame true by default to fetch the result and monitor a new frame, if false the time monitored will be added to the current frame counter
  10126. */
  10127. PerfCounter.prototype.endMonitoring = function (newFrame) {
  10128. if (newFrame === void 0) { newFrame = true; }
  10129. if (!PerfCounter.Enabled) {
  10130. return;
  10131. }
  10132. if (newFrame) {
  10133. this.fetchNewFrame();
  10134. }
  10135. var currentTime = Tools.Now;
  10136. this._current = currentTime - this._startMonitoringTime;
  10137. if (newFrame) {
  10138. this._fetchResult();
  10139. }
  10140. };
  10141. PerfCounter.prototype._fetchResult = function () {
  10142. this._totalAccumulated += this._current;
  10143. this._lastSecAccumulated += this._current;
  10144. // Min/Max update
  10145. this._min = Math.min(this._min, this._current);
  10146. this._max = Math.max(this._max, this._current);
  10147. this._average = this._totalAccumulated / this._totalValueCount;
  10148. // Reset last sec?
  10149. var now = Tools.Now;
  10150. if ((now - this._lastSecTime) > 1000) {
  10151. this._lastSecAverage = this._lastSecAccumulated / this._lastSecValueCount;
  10152. this._lastSecTime = now;
  10153. this._lastSecAccumulated = 0;
  10154. this._lastSecValueCount = 0;
  10155. }
  10156. };
  10157. PerfCounter.Enabled = true;
  10158. return PerfCounter;
  10159. }());
  10160. BABYLON.PerfCounter = PerfCounter;
  10161. /**
  10162. * Use this className as a decorator on a given class definition to add it a name and optionally its module.
  10163. * You can then use the Tools.getClassName(obj) on an instance to retrieve its class name.
  10164. * This method is the only way to get it done in all cases, even if the .js file declaring the class is minified
  10165. * @param name The name of the class, case should be preserved
  10166. * @param module The name of the Module hosting the class, optional, but strongly recommended to specify if possible. Case should be preserved.
  10167. */
  10168. function className(name, module) {
  10169. return function (target) {
  10170. target["__bjsclassName__"] = name;
  10171. target["__bjsmoduleName__"] = (module != null) ? module : null;
  10172. };
  10173. }
  10174. BABYLON.className = className;
  10175. /**
  10176. * An implementation of a loop for asynchronous functions.
  10177. */
  10178. var AsyncLoop = /** @class */ (function () {
  10179. /**
  10180. * Constroctor.
  10181. * @param iterations the number of iterations.
  10182. * @param _fn the function to run each iteration
  10183. * @param _successCallback the callback that will be called upon succesful execution
  10184. * @param offset starting offset.
  10185. */
  10186. function AsyncLoop(iterations, _fn, _successCallback, offset) {
  10187. if (offset === void 0) { offset = 0; }
  10188. this.iterations = iterations;
  10189. this._fn = _fn;
  10190. this._successCallback = _successCallback;
  10191. this.index = offset - 1;
  10192. this._done = false;
  10193. }
  10194. /**
  10195. * Execute the next iteration. Must be called after the last iteration was finished.
  10196. */
  10197. AsyncLoop.prototype.executeNext = function () {
  10198. if (!this._done) {
  10199. if (this.index + 1 < this.iterations) {
  10200. ++this.index;
  10201. this._fn(this);
  10202. }
  10203. else {
  10204. this.breakLoop();
  10205. }
  10206. }
  10207. };
  10208. /**
  10209. * Break the loop and run the success callback.
  10210. */
  10211. AsyncLoop.prototype.breakLoop = function () {
  10212. this._done = true;
  10213. this._successCallback();
  10214. };
  10215. /**
  10216. * Helper function
  10217. */
  10218. AsyncLoop.Run = function (iterations, _fn, _successCallback, offset) {
  10219. if (offset === void 0) { offset = 0; }
  10220. var loop = new AsyncLoop(iterations, _fn, _successCallback, offset);
  10221. loop.executeNext();
  10222. return loop;
  10223. };
  10224. /**
  10225. * A for-loop that will run a given number of iterations synchronous and the rest async.
  10226. * @param iterations total number of iterations
  10227. * @param syncedIterations number of synchronous iterations in each async iteration.
  10228. * @param fn the function to call each iteration.
  10229. * @param callback a success call back that will be called when iterating stops.
  10230. * @param breakFunction a break condition (optional)
  10231. * @param timeout timeout settings for the setTimeout function. default - 0.
  10232. * @constructor
  10233. */
  10234. AsyncLoop.SyncAsyncForLoop = function (iterations, syncedIterations, fn, callback, breakFunction, timeout) {
  10235. if (timeout === void 0) { timeout = 0; }
  10236. AsyncLoop.Run(Math.ceil(iterations / syncedIterations), function (loop) {
  10237. if (breakFunction && breakFunction())
  10238. loop.breakLoop();
  10239. else {
  10240. setTimeout(function () {
  10241. for (var i = 0; i < syncedIterations; ++i) {
  10242. var iteration = (loop.index * syncedIterations) + i;
  10243. if (iteration >= iterations)
  10244. break;
  10245. fn(iteration);
  10246. if (breakFunction && breakFunction()) {
  10247. loop.breakLoop();
  10248. break;
  10249. }
  10250. }
  10251. loop.executeNext();
  10252. }, timeout);
  10253. }
  10254. }, callback);
  10255. };
  10256. return AsyncLoop;
  10257. }());
  10258. BABYLON.AsyncLoop = AsyncLoop;
  10259. })(BABYLON || (BABYLON = {}));
  10260. //# sourceMappingURL=babylon.tools.js.map
  10261. var BABYLON;
  10262. (function (BABYLON) {
  10263. var PromiseStates;
  10264. (function (PromiseStates) {
  10265. PromiseStates[PromiseStates["Pending"] = 0] = "Pending";
  10266. PromiseStates[PromiseStates["Fulfilled"] = 1] = "Fulfilled";
  10267. PromiseStates[PromiseStates["Rejected"] = 2] = "Rejected";
  10268. })(PromiseStates || (PromiseStates = {}));
  10269. var FulFillmentAgregator = /** @class */ (function () {
  10270. function FulFillmentAgregator() {
  10271. this.count = 0;
  10272. this.target = 0;
  10273. this.results = [];
  10274. }
  10275. return FulFillmentAgregator;
  10276. }());
  10277. var InternalPromise = /** @class */ (function () {
  10278. function InternalPromise(resolver) {
  10279. var _this = this;
  10280. this._state = PromiseStates.Pending;
  10281. this._children = new Array();
  10282. this._rejectWasConsumed = false;
  10283. if (!resolver) {
  10284. return;
  10285. }
  10286. try {
  10287. resolver(function (value) {
  10288. _this._resolve(value);
  10289. }, function (reason) {
  10290. _this._reject(reason);
  10291. });
  10292. }
  10293. catch (e) {
  10294. this._reject(e);
  10295. }
  10296. }
  10297. Object.defineProperty(InternalPromise.prototype, "_result", {
  10298. get: function () {
  10299. return this._resultValue;
  10300. },
  10301. set: function (value) {
  10302. this._resultValue = value;
  10303. if (this._parent && this._parent._result === undefined) {
  10304. this._parent._result = value;
  10305. }
  10306. },
  10307. enumerable: true,
  10308. configurable: true
  10309. });
  10310. InternalPromise.prototype.catch = function (onRejected) {
  10311. return this.then(undefined, onRejected);
  10312. };
  10313. InternalPromise.prototype.then = function (onFulfilled, onRejected) {
  10314. var _this = this;
  10315. var newPromise = new InternalPromise();
  10316. newPromise._onFulfilled = onFulfilled;
  10317. newPromise._onRejected = onRejected;
  10318. // Composition
  10319. this._children.push(newPromise);
  10320. newPromise._parent = this;
  10321. if (this._state !== PromiseStates.Pending) {
  10322. BABYLON.Tools.SetImmediate(function () {
  10323. if (_this._state === PromiseStates.Fulfilled || _this._rejectWasConsumed) {
  10324. var returnedValue = newPromise._resolve(_this._result);
  10325. if (returnedValue !== undefined && returnedValue !== null) {
  10326. if (returnedValue._state !== undefined) {
  10327. var returnedPromise = returnedValue;
  10328. newPromise._children.push(returnedPromise);
  10329. returnedPromise._parent = newPromise;
  10330. newPromise = returnedPromise;
  10331. }
  10332. else {
  10333. newPromise._result = returnedValue;
  10334. }
  10335. }
  10336. }
  10337. else {
  10338. newPromise._reject(_this._reason);
  10339. }
  10340. });
  10341. }
  10342. return newPromise;
  10343. };
  10344. InternalPromise.prototype._moveChildren = function (children) {
  10345. var _this = this;
  10346. (_a = this._children).push.apply(_a, children.splice(0, children.length));
  10347. this._children.forEach(function (child) {
  10348. child._parent = _this;
  10349. });
  10350. if (this._state === PromiseStates.Fulfilled) {
  10351. for (var _i = 0, _b = this._children; _i < _b.length; _i++) {
  10352. var child = _b[_i];
  10353. child._resolve(this._result);
  10354. }
  10355. }
  10356. else if (this._state === PromiseStates.Rejected) {
  10357. for (var _c = 0, _d = this._children; _c < _d.length; _c++) {
  10358. var child = _d[_c];
  10359. child._reject(this._reason);
  10360. }
  10361. }
  10362. var _a;
  10363. };
  10364. InternalPromise.prototype._resolve = function (value) {
  10365. try {
  10366. this._state = PromiseStates.Fulfilled;
  10367. var returnedValue = null;
  10368. if (this._onFulfilled) {
  10369. returnedValue = this._onFulfilled(value);
  10370. }
  10371. if (returnedValue !== undefined && returnedValue !== null) {
  10372. if (returnedValue._state !== undefined) {
  10373. // Transmit children
  10374. var returnedPromise = returnedValue;
  10375. returnedPromise._parent = this;
  10376. returnedPromise._moveChildren(this._children);
  10377. value = returnedPromise._result;
  10378. }
  10379. else {
  10380. value = returnedValue;
  10381. }
  10382. }
  10383. this._result = value;
  10384. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10385. var child = _a[_i];
  10386. child._resolve(value);
  10387. }
  10388. this._children.length = 0;
  10389. delete this._onFulfilled;
  10390. delete this._onRejected;
  10391. }
  10392. catch (e) {
  10393. this._reject(e, true);
  10394. }
  10395. };
  10396. InternalPromise.prototype._reject = function (reason, onLocalThrow) {
  10397. if (onLocalThrow === void 0) { onLocalThrow = false; }
  10398. this._state = PromiseStates.Rejected;
  10399. this._reason = reason;
  10400. if (this._onRejected && !onLocalThrow) {
  10401. try {
  10402. this._onRejected(reason);
  10403. this._rejectWasConsumed = true;
  10404. }
  10405. catch (e) {
  10406. reason = e;
  10407. }
  10408. }
  10409. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10410. var child = _a[_i];
  10411. if (this._rejectWasConsumed) {
  10412. child._resolve(null);
  10413. }
  10414. else {
  10415. child._reject(reason);
  10416. }
  10417. }
  10418. this._children.length = 0;
  10419. delete this._onFulfilled;
  10420. delete this._onRejected;
  10421. };
  10422. InternalPromise.resolve = function (value) {
  10423. var newPromise = new InternalPromise();
  10424. newPromise._resolve(value);
  10425. return newPromise;
  10426. };
  10427. InternalPromise._RegisterForFulfillment = function (promise, agregator, index) {
  10428. promise.then(function (value) {
  10429. agregator.results[index] = value;
  10430. agregator.count++;
  10431. if (agregator.count === agregator.target) {
  10432. agregator.rootPromise._resolve(agregator.results);
  10433. }
  10434. return null;
  10435. }, function (reason) {
  10436. if (agregator.rootPromise._state !== PromiseStates.Rejected) {
  10437. agregator.rootPromise._reject(reason);
  10438. }
  10439. });
  10440. };
  10441. InternalPromise.all = function (promises) {
  10442. var newPromise = new InternalPromise();
  10443. var agregator = new FulFillmentAgregator();
  10444. agregator.target = promises.length;
  10445. agregator.rootPromise = newPromise;
  10446. if (promises.length) {
  10447. for (var index = 0; index < promises.length; index++) {
  10448. InternalPromise._RegisterForFulfillment(promises[index], agregator, index);
  10449. }
  10450. }
  10451. else {
  10452. newPromise._resolve([]);
  10453. }
  10454. return newPromise;
  10455. };
  10456. InternalPromise.race = function (promises) {
  10457. var newPromise = new InternalPromise();
  10458. if (promises.length) {
  10459. for (var _i = 0, promises_1 = promises; _i < promises_1.length; _i++) {
  10460. var promise = promises_1[_i];
  10461. promise.then(function (value) {
  10462. if (newPromise) {
  10463. newPromise._resolve(value);
  10464. newPromise = null;
  10465. }
  10466. return null;
  10467. }, function (reason) {
  10468. if (newPromise) {
  10469. newPromise._reject(reason);
  10470. newPromise = null;
  10471. }
  10472. });
  10473. }
  10474. }
  10475. return newPromise;
  10476. };
  10477. return InternalPromise;
  10478. }());
  10479. /**
  10480. * Helper class that provides a small promise polyfill
  10481. */
  10482. var PromisePolyfill = /** @class */ (function () {
  10483. function PromisePolyfill() {
  10484. }
  10485. /**
  10486. * Static function used to check if the polyfill is required
  10487. * If this is the case then the function will inject the polyfill to window.Promise
  10488. * @param force defines a boolean used to force the injection (mostly for testing purposes)
  10489. */
  10490. PromisePolyfill.Apply = function (force) {
  10491. if (force === void 0) { force = false; }
  10492. if (force || typeof Promise === 'undefined') {
  10493. var root = window;
  10494. root.Promise = InternalPromise;
  10495. }
  10496. };
  10497. return PromisePolyfill;
  10498. }());
  10499. BABYLON.PromisePolyfill = PromisePolyfill;
  10500. })(BABYLON || (BABYLON = {}));
  10501. //# sourceMappingURL=babylon.promise.js.map
  10502. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  10503. var BABYLON;
  10504. (function (BABYLON) {
  10505. /**
  10506. * Helper class to push actions to a pool of workers.
  10507. */
  10508. var WorkerPool = /** @class */ (function () {
  10509. /**
  10510. * Constructor
  10511. * @param workers Array of workers to use for actions
  10512. */
  10513. function WorkerPool(workers) {
  10514. this._pendingActions = new Array();
  10515. this._workerInfos = workers.map(function (worker) { return ({
  10516. worker: worker,
  10517. active: false
  10518. }); });
  10519. }
  10520. /**
  10521. * Terminates all workers and clears any pending actions.
  10522. */
  10523. WorkerPool.prototype.dispose = function () {
  10524. for (var _i = 0, _a = this._workerInfos; _i < _a.length; _i++) {
  10525. var workerInfo = _a[_i];
  10526. workerInfo.worker.terminate();
  10527. }
  10528. delete this._workerInfos;
  10529. delete this._pendingActions;
  10530. };
  10531. /**
  10532. * Pushes an action to the worker pool. If all the workers are active, the action will be
  10533. * pended until a worker has completed its action.
  10534. * @param action The action to perform. Call onComplete when the action is complete.
  10535. */
  10536. WorkerPool.prototype.push = function (action) {
  10537. for (var _i = 0, _a = this._workerInfos; _i < _a.length; _i++) {
  10538. var workerInfo = _a[_i];
  10539. if (!workerInfo.active) {
  10540. this._execute(workerInfo, action);
  10541. return;
  10542. }
  10543. }
  10544. this._pendingActions.push(action);
  10545. };
  10546. WorkerPool.prototype._execute = function (workerInfo, action) {
  10547. var _this = this;
  10548. workerInfo.active = true;
  10549. action(workerInfo.worker, function () {
  10550. workerInfo.active = false;
  10551. var nextAction = _this._pendingActions.shift();
  10552. if (nextAction) {
  10553. _this._execute(workerInfo, nextAction);
  10554. }
  10555. });
  10556. };
  10557. return WorkerPool;
  10558. }());
  10559. BABYLON.WorkerPool = WorkerPool;
  10560. })(BABYLON || (BABYLON = {}));
  10561. //# sourceMappingURL=babylon.workerPool.js.map
  10562. var BABYLON;
  10563. (function (BABYLON) {
  10564. /**
  10565. * @hidden
  10566. **/
  10567. var _AlphaState = /** @class */ (function () {
  10568. /**
  10569. * Initializes the state.
  10570. */
  10571. function _AlphaState() {
  10572. this._isAlphaBlendDirty = false;
  10573. this._isBlendFunctionParametersDirty = false;
  10574. this._isBlendEquationParametersDirty = false;
  10575. this._isBlendConstantsDirty = false;
  10576. this._alphaBlend = false;
  10577. this._blendFunctionParameters = new Array(4);
  10578. this._blendEquationParameters = new Array(2);
  10579. this._blendConstants = new Array(4);
  10580. this.reset();
  10581. }
  10582. Object.defineProperty(_AlphaState.prototype, "isDirty", {
  10583. get: function () {
  10584. return this._isAlphaBlendDirty || this._isBlendFunctionParametersDirty;
  10585. },
  10586. enumerable: true,
  10587. configurable: true
  10588. });
  10589. Object.defineProperty(_AlphaState.prototype, "alphaBlend", {
  10590. get: function () {
  10591. return this._alphaBlend;
  10592. },
  10593. set: function (value) {
  10594. if (this._alphaBlend === value) {
  10595. return;
  10596. }
  10597. this._alphaBlend = value;
  10598. this._isAlphaBlendDirty = true;
  10599. },
  10600. enumerable: true,
  10601. configurable: true
  10602. });
  10603. _AlphaState.prototype.setAlphaBlendConstants = function (r, g, b, a) {
  10604. if (this._blendConstants[0] === r &&
  10605. this._blendConstants[1] === g &&
  10606. this._blendConstants[2] === b &&
  10607. this._blendConstants[3] === a) {
  10608. return;
  10609. }
  10610. this._blendConstants[0] = r;
  10611. this._blendConstants[1] = g;
  10612. this._blendConstants[2] = b;
  10613. this._blendConstants[3] = a;
  10614. this._isBlendConstantsDirty = true;
  10615. };
  10616. _AlphaState.prototype.setAlphaBlendFunctionParameters = function (value0, value1, value2, value3) {
  10617. if (this._blendFunctionParameters[0] === value0 &&
  10618. this._blendFunctionParameters[1] === value1 &&
  10619. this._blendFunctionParameters[2] === value2 &&
  10620. this._blendFunctionParameters[3] === value3) {
  10621. return;
  10622. }
  10623. this._blendFunctionParameters[0] = value0;
  10624. this._blendFunctionParameters[1] = value1;
  10625. this._blendFunctionParameters[2] = value2;
  10626. this._blendFunctionParameters[3] = value3;
  10627. this._isBlendFunctionParametersDirty = true;
  10628. };
  10629. _AlphaState.prototype.setAlphaEquationParameters = function (rgb, alpha) {
  10630. if (this._blendEquationParameters[0] === rgb &&
  10631. this._blendEquationParameters[1] === alpha) {
  10632. return;
  10633. }
  10634. this._blendEquationParameters[0] = rgb;
  10635. this._blendEquationParameters[1] = alpha;
  10636. this._isBlendEquationParametersDirty = true;
  10637. };
  10638. _AlphaState.prototype.reset = function () {
  10639. this._alphaBlend = false;
  10640. this._blendFunctionParameters[0] = null;
  10641. this._blendFunctionParameters[1] = null;
  10642. this._blendFunctionParameters[2] = null;
  10643. this._blendFunctionParameters[3] = null;
  10644. this._blendEquationParameters[0] = null;
  10645. this._blendEquationParameters[1] = null;
  10646. this._blendConstants[0] = null;
  10647. this._blendConstants[1] = null;
  10648. this._blendConstants[2] = null;
  10649. this._blendConstants[3] = null;
  10650. this._isAlphaBlendDirty = true;
  10651. this._isBlendFunctionParametersDirty = false;
  10652. this._isBlendEquationParametersDirty = false;
  10653. this._isBlendConstantsDirty = false;
  10654. };
  10655. _AlphaState.prototype.apply = function (gl) {
  10656. if (!this.isDirty) {
  10657. return;
  10658. }
  10659. // Alpha blend
  10660. if (this._isAlphaBlendDirty) {
  10661. if (this._alphaBlend) {
  10662. gl.enable(gl.BLEND);
  10663. }
  10664. else {
  10665. gl.disable(gl.BLEND);
  10666. }
  10667. this._isAlphaBlendDirty = false;
  10668. }
  10669. // Alpha function
  10670. if (this._isBlendFunctionParametersDirty) {
  10671. gl.blendFuncSeparate(this._blendFunctionParameters[0], this._blendFunctionParameters[1], this._blendFunctionParameters[2], this._blendFunctionParameters[3]);
  10672. this._isBlendFunctionParametersDirty = false;
  10673. }
  10674. // Alpha equation
  10675. if (this._isBlendEquationParametersDirty) {
  10676. gl.blendEquationSeparate(this._isBlendEquationParametersDirty[0], this._isBlendEquationParametersDirty[1]);
  10677. this._isBlendEquationParametersDirty = false;
  10678. }
  10679. // Constants
  10680. if (this._isBlendConstantsDirty) {
  10681. gl.blendColor(this._blendConstants[0], this._blendConstants[1], this._blendConstants[2], this._blendConstants[3]);
  10682. this._isBlendConstantsDirty = false;
  10683. }
  10684. };
  10685. return _AlphaState;
  10686. }());
  10687. BABYLON._AlphaState = _AlphaState;
  10688. })(BABYLON || (BABYLON = {}));
  10689. //# sourceMappingURL=babylon.alphaCullingState.js.map
  10690. var BABYLON;
  10691. (function (BABYLON) {
  10692. /**
  10693. * @hidden
  10694. **/
  10695. var _DepthCullingState = /** @class */ (function () {
  10696. /**
  10697. * Initializes the state.
  10698. */
  10699. function _DepthCullingState() {
  10700. this._isDepthTestDirty = false;
  10701. this._isDepthMaskDirty = false;
  10702. this._isDepthFuncDirty = false;
  10703. this._isCullFaceDirty = false;
  10704. this._isCullDirty = false;
  10705. this._isZOffsetDirty = false;
  10706. this._isFrontFaceDirty = false;
  10707. this.reset();
  10708. }
  10709. Object.defineProperty(_DepthCullingState.prototype, "isDirty", {
  10710. get: function () {
  10711. return this._isDepthFuncDirty || this._isDepthTestDirty || this._isDepthMaskDirty || this._isCullFaceDirty || this._isCullDirty || this._isZOffsetDirty || this._isFrontFaceDirty;
  10712. },
  10713. enumerable: true,
  10714. configurable: true
  10715. });
  10716. Object.defineProperty(_DepthCullingState.prototype, "zOffset", {
  10717. get: function () {
  10718. return this._zOffset;
  10719. },
  10720. set: function (value) {
  10721. if (this._zOffset === value) {
  10722. return;
  10723. }
  10724. this._zOffset = value;
  10725. this._isZOffsetDirty = true;
  10726. },
  10727. enumerable: true,
  10728. configurable: true
  10729. });
  10730. Object.defineProperty(_DepthCullingState.prototype, "cullFace", {
  10731. get: function () {
  10732. return this._cullFace;
  10733. },
  10734. set: function (value) {
  10735. if (this._cullFace === value) {
  10736. return;
  10737. }
  10738. this._cullFace = value;
  10739. this._isCullFaceDirty = true;
  10740. },
  10741. enumerable: true,
  10742. configurable: true
  10743. });
  10744. Object.defineProperty(_DepthCullingState.prototype, "cull", {
  10745. get: function () {
  10746. return this._cull;
  10747. },
  10748. set: function (value) {
  10749. if (this._cull === value) {
  10750. return;
  10751. }
  10752. this._cull = value;
  10753. this._isCullDirty = true;
  10754. },
  10755. enumerable: true,
  10756. configurable: true
  10757. });
  10758. Object.defineProperty(_DepthCullingState.prototype, "depthFunc", {
  10759. get: function () {
  10760. return this._depthFunc;
  10761. },
  10762. set: function (value) {
  10763. if (this._depthFunc === value) {
  10764. return;
  10765. }
  10766. this._depthFunc = value;
  10767. this._isDepthFuncDirty = true;
  10768. },
  10769. enumerable: true,
  10770. configurable: true
  10771. });
  10772. Object.defineProperty(_DepthCullingState.prototype, "depthMask", {
  10773. get: function () {
  10774. return this._depthMask;
  10775. },
  10776. set: function (value) {
  10777. if (this._depthMask === value) {
  10778. return;
  10779. }
  10780. this._depthMask = value;
  10781. this._isDepthMaskDirty = true;
  10782. },
  10783. enumerable: true,
  10784. configurable: true
  10785. });
  10786. Object.defineProperty(_DepthCullingState.prototype, "depthTest", {
  10787. get: function () {
  10788. return this._depthTest;
  10789. },
  10790. set: function (value) {
  10791. if (this._depthTest === value) {
  10792. return;
  10793. }
  10794. this._depthTest = value;
  10795. this._isDepthTestDirty = true;
  10796. },
  10797. enumerable: true,
  10798. configurable: true
  10799. });
  10800. Object.defineProperty(_DepthCullingState.prototype, "frontFace", {
  10801. get: function () {
  10802. return this._frontFace;
  10803. },
  10804. set: function (value) {
  10805. if (this._frontFace === value) {
  10806. return;
  10807. }
  10808. this._frontFace = value;
  10809. this._isFrontFaceDirty = true;
  10810. },
  10811. enumerable: true,
  10812. configurable: true
  10813. });
  10814. _DepthCullingState.prototype.reset = function () {
  10815. this._depthMask = true;
  10816. this._depthTest = true;
  10817. this._depthFunc = null;
  10818. this._cullFace = null;
  10819. this._cull = null;
  10820. this._zOffset = 0;
  10821. this._frontFace = null;
  10822. this._isDepthTestDirty = true;
  10823. this._isDepthMaskDirty = true;
  10824. this._isDepthFuncDirty = false;
  10825. this._isCullFaceDirty = false;
  10826. this._isCullDirty = false;
  10827. this._isZOffsetDirty = false;
  10828. this._isFrontFaceDirty = false;
  10829. };
  10830. _DepthCullingState.prototype.apply = function (gl) {
  10831. if (!this.isDirty) {
  10832. return;
  10833. }
  10834. // Cull
  10835. if (this._isCullDirty) {
  10836. if (this.cull) {
  10837. gl.enable(gl.CULL_FACE);
  10838. }
  10839. else {
  10840. gl.disable(gl.CULL_FACE);
  10841. }
  10842. this._isCullDirty = false;
  10843. }
  10844. // Cull face
  10845. if (this._isCullFaceDirty) {
  10846. gl.cullFace(this.cullFace);
  10847. this._isCullFaceDirty = false;
  10848. }
  10849. // Depth mask
  10850. if (this._isDepthMaskDirty) {
  10851. gl.depthMask(this.depthMask);
  10852. this._isDepthMaskDirty = false;
  10853. }
  10854. // Depth test
  10855. if (this._isDepthTestDirty) {
  10856. if (this.depthTest) {
  10857. gl.enable(gl.DEPTH_TEST);
  10858. }
  10859. else {
  10860. gl.disable(gl.DEPTH_TEST);
  10861. }
  10862. this._isDepthTestDirty = false;
  10863. }
  10864. // Depth func
  10865. if (this._isDepthFuncDirty) {
  10866. gl.depthFunc(this.depthFunc);
  10867. this._isDepthFuncDirty = false;
  10868. }
  10869. // zOffset
  10870. if (this._isZOffsetDirty) {
  10871. if (this.zOffset) {
  10872. gl.enable(gl.POLYGON_OFFSET_FILL);
  10873. gl.polygonOffset(this.zOffset, 0);
  10874. }
  10875. else {
  10876. gl.disable(gl.POLYGON_OFFSET_FILL);
  10877. }
  10878. this._isZOffsetDirty = false;
  10879. }
  10880. // Front face
  10881. if (this._isFrontFaceDirty) {
  10882. gl.frontFace(this.frontFace);
  10883. this._isFrontFaceDirty = false;
  10884. }
  10885. };
  10886. return _DepthCullingState;
  10887. }());
  10888. BABYLON._DepthCullingState = _DepthCullingState;
  10889. })(BABYLON || (BABYLON = {}));
  10890. //# sourceMappingURL=babylon.depthCullingState.js.map
  10891. var BABYLON;
  10892. (function (BABYLON) {
  10893. /**
  10894. * @hidden
  10895. **/
  10896. var _StencilState = /** @class */ (function () {
  10897. function _StencilState() {
  10898. this._isStencilTestDirty = false;
  10899. this._isStencilMaskDirty = false;
  10900. this._isStencilFuncDirty = false;
  10901. this._isStencilOpDirty = false;
  10902. this.reset();
  10903. }
  10904. Object.defineProperty(_StencilState.prototype, "isDirty", {
  10905. get: function () {
  10906. return this._isStencilTestDirty || this._isStencilMaskDirty || this._isStencilFuncDirty || this._isStencilOpDirty;
  10907. },
  10908. enumerable: true,
  10909. configurable: true
  10910. });
  10911. Object.defineProperty(_StencilState.prototype, "stencilFunc", {
  10912. get: function () {
  10913. return this._stencilFunc;
  10914. },
  10915. set: function (value) {
  10916. if (this._stencilFunc === value) {
  10917. return;
  10918. }
  10919. this._stencilFunc = value;
  10920. this._isStencilFuncDirty = true;
  10921. },
  10922. enumerable: true,
  10923. configurable: true
  10924. });
  10925. Object.defineProperty(_StencilState.prototype, "stencilFuncRef", {
  10926. get: function () {
  10927. return this._stencilFuncRef;
  10928. },
  10929. set: function (value) {
  10930. if (this._stencilFuncRef === value) {
  10931. return;
  10932. }
  10933. this._stencilFuncRef = value;
  10934. this._isStencilFuncDirty = true;
  10935. },
  10936. enumerable: true,
  10937. configurable: true
  10938. });
  10939. Object.defineProperty(_StencilState.prototype, "stencilFuncMask", {
  10940. get: function () {
  10941. return this._stencilFuncMask;
  10942. },
  10943. set: function (value) {
  10944. if (this._stencilFuncMask === value) {
  10945. return;
  10946. }
  10947. this._stencilFuncMask = value;
  10948. this._isStencilFuncDirty = true;
  10949. },
  10950. enumerable: true,
  10951. configurable: true
  10952. });
  10953. Object.defineProperty(_StencilState.prototype, "stencilOpStencilFail", {
  10954. get: function () {
  10955. return this._stencilOpStencilFail;
  10956. },
  10957. set: function (value) {
  10958. if (this._stencilOpStencilFail === value) {
  10959. return;
  10960. }
  10961. this._stencilOpStencilFail = value;
  10962. this._isStencilOpDirty = true;
  10963. },
  10964. enumerable: true,
  10965. configurable: true
  10966. });
  10967. Object.defineProperty(_StencilState.prototype, "stencilOpDepthFail", {
  10968. get: function () {
  10969. return this._stencilOpDepthFail;
  10970. },
  10971. set: function (value) {
  10972. if (this._stencilOpDepthFail === value) {
  10973. return;
  10974. }
  10975. this._stencilOpDepthFail = value;
  10976. this._isStencilOpDirty = true;
  10977. },
  10978. enumerable: true,
  10979. configurable: true
  10980. });
  10981. Object.defineProperty(_StencilState.prototype, "stencilOpStencilDepthPass", {
  10982. get: function () {
  10983. return this._stencilOpStencilDepthPass;
  10984. },
  10985. set: function (value) {
  10986. if (this._stencilOpStencilDepthPass === value) {
  10987. return;
  10988. }
  10989. this._stencilOpStencilDepthPass = value;
  10990. this._isStencilOpDirty = true;
  10991. },
  10992. enumerable: true,
  10993. configurable: true
  10994. });
  10995. Object.defineProperty(_StencilState.prototype, "stencilMask", {
  10996. get: function () {
  10997. return this._stencilMask;
  10998. },
  10999. set: function (value) {
  11000. if (this._stencilMask === value) {
  11001. return;
  11002. }
  11003. this._stencilMask = value;
  11004. this._isStencilMaskDirty = true;
  11005. },
  11006. enumerable: true,
  11007. configurable: true
  11008. });
  11009. Object.defineProperty(_StencilState.prototype, "stencilTest", {
  11010. get: function () {
  11011. return this._stencilTest;
  11012. },
  11013. set: function (value) {
  11014. if (this._stencilTest === value) {
  11015. return;
  11016. }
  11017. this._stencilTest = value;
  11018. this._isStencilTestDirty = true;
  11019. },
  11020. enumerable: true,
  11021. configurable: true
  11022. });
  11023. _StencilState.prototype.reset = function () {
  11024. this._stencilTest = false;
  11025. this._stencilMask = 0xFF;
  11026. this._stencilFunc = BABYLON.Engine.ALWAYS;
  11027. this._stencilFuncRef = 1;
  11028. this._stencilFuncMask = 0xFF;
  11029. this._stencilOpStencilFail = BABYLON.Engine.KEEP;
  11030. this._stencilOpDepthFail = BABYLON.Engine.KEEP;
  11031. this._stencilOpStencilDepthPass = BABYLON.Engine.REPLACE;
  11032. this._isStencilTestDirty = true;
  11033. this._isStencilMaskDirty = true;
  11034. this._isStencilFuncDirty = true;
  11035. this._isStencilOpDirty = true;
  11036. };
  11037. _StencilState.prototype.apply = function (gl) {
  11038. if (!this.isDirty) {
  11039. return;
  11040. }
  11041. // Stencil test
  11042. if (this._isStencilTestDirty) {
  11043. if (this.stencilTest) {
  11044. gl.enable(gl.STENCIL_TEST);
  11045. }
  11046. else {
  11047. gl.disable(gl.STENCIL_TEST);
  11048. }
  11049. this._isStencilTestDirty = false;
  11050. }
  11051. // Stencil mask
  11052. if (this._isStencilMaskDirty) {
  11053. gl.stencilMask(this.stencilMask);
  11054. this._isStencilMaskDirty = false;
  11055. }
  11056. // Stencil func
  11057. if (this._isStencilFuncDirty) {
  11058. gl.stencilFunc(this.stencilFunc, this.stencilFuncRef, this.stencilFuncMask);
  11059. this._isStencilFuncDirty = false;
  11060. }
  11061. // Stencil op
  11062. if (this._isStencilOpDirty) {
  11063. gl.stencilOp(this.stencilOpStencilFail, this.stencilOpDepthFail, this.stencilOpStencilDepthPass);
  11064. this._isStencilOpDirty = false;
  11065. }
  11066. };
  11067. return _StencilState;
  11068. }());
  11069. BABYLON._StencilState = _StencilState;
  11070. })(BABYLON || (BABYLON = {}));
  11071. //# sourceMappingURL=babylon.stencilState.js.map
  11072. var __assign = (this && this.__assign) || Object.assign || function(t) {
  11073. for (var s, i = 1, n = arguments.length; i < n; i++) {
  11074. s = arguments[i];
  11075. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  11076. t[p] = s[p];
  11077. }
  11078. return t;
  11079. };
  11080. var BABYLON;
  11081. (function (BABYLON) {
  11082. var compileShader = function (gl, source, type, defines, shaderVersion) {
  11083. return compileRawShader(gl, shaderVersion + (defines ? defines + "\n" : "") + source, type);
  11084. };
  11085. var compileRawShader = function (gl, source, type) {
  11086. var shader = gl.createShader(type === "vertex" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
  11087. gl.shaderSource(shader, source);
  11088. gl.compileShader(shader);
  11089. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  11090. var log = gl.getShaderInfoLog(shader);
  11091. if (log) {
  11092. throw new Error(log);
  11093. }
  11094. }
  11095. if (!shader) {
  11096. throw new Error("Something went wrong while compile the shader.");
  11097. }
  11098. return shader;
  11099. };
  11100. var getSamplingParameters = function (samplingMode, generateMipMaps, gl) {
  11101. var magFilter = gl.NEAREST;
  11102. var minFilter = gl.NEAREST;
  11103. switch (samplingMode) {
  11104. case BABYLON.Texture.BILINEAR_SAMPLINGMODE:
  11105. magFilter = gl.LINEAR;
  11106. if (generateMipMaps) {
  11107. minFilter = gl.LINEAR_MIPMAP_NEAREST;
  11108. }
  11109. else {
  11110. minFilter = gl.LINEAR;
  11111. }
  11112. break;
  11113. case BABYLON.Texture.TRILINEAR_SAMPLINGMODE:
  11114. magFilter = gl.LINEAR;
  11115. if (generateMipMaps) {
  11116. minFilter = gl.LINEAR_MIPMAP_LINEAR;
  11117. }
  11118. else {
  11119. minFilter = gl.LINEAR;
  11120. }
  11121. break;
  11122. case BABYLON.Texture.NEAREST_SAMPLINGMODE:
  11123. magFilter = gl.NEAREST;
  11124. if (generateMipMaps) {
  11125. minFilter = gl.NEAREST_MIPMAP_LINEAR;
  11126. }
  11127. else {
  11128. minFilter = gl.NEAREST;
  11129. }
  11130. break;
  11131. case BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST:
  11132. magFilter = gl.NEAREST;
  11133. if (generateMipMaps) {
  11134. minFilter = gl.NEAREST_MIPMAP_NEAREST;
  11135. }
  11136. else {
  11137. minFilter = gl.NEAREST;
  11138. }
  11139. break;
  11140. case BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST:
  11141. magFilter = gl.NEAREST;
  11142. if (generateMipMaps) {
  11143. minFilter = gl.LINEAR_MIPMAP_NEAREST;
  11144. }
  11145. else {
  11146. minFilter = gl.LINEAR;
  11147. }
  11148. break;
  11149. case BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR:
  11150. magFilter = gl.NEAREST;
  11151. if (generateMipMaps) {
  11152. minFilter = gl.LINEAR_MIPMAP_LINEAR;
  11153. }
  11154. else {
  11155. minFilter = gl.LINEAR;
  11156. }
  11157. break;
  11158. case BABYLON.Texture.NEAREST_LINEAR:
  11159. magFilter = gl.NEAREST;
  11160. minFilter = gl.LINEAR;
  11161. break;
  11162. case BABYLON.Texture.NEAREST_NEAREST:
  11163. magFilter = gl.NEAREST;
  11164. minFilter = gl.NEAREST;
  11165. break;
  11166. case BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST:
  11167. magFilter = gl.LINEAR;
  11168. if (generateMipMaps) {
  11169. minFilter = gl.NEAREST_MIPMAP_NEAREST;
  11170. }
  11171. else {
  11172. minFilter = gl.NEAREST;
  11173. }
  11174. break;
  11175. case BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR:
  11176. magFilter = gl.LINEAR;
  11177. if (generateMipMaps) {
  11178. minFilter = gl.NEAREST_MIPMAP_LINEAR;
  11179. }
  11180. else {
  11181. minFilter = gl.NEAREST;
  11182. }
  11183. break;
  11184. case BABYLON.Texture.LINEAR_LINEAR:
  11185. magFilter = gl.LINEAR;
  11186. minFilter = gl.LINEAR;
  11187. break;
  11188. case BABYLON.Texture.LINEAR_NEAREST:
  11189. magFilter = gl.LINEAR;
  11190. minFilter = gl.NEAREST;
  11191. break;
  11192. }
  11193. return {
  11194. min: minFilter,
  11195. mag: magFilter
  11196. };
  11197. };
  11198. var partialLoadImg = function (url, index, loadedImages, scene, onfinish, onErrorCallBack) {
  11199. if (onErrorCallBack === void 0) { onErrorCallBack = null; }
  11200. var img;
  11201. var onload = function () {
  11202. loadedImages[index] = img;
  11203. loadedImages._internalCount++;
  11204. if (scene) {
  11205. scene._removePendingData(img);
  11206. }
  11207. if (loadedImages._internalCount === 6) {
  11208. onfinish(loadedImages);
  11209. }
  11210. };
  11211. var onerror = function (message, exception) {
  11212. if (scene) {
  11213. scene._removePendingData(img);
  11214. }
  11215. if (onErrorCallBack) {
  11216. onErrorCallBack(message, exception);
  11217. }
  11218. };
  11219. img = BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
  11220. if (scene) {
  11221. scene._addPendingData(img);
  11222. }
  11223. };
  11224. var cascadeLoadImgs = function (rootUrl, scene, onfinish, files, onError) {
  11225. if (onError === void 0) { onError = null; }
  11226. var loadedImages = [];
  11227. loadedImages._internalCount = 0;
  11228. for (var index = 0; index < 6; index++) {
  11229. partialLoadImg(files[index], index, loadedImages, scene, onfinish, onError);
  11230. }
  11231. };
  11232. var BufferPointer = /** @class */ (function () {
  11233. function BufferPointer() {
  11234. }
  11235. return BufferPointer;
  11236. }());
  11237. /**
  11238. * Interface for attribute information associated with buffer instanciation
  11239. */
  11240. var InstancingAttributeInfo = /** @class */ (function () {
  11241. function InstancingAttributeInfo() {
  11242. }
  11243. return InstancingAttributeInfo;
  11244. }());
  11245. BABYLON.InstancingAttributeInfo = InstancingAttributeInfo;
  11246. /**
  11247. * Define options used to create a render target texture
  11248. */
  11249. var RenderTargetCreationOptions = /** @class */ (function () {
  11250. function RenderTargetCreationOptions() {
  11251. }
  11252. return RenderTargetCreationOptions;
  11253. }());
  11254. BABYLON.RenderTargetCreationOptions = RenderTargetCreationOptions;
  11255. /**
  11256. * Define options used to create a depth texture
  11257. */
  11258. var DepthTextureCreationOptions = /** @class */ (function () {
  11259. function DepthTextureCreationOptions() {
  11260. }
  11261. return DepthTextureCreationOptions;
  11262. }());
  11263. BABYLON.DepthTextureCreationOptions = DepthTextureCreationOptions;
  11264. /**
  11265. * Class used to describe the capabilities of the engine relatively to the current browser
  11266. */
  11267. var EngineCapabilities = /** @class */ (function () {
  11268. function EngineCapabilities() {
  11269. }
  11270. return EngineCapabilities;
  11271. }());
  11272. BABYLON.EngineCapabilities = EngineCapabilities;
  11273. /**
  11274. * The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio
  11275. */
  11276. var Engine = /** @class */ (function () {
  11277. /**
  11278. * Creates a new engine
  11279. * @param canvasOrContext defines the canvas or WebGL context to use for rendering
  11280. * @param antialias defines enable antialiasing (default: false)
  11281. * @param options defines further options to be sent to the getContext() function
  11282. * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
  11283. */
  11284. function Engine(canvasOrContext, antialias, options, adaptToDeviceRatio) {
  11285. if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = false; }
  11286. var _this = this;
  11287. // Public members
  11288. /**
  11289. * Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required
  11290. */
  11291. this.forcePOTTextures = false;
  11292. /**
  11293. * Gets a boolean indicating if the engine is currently rendering in fullscreen mode
  11294. */
  11295. this.isFullscreen = false;
  11296. /**
  11297. * Gets a boolean indicating if the pointer is currently locked
  11298. */
  11299. this.isPointerLock = false;
  11300. /**
  11301. * Gets or sets a boolean indicating if back faces must be culled (true by default)
  11302. */
  11303. this.cullBackFaces = true;
  11304. /**
  11305. * Gets or sets a boolean indicating if the engine must keep rendering even if the window is not in foregroun
  11306. */
  11307. this.renderEvenInBackground = true;
  11308. /**
  11309. * Gets or sets a boolean indicating that cache can be kept between frames
  11310. */
  11311. this.preventCacheWipeBetweenFrames = false;
  11312. /**
  11313. * Gets or sets a boolean to enable/disable IndexedDB support and avoid XHR on .manifest
  11314. **/
  11315. this.enableOfflineSupport = false;
  11316. /**
  11317. * Gets or sets a boolean to enable/disable checking manifest if IndexedDB support is enabled (Babylon.js will always consider the database is up to date)
  11318. **/
  11319. this.disableManifestCheck = false;
  11320. /**
  11321. * Gets the list of created scenes
  11322. */
  11323. this.scenes = new Array();
  11324. /**
  11325. * Gets the list of created postprocesses
  11326. */
  11327. this.postProcesses = new Array();
  11328. // Observables
  11329. /**
  11330. * Observable event triggered each time the rendering canvas is resized
  11331. */
  11332. this.onResizeObservable = new BABYLON.Observable();
  11333. /**
  11334. * Observable event triggered each time the canvas loses focus
  11335. */
  11336. this.onCanvasBlurObservable = new BABYLON.Observable();
  11337. /**
  11338. * Observable event triggered each time the canvas gains focus
  11339. */
  11340. this.onCanvasFocusObservable = new BABYLON.Observable();
  11341. /**
  11342. * Observable event triggered each time the canvas receives pointerout event
  11343. */
  11344. this.onCanvasPointerOutObservable = new BABYLON.Observable();
  11345. /**
  11346. * Observable event triggered before each texture is initialized
  11347. */
  11348. this.onBeforeTextureInitObservable = new BABYLON.Observable();
  11349. //WebVR
  11350. this._vrDisplay = undefined;
  11351. this._vrSupported = false;
  11352. this._vrExclusivePointerMode = false;
  11353. // Uniform buffers list
  11354. /**
  11355. * Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported
  11356. */
  11357. this.disableUniformBuffers = false;
  11358. /** @hidden */
  11359. this._uniformBuffers = new Array();
  11360. // Observables
  11361. /**
  11362. * Observable raised when the engine begins a new frame
  11363. */
  11364. this.onBeginFrameObservable = new BABYLON.Observable();
  11365. /**
  11366. * Observable raised when the engine ends the current frame
  11367. */
  11368. this.onEndFrameObservable = new BABYLON.Observable();
  11369. /**
  11370. * Observable raised when the engine is about to compile a shader
  11371. */
  11372. this.onBeforeShaderCompilationObservable = new BABYLON.Observable();
  11373. /**
  11374. * Observable raised when the engine has jsut compiled a shader
  11375. */
  11376. this.onAfterShaderCompilationObservable = new BABYLON.Observable();
  11377. this._windowIsBackground = false;
  11378. this._webGLVersion = 1.0;
  11379. /** @hidden */
  11380. this._badOS = false;
  11381. /** @hidden */
  11382. this._badDesktopOS = false;
  11383. /**
  11384. * Gets or sets a value indicating if we want to disable texture binding optmization.
  11385. * This could be required on some buggy drivers which wants to have textures bound in a progressive order.
  11386. * By default Babylon.js will try to let textures bound where they are and only update the samplers to point where the texture is
  11387. */
  11388. this.disableTextureBindingOptimization = false;
  11389. /**
  11390. * Observable signaled when VR display mode changes
  11391. */
  11392. this.onVRDisplayChangedObservable = new BABYLON.Observable();
  11393. /**
  11394. * Observable signaled when VR request present is complete
  11395. */
  11396. this.onVRRequestPresentComplete = new BABYLON.Observable();
  11397. /**
  11398. * Observable signaled when VR request present starts
  11399. */
  11400. this.onVRRequestPresentStart = new BABYLON.Observable();
  11401. this._colorWrite = true;
  11402. /** @hidden */
  11403. this._drawCalls = new BABYLON.PerfCounter();
  11404. /** @hidden */
  11405. this._textureCollisions = new BABYLON.PerfCounter();
  11406. this._renderingQueueLaunched = false;
  11407. this._activeRenderLoops = new Array();
  11408. // Deterministic lockstepMaxSteps
  11409. this._deterministicLockstep = false;
  11410. this._lockstepMaxSteps = 4;
  11411. // Lost context
  11412. /**
  11413. * Observable signaled when a context lost event is raised
  11414. */
  11415. this.onContextLostObservable = new BABYLON.Observable();
  11416. /**
  11417. * Observable signaled when a context restored event is raised
  11418. */
  11419. this.onContextRestoredObservable = new BABYLON.Observable();
  11420. this._contextWasLost = false;
  11421. this._doNotHandleContextLost = false;
  11422. // FPS
  11423. this._performanceMonitor = new BABYLON.PerformanceMonitor();
  11424. this._fps = 60;
  11425. this._deltaTime = 0;
  11426. /**
  11427. * Turn this value on if you want to pause FPS computation when in background
  11428. */
  11429. this.disablePerformanceMonitorInBackground = false;
  11430. // States
  11431. /** @hidden */
  11432. this._depthCullingState = new BABYLON._DepthCullingState();
  11433. /** @hidden */
  11434. this._stencilState = new BABYLON._StencilState();
  11435. /** @hidden */
  11436. this._alphaState = new BABYLON._AlphaState();
  11437. /** @hidden */
  11438. this._alphaMode = Engine.ALPHA_DISABLE;
  11439. // Cache
  11440. this._internalTexturesCache = new Array();
  11441. /** @hidden */
  11442. this._activeChannel = 0;
  11443. this._currentTextureChannel = -1;
  11444. /** @hidden */
  11445. this._boundTexturesCache = {};
  11446. this._compiledEffects = {};
  11447. this._vertexAttribArraysEnabled = [];
  11448. this._uintIndicesCurrentlySet = false;
  11449. this._currentBoundBuffer = new Array();
  11450. this._currentBufferPointers = new Array();
  11451. this._currentInstanceLocations = new Array();
  11452. this._currentInstanceBuffers = new Array();
  11453. this._firstBoundInternalTextureTracker = new BABYLON.DummyInternalTextureTracker();
  11454. this._lastBoundInternalTextureTracker = new BABYLON.DummyInternalTextureTracker();
  11455. this._vaoRecordInProgress = false;
  11456. this._mustWipeVertexAttributes = false;
  11457. this._nextFreeTextureSlots = new Array();
  11458. this._maxSimultaneousTextures = 0;
  11459. this._activeRequests = new Array();
  11460. // Hardware supported Compressed Textures
  11461. this._texturesSupported = new Array();
  11462. /**
  11463. * Defines whether the engine has been created with the premultipliedAlpha option on or not.
  11464. */
  11465. this.premultipliedAlpha = true;
  11466. this._onVRFullScreenTriggered = function () {
  11467. if (_this._vrDisplay && _this._vrDisplay.isPresenting) {
  11468. //get the old size before we change
  11469. _this._oldSize = new BABYLON.Size(_this.getRenderWidth(), _this.getRenderHeight());
  11470. _this._oldHardwareScaleFactor = _this.getHardwareScalingLevel();
  11471. //get the width and height, change the render size
  11472. var leftEye = _this._vrDisplay.getEyeParameters('left');
  11473. _this.setHardwareScalingLevel(1);
  11474. _this.setSize(leftEye.renderWidth * 2, leftEye.renderHeight);
  11475. }
  11476. else {
  11477. _this.setHardwareScalingLevel(_this._oldHardwareScaleFactor);
  11478. _this.setSize(_this._oldSize.width, _this._oldSize.height);
  11479. }
  11480. };
  11481. this._boundUniforms = {};
  11482. // Register promises
  11483. BABYLON.PromisePolyfill.Apply();
  11484. var canvas = null;
  11485. Engine.Instances.push(this);
  11486. if (!canvasOrContext) {
  11487. return;
  11488. }
  11489. options = options || {};
  11490. if (canvasOrContext.getContext) {
  11491. canvas = canvasOrContext;
  11492. this._renderingCanvas = canvas;
  11493. if (antialias != null) {
  11494. options.antialias = antialias;
  11495. }
  11496. if (options.deterministicLockstep === undefined) {
  11497. options.deterministicLockstep = false;
  11498. }
  11499. if (options.lockstepMaxSteps === undefined) {
  11500. options.lockstepMaxSteps = 4;
  11501. }
  11502. if (options.preserveDrawingBuffer === undefined) {
  11503. options.preserveDrawingBuffer = false;
  11504. }
  11505. if (options.audioEngine === undefined) {
  11506. options.audioEngine = true;
  11507. }
  11508. if (options.stencil === undefined) {
  11509. options.stencil = true;
  11510. }
  11511. if (options.premultipliedAlpha === false) {
  11512. this.premultipliedAlpha = false;
  11513. }
  11514. this._deterministicLockstep = options.deterministicLockstep;
  11515. this._lockstepMaxSteps = options.lockstepMaxSteps;
  11516. this._doNotHandleContextLost = options.doNotHandleContextLost ? true : false;
  11517. // Exceptions
  11518. if (navigator && navigator.userAgent) {
  11519. var ua = navigator.userAgent;
  11520. for (var _i = 0, _a = Engine.ExceptionList; _i < _a.length; _i++) {
  11521. var exception = _a[_i];
  11522. var key = exception.key;
  11523. var targets = exception.targets;
  11524. if (ua.indexOf(key) > -1) {
  11525. if (exception.capture && exception.captureConstraint) {
  11526. var capture = exception.capture;
  11527. var constraint = exception.captureConstraint;
  11528. var regex = new RegExp(capture);
  11529. var matches = regex.exec(ua);
  11530. if (matches && matches.length > 0) {
  11531. var capturedValue = parseInt(matches[matches.length - 1]);
  11532. if (capturedValue >= constraint) {
  11533. continue;
  11534. }
  11535. }
  11536. }
  11537. for (var _b = 0, targets_1 = targets; _b < targets_1.length; _b++) {
  11538. var target = targets_1[_b];
  11539. switch (target) {
  11540. case "uniformBuffer":
  11541. this.disableUniformBuffers = true;
  11542. break;
  11543. case "textureBindingOptimization":
  11544. this.disableTextureBindingOptimization = true;
  11545. break;
  11546. }
  11547. }
  11548. }
  11549. }
  11550. }
  11551. // GL
  11552. if (!options.disableWebGL2Support) {
  11553. try {
  11554. this._gl = (canvas.getContext("webgl2", options) || canvas.getContext("experimental-webgl2", options));
  11555. if (this._gl) {
  11556. this._webGLVersion = 2.0;
  11557. }
  11558. }
  11559. catch (e) {
  11560. // Do nothing
  11561. }
  11562. }
  11563. if (!this._gl) {
  11564. if (!canvas) {
  11565. throw new Error("The provided canvas is null or undefined.");
  11566. }
  11567. try {
  11568. this._gl = (canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options));
  11569. }
  11570. catch (e) {
  11571. throw new Error("WebGL not supported");
  11572. }
  11573. }
  11574. if (!this._gl) {
  11575. throw new Error("WebGL not supported");
  11576. }
  11577. this._onCanvasFocus = function () {
  11578. _this.onCanvasFocusObservable.notifyObservers(_this);
  11579. };
  11580. this._onCanvasBlur = function () {
  11581. _this.onCanvasBlurObservable.notifyObservers(_this);
  11582. };
  11583. canvas.addEventListener("focus", this._onCanvasFocus);
  11584. canvas.addEventListener("blur", this._onCanvasBlur);
  11585. this._onBlur = function () {
  11586. if (_this.disablePerformanceMonitorInBackground) {
  11587. _this._performanceMonitor.disable();
  11588. }
  11589. _this._windowIsBackground = true;
  11590. };
  11591. this._onFocus = function () {
  11592. if (_this.disablePerformanceMonitorInBackground) {
  11593. _this._performanceMonitor.enable();
  11594. }
  11595. _this._windowIsBackground = false;
  11596. };
  11597. this._onCanvasPointerOut = function (ev) {
  11598. _this.onCanvasPointerOutObservable.notifyObservers(ev);
  11599. };
  11600. window.addEventListener("blur", this._onBlur);
  11601. window.addEventListener("focus", this._onFocus);
  11602. canvas.addEventListener("pointerout", this._onCanvasPointerOut);
  11603. // Context lost
  11604. if (!this._doNotHandleContextLost) {
  11605. this._onContextLost = function (evt) {
  11606. evt.preventDefault();
  11607. _this._contextWasLost = true;
  11608. BABYLON.Tools.Warn("WebGL context lost.");
  11609. _this.onContextLostObservable.notifyObservers(_this);
  11610. };
  11611. this._onContextRestored = function (evt) {
  11612. // Adding a timeout to avoid race condition at browser level
  11613. setTimeout(function () {
  11614. // Rebuild gl context
  11615. _this._initGLContext();
  11616. // Rebuild effects
  11617. _this._rebuildEffects();
  11618. // Rebuild textures
  11619. _this._rebuildInternalTextures();
  11620. // Rebuild buffers
  11621. _this._rebuildBuffers();
  11622. // Cache
  11623. _this.wipeCaches(true);
  11624. BABYLON.Tools.Warn("WebGL context successfully restored.");
  11625. _this.onContextRestoredObservable.notifyObservers(_this);
  11626. _this._contextWasLost = false;
  11627. }, 0);
  11628. };
  11629. canvas.addEventListener("webglcontextlost", this._onContextLost, false);
  11630. canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
  11631. }
  11632. }
  11633. else {
  11634. this._gl = canvasOrContext;
  11635. this._renderingCanvas = this._gl.canvas;
  11636. if (this._gl.renderbufferStorageMultisample) {
  11637. this._webGLVersion = 2.0;
  11638. }
  11639. options.stencil = this._gl.getContextAttributes().stencil;
  11640. }
  11641. // Viewport
  11642. var limitDeviceRatio = options.limitDeviceRatio || window.devicePixelRatio || 1.0;
  11643. this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, window.devicePixelRatio || 1.0) : 1.0;
  11644. this.resize();
  11645. this._isStencilEnable = options.stencil ? true : false;
  11646. this._initGLContext();
  11647. if (canvas) {
  11648. // Fullscreen
  11649. this._onFullscreenChange = function () {
  11650. if (document.fullscreen !== undefined) {
  11651. _this.isFullscreen = document.fullscreen;
  11652. }
  11653. else if (document.mozFullScreen !== undefined) {
  11654. _this.isFullscreen = document.mozFullScreen;
  11655. }
  11656. else if (document.webkitIsFullScreen !== undefined) {
  11657. _this.isFullscreen = document.webkitIsFullScreen;
  11658. }
  11659. else if (document.msIsFullScreen !== undefined) {
  11660. _this.isFullscreen = document.msIsFullScreen;
  11661. }
  11662. // Pointer lock
  11663. if (_this.isFullscreen && _this._pointerLockRequested && canvas) {
  11664. canvas.requestPointerLock = canvas.requestPointerLock ||
  11665. canvas.msRequestPointerLock ||
  11666. canvas.mozRequestPointerLock ||
  11667. canvas.webkitRequestPointerLock;
  11668. if (canvas.requestPointerLock) {
  11669. canvas.requestPointerLock();
  11670. }
  11671. }
  11672. };
  11673. document.addEventListener("fullscreenchange", this._onFullscreenChange, false);
  11674. document.addEventListener("mozfullscreenchange", this._onFullscreenChange, false);
  11675. document.addEventListener("webkitfullscreenchange", this._onFullscreenChange, false);
  11676. document.addEventListener("msfullscreenchange", this._onFullscreenChange, false);
  11677. // Pointer lock
  11678. this._onPointerLockChange = function () {
  11679. _this.isPointerLock = (document.mozPointerLockElement === canvas ||
  11680. document.webkitPointerLockElement === canvas ||
  11681. document.msPointerLockElement === canvas ||
  11682. document.pointerLockElement === canvas);
  11683. };
  11684. document.addEventListener("pointerlockchange", this._onPointerLockChange, false);
  11685. document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
  11686. document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
  11687. document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
  11688. this._onVRDisplayPointerRestricted = function () {
  11689. if (canvas) {
  11690. canvas.requestPointerLock();
  11691. }
  11692. };
  11693. this._onVRDisplayPointerUnrestricted = function () {
  11694. document.exitPointerLock();
  11695. };
  11696. window.addEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted, false);
  11697. window.addEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted, false);
  11698. }
  11699. if (options.audioEngine && BABYLON.AudioEngine && !Engine.audioEngine) {
  11700. Engine.audioEngine = new BABYLON.AudioEngine();
  11701. }
  11702. // Prepare buffer pointers
  11703. for (var i = 0; i < this._caps.maxVertexAttribs; i++) {
  11704. this._currentBufferPointers[i] = new BufferPointer();
  11705. }
  11706. this._linkTrackers(this._firstBoundInternalTextureTracker, this._lastBoundInternalTextureTracker);
  11707. // Load WebVR Devices
  11708. if (options.autoEnableWebVR) {
  11709. this.initWebVR();
  11710. }
  11711. // Detect if we are running on a faulty buggy OS.
  11712. this._badOS = /iPad/i.test(navigator.userAgent) || /iPhone/i.test(navigator.userAgent);
  11713. // Detect if we are running on a faulty buggy desktop OS.
  11714. this._badDesktopOS = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  11715. console.log("Babylon.js engine (v" + Engine.Version + ") launched");
  11716. this.enableOfflineSupport = (BABYLON.Database !== undefined);
  11717. }
  11718. Object.defineProperty(Engine, "LastCreatedEngine", {
  11719. /**
  11720. * Gets the latest created engine
  11721. */
  11722. get: function () {
  11723. if (Engine.Instances.length === 0) {
  11724. return null;
  11725. }
  11726. return Engine.Instances[Engine.Instances.length - 1];
  11727. },
  11728. enumerable: true,
  11729. configurable: true
  11730. });
  11731. Object.defineProperty(Engine, "LastCreatedScene", {
  11732. /**
  11733. * Gets the latest created scene
  11734. */
  11735. get: function () {
  11736. var lastCreatedEngine = Engine.LastCreatedEngine;
  11737. if (!lastCreatedEngine) {
  11738. return null;
  11739. }
  11740. if (lastCreatedEngine.scenes.length === 0) {
  11741. return null;
  11742. }
  11743. return lastCreatedEngine.scenes[lastCreatedEngine.scenes.length - 1];
  11744. },
  11745. enumerable: true,
  11746. configurable: true
  11747. });
  11748. /**
  11749. * Will flag all materials in all scenes in all engines as dirty to trigger new shader compilation
  11750. * @param flag defines which part of the materials must be marked as dirty
  11751. * @param predicate defines a predicate used to filter which materials should be affected
  11752. */
  11753. Engine.MarkAllMaterialsAsDirty = function (flag, predicate) {
  11754. for (var engineIndex = 0; engineIndex < Engine.Instances.length; engineIndex++) {
  11755. var engine = Engine.Instances[engineIndex];
  11756. for (var sceneIndex = 0; sceneIndex < engine.scenes.length; sceneIndex++) {
  11757. engine.scenes[sceneIndex].markAllMaterialsAsDirty(flag, predicate);
  11758. }
  11759. }
  11760. };
  11761. Object.defineProperty(Engine, "NEVER", {
  11762. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */
  11763. get: function () {
  11764. return Engine._NEVER;
  11765. },
  11766. enumerable: true,
  11767. configurable: true
  11768. });
  11769. Object.defineProperty(Engine, "ALWAYS", {
  11770. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */
  11771. get: function () {
  11772. return Engine._ALWAYS;
  11773. },
  11774. enumerable: true,
  11775. configurable: true
  11776. });
  11777. Object.defineProperty(Engine, "LESS", {
  11778. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */
  11779. get: function () {
  11780. return Engine._LESS;
  11781. },
  11782. enumerable: true,
  11783. configurable: true
  11784. });
  11785. Object.defineProperty(Engine, "EQUAL", {
  11786. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */
  11787. get: function () {
  11788. return Engine._EQUAL;
  11789. },
  11790. enumerable: true,
  11791. configurable: true
  11792. });
  11793. Object.defineProperty(Engine, "LEQUAL", {
  11794. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */
  11795. get: function () {
  11796. return Engine._LEQUAL;
  11797. },
  11798. enumerable: true,
  11799. configurable: true
  11800. });
  11801. Object.defineProperty(Engine, "GREATER", {
  11802. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */
  11803. get: function () {
  11804. return Engine._GREATER;
  11805. },
  11806. enumerable: true,
  11807. configurable: true
  11808. });
  11809. Object.defineProperty(Engine, "GEQUAL", {
  11810. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */
  11811. get: function () {
  11812. return Engine._GEQUAL;
  11813. },
  11814. enumerable: true,
  11815. configurable: true
  11816. });
  11817. Object.defineProperty(Engine, "NOTEQUAL", {
  11818. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */
  11819. get: function () {
  11820. return Engine._NOTEQUAL;
  11821. },
  11822. enumerable: true,
  11823. configurable: true
  11824. });
  11825. Object.defineProperty(Engine, "KEEP", {
  11826. /** Passed to stencilOperation to specify that stencil value must be kept */
  11827. get: function () {
  11828. return Engine._KEEP;
  11829. },
  11830. enumerable: true,
  11831. configurable: true
  11832. });
  11833. Object.defineProperty(Engine, "REPLACE", {
  11834. /** Passed to stencilOperation to specify that stencil value must be replaced */
  11835. get: function () {
  11836. return Engine._REPLACE;
  11837. },
  11838. enumerable: true,
  11839. configurable: true
  11840. });
  11841. Object.defineProperty(Engine, "INCR", {
  11842. /** Passed to stencilOperation to specify that stencil value must be incremented */
  11843. get: function () {
  11844. return Engine._INCR;
  11845. },
  11846. enumerable: true,
  11847. configurable: true
  11848. });
  11849. Object.defineProperty(Engine, "DECR", {
  11850. /** Passed to stencilOperation to specify that stencil value must be decremented */
  11851. get: function () {
  11852. return Engine._DECR;
  11853. },
  11854. enumerable: true,
  11855. configurable: true
  11856. });
  11857. Object.defineProperty(Engine, "INVERT", {
  11858. /** Passed to stencilOperation to specify that stencil value must be inverted */
  11859. get: function () {
  11860. return Engine._INVERT;
  11861. },
  11862. enumerable: true,
  11863. configurable: true
  11864. });
  11865. Object.defineProperty(Engine, "INCR_WRAP", {
  11866. /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */
  11867. get: function () {
  11868. return Engine._INCR_WRAP;
  11869. },
  11870. enumerable: true,
  11871. configurable: true
  11872. });
  11873. Object.defineProperty(Engine, "DECR_WRAP", {
  11874. /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */
  11875. get: function () {
  11876. return Engine._DECR_WRAP;
  11877. },
  11878. enumerable: true,
  11879. configurable: true
  11880. });
  11881. Object.defineProperty(Engine, "ALPHA_DISABLE", {
  11882. // Alpha
  11883. /** Defines that alpha blending is disabled */
  11884. get: function () {
  11885. return Engine._ALPHA_DISABLE;
  11886. },
  11887. enumerable: true,
  11888. configurable: true
  11889. });
  11890. Object.defineProperty(Engine, "ALPHA_ONEONE", {
  11891. /** Defines that alpha blending to SRC + DEST */
  11892. get: function () {
  11893. return Engine._ALPHA_ONEONE;
  11894. },
  11895. enumerable: true,
  11896. configurable: true
  11897. });
  11898. Object.defineProperty(Engine, "ALPHA_ADD", {
  11899. /** Defines that alpha blending to SRC ALPHA * SRC + DEST */
  11900. get: function () {
  11901. return Engine._ALPHA_ADD;
  11902. },
  11903. enumerable: true,
  11904. configurable: true
  11905. });
  11906. Object.defineProperty(Engine, "ALPHA_COMBINE", {
  11907. /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */
  11908. get: function () {
  11909. return Engine._ALPHA_COMBINE;
  11910. },
  11911. enumerable: true,
  11912. configurable: true
  11913. });
  11914. Object.defineProperty(Engine, "ALPHA_SUBTRACT", {
  11915. /** Defines that alpha blending to DEST - SRC * DEST */
  11916. get: function () {
  11917. return Engine._ALPHA_SUBTRACT;
  11918. },
  11919. enumerable: true,
  11920. configurable: true
  11921. });
  11922. Object.defineProperty(Engine, "ALPHA_MULTIPLY", {
  11923. /** Defines that alpha blending to SRC * DEST */
  11924. get: function () {
  11925. return Engine._ALPHA_MULTIPLY;
  11926. },
  11927. enumerable: true,
  11928. configurable: true
  11929. });
  11930. Object.defineProperty(Engine, "ALPHA_MAXIMIZED", {
  11931. /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC) * DEST */
  11932. get: function () {
  11933. return Engine._ALPHA_MAXIMIZED;
  11934. },
  11935. enumerable: true,
  11936. configurable: true
  11937. });
  11938. Object.defineProperty(Engine, "ALPHA_PREMULTIPLIED", {
  11939. /** Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST */
  11940. get: function () {
  11941. return Engine._ALPHA_PREMULTIPLIED;
  11942. },
  11943. enumerable: true,
  11944. configurable: true
  11945. });
  11946. Object.defineProperty(Engine, "ALPHA_PREMULTIPLIED_PORTERDUFF", {
  11947. /**
  11948. * Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST
  11949. * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA
  11950. */
  11951. get: function () {
  11952. return Engine._ALPHA_PREMULTIPLIED_PORTERDUFF;
  11953. },
  11954. enumerable: true,
  11955. configurable: true
  11956. });
  11957. Object.defineProperty(Engine, "ALPHA_INTERPOLATE", {
  11958. /** Defines that alpha blending to CST * SRC + (1 - CST) * DEST */
  11959. get: function () {
  11960. return Engine._ALPHA_INTERPOLATE;
  11961. },
  11962. enumerable: true,
  11963. configurable: true
  11964. });
  11965. Object.defineProperty(Engine, "ALPHA_SCREENMODE", {
  11966. /**
  11967. * Defines that alpha blending to SRC + (1 - SRC) * DEST
  11968. * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA
  11969. */
  11970. get: function () {
  11971. return Engine._ALPHA_SCREENMODE;
  11972. },
  11973. enumerable: true,
  11974. configurable: true
  11975. });
  11976. Object.defineProperty(Engine, "DELAYLOADSTATE_NONE", {
  11977. // Delays
  11978. /** Defines that the ressource is not delayed*/
  11979. get: function () {
  11980. return Engine._DELAYLOADSTATE_NONE;
  11981. },
  11982. enumerable: true,
  11983. configurable: true
  11984. });
  11985. Object.defineProperty(Engine, "DELAYLOADSTATE_LOADED", {
  11986. /** Defines that the ressource was successfully delay loaded */
  11987. get: function () {
  11988. return Engine._DELAYLOADSTATE_LOADED;
  11989. },
  11990. enumerable: true,
  11991. configurable: true
  11992. });
  11993. Object.defineProperty(Engine, "DELAYLOADSTATE_LOADING", {
  11994. /** Defines that the ressource is currently delay loading */
  11995. get: function () {
  11996. return Engine._DELAYLOADSTATE_LOADING;
  11997. },
  11998. enumerable: true,
  11999. configurable: true
  12000. });
  12001. Object.defineProperty(Engine, "DELAYLOADSTATE_NOTLOADED", {
  12002. /** Defines that the ressource is delayed and has not started loading */
  12003. get: function () {
  12004. return Engine._DELAYLOADSTATE_NOTLOADED;
  12005. },
  12006. enumerable: true,
  12007. configurable: true
  12008. });
  12009. Object.defineProperty(Engine, "TEXTUREFORMAT_ALPHA", {
  12010. /** ALPHA */
  12011. get: function () {
  12012. return Engine._TEXTUREFORMAT_ALPHA;
  12013. },
  12014. enumerable: true,
  12015. configurable: true
  12016. });
  12017. Object.defineProperty(Engine, "TEXTUREFORMAT_LUMINANCE", {
  12018. /** LUMINANCE */
  12019. get: function () {
  12020. return Engine._TEXTUREFORMAT_LUMINANCE;
  12021. },
  12022. enumerable: true,
  12023. configurable: true
  12024. });
  12025. Object.defineProperty(Engine, "TEXTUREFORMAT_R", {
  12026. /**
  12027. * R
  12028. */
  12029. get: function () {
  12030. return Engine._TEXTUREFORMAT_R;
  12031. },
  12032. enumerable: true,
  12033. configurable: true
  12034. });
  12035. Object.defineProperty(Engine, "TEXTUREFORMAT_RG", {
  12036. /**
  12037. * RG
  12038. */
  12039. get: function () {
  12040. return Engine._TEXTUREFORMAT_RG;
  12041. },
  12042. enumerable: true,
  12043. configurable: true
  12044. });
  12045. Object.defineProperty(Engine, "TEXTUREFORMAT_LUMINANCE_ALPHA", {
  12046. /** LUMINANCE_ALPHA */
  12047. get: function () {
  12048. return Engine._TEXTUREFORMAT_LUMINANCE_ALPHA;
  12049. },
  12050. enumerable: true,
  12051. configurable: true
  12052. });
  12053. Object.defineProperty(Engine, "TEXTUREFORMAT_RGB", {
  12054. /** RGB */
  12055. get: function () {
  12056. return Engine._TEXTUREFORMAT_RGB;
  12057. },
  12058. enumerable: true,
  12059. configurable: true
  12060. });
  12061. Object.defineProperty(Engine, "TEXTUREFORMAT_RGBA", {
  12062. /** RGBA */
  12063. get: function () {
  12064. return Engine._TEXTUREFORMAT_RGBA;
  12065. },
  12066. enumerable: true,
  12067. configurable: true
  12068. });
  12069. Object.defineProperty(Engine, "TEXTURETYPE_UNSIGNED_INT", {
  12070. /** UNSIGNED_INT */
  12071. get: function () {
  12072. return Engine._TEXTURETYPE_UNSIGNED_INT;
  12073. },
  12074. enumerable: true,
  12075. configurable: true
  12076. });
  12077. Object.defineProperty(Engine, "TEXTURETYPE_FLOAT", {
  12078. /** FLOAT */
  12079. get: function () {
  12080. return Engine._TEXTURETYPE_FLOAT;
  12081. },
  12082. enumerable: true,
  12083. configurable: true
  12084. });
  12085. Object.defineProperty(Engine, "TEXTURETYPE_HALF_FLOAT", {
  12086. /** HALF_FLOAT */
  12087. get: function () {
  12088. return Engine._TEXTURETYPE_HALF_FLOAT;
  12089. },
  12090. enumerable: true,
  12091. configurable: true
  12092. });
  12093. Object.defineProperty(Engine, "SCALEMODE_FLOOR", {
  12094. /** Defines that texture rescaling will use a floor to find the closer power of 2 size */
  12095. get: function () {
  12096. return Engine._SCALEMODE_FLOOR;
  12097. },
  12098. enumerable: true,
  12099. configurable: true
  12100. });
  12101. Object.defineProperty(Engine, "SCALEMODE_NEAREST", {
  12102. /** Defines that texture rescaling will look for the nearest power of 2 size */
  12103. get: function () {
  12104. return Engine._SCALEMODE_NEAREST;
  12105. },
  12106. enumerable: true,
  12107. configurable: true
  12108. });
  12109. Object.defineProperty(Engine, "SCALEMODE_CEILING", {
  12110. /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */
  12111. get: function () {
  12112. return Engine._SCALEMODE_CEILING;
  12113. },
  12114. enumerable: true,
  12115. configurable: true
  12116. });
  12117. Object.defineProperty(Engine, "Version", {
  12118. /**
  12119. * Returns the current version of the framework
  12120. */
  12121. get: function () {
  12122. return "3.3.0-alpha.6";
  12123. },
  12124. enumerable: true,
  12125. configurable: true
  12126. });
  12127. Object.defineProperty(Engine.prototype, "isInVRExclusivePointerMode", {
  12128. /**
  12129. * Gets a boolean indicating that the engine is currently in VR exclusive mode for the pointers
  12130. * @see https://docs.microsoft.com/en-us/microsoft-edge/webvr/essentials#mouse-input
  12131. */
  12132. get: function () {
  12133. return this._vrExclusivePointerMode;
  12134. },
  12135. enumerable: true,
  12136. configurable: true
  12137. });
  12138. Object.defineProperty(Engine.prototype, "supportsUniformBuffers", {
  12139. /**
  12140. * Gets a boolean indicating that the engine supports uniform buffers
  12141. * @see http://doc.babylonjs.com/features/webgl2#uniform-buffer-objets
  12142. */
  12143. get: function () {
  12144. return this.webGLVersion > 1 && !this.disableUniformBuffers;
  12145. },
  12146. enumerable: true,
  12147. configurable: true
  12148. });
  12149. Object.defineProperty(Engine.prototype, "needPOTTextures", {
  12150. /**
  12151. * Gets a boolean indicating that only power of 2 textures are supported
  12152. * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them
  12153. */
  12154. get: function () {
  12155. return this._webGLVersion < 2 || this.forcePOTTextures;
  12156. },
  12157. enumerable: true,
  12158. configurable: true
  12159. });
  12160. Object.defineProperty(Engine.prototype, "doNotHandleContextLost", {
  12161. /**
  12162. * Gets or sets a boolean indicating if resources should be retained to be able to handle context lost events
  12163. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#handling-webgl-context-lost
  12164. */
  12165. get: function () {
  12166. return this._doNotHandleContextLost;
  12167. },
  12168. set: function (value) {
  12169. this._doNotHandleContextLost = value;
  12170. },
  12171. enumerable: true,
  12172. configurable: true
  12173. });
  12174. Object.defineProperty(Engine.prototype, "performanceMonitor", {
  12175. /**
  12176. * Gets the performance monitor attached to this engine
  12177. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#engineinstrumentation
  12178. */
  12179. get: function () {
  12180. return this._performanceMonitor;
  12181. },
  12182. enumerable: true,
  12183. configurable: true
  12184. });
  12185. Object.defineProperty(Engine.prototype, "texturesSupported", {
  12186. /**
  12187. * Gets the list of texture formats supported
  12188. */
  12189. get: function () {
  12190. return this._texturesSupported;
  12191. },
  12192. enumerable: true,
  12193. configurable: true
  12194. });
  12195. Object.defineProperty(Engine.prototype, "textureFormatInUse", {
  12196. /**
  12197. * Gets the list of texture formats in use
  12198. */
  12199. get: function () {
  12200. return this._textureFormatInUse;
  12201. },
  12202. enumerable: true,
  12203. configurable: true
  12204. });
  12205. Object.defineProperty(Engine.prototype, "currentViewport", {
  12206. /**
  12207. * Gets the current viewport
  12208. */
  12209. get: function () {
  12210. return this._cachedViewport;
  12211. },
  12212. enumerable: true,
  12213. configurable: true
  12214. });
  12215. Object.defineProperty(Engine.prototype, "emptyTexture", {
  12216. /**
  12217. * Gets the default empty texture
  12218. */
  12219. get: function () {
  12220. if (!this._emptyTexture) {
  12221. this._emptyTexture = this.createRawTexture(new Uint8Array(4), 1, 1, Engine.TEXTUREFORMAT_RGBA, false, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
  12222. }
  12223. return this._emptyTexture;
  12224. },
  12225. enumerable: true,
  12226. configurable: true
  12227. });
  12228. Object.defineProperty(Engine.prototype, "emptyTexture3D", {
  12229. /**
  12230. * Gets the default empty 3D texture
  12231. */
  12232. get: function () {
  12233. if (!this._emptyTexture3D) {
  12234. this._emptyTexture3D = this.createRawTexture3D(new Uint8Array(4), 1, 1, 1, Engine.TEXTUREFORMAT_RGBA, false, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
  12235. }
  12236. return this._emptyTexture3D;
  12237. },
  12238. enumerable: true,
  12239. configurable: true
  12240. });
  12241. Object.defineProperty(Engine.prototype, "emptyCubeTexture", {
  12242. /**
  12243. * Gets the default empty cube texture
  12244. */
  12245. get: function () {
  12246. if (!this._emptyCubeTexture) {
  12247. var faceData = new Uint8Array(4);
  12248. var cubeData = [faceData, faceData, faceData, faceData, faceData, faceData];
  12249. this._emptyCubeTexture = this.createRawCubeTexture(cubeData, 1, Engine.TEXTUREFORMAT_RGBA, Engine.TEXTURETYPE_UNSIGNED_INT, false, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);
  12250. }
  12251. return this._emptyCubeTexture;
  12252. },
  12253. enumerable: true,
  12254. configurable: true
  12255. });
  12256. Engine.prototype._rebuildInternalTextures = function () {
  12257. var currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies
  12258. for (var _i = 0, currentState_1 = currentState; _i < currentState_1.length; _i++) {
  12259. var internalTexture = currentState_1[_i];
  12260. internalTexture._rebuild();
  12261. }
  12262. };
  12263. Engine.prototype._rebuildEffects = function () {
  12264. for (var key in this._compiledEffects) {
  12265. var effect = this._compiledEffects[key];
  12266. effect._prepareEffect();
  12267. }
  12268. BABYLON.Effect.ResetCache();
  12269. };
  12270. Engine.prototype._rebuildBuffers = function () {
  12271. // Index / Vertex
  12272. for (var _i = 0, _a = this.scenes; _i < _a.length; _i++) {
  12273. var scene = _a[_i];
  12274. scene.resetCachedMaterial();
  12275. scene._rebuildGeometries();
  12276. scene._rebuildTextures();
  12277. }
  12278. // Uniforms
  12279. for (var _b = 0, _c = this._uniformBuffers; _b < _c.length; _b++) {
  12280. var uniformBuffer = _c[_b];
  12281. uniformBuffer._rebuild();
  12282. }
  12283. };
  12284. Engine.prototype._initGLContext = function () {
  12285. // Caps
  12286. this._caps = new EngineCapabilities();
  12287. this._caps.maxTexturesImageUnits = this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS);
  12288. this._caps.maxCombinedTexturesImageUnits = this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
  12289. this._caps.maxVertexTextureImageUnits = this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
  12290. this._caps.maxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
  12291. this._caps.maxCubemapTextureSize = this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE);
  12292. this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
  12293. this._caps.maxVertexAttribs = this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS);
  12294. this._caps.maxVaryingVectors = this._gl.getParameter(this._gl.MAX_VARYING_VECTORS);
  12295. this._caps.maxFragmentUniformVectors = this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS);
  12296. this._caps.maxVertexUniformVectors = this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS);
  12297. // Infos
  12298. this._glVersion = this._gl.getParameter(this._gl.VERSION);
  12299. var rendererInfo = this._gl.getExtension("WEBGL_debug_renderer_info");
  12300. if (rendererInfo != null) {
  12301. this._glRenderer = this._gl.getParameter(rendererInfo.UNMASKED_RENDERER_WEBGL);
  12302. this._glVendor = this._gl.getParameter(rendererInfo.UNMASKED_VENDOR_WEBGL);
  12303. }
  12304. if (!this._glVendor) {
  12305. this._glVendor = "Unknown vendor";
  12306. }
  12307. if (!this._glRenderer) {
  12308. this._glRenderer = "Unknown renderer";
  12309. }
  12310. // Constants
  12311. this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
  12312. if (this._gl.RGBA16F !== 0x881A) {
  12313. this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
  12314. }
  12315. if (this._gl.RGBA32F !== 0x8814) {
  12316. this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
  12317. }
  12318. if (this._gl.DEPTH24_STENCIL8 !== 35056) {
  12319. this._gl.DEPTH24_STENCIL8 = 35056;
  12320. }
  12321. // Extensions
  12322. this._caps.standardDerivatives = this._webGLVersion > 1 || (this._gl.getExtension('OES_standard_derivatives') !== null);
  12323. this._caps.astc = this._gl.getExtension('WEBGL_compressed_texture_astc') || this._gl.getExtension('WEBKIT_WEBGL_compressed_texture_astc');
  12324. this._caps.s3tc = this._gl.getExtension('WEBGL_compressed_texture_s3tc') || this._gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  12325. this._caps.pvrtc = this._gl.getExtension('WEBGL_compressed_texture_pvrtc') || this._gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  12326. this._caps.etc1 = this._gl.getExtension('WEBGL_compressed_texture_etc1') || this._gl.getExtension('WEBKIT_WEBGL_compressed_texture_etc1');
  12327. this._caps.etc2 = this._gl.getExtension('WEBGL_compressed_texture_etc') || this._gl.getExtension('WEBKIT_WEBGL_compressed_texture_etc') ||
  12328. this._gl.getExtension('WEBGL_compressed_texture_es3_0'); // also a requirement of OpenGL ES 3
  12329. this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
  12330. this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
  12331. this._caps.uintIndices = this._webGLVersion > 1 || this._gl.getExtension('OES_element_index_uint') !== null;
  12332. this._caps.fragmentDepthSupported = this._webGLVersion > 1 || this._gl.getExtension('EXT_frag_depth') !== null;
  12333. this._caps.highPrecisionShaderSupported = true;
  12334. this._caps.timerQuery = this._gl.getExtension('EXT_disjoint_timer_query_webgl2') || this._gl.getExtension("EXT_disjoint_timer_query");
  12335. if (this._caps.timerQuery) {
  12336. if (this._webGLVersion === 1) {
  12337. this._gl.getQuery = this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery);
  12338. }
  12339. this._caps.canUseTimestampForTimerQuery = this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT, this._caps.timerQuery.QUERY_COUNTER_BITS_EXT) > 0;
  12340. }
  12341. // Checks if some of the format renders first to allow the use of webgl inspector.
  12342. this._caps.colorBufferFloat = this._webGLVersion > 1 && this._gl.getExtension('EXT_color_buffer_float');
  12343. this._caps.textureFloat = (this._webGLVersion > 1 || this._gl.getExtension('OES_texture_float')) ? true : false;
  12344. this._caps.textureFloatLinearFiltering = this._caps.textureFloat && this._gl.getExtension('OES_texture_float_linear') ? true : false;
  12345. this._caps.textureFloatRender = this._caps.textureFloat && this._canRenderToFloatFramebuffer() ? true : false;
  12346. this._caps.textureHalfFloat = (this._webGLVersion > 1 || this._gl.getExtension('OES_texture_half_float')) ? true : false;
  12347. this._caps.textureHalfFloatLinearFiltering = (this._webGLVersion > 1 || (this._caps.textureHalfFloat && this._gl.getExtension('OES_texture_half_float_linear'))) ? true : false;
  12348. if (this._webGLVersion > 1) {
  12349. this._gl.HALF_FLOAT_OES = 0x140B;
  12350. }
  12351. this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer();
  12352. this._caps.textureLOD = (this._webGLVersion > 1 || this._gl.getExtension('EXT_shader_texture_lod')) ? true : false;
  12353. // Draw buffers
  12354. if (this._webGLVersion > 1) {
  12355. this._caps.drawBuffersExtension = true;
  12356. }
  12357. else {
  12358. var drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
  12359. if (drawBuffersExtension !== null) {
  12360. this._caps.drawBuffersExtension = true;
  12361. this._gl.drawBuffers = drawBuffersExtension.drawBuffersWEBGL.bind(drawBuffersExtension);
  12362. this._gl.DRAW_FRAMEBUFFER = this._gl.FRAMEBUFFER;
  12363. for (var i = 0; i < 16; i++) {
  12364. this._gl["COLOR_ATTACHMENT" + i + "_WEBGL"] = drawBuffersExtension["COLOR_ATTACHMENT" + i + "_WEBGL"];
  12365. }
  12366. }
  12367. else {
  12368. this._caps.drawBuffersExtension = false;
  12369. }
  12370. }
  12371. // Depth Texture
  12372. if (this._webGLVersion > 1) {
  12373. this._caps.depthTextureExtension = true;
  12374. }
  12375. else {
  12376. var depthTextureExtension = this._gl.getExtension('WEBGL_depth_texture');
  12377. if (depthTextureExtension != null) {
  12378. this._caps.depthTextureExtension = true;
  12379. this._gl.UNSIGNED_INT_24_8 = depthTextureExtension.UNSIGNED_INT_24_8_WEBGL;
  12380. }
  12381. }
  12382. // Vertex array object
  12383. if (this._webGLVersion > 1) {
  12384. this._caps.vertexArrayObject = true;
  12385. }
  12386. else {
  12387. var vertexArrayObjectExtension = this._gl.getExtension('OES_vertex_array_object');
  12388. if (vertexArrayObjectExtension != null) {
  12389. this._caps.vertexArrayObject = true;
  12390. this._gl.createVertexArray = vertexArrayObjectExtension.createVertexArrayOES.bind(vertexArrayObjectExtension);
  12391. this._gl.bindVertexArray = vertexArrayObjectExtension.bindVertexArrayOES.bind(vertexArrayObjectExtension);
  12392. this._gl.deleteVertexArray = vertexArrayObjectExtension.deleteVertexArrayOES.bind(vertexArrayObjectExtension);
  12393. }
  12394. else {
  12395. this._caps.vertexArrayObject = false;
  12396. }
  12397. }
  12398. // Instances count
  12399. if (this._webGLVersion > 1) {
  12400. this._caps.instancedArrays = true;
  12401. }
  12402. else {
  12403. var instanceExtension = this._gl.getExtension('ANGLE_instanced_arrays');
  12404. if (instanceExtension != null) {
  12405. this._caps.instancedArrays = true;
  12406. this._gl.drawArraysInstanced = instanceExtension.drawArraysInstancedANGLE.bind(instanceExtension);
  12407. this._gl.drawElementsInstanced = instanceExtension.drawElementsInstancedANGLE.bind(instanceExtension);
  12408. this._gl.vertexAttribDivisor = instanceExtension.vertexAttribDivisorANGLE.bind(instanceExtension);
  12409. }
  12410. else {
  12411. this._caps.instancedArrays = false;
  12412. }
  12413. }
  12414. // Intelligently add supported compressed formats in order to check for.
  12415. // Check for ASTC support first as it is most powerful and to be very cross platform.
  12416. // Next PVRTC & DXT, which are probably superior to ETC1/2.
  12417. // Likely no hardware which supports both PVR & DXT, so order matters little.
  12418. // ETC2 is newer and handles ETC1 (no alpha capability), so check for first.
  12419. if (this._caps.astc)
  12420. this.texturesSupported.push('-astc.ktx');
  12421. if (this._caps.s3tc)
  12422. this.texturesSupported.push('-dxt.ktx');
  12423. if (this._caps.pvrtc)
  12424. this.texturesSupported.push('-pvrtc.ktx');
  12425. if (this._caps.etc2)
  12426. this.texturesSupported.push('-etc2.ktx');
  12427. if (this._caps.etc1)
  12428. this.texturesSupported.push('-etc1.ktx');
  12429. if (this._gl.getShaderPrecisionFormat) {
  12430. var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
  12431. if (highp) {
  12432. this._caps.highPrecisionShaderSupported = highp.precision !== 0;
  12433. }
  12434. }
  12435. // Depth buffer
  12436. this.setDepthBuffer(true);
  12437. this.setDepthFunctionToLessOrEqual();
  12438. this.setDepthWrite(true);
  12439. // Texture maps
  12440. this._maxSimultaneousTextures = this._caps.maxCombinedTexturesImageUnits;
  12441. for (var slot = 0; slot < this._maxSimultaneousTextures; slot++) {
  12442. this._nextFreeTextureSlots.push(slot);
  12443. }
  12444. };
  12445. Object.defineProperty(Engine.prototype, "webGLVersion", {
  12446. /**
  12447. * Gets version of the current webGL context
  12448. */
  12449. get: function () {
  12450. return this._webGLVersion;
  12451. },
  12452. enumerable: true,
  12453. configurable: true
  12454. });
  12455. Object.defineProperty(Engine.prototype, "isStencilEnable", {
  12456. /**
  12457. * Returns true if the stencil buffer has been enabled through the creation option of the context.
  12458. */
  12459. get: function () {
  12460. return this._isStencilEnable;
  12461. },
  12462. enumerable: true,
  12463. configurable: true
  12464. });
  12465. Engine.prototype._prepareWorkingCanvas = function () {
  12466. if (this._workingCanvas) {
  12467. return;
  12468. }
  12469. this._workingCanvas = document.createElement("canvas");
  12470. var context = this._workingCanvas.getContext("2d");
  12471. if (context) {
  12472. this._workingContext = context;
  12473. }
  12474. };
  12475. /**
  12476. * Reset the texture cache to empty state
  12477. */
  12478. Engine.prototype.resetTextureCache = function () {
  12479. for (var key in this._boundTexturesCache) {
  12480. if (!this._boundTexturesCache.hasOwnProperty(key)) {
  12481. continue;
  12482. }
  12483. var boundTexture = this._boundTexturesCache[key];
  12484. if (boundTexture) {
  12485. this._removeDesignatedSlot(boundTexture);
  12486. }
  12487. this._boundTexturesCache[key] = null;
  12488. }
  12489. if (!this.disableTextureBindingOptimization) {
  12490. this._nextFreeTextureSlots = [];
  12491. for (var slot = 0; slot < this._maxSimultaneousTextures; slot++) {
  12492. this._nextFreeTextureSlots.push(slot);
  12493. }
  12494. }
  12495. this._currentTextureChannel = -1;
  12496. };
  12497. /**
  12498. * Gets a boolean indicating that the engine is running in deterministic lock step mode
  12499. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  12500. * @returns true if engine is in deterministic lock step mode
  12501. */
  12502. Engine.prototype.isDeterministicLockStep = function () {
  12503. return this._deterministicLockstep;
  12504. };
  12505. /**
  12506. * Gets the max steps when engine is running in deterministic lock step
  12507. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  12508. * @returns the max steps
  12509. */
  12510. Engine.prototype.getLockstepMaxSteps = function () {
  12511. return this._lockstepMaxSteps;
  12512. };
  12513. /**
  12514. * Gets an object containing information about the current webGL context
  12515. * @returns an object containing the vender, the renderer and the version of the current webGL context
  12516. */
  12517. Engine.prototype.getGlInfo = function () {
  12518. return {
  12519. vendor: this._glVendor,
  12520. renderer: this._glRenderer,
  12521. version: this._glVersion
  12522. };
  12523. };
  12524. /**
  12525. * Gets current aspect ratio
  12526. * @param camera defines the camera to use to get the aspect ratio
  12527. * @param useScreen defines if screen size must be used (or the current render target if any)
  12528. * @returns a number defining the aspect ratio
  12529. */
  12530. Engine.prototype.getAspectRatio = function (camera, useScreen) {
  12531. if (useScreen === void 0) { useScreen = false; }
  12532. var viewport = camera.viewport;
  12533. return (this.getRenderWidth(useScreen) * viewport.width) / (this.getRenderHeight(useScreen) * viewport.height);
  12534. };
  12535. /**
  12536. * Gets current screen aspect ratio
  12537. * @returns a number defining the aspect ratio
  12538. */
  12539. Engine.prototype.getScreenAspectRatio = function () {
  12540. return (this.getRenderWidth(true)) / (this.getRenderHeight(true));
  12541. };
  12542. /**
  12543. * Gets the current render width
  12544. * @param useScreen defines if screen size must be used (or the current render target if any)
  12545. * @returns a number defining the current render width
  12546. */
  12547. Engine.prototype.getRenderWidth = function (useScreen) {
  12548. if (useScreen === void 0) { useScreen = false; }
  12549. if (!useScreen && this._currentRenderTarget) {
  12550. return this._currentRenderTarget.width;
  12551. }
  12552. return this._gl.drawingBufferWidth;
  12553. };
  12554. /**
  12555. * Gets the current render height
  12556. * @param useScreen defines if screen size must be used (or the current render target if any)
  12557. * @returns a number defining the current render height
  12558. */
  12559. Engine.prototype.getRenderHeight = function (useScreen) {
  12560. if (useScreen === void 0) { useScreen = false; }
  12561. if (!useScreen && this._currentRenderTarget) {
  12562. return this._currentRenderTarget.height;
  12563. }
  12564. return this._gl.drawingBufferHeight;
  12565. };
  12566. /**
  12567. * Gets the HTML canvas attached with the current webGL context
  12568. * @returns a HTML canvas
  12569. */
  12570. Engine.prototype.getRenderingCanvas = function () {
  12571. return this._renderingCanvas;
  12572. };
  12573. /**
  12574. * Gets the client rect of the HTML canvas attached with the current webGL context
  12575. * @returns a client rectanglee
  12576. */
  12577. Engine.prototype.getRenderingCanvasClientRect = function () {
  12578. if (!this._renderingCanvas) {
  12579. return null;
  12580. }
  12581. return this._renderingCanvas.getBoundingClientRect();
  12582. };
  12583. /**
  12584. * Defines the hardware scaling level.
  12585. * By default the hardware scaling level is computed from the window device ratio.
  12586. * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.
  12587. * @param level defines the level to use
  12588. */
  12589. Engine.prototype.setHardwareScalingLevel = function (level) {
  12590. this._hardwareScalingLevel = level;
  12591. this.resize();
  12592. };
  12593. /**
  12594. * Gets the current hardware scaling level.
  12595. * By default the hardware scaling level is computed from the window device ratio.
  12596. * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.
  12597. * @returns a number indicating the current hardware scaling level
  12598. */
  12599. Engine.prototype.getHardwareScalingLevel = function () {
  12600. return this._hardwareScalingLevel;
  12601. };
  12602. /**
  12603. * Gets the list of loaded textures
  12604. * @returns an array containing all loaded textures
  12605. */
  12606. Engine.prototype.getLoadedTexturesCache = function () {
  12607. return this._internalTexturesCache;
  12608. };
  12609. /**
  12610. * Gets the object containing all engine capabilities
  12611. * @returns the EngineCapabilities object
  12612. */
  12613. Engine.prototype.getCaps = function () {
  12614. return this._caps;
  12615. };
  12616. Object.defineProperty(Engine.prototype, "drawCalls", {
  12617. /** @hidden */
  12618. get: function () {
  12619. BABYLON.Tools.Warn("drawCalls is deprecated. Please use SceneInstrumentation class");
  12620. return 0;
  12621. },
  12622. enumerable: true,
  12623. configurable: true
  12624. });
  12625. Object.defineProperty(Engine.prototype, "drawCallsPerfCounter", {
  12626. /** @hidden */
  12627. get: function () {
  12628. BABYLON.Tools.Warn("drawCallsPerfCounter is deprecated. Please use SceneInstrumentation class");
  12629. return null;
  12630. },
  12631. enumerable: true,
  12632. configurable: true
  12633. });
  12634. /**
  12635. * Gets the current depth function
  12636. * @returns a number defining the depth function
  12637. */
  12638. Engine.prototype.getDepthFunction = function () {
  12639. return this._depthCullingState.depthFunc;
  12640. };
  12641. /**
  12642. * Sets the current depth function
  12643. * @param depthFunc defines the function to use
  12644. */
  12645. Engine.prototype.setDepthFunction = function (depthFunc) {
  12646. this._depthCullingState.depthFunc = depthFunc;
  12647. };
  12648. /**
  12649. * Sets the current depth function to GREATER
  12650. */
  12651. Engine.prototype.setDepthFunctionToGreater = function () {
  12652. this._depthCullingState.depthFunc = this._gl.GREATER;
  12653. };
  12654. /**
  12655. * Sets the current depth function to GEQUAL
  12656. */
  12657. Engine.prototype.setDepthFunctionToGreaterOrEqual = function () {
  12658. this._depthCullingState.depthFunc = this._gl.GEQUAL;
  12659. };
  12660. /**
  12661. * Sets the current depth function to LESS
  12662. */
  12663. Engine.prototype.setDepthFunctionToLess = function () {
  12664. this._depthCullingState.depthFunc = this._gl.LESS;
  12665. };
  12666. /**
  12667. * Sets the current depth function to LEQUAL
  12668. */
  12669. Engine.prototype.setDepthFunctionToLessOrEqual = function () {
  12670. this._depthCullingState.depthFunc = this._gl.LEQUAL;
  12671. };
  12672. /**
  12673. * Gets a boolean indicating if stencil buffer is enabled
  12674. * @returns the current stencil buffer state
  12675. */
  12676. Engine.prototype.getStencilBuffer = function () {
  12677. return this._stencilState.stencilTest;
  12678. };
  12679. /**
  12680. * Enable or disable the stencil buffer
  12681. * @param enable defines if the stencil buffer must be enabled or disabled
  12682. */
  12683. Engine.prototype.setStencilBuffer = function (enable) {
  12684. this._stencilState.stencilTest = enable;
  12685. };
  12686. /**
  12687. * Gets the current stencil mask
  12688. * @returns a number defining the new stencil mask to use
  12689. */
  12690. Engine.prototype.getStencilMask = function () {
  12691. return this._stencilState.stencilMask;
  12692. };
  12693. /**
  12694. * Sets the current stencil mask
  12695. * @param mask defines the new stencil mask to use
  12696. */
  12697. Engine.prototype.setStencilMask = function (mask) {
  12698. this._stencilState.stencilMask = mask;
  12699. };
  12700. /**
  12701. * Gets the current stencil function
  12702. * @returns a number defining the stencil function to use
  12703. */
  12704. Engine.prototype.getStencilFunction = function () {
  12705. return this._stencilState.stencilFunc;
  12706. };
  12707. /**
  12708. * Gets the current stencil reference value
  12709. * @returns a number defining the stencil reference value to use
  12710. */
  12711. Engine.prototype.getStencilFunctionReference = function () {
  12712. return this._stencilState.stencilFuncRef;
  12713. };
  12714. /**
  12715. * Gets the current stencil mask
  12716. * @returns a number defining the stencil mask to use
  12717. */
  12718. Engine.prototype.getStencilFunctionMask = function () {
  12719. return this._stencilState.stencilFuncMask;
  12720. };
  12721. /**
  12722. * Sets the current stencil function
  12723. * @param stencilFunc defines the new stencil function to use
  12724. */
  12725. Engine.prototype.setStencilFunction = function (stencilFunc) {
  12726. this._stencilState.stencilFunc = stencilFunc;
  12727. };
  12728. /**
  12729. * Sets the current stencil reference
  12730. * @param reference defines the new stencil reference to use
  12731. */
  12732. Engine.prototype.setStencilFunctionReference = function (reference) {
  12733. this._stencilState.stencilFuncRef = reference;
  12734. };
  12735. /**
  12736. * Sets the current stencil mask
  12737. * @param mask defines the new stencil mask to use
  12738. */
  12739. Engine.prototype.setStencilFunctionMask = function (mask) {
  12740. this._stencilState.stencilFuncMask = mask;
  12741. };
  12742. /**
  12743. * Gets the current stencil operation when stencil fails
  12744. * @returns a number defining stencil operation to use when stencil fails
  12745. */
  12746. Engine.prototype.getStencilOperationFail = function () {
  12747. return this._stencilState.stencilOpStencilFail;
  12748. };
  12749. /**
  12750. * Gets the current stencil operation when depth fails
  12751. * @returns a number defining stencil operation to use when depth fails
  12752. */
  12753. Engine.prototype.getStencilOperationDepthFail = function () {
  12754. return this._stencilState.stencilOpDepthFail;
  12755. };
  12756. /**
  12757. * Gets the current stencil operation when stencil passes
  12758. * @returns a number defining stencil operation to use when stencil passes
  12759. */
  12760. Engine.prototype.getStencilOperationPass = function () {
  12761. return this._stencilState.stencilOpStencilDepthPass;
  12762. };
  12763. /**
  12764. * Sets the stencil operation to use when stencil fails
  12765. * @param operation defines the stencil operation to use when stencil fails
  12766. */
  12767. Engine.prototype.setStencilOperationFail = function (operation) {
  12768. this._stencilState.stencilOpStencilFail = operation;
  12769. };
  12770. /**
  12771. * Sets the stencil operation to use when depth fails
  12772. * @param operation defines the stencil operation to use when depth fails
  12773. */
  12774. Engine.prototype.setStencilOperationDepthFail = function (operation) {
  12775. this._stencilState.stencilOpDepthFail = operation;
  12776. };
  12777. /**
  12778. * Sets the stencil operation to use when stencil passes
  12779. * @param operation defines the stencil operation to use when stencil passes
  12780. */
  12781. Engine.prototype.setStencilOperationPass = function (operation) {
  12782. this._stencilState.stencilOpStencilDepthPass = operation;
  12783. };
  12784. /**
  12785. * Sets a boolean indicating if the dithering state is enabled or disabled
  12786. * @param value defines the dithering state
  12787. */
  12788. Engine.prototype.setDitheringState = function (value) {
  12789. if (value) {
  12790. this._gl.enable(this._gl.DITHER);
  12791. }
  12792. else {
  12793. this._gl.disable(this._gl.DITHER);
  12794. }
  12795. };
  12796. /**
  12797. * Sets a boolean indicating if the rasterizer state is enabled or disabled
  12798. * @param value defines the rasterizer state
  12799. */
  12800. Engine.prototype.setRasterizerState = function (value) {
  12801. if (value) {
  12802. this._gl.disable(this._gl.RASTERIZER_DISCARD);
  12803. }
  12804. else {
  12805. this._gl.enable(this._gl.RASTERIZER_DISCARD);
  12806. }
  12807. };
  12808. /**
  12809. * stop executing a render loop function and remove it from the execution array
  12810. * @param renderFunction defines the function to be removed. If not provided all functions will be removed.
  12811. */
  12812. Engine.prototype.stopRenderLoop = function (renderFunction) {
  12813. if (!renderFunction) {
  12814. this._activeRenderLoops = [];
  12815. return;
  12816. }
  12817. var index = this._activeRenderLoops.indexOf(renderFunction);
  12818. if (index >= 0) {
  12819. this._activeRenderLoops.splice(index, 1);
  12820. }
  12821. };
  12822. /** @hidden */
  12823. Engine.prototype._renderLoop = function () {
  12824. if (!this._contextWasLost) {
  12825. var shouldRender = true;
  12826. if (!this.renderEvenInBackground && this._windowIsBackground) {
  12827. shouldRender = false;
  12828. }
  12829. if (shouldRender) {
  12830. // Start new frame
  12831. this.beginFrame();
  12832. for (var index = 0; index < this._activeRenderLoops.length; index++) {
  12833. var renderFunction = this._activeRenderLoops[index];
  12834. renderFunction();
  12835. }
  12836. // Present
  12837. this.endFrame();
  12838. }
  12839. }
  12840. if (this._activeRenderLoops.length > 0) {
  12841. // Register new frame
  12842. var requester = null;
  12843. if (this._vrDisplay && this._vrDisplay.isPresenting)
  12844. requester = this._vrDisplay;
  12845. this._frameHandler = BABYLON.Tools.QueueNewFrame(this._bindedRenderFunction, requester);
  12846. }
  12847. else {
  12848. this._renderingQueueLaunched = false;
  12849. }
  12850. };
  12851. /**
  12852. * Register and execute a render loop. The engine can have more than one render function
  12853. * @param renderFunction defines the function to continuously execute
  12854. */
  12855. Engine.prototype.runRenderLoop = function (renderFunction) {
  12856. if (this._activeRenderLoops.indexOf(renderFunction) !== -1) {
  12857. return;
  12858. }
  12859. this._activeRenderLoops.push(renderFunction);
  12860. if (!this._renderingQueueLaunched) {
  12861. this._renderingQueueLaunched = true;
  12862. this._bindedRenderFunction = this._renderLoop.bind(this);
  12863. this._frameHandler = BABYLON.Tools.QueueNewFrame(this._bindedRenderFunction);
  12864. }
  12865. };
  12866. /**
  12867. * Toggle full screen mode
  12868. * @param requestPointerLock defines if a pointer lock should be requested from the user
  12869. * @param options defines an option object to be sent to the requestFullscreen function
  12870. */
  12871. Engine.prototype.switchFullscreen = function (requestPointerLock) {
  12872. if (this.isFullscreen) {
  12873. BABYLON.Tools.ExitFullscreen();
  12874. }
  12875. else {
  12876. this._pointerLockRequested = requestPointerLock;
  12877. if (this._renderingCanvas) {
  12878. BABYLON.Tools.RequestFullscreen(this._renderingCanvas);
  12879. }
  12880. }
  12881. };
  12882. /**
  12883. * Clear the current render buffer or the current render target (if any is set up)
  12884. * @param color defines the color to use
  12885. * @param backBuffer defines if the back buffer must be cleared
  12886. * @param depth defines if the depth buffer must be cleared
  12887. * @param stencil defines if the stencil buffer must be cleared
  12888. */
  12889. Engine.prototype.clear = function (color, backBuffer, depth, stencil) {
  12890. if (stencil === void 0) { stencil = false; }
  12891. this.applyStates();
  12892. var mode = 0;
  12893. if (backBuffer && color) {
  12894. this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
  12895. mode |= this._gl.COLOR_BUFFER_BIT;
  12896. }
  12897. if (depth) {
  12898. this._gl.clearDepth(1.0);
  12899. mode |= this._gl.DEPTH_BUFFER_BIT;
  12900. }
  12901. if (stencil) {
  12902. this._gl.clearStencil(0);
  12903. mode |= this._gl.STENCIL_BUFFER_BIT;
  12904. }
  12905. this._gl.clear(mode);
  12906. };
  12907. /**
  12908. * Executes a scissor clear (ie. a clear on a specific portion of the screen)
  12909. * @param x defines the x-coordinate of the top left corner of the clear rectangle
  12910. * @param y defines the y-coordinate of the corner of the clear rectangle
  12911. * @param width defines the width of the clear rectangle
  12912. * @param height defines the height of the clear rectangle
  12913. * @param clearColor defines the clear color
  12914. */
  12915. Engine.prototype.scissorClear = function (x, y, width, height, clearColor) {
  12916. var gl = this._gl;
  12917. // Save state
  12918. var curScissor = gl.getParameter(gl.SCISSOR_TEST);
  12919. var curScissorBox = gl.getParameter(gl.SCISSOR_BOX);
  12920. // Change state
  12921. gl.enable(gl.SCISSOR_TEST);
  12922. gl.scissor(x, y, width, height);
  12923. // Clear
  12924. this.clear(clearColor, true, true, true);
  12925. // Restore state
  12926. gl.scissor(curScissorBox[0], curScissorBox[1], curScissorBox[2], curScissorBox[3]);
  12927. if (curScissor === true) {
  12928. gl.enable(gl.SCISSOR_TEST);
  12929. }
  12930. else {
  12931. gl.disable(gl.SCISSOR_TEST);
  12932. }
  12933. };
  12934. /**
  12935. * Set the WebGL's viewport
  12936. * @param viewport defines the viewport element to be used
  12937. * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used
  12938. * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used
  12939. */
  12940. Engine.prototype.setViewport = function (viewport, requiredWidth, requiredHeight) {
  12941. var width = requiredWidth || this.getRenderWidth();
  12942. var height = requiredHeight || this.getRenderHeight();
  12943. var x = viewport.x || 0;
  12944. var y = viewport.y || 0;
  12945. this._cachedViewport = viewport;
  12946. this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
  12947. };
  12948. /**
  12949. * Directly set the WebGL Viewport
  12950. * @param x defines the x coordinate of the viewport (in screen space)
  12951. * @param y defines the y coordinate of the viewport (in screen space)
  12952. * @param width defines the width of the viewport (in screen space)
  12953. * @param height defines the height of the viewport (in screen space)
  12954. * @return the current viewport Object (if any) that is being replaced by this call. You can restore this viewport later on to go back to the original state
  12955. */
  12956. Engine.prototype.setDirectViewport = function (x, y, width, height) {
  12957. var currentViewport = this._cachedViewport;
  12958. this._cachedViewport = null;
  12959. this._gl.viewport(x, y, width, height);
  12960. return currentViewport;
  12961. };
  12962. /**
  12963. * Begin a new frame
  12964. */
  12965. Engine.prototype.beginFrame = function () {
  12966. this.onBeginFrameObservable.notifyObservers(this);
  12967. this._measureFps();
  12968. };
  12969. /**
  12970. * Enf the current frame
  12971. */
  12972. Engine.prototype.endFrame = function () {
  12973. // Force a flush in case we are using a bad OS.
  12974. if (this._badOS) {
  12975. this.flushFramebuffer();
  12976. }
  12977. // Submit frame to the vr device, if enabled
  12978. if (this._vrDisplay && this._vrDisplay.isPresenting) {
  12979. // TODO: We should only submit the frame if we read frameData successfully.
  12980. this._vrDisplay.submitFrame();
  12981. }
  12982. this.onEndFrameObservable.notifyObservers(this);
  12983. };
  12984. /**
  12985. * Resize the view according to the canvas' size
  12986. */
  12987. Engine.prototype.resize = function () {
  12988. // We're not resizing the size of the canvas while in VR mode & presenting
  12989. if (!(this._vrDisplay && this._vrDisplay.isPresenting)) {
  12990. var width = this._renderingCanvas ? this._renderingCanvas.clientWidth : window.innerWidth;
  12991. var height = this._renderingCanvas ? this._renderingCanvas.clientHeight : window.innerHeight;
  12992. this.setSize(width / this._hardwareScalingLevel, height / this._hardwareScalingLevel);
  12993. }
  12994. };
  12995. /**
  12996. * Force a specific size of the canvas
  12997. * @param width defines the new canvas' width
  12998. * @param height defines the new canvas' height
  12999. */
  13000. Engine.prototype.setSize = function (width, height) {
  13001. if (!this._renderingCanvas) {
  13002. return;
  13003. }
  13004. if (this._renderingCanvas.width === width && this._renderingCanvas.height === height) {
  13005. return;
  13006. }
  13007. this._renderingCanvas.width = width;
  13008. this._renderingCanvas.height = height;
  13009. for (var index = 0; index < this.scenes.length; index++) {
  13010. var scene = this.scenes[index];
  13011. for (var camIndex = 0; camIndex < scene.cameras.length; camIndex++) {
  13012. var cam = scene.cameras[camIndex];
  13013. cam._currentRenderId = 0;
  13014. }
  13015. }
  13016. if (this.onResizeObservable.hasObservers) {
  13017. this.onResizeObservable.notifyObservers(this);
  13018. }
  13019. };
  13020. // WebVR functions
  13021. /**
  13022. * Gets a boolean indicating if a webVR device was detected
  13023. * @returns true if a webVR device was detected
  13024. */
  13025. Engine.prototype.isVRDevicePresent = function () {
  13026. return !!this._vrDisplay;
  13027. };
  13028. /**
  13029. * Gets the current webVR device
  13030. * @returns the current webVR device (or null)
  13031. */
  13032. Engine.prototype.getVRDevice = function () {
  13033. return this._vrDisplay;
  13034. };
  13035. /**
  13036. * Initializes a webVR display and starts listening to display change events
  13037. * The onVRDisplayChangedObservable will be notified upon these changes
  13038. * @returns The onVRDisplayChangedObservable
  13039. */
  13040. Engine.prototype.initWebVR = function () {
  13041. this.initWebVRAsync();
  13042. return this.onVRDisplayChangedObservable;
  13043. };
  13044. /**
  13045. * Initializes a webVR display and starts listening to display change events
  13046. * The onVRDisplayChangedObservable will be notified upon these changes
  13047. * @returns A promise containing a VRDisplay and if vr is supported
  13048. */
  13049. Engine.prototype.initWebVRAsync = function () {
  13050. var _this = this;
  13051. var notifyObservers = function () {
  13052. var eventArgs = {
  13053. vrDisplay: _this._vrDisplay,
  13054. vrSupported: _this._vrSupported
  13055. };
  13056. _this.onVRDisplayChangedObservable.notifyObservers(eventArgs);
  13057. _this._webVRInitPromise = new Promise(function (res) { res(eventArgs); });
  13058. };
  13059. if (!this._onVrDisplayConnect) {
  13060. this._onVrDisplayConnect = function (event) {
  13061. _this._vrDisplay = event.display;
  13062. notifyObservers();
  13063. };
  13064. this._onVrDisplayDisconnect = function () {
  13065. _this._vrDisplay.cancelAnimationFrame(_this._frameHandler);
  13066. _this._vrDisplay = undefined;
  13067. _this._frameHandler = BABYLON.Tools.QueueNewFrame(_this._bindedRenderFunction);
  13068. notifyObservers();
  13069. };
  13070. this._onVrDisplayPresentChange = function () {
  13071. _this._vrExclusivePointerMode = _this._vrDisplay && _this._vrDisplay.isPresenting;
  13072. };
  13073. window.addEventListener('vrdisplayconnect', this._onVrDisplayConnect);
  13074. window.addEventListener('vrdisplaydisconnect', this._onVrDisplayDisconnect);
  13075. window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
  13076. }
  13077. this._webVRInitPromise = this._webVRInitPromise || this._getVRDisplaysAsync();
  13078. this._webVRInitPromise.then(notifyObservers);
  13079. return this._webVRInitPromise;
  13080. };
  13081. /**
  13082. * Call this function to switch to webVR mode
  13083. * Will do nothing if webVR is not supported or if there is no webVR device
  13084. * @see http://doc.babylonjs.com/how_to/webvr_camera
  13085. */
  13086. Engine.prototype.enableVR = function () {
  13087. var _this = this;
  13088. if (this._vrDisplay && !this._vrDisplay.isPresenting) {
  13089. var onResolved = function () {
  13090. _this.onVRRequestPresentComplete.notifyObservers(true);
  13091. _this._onVRFullScreenTriggered();
  13092. };
  13093. var onRejected = function () {
  13094. _this.onVRRequestPresentComplete.notifyObservers(false);
  13095. };
  13096. this.onVRRequestPresentStart.notifyObservers(this);
  13097. this._vrDisplay.requestPresent([{ source: this.getRenderingCanvas() }]).then(onResolved).catch(onRejected);
  13098. }
  13099. };
  13100. /**
  13101. * Call this function to leave webVR mode
  13102. * Will do nothing if webVR is not supported or if there is no webVR device
  13103. * @see http://doc.babylonjs.com/how_to/webvr_camera
  13104. */
  13105. Engine.prototype.disableVR = function () {
  13106. if (this._vrDisplay && this._vrDisplay.isPresenting) {
  13107. this._vrDisplay.exitPresent().then(this._onVRFullScreenTriggered).catch(this._onVRFullScreenTriggered);
  13108. }
  13109. };
  13110. Engine.prototype._getVRDisplaysAsync = function () {
  13111. var _this = this;
  13112. return new Promise(function (res, rej) {
  13113. if (navigator.getVRDisplays) {
  13114. navigator.getVRDisplays().then(function (devices) {
  13115. _this._vrSupported = true;
  13116. // note that devices may actually be an empty array. This is fine;
  13117. // we expect this._vrDisplay to be undefined in this case.
  13118. _this._vrDisplay = devices[0];
  13119. res({
  13120. vrDisplay: _this._vrDisplay,
  13121. vrSupported: _this._vrSupported
  13122. });
  13123. });
  13124. }
  13125. else {
  13126. _this._vrDisplay = undefined;
  13127. _this._vrSupported = false;
  13128. res({
  13129. vrDisplay: _this._vrDisplay,
  13130. vrSupported: _this._vrSupported
  13131. });
  13132. }
  13133. });
  13134. };
  13135. /**
  13136. * Binds the frame buffer to the specified texture.
  13137. * @param texture The texture to render to or null for the default canvas
  13138. * @param faceIndex The face of the texture to render to in case of cube texture
  13139. * @param requiredWidth The width of the target to render to
  13140. * @param requiredHeight The height of the target to render to
  13141. * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
  13142. * @param depthStencilTexture The depth stencil texture to use to render
  13143. * @param lodLevel defines le lod level to bind to the frame buffer
  13144. */
  13145. Engine.prototype.bindFramebuffer = function (texture, faceIndex, requiredWidth, requiredHeight, forceFullscreenViewport, depthStencilTexture, lodLevel) {
  13146. if (lodLevel === void 0) { lodLevel = 0; }
  13147. if (this._currentRenderTarget) {
  13148. this.unBindFramebuffer(this._currentRenderTarget);
  13149. }
  13150. this._currentRenderTarget = texture;
  13151. this.bindUnboundFramebuffer(texture._MSAAFramebuffer ? texture._MSAAFramebuffer : texture._framebuffer);
  13152. var gl = this._gl;
  13153. if (texture.isCube) {
  13154. if (faceIndex === undefined) {
  13155. faceIndex = 0;
  13156. }
  13157. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, texture._webGLTexture, lodLevel);
  13158. if (depthStencilTexture) {
  13159. if (depthStencilTexture._generateStencilBuffer) {
  13160. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, depthStencilTexture._webGLTexture, lodLevel);
  13161. }
  13162. else {
  13163. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, depthStencilTexture._webGLTexture, lodLevel);
  13164. }
  13165. }
  13166. }
  13167. if (this._cachedViewport && !forceFullscreenViewport) {
  13168. this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
  13169. }
  13170. else {
  13171. if (!requiredWidth) {
  13172. requiredWidth = texture.width;
  13173. if (lodLevel) {
  13174. requiredWidth = requiredWidth / Math.pow(2, lodLevel);
  13175. }
  13176. }
  13177. if (!requiredHeight) {
  13178. requiredHeight = texture.height;
  13179. if (lodLevel) {
  13180. requiredHeight = requiredHeight / Math.pow(2, lodLevel);
  13181. }
  13182. }
  13183. gl.viewport(0, 0, requiredWidth, requiredHeight);
  13184. }
  13185. this.wipeCaches();
  13186. };
  13187. Engine.prototype.bindUnboundFramebuffer = function (framebuffer) {
  13188. if (this._currentFramebuffer !== framebuffer) {
  13189. this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, framebuffer);
  13190. this._currentFramebuffer = framebuffer;
  13191. }
  13192. };
  13193. /**
  13194. * Unbind the current render target texture from the webGL context
  13195. * @param texture defines the render target texture to unbind
  13196. * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
  13197. * @param onBeforeUnbind defines a function which will be called before the effective unbind
  13198. */
  13199. Engine.prototype.unBindFramebuffer = function (texture, disableGenerateMipMaps, onBeforeUnbind) {
  13200. if (disableGenerateMipMaps === void 0) { disableGenerateMipMaps = false; }
  13201. this._currentRenderTarget = null;
  13202. // If MSAA, we need to bitblt back to main texture
  13203. var gl = this._gl;
  13204. if (texture._MSAAFramebuffer) {
  13205. gl.bindFramebuffer(gl.READ_FRAMEBUFFER, texture._MSAAFramebuffer);
  13206. gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, texture._framebuffer);
  13207. gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
  13208. }
  13209. if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {
  13210. this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
  13211. gl.generateMipmap(gl.TEXTURE_2D);
  13212. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  13213. }
  13214. if (onBeforeUnbind) {
  13215. if (texture._MSAAFramebuffer) {
  13216. // Bind the correct framebuffer
  13217. this.bindUnboundFramebuffer(texture._framebuffer);
  13218. }
  13219. onBeforeUnbind();
  13220. }
  13221. this.bindUnboundFramebuffer(null);
  13222. };
  13223. /**
  13224. * Unbind a list of render target textures from the webGL context
  13225. * This is used only when drawBuffer extension or webGL2 are active
  13226. * @param textures defines the render target textures to unbind
  13227. * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
  13228. * @param onBeforeUnbind defines a function which will be called before the effective unbind
  13229. */
  13230. Engine.prototype.unBindMultiColorAttachmentFramebuffer = function (textures, disableGenerateMipMaps, onBeforeUnbind) {
  13231. if (disableGenerateMipMaps === void 0) { disableGenerateMipMaps = false; }
  13232. this._currentRenderTarget = null;
  13233. // If MSAA, we need to bitblt back to main texture
  13234. var gl = this._gl;
  13235. if (textures[0]._MSAAFramebuffer) {
  13236. gl.bindFramebuffer(gl.READ_FRAMEBUFFER, textures[0]._MSAAFramebuffer);
  13237. gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, textures[0]._framebuffer);
  13238. var attachments = textures[0]._attachments;
  13239. if (!attachments) {
  13240. attachments = new Array(textures.length);
  13241. textures[0]._attachments = attachments;
  13242. }
  13243. for (var i = 0; i < textures.length; i++) {
  13244. var texture = textures[i];
  13245. for (var j = 0; j < attachments.length; j++) {
  13246. attachments[j] = gl.NONE;
  13247. }
  13248. attachments[i] = gl[this.webGLVersion > 1 ? "COLOR_ATTACHMENT" + i : "COLOR_ATTACHMENT" + i + "_WEBGL"];
  13249. gl.readBuffer(attachments[i]);
  13250. gl.drawBuffers(attachments);
  13251. gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
  13252. }
  13253. for (var i = 0; i < attachments.length; i++) {
  13254. attachments[i] = gl[this.webGLVersion > 1 ? "COLOR_ATTACHMENT" + i : "COLOR_ATTACHMENT" + i + "_WEBGL"];
  13255. }
  13256. gl.drawBuffers(attachments);
  13257. }
  13258. for (var i = 0; i < textures.length; i++) {
  13259. var texture = textures[i];
  13260. if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {
  13261. this._bindTextureDirectly(gl.TEXTURE_2D, texture);
  13262. gl.generateMipmap(gl.TEXTURE_2D);
  13263. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  13264. }
  13265. }
  13266. if (onBeforeUnbind) {
  13267. if (textures[0]._MSAAFramebuffer) {
  13268. // Bind the correct framebuffer
  13269. this.bindUnboundFramebuffer(textures[0]._framebuffer);
  13270. }
  13271. onBeforeUnbind();
  13272. }
  13273. this.bindUnboundFramebuffer(null);
  13274. };
  13275. /**
  13276. * Force the mipmap generation for the given render target texture
  13277. * @param texture defines the render target texture to use
  13278. */
  13279. Engine.prototype.generateMipMapsForCubemap = function (texture) {
  13280. if (texture.generateMipMaps) {
  13281. var gl = this._gl;
  13282. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  13283. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  13284. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  13285. }
  13286. };
  13287. /**
  13288. * Force a webGL flush (ie. a flush of all waiting webGL commands)
  13289. */
  13290. Engine.prototype.flushFramebuffer = function () {
  13291. this._gl.flush();
  13292. };
  13293. /**
  13294. * Unbind the current render target and bind the default framebuffer
  13295. */
  13296. Engine.prototype.restoreDefaultFramebuffer = function () {
  13297. if (this._currentRenderTarget) {
  13298. this.unBindFramebuffer(this._currentRenderTarget);
  13299. }
  13300. else {
  13301. this.bindUnboundFramebuffer(null);
  13302. }
  13303. if (this._cachedViewport) {
  13304. this.setViewport(this._cachedViewport);
  13305. }
  13306. this.wipeCaches();
  13307. };
  13308. // UBOs
  13309. /**
  13310. * Create an uniform buffer
  13311. * @see http://doc.babylonjs.com/features/webgl2#uniform-buffer-objets
  13312. * @param elements defines the content of the uniform buffer
  13313. * @returns the webGL uniform buffer
  13314. */
  13315. Engine.prototype.createUniformBuffer = function (elements) {
  13316. var ubo = this._gl.createBuffer();
  13317. if (!ubo) {
  13318. throw new Error("Unable to create uniform buffer");
  13319. }
  13320. this.bindUniformBuffer(ubo);
  13321. if (elements instanceof Float32Array) {
  13322. this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.STATIC_DRAW);
  13323. }
  13324. else {
  13325. this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.STATIC_DRAW);
  13326. }
  13327. this.bindUniformBuffer(null);
  13328. ubo.references = 1;
  13329. return ubo;
  13330. };
  13331. /**
  13332. * Create a dynamic uniform buffer
  13333. * @see http://doc.babylonjs.com/features/webgl2#uniform-buffer-objets
  13334. * @param elements defines the content of the uniform buffer
  13335. * @returns the webGL uniform buffer
  13336. */
  13337. Engine.prototype.createDynamicUniformBuffer = function (elements) {
  13338. var ubo = this._gl.createBuffer();
  13339. if (!ubo) {
  13340. throw new Error("Unable to create dynamic uniform buffer");
  13341. }
  13342. this.bindUniformBuffer(ubo);
  13343. if (elements instanceof Float32Array) {
  13344. this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.DYNAMIC_DRAW);
  13345. }
  13346. else {
  13347. this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.DYNAMIC_DRAW);
  13348. }
  13349. this.bindUniformBuffer(null);
  13350. ubo.references = 1;
  13351. return ubo;
  13352. };
  13353. /**
  13354. * Update an existing uniform buffer
  13355. * @see http://doc.babylonjs.com/features/webgl2#uniform-buffer-objets
  13356. * @param uniformBuffer defines the target uniform buffer
  13357. * @param elements defines the content to update
  13358. * @param offset defines the offset in the uniform buffer where update should start
  13359. * @param count defines the size of the data to update
  13360. */
  13361. Engine.prototype.updateUniformBuffer = function (uniformBuffer, elements, offset, count) {
  13362. this.bindUniformBuffer(uniformBuffer);
  13363. if (offset === undefined) {
  13364. offset = 0;
  13365. }
  13366. if (count === undefined) {
  13367. if (elements instanceof Float32Array) {
  13368. this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, elements);
  13369. }
  13370. else {
  13371. this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, new Float32Array(elements));
  13372. }
  13373. }
  13374. else {
  13375. if (elements instanceof Float32Array) {
  13376. this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, elements.subarray(offset, offset + count));
  13377. }
  13378. else {
  13379. this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, new Float32Array(elements).subarray(offset, offset + count));
  13380. }
  13381. }
  13382. this.bindUniformBuffer(null);
  13383. };
  13384. // VBOs
  13385. Engine.prototype._resetVertexBufferBinding = function () {
  13386. this.bindArrayBuffer(null);
  13387. this._cachedVertexBuffers = null;
  13388. };
  13389. /**
  13390. * Creates a vertex buffer
  13391. * @param data the data for the vertex buffer
  13392. * @returns the new WebGL static buffer
  13393. */
  13394. Engine.prototype.createVertexBuffer = function (data) {
  13395. var vbo = this._gl.createBuffer();
  13396. if (!vbo) {
  13397. throw new Error("Unable to create vertex buffer");
  13398. }
  13399. this.bindArrayBuffer(vbo);
  13400. if (data instanceof Array) {
  13401. this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), this._gl.STATIC_DRAW);
  13402. }
  13403. else {
  13404. this._gl.bufferData(this._gl.ARRAY_BUFFER, data, this._gl.STATIC_DRAW);
  13405. }
  13406. this._resetVertexBufferBinding();
  13407. vbo.references = 1;
  13408. return vbo;
  13409. };
  13410. /**
  13411. * Creates a dynamic vertex buffer
  13412. * @param data the data for the dynamic vertex buffer
  13413. * @returns the new WebGL dynamic buffer
  13414. */
  13415. Engine.prototype.createDynamicVertexBuffer = function (data) {
  13416. var vbo = this._gl.createBuffer();
  13417. if (!vbo) {
  13418. throw new Error("Unable to create dynamic vertex buffer");
  13419. }
  13420. this.bindArrayBuffer(vbo);
  13421. if (data instanceof Array) {
  13422. this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), this._gl.DYNAMIC_DRAW);
  13423. }
  13424. else {
  13425. this._gl.bufferData(this._gl.ARRAY_BUFFER, data, this._gl.DYNAMIC_DRAW);
  13426. }
  13427. this._resetVertexBufferBinding();
  13428. vbo.references = 1;
  13429. return vbo;
  13430. };
  13431. /**
  13432. * Update a dynamic index buffer
  13433. * @param indexBuffer defines the target index buffer
  13434. * @param indices defines the data to update
  13435. * @param offset defines the offset in the target index buffer where update should start
  13436. */
  13437. Engine.prototype.updateDynamicIndexBuffer = function (indexBuffer, indices, offset) {
  13438. if (offset === void 0) { offset = 0; }
  13439. // Force cache update
  13440. this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER] = null;
  13441. this.bindIndexBuffer(indexBuffer);
  13442. var arrayBuffer;
  13443. if (indices instanceof Uint16Array || indices instanceof Uint32Array) {
  13444. arrayBuffer = indices;
  13445. }
  13446. else {
  13447. arrayBuffer = indexBuffer.is32Bits ? new Uint32Array(indices) : new Uint16Array(indices);
  13448. }
  13449. this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.DYNAMIC_DRAW);
  13450. this._resetIndexBufferBinding();
  13451. };
  13452. /**
  13453. * Updates a dynamic vertex buffer.
  13454. * @param vertexBuffer the vertex buffer to update
  13455. * @param data the data used to update the vertex buffer
  13456. * @param byteOffset the byte offset of the data
  13457. * @param byteLength the byte length of the data
  13458. */
  13459. Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, data, byteOffset, byteLength) {
  13460. this.bindArrayBuffer(vertexBuffer);
  13461. if (byteOffset === undefined) {
  13462. byteOffset = 0;
  13463. }
  13464. if (byteLength === undefined) {
  13465. if (data instanceof Array) {
  13466. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, new Float32Array(data));
  13467. }
  13468. else {
  13469. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, data);
  13470. }
  13471. }
  13472. else {
  13473. if (data instanceof Array) {
  13474. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(data).subarray(byteOffset, byteOffset + byteLength));
  13475. }
  13476. else {
  13477. if (data instanceof ArrayBuffer) {
  13478. data = new Uint8Array(data, byteOffset, byteLength);
  13479. }
  13480. else {
  13481. data = new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  13482. }
  13483. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
  13484. }
  13485. }
  13486. this._resetVertexBufferBinding();
  13487. };
  13488. Engine.prototype._resetIndexBufferBinding = function () {
  13489. this.bindIndexBuffer(null);
  13490. this._cachedIndexBuffer = null;
  13491. };
  13492. /**
  13493. * Creates a new index buffer
  13494. * @param indices defines the content of the index buffer
  13495. * @param updatable defines if the index buffer must be updatable
  13496. * @returns a new webGL buffer
  13497. */
  13498. Engine.prototype.createIndexBuffer = function (indices, updatable) {
  13499. var vbo = this._gl.createBuffer();
  13500. if (!vbo) {
  13501. throw new Error("Unable to create index buffer");
  13502. }
  13503. this.bindIndexBuffer(vbo);
  13504. // Check for 32 bits indices
  13505. var arrayBuffer;
  13506. var need32Bits = false;
  13507. if (indices instanceof Uint16Array) {
  13508. arrayBuffer = indices;
  13509. }
  13510. else {
  13511. //check 32 bit support
  13512. if (this._caps.uintIndices) {
  13513. if (indices instanceof Uint32Array) {
  13514. arrayBuffer = indices;
  13515. need32Bits = true;
  13516. }
  13517. else {
  13518. //number[] or Int32Array, check if 32 bit is necessary
  13519. for (var index = 0; index < indices.length; index++) {
  13520. if (indices[index] > 65535) {
  13521. need32Bits = true;
  13522. break;
  13523. }
  13524. }
  13525. arrayBuffer = need32Bits ? new Uint32Array(indices) : new Uint16Array(indices);
  13526. }
  13527. }
  13528. else {
  13529. //no 32 bit support, force conversion to 16 bit (values greater 16 bit are lost)
  13530. arrayBuffer = new Uint16Array(indices);
  13531. }
  13532. }
  13533. this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, updatable ? this._gl.DYNAMIC_DRAW : this._gl.STATIC_DRAW);
  13534. this._resetIndexBufferBinding();
  13535. vbo.references = 1;
  13536. vbo.is32Bits = need32Bits;
  13537. return vbo;
  13538. };
  13539. /**
  13540. * Bind a webGL buffer to the webGL context
  13541. * @param buffer defines the buffer to bind
  13542. */
  13543. Engine.prototype.bindArrayBuffer = function (buffer) {
  13544. if (!this._vaoRecordInProgress) {
  13545. this._unbindVertexArrayObject();
  13546. }
  13547. this.bindBuffer(buffer, this._gl.ARRAY_BUFFER);
  13548. };
  13549. /**
  13550. * Bind an uniform buffer to the current webGL context
  13551. * @param buffer defines the buffer to bind
  13552. */
  13553. Engine.prototype.bindUniformBuffer = function (buffer) {
  13554. this._gl.bindBuffer(this._gl.UNIFORM_BUFFER, buffer);
  13555. };
  13556. /**
  13557. * Bind a buffer to the current webGL context at a given location
  13558. * @param buffer defines the buffer to bind
  13559. * @param location defines the index where to bind the buffer
  13560. */
  13561. Engine.prototype.bindUniformBufferBase = function (buffer, location) {
  13562. this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER, location, buffer);
  13563. };
  13564. /**
  13565. * Bind a specific block at a given index in a specific shader program
  13566. * @param shaderProgram defines the shader program
  13567. * @param blockName defines the block name
  13568. * @param index defines the index where to bind the block
  13569. */
  13570. Engine.prototype.bindUniformBlock = function (shaderProgram, blockName, index) {
  13571. var uniformLocation = this._gl.getUniformBlockIndex(shaderProgram, blockName);
  13572. this._gl.uniformBlockBinding(shaderProgram, uniformLocation, index);
  13573. };
  13574. ;
  13575. Engine.prototype.bindIndexBuffer = function (buffer) {
  13576. if (!this._vaoRecordInProgress) {
  13577. this._unbindVertexArrayObject();
  13578. }
  13579. this.bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
  13580. };
  13581. Engine.prototype.bindBuffer = function (buffer, target) {
  13582. if (this._vaoRecordInProgress || this._currentBoundBuffer[target] !== buffer) {
  13583. this._gl.bindBuffer(target, buffer);
  13584. this._currentBoundBuffer[target] = buffer;
  13585. }
  13586. };
  13587. /**
  13588. * update the bound buffer with the given data
  13589. * @param data defines the data to update
  13590. */
  13591. Engine.prototype.updateArrayBuffer = function (data) {
  13592. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
  13593. };
  13594. Engine.prototype._vertexAttribPointer = function (buffer, indx, size, type, normalized, stride, offset) {
  13595. var pointer = this._currentBufferPointers[indx];
  13596. var changed = false;
  13597. if (!pointer.active) {
  13598. changed = true;
  13599. pointer.active = true;
  13600. pointer.index = indx;
  13601. pointer.size = size;
  13602. pointer.type = type;
  13603. pointer.normalized = normalized;
  13604. pointer.stride = stride;
  13605. pointer.offset = offset;
  13606. pointer.buffer = buffer;
  13607. }
  13608. else {
  13609. if (pointer.buffer !== buffer) {
  13610. pointer.buffer = buffer;
  13611. changed = true;
  13612. }
  13613. if (pointer.size !== size) {
  13614. pointer.size = size;
  13615. changed = true;
  13616. }
  13617. if (pointer.type !== type) {
  13618. pointer.type = type;
  13619. changed = true;
  13620. }
  13621. if (pointer.normalized !== normalized) {
  13622. pointer.normalized = normalized;
  13623. changed = true;
  13624. }
  13625. if (pointer.stride !== stride) {
  13626. pointer.stride = stride;
  13627. changed = true;
  13628. }
  13629. if (pointer.offset !== offset) {
  13630. pointer.offset = offset;
  13631. changed = true;
  13632. }
  13633. }
  13634. if (changed || this._vaoRecordInProgress) {
  13635. this.bindArrayBuffer(buffer);
  13636. this._gl.vertexAttribPointer(indx, size, type, normalized, stride, offset);
  13637. }
  13638. };
  13639. Engine.prototype._bindIndexBufferWithCache = function (indexBuffer) {
  13640. if (indexBuffer == null) {
  13641. return;
  13642. }
  13643. if (this._cachedIndexBuffer !== indexBuffer) {
  13644. this._cachedIndexBuffer = indexBuffer;
  13645. this.bindIndexBuffer(indexBuffer);
  13646. this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
  13647. }
  13648. };
  13649. Engine.prototype._bindVertexBuffersAttributes = function (vertexBuffers, effect) {
  13650. var attributes = effect.getAttributesNames();
  13651. if (!this._vaoRecordInProgress) {
  13652. this._unbindVertexArrayObject();
  13653. }
  13654. this.unbindAllAttributes();
  13655. for (var index = 0; index < attributes.length; index++) {
  13656. var order = effect.getAttributeLocation(index);
  13657. if (order >= 0) {
  13658. var vertexBuffer = vertexBuffers[attributes[index]];
  13659. if (!vertexBuffer) {
  13660. continue;
  13661. }
  13662. this._gl.enableVertexAttribArray(order);
  13663. if (!this._vaoRecordInProgress) {
  13664. this._vertexAttribArraysEnabled[order] = true;
  13665. }
  13666. var buffer = vertexBuffer.getBuffer();
  13667. if (buffer) {
  13668. this._vertexAttribPointer(buffer, order, vertexBuffer.getSize(), vertexBuffer.type, vertexBuffer.normalized, vertexBuffer.byteStride, vertexBuffer.byteOffset);
  13669. if (vertexBuffer.getIsInstanced()) {
  13670. this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());
  13671. if (!this._vaoRecordInProgress) {
  13672. this._currentInstanceLocations.push(order);
  13673. this._currentInstanceBuffers.push(buffer);
  13674. }
  13675. }
  13676. }
  13677. }
  13678. }
  13679. };
  13680. /**
  13681. * Records a vertex array object
  13682. * @see http://doc.babylonjs.com/features/webgl2#vertex-array-objects
  13683. * @param vertexBuffers defines the list of vertex buffers to store
  13684. * @param indexBuffer defines the index buffer to store
  13685. * @param effect defines the effect to store
  13686. * @returns the new vertex array object
  13687. */
  13688. Engine.prototype.recordVertexArrayObject = function (vertexBuffers, indexBuffer, effect) {
  13689. var vao = this._gl.createVertexArray();
  13690. this._vaoRecordInProgress = true;
  13691. this._gl.bindVertexArray(vao);
  13692. this._mustWipeVertexAttributes = true;
  13693. this._bindVertexBuffersAttributes(vertexBuffers, effect);
  13694. this.bindIndexBuffer(indexBuffer);
  13695. this._vaoRecordInProgress = false;
  13696. this._gl.bindVertexArray(null);
  13697. return vao;
  13698. };
  13699. /**
  13700. * Bind a specific vertex array object
  13701. * @see http://doc.babylonjs.com/features/webgl2#vertex-array-objects
  13702. * @param vertexArrayObject defines the vertex array object to bind
  13703. * @param indexBuffer defines the index buffer to bind
  13704. */
  13705. Engine.prototype.bindVertexArrayObject = function (vertexArrayObject, indexBuffer) {
  13706. if (this._cachedVertexArrayObject !== vertexArrayObject) {
  13707. this._cachedVertexArrayObject = vertexArrayObject;
  13708. this._gl.bindVertexArray(vertexArrayObject);
  13709. this._cachedVertexBuffers = null;
  13710. this._cachedIndexBuffer = null;
  13711. this._uintIndicesCurrentlySet = indexBuffer != null && indexBuffer.is32Bits;
  13712. this._mustWipeVertexAttributes = true;
  13713. }
  13714. };
  13715. /**
  13716. * Bind webGl buffers directly to the webGL context
  13717. * @param vertexBuffer defines the vertex buffer to bind
  13718. * @param indexBuffer defines the index buffer to bind
  13719. * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
  13720. * @param vertexStrideSize defines the vertex stride of the vertex buffer
  13721. * @param effect defines the effect associated with the vertex buffer
  13722. */
  13723. Engine.prototype.bindBuffersDirectly = function (vertexBuffer, indexBuffer, vertexDeclaration, vertexStrideSize, effect) {
  13724. if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
  13725. this._cachedVertexBuffers = vertexBuffer;
  13726. this._cachedEffectForVertexBuffers = effect;
  13727. var attributesCount = effect.getAttributesCount();
  13728. this._unbindVertexArrayObject();
  13729. this.unbindAllAttributes();
  13730. var offset = 0;
  13731. for (var index = 0; index < attributesCount; index++) {
  13732. if (index < vertexDeclaration.length) {
  13733. var order = effect.getAttributeLocation(index);
  13734. if (order >= 0) {
  13735. this._gl.enableVertexAttribArray(order);
  13736. this._vertexAttribArraysEnabled[order] = true;
  13737. this._vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
  13738. }
  13739. offset += vertexDeclaration[index] * 4;
  13740. }
  13741. }
  13742. }
  13743. this._bindIndexBufferWithCache(indexBuffer);
  13744. };
  13745. Engine.prototype._unbindVertexArrayObject = function () {
  13746. if (!this._cachedVertexArrayObject) {
  13747. return;
  13748. }
  13749. this._cachedVertexArrayObject = null;
  13750. this._gl.bindVertexArray(null);
  13751. };
  13752. /**
  13753. * Bind a list of vertex buffers to the webGL context
  13754. * @param vertexBuffers defines the list of vertex buffers to bind
  13755. * @param indexBuffer defines the index buffer to bind
  13756. * @param effect defines the effect associated with the vertex buffers
  13757. */
  13758. Engine.prototype.bindBuffers = function (vertexBuffers, indexBuffer, effect) {
  13759. if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
  13760. this._cachedVertexBuffers = vertexBuffers;
  13761. this._cachedEffectForVertexBuffers = effect;
  13762. this._bindVertexBuffersAttributes(vertexBuffers, effect);
  13763. }
  13764. this._bindIndexBufferWithCache(indexBuffer);
  13765. };
  13766. /**
  13767. * Unbind all instance attributes
  13768. */
  13769. Engine.prototype.unbindInstanceAttributes = function () {
  13770. var boundBuffer;
  13771. for (var i = 0, ul = this._currentInstanceLocations.length; i < ul; i++) {
  13772. var instancesBuffer = this._currentInstanceBuffers[i];
  13773. if (boundBuffer != instancesBuffer && instancesBuffer.references) {
  13774. boundBuffer = instancesBuffer;
  13775. this.bindArrayBuffer(instancesBuffer);
  13776. }
  13777. var offsetLocation = this._currentInstanceLocations[i];
  13778. this._gl.vertexAttribDivisor(offsetLocation, 0);
  13779. }
  13780. this._currentInstanceBuffers.length = 0;
  13781. this._currentInstanceLocations.length = 0;
  13782. };
  13783. /**
  13784. * Release and free the memory of a vertex array object
  13785. * @param vao defines the vertex array object to delete
  13786. */
  13787. Engine.prototype.releaseVertexArrayObject = function (vao) {
  13788. this._gl.deleteVertexArray(vao);
  13789. };
  13790. /** @hidden */
  13791. Engine.prototype._releaseBuffer = function (buffer) {
  13792. buffer.references--;
  13793. if (buffer.references === 0) {
  13794. this._gl.deleteBuffer(buffer);
  13795. return true;
  13796. }
  13797. return false;
  13798. };
  13799. /**
  13800. * Creates a webGL buffer to use with instanciation
  13801. * @param capacity defines the size of the buffer
  13802. * @returns the webGL buffer
  13803. */
  13804. Engine.prototype.createInstancesBuffer = function (capacity) {
  13805. var buffer = this._gl.createBuffer();
  13806. if (!buffer) {
  13807. throw new Error("Unable to create instance buffer");
  13808. }
  13809. buffer.capacity = capacity;
  13810. this.bindArrayBuffer(buffer);
  13811. this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);
  13812. return buffer;
  13813. };
  13814. /**
  13815. * Delete a webGL buffer used with instanciation
  13816. * @param buffer defines the webGL buffer to delete
  13817. */
  13818. Engine.prototype.deleteInstancesBuffer = function (buffer) {
  13819. this._gl.deleteBuffer(buffer);
  13820. };
  13821. /**
  13822. * Update the content of a webGL buffer used with instanciation and bind it to the webGL context
  13823. * @param instancesBuffer defines the webGL buffer to update and bind
  13824. * @param data defines the data to store in the buffer
  13825. * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer
  13826. */
  13827. Engine.prototype.updateAndBindInstancesBuffer = function (instancesBuffer, data, offsetLocations) {
  13828. this.bindArrayBuffer(instancesBuffer);
  13829. if (data) {
  13830. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
  13831. }
  13832. if (offsetLocations[0].index !== undefined) {
  13833. var stride = 0;
  13834. for (var i = 0; i < offsetLocations.length; i++) {
  13835. var ai = offsetLocations[i];
  13836. stride += ai.attributeSize * 4;
  13837. }
  13838. for (var i = 0; i < offsetLocations.length; i++) {
  13839. var ai = offsetLocations[i];
  13840. if (!this._vertexAttribArraysEnabled[ai.index]) {
  13841. this._gl.enableVertexAttribArray(ai.index);
  13842. this._vertexAttribArraysEnabled[ai.index] = true;
  13843. }
  13844. this._vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attribyteType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);
  13845. this._gl.vertexAttribDivisor(ai.index, 1);
  13846. this._currentInstanceLocations.push(ai.index);
  13847. this._currentInstanceBuffers.push(instancesBuffer);
  13848. }
  13849. }
  13850. else {
  13851. for (var index = 0; index < 4; index++) {
  13852. var offsetLocation = offsetLocations[index];
  13853. if (!this._vertexAttribArraysEnabled[offsetLocation]) {
  13854. this._gl.enableVertexAttribArray(offsetLocation);
  13855. this._vertexAttribArraysEnabled[offsetLocation] = true;
  13856. }
  13857. this._vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
  13858. this._gl.vertexAttribDivisor(offsetLocation, 1);
  13859. this._currentInstanceLocations.push(offsetLocation);
  13860. this._currentInstanceBuffers.push(instancesBuffer);
  13861. }
  13862. }
  13863. };
  13864. /**
  13865. * Apply all cached states (depth, culling, stencil and alpha)
  13866. */
  13867. Engine.prototype.applyStates = function () {
  13868. this._depthCullingState.apply(this._gl);
  13869. this._stencilState.apply(this._gl);
  13870. this._alphaState.apply(this._gl);
  13871. };
  13872. /**
  13873. * Send a draw order
  13874. * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
  13875. * @param indexStart defines the starting index
  13876. * @param indexCount defines the number of index to draw
  13877. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  13878. */
  13879. Engine.prototype.draw = function (useTriangles, indexStart, indexCount, instancesCount) {
  13880. this.drawElementsType(useTriangles ? BABYLON.Material.TriangleFillMode : BABYLON.Material.WireFrameFillMode, indexStart, indexCount, instancesCount);
  13881. };
  13882. /**
  13883. * Draw a list of points
  13884. * @param verticesStart defines the index of first vertex to draw
  13885. * @param verticesCount defines the count of vertices to draw
  13886. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  13887. */
  13888. Engine.prototype.drawPointClouds = function (verticesStart, verticesCount, instancesCount) {
  13889. this.drawArraysType(BABYLON.Material.PointFillMode, verticesStart, verticesCount, instancesCount);
  13890. };
  13891. /**
  13892. * Draw a list of unindexed primitives
  13893. * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
  13894. * @param verticesStart defines the index of first vertex to draw
  13895. * @param verticesCount defines the count of vertices to draw
  13896. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  13897. */
  13898. Engine.prototype.drawUnIndexed = function (useTriangles, verticesStart, verticesCount, instancesCount) {
  13899. this.drawArraysType(useTriangles ? BABYLON.Material.TriangleFillMode : BABYLON.Material.WireFrameFillMode, verticesStart, verticesCount, instancesCount);
  13900. };
  13901. /**
  13902. * Draw a list of indexed primitives
  13903. * @param fillMode defines the primitive to use
  13904. * @param indexStart defines the starting index
  13905. * @param indexCount defines the number of index to draw
  13906. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  13907. */
  13908. Engine.prototype.drawElementsType = function (fillMode, indexStart, indexCount, instancesCount) {
  13909. // Apply states
  13910. this.applyStates();
  13911. this._drawCalls.addCount(1, false);
  13912. // Render
  13913. var drawMode = this._drawMode(fillMode);
  13914. var indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;
  13915. var mult = this._uintIndicesCurrentlySet ? 4 : 2;
  13916. if (instancesCount) {
  13917. this._gl.drawElementsInstanced(drawMode, indexCount, indexFormat, indexStart * mult, instancesCount);
  13918. }
  13919. else {
  13920. this._gl.drawElements(drawMode, indexCount, indexFormat, indexStart * mult);
  13921. }
  13922. };
  13923. /**
  13924. * Draw a list of unindexed primitives
  13925. * @param fillMode defines the primitive to use
  13926. * @param verticesStart defines the index of first vertex to draw
  13927. * @param verticesCount defines the count of vertices to draw
  13928. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  13929. */
  13930. Engine.prototype.drawArraysType = function (fillMode, verticesStart, verticesCount, instancesCount) {
  13931. // Apply states
  13932. this.applyStates();
  13933. this._drawCalls.addCount(1, false);
  13934. var drawMode = this._drawMode(fillMode);
  13935. if (instancesCount) {
  13936. this._gl.drawArraysInstanced(drawMode, verticesStart, verticesCount, instancesCount);
  13937. }
  13938. else {
  13939. this._gl.drawArrays(drawMode, verticesStart, verticesCount);
  13940. }
  13941. };
  13942. Engine.prototype._drawMode = function (fillMode) {
  13943. switch (fillMode) {
  13944. // Triangle views
  13945. case BABYLON.Material.TriangleFillMode:
  13946. return this._gl.TRIANGLES;
  13947. case BABYLON.Material.PointFillMode:
  13948. return this._gl.POINTS;
  13949. case BABYLON.Material.WireFrameFillMode:
  13950. return this._gl.LINES;
  13951. // Draw modes
  13952. case BABYLON.Material.PointListDrawMode:
  13953. return this._gl.POINTS;
  13954. case BABYLON.Material.LineListDrawMode:
  13955. return this._gl.LINES;
  13956. case BABYLON.Material.LineLoopDrawMode:
  13957. return this._gl.LINE_LOOP;
  13958. case BABYLON.Material.LineStripDrawMode:
  13959. return this._gl.LINE_STRIP;
  13960. case BABYLON.Material.TriangleStripDrawMode:
  13961. return this._gl.TRIANGLE_STRIP;
  13962. case BABYLON.Material.TriangleFanDrawMode:
  13963. return this._gl.TRIANGLE_FAN;
  13964. default:
  13965. return this._gl.TRIANGLES;
  13966. }
  13967. };
  13968. // Shaders
  13969. /** @hidden */
  13970. Engine.prototype._releaseEffect = function (effect) {
  13971. if (this._compiledEffects[effect._key]) {
  13972. delete this._compiledEffects[effect._key];
  13973. this._deleteProgram(effect.getProgram());
  13974. }
  13975. };
  13976. /** @hidden */
  13977. Engine.prototype._deleteProgram = function (program) {
  13978. if (program) {
  13979. program.__SPECTOR_rebuildProgram = null;
  13980. if (program.transformFeedback) {
  13981. this.deleteTransformFeedback(program.transformFeedback);
  13982. program.transformFeedback = null;
  13983. }
  13984. this._gl.deleteProgram(program);
  13985. }
  13986. };
  13987. /**
  13988. * Create a new effect (used to store vertex/fragment shaders)
  13989. * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)
  13990. * @param attributesNamesOrOptions defines either a list of attribute names or an EffectCreationOptions object
  13991. * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use
  13992. * @param samplers defines an array of string used to represent textures
  13993. * @param defines defines the string containing the defines to use to compile the shaders
  13994. * @param fallbacks defines the list of potential fallbacks to use if shader conmpilation fails
  13995. * @param onCompiled defines a function to call when the effect creation is successful
  13996. * @param onError defines a function to call when the effect creation has failed
  13997. * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)
  13998. * @returns the new Effect
  13999. */
  14000. Engine.prototype.createEffect = function (baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, defines, fallbacks, onCompiled, onError, indexParameters) {
  14001. var vertex = baseName.vertexElement || baseName.vertex || baseName;
  14002. var fragment = baseName.fragmentElement || baseName.fragment || baseName;
  14003. var name = vertex + "+" + fragment + "@" + (defines ? defines : attributesNamesOrOptions.defines);
  14004. if (this._compiledEffects[name]) {
  14005. var compiledEffect = this._compiledEffects[name];
  14006. if (onCompiled && compiledEffect.isReady()) {
  14007. onCompiled(compiledEffect);
  14008. }
  14009. return compiledEffect;
  14010. }
  14011. var effect = new BABYLON.Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, this, defines, fallbacks, onCompiled, onError, indexParameters);
  14012. effect._key = name;
  14013. this._compiledEffects[name] = effect;
  14014. return effect;
  14015. };
  14016. /**
  14017. * Create an effect to use with particle systems
  14018. * @param fragmentName defines the base name of the effect (The name of file without .fragment.fx)
  14019. * @param uniformsNames defines a list of attribute names
  14020. * @param samplers defines an array of string used to represent textures
  14021. * @param defines defines the string containing the defines to use to compile the shaders
  14022. * @param fallbacks defines the list of potential fallbacks to use if shader conmpilation fails
  14023. * @param onCompiled defines a function to call when the effect creation is successful
  14024. * @param onError defines a function to call when the effect creation has failed
  14025. * @returns the new Effect
  14026. */
  14027. Engine.prototype.createEffectForParticles = function (fragmentName, uniformsNames, samplers, defines, fallbacks, onCompiled, onError) {
  14028. if (uniformsNames === void 0) { uniformsNames = []; }
  14029. if (samplers === void 0) { samplers = []; }
  14030. if (defines === void 0) { defines = ""; }
  14031. return this.createEffect({
  14032. vertex: "particles",
  14033. fragmentElement: fragmentName
  14034. }, ["position", "color", "options"], ["view", "projection"].concat(uniformsNames), ["diffuseSampler"].concat(samplers), defines, fallbacks, onCompiled, onError);
  14035. };
  14036. /**
  14037. * Directly creates a webGL program
  14038. * @param vertexCode defines the vertex shader code to use
  14039. * @param fragmentCode defines the fragment shader code to use
  14040. * @param context defines the webGL context to use (if not set, the current one will be used)
  14041. * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
  14042. * @returns the new webGL program
  14043. */
  14044. Engine.prototype.createRawShaderProgram = function (vertexCode, fragmentCode, context, transformFeedbackVaryings) {
  14045. if (transformFeedbackVaryings === void 0) { transformFeedbackVaryings = null; }
  14046. context = context || this._gl;
  14047. var vertexShader = compileRawShader(context, vertexCode, "vertex");
  14048. var fragmentShader = compileRawShader(context, fragmentCode, "fragment");
  14049. return this._createShaderProgram(vertexShader, fragmentShader, context, transformFeedbackVaryings);
  14050. };
  14051. /**
  14052. * Creates a webGL program
  14053. * @param vertexCode defines the vertex shader code to use
  14054. * @param fragmentCode defines the fragment shader code to use
  14055. * @param defines defines the string containing the defines to use to compile the shaders
  14056. * @param context defines the webGL context to use (if not set, the current one will be used)
  14057. * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
  14058. * @returns the new webGL program
  14059. */
  14060. Engine.prototype.createShaderProgram = function (vertexCode, fragmentCode, defines, context, transformFeedbackVaryings) {
  14061. if (transformFeedbackVaryings === void 0) { transformFeedbackVaryings = null; }
  14062. context = context || this._gl;
  14063. this.onBeforeShaderCompilationObservable.notifyObservers(this);
  14064. var shaderVersion = (this._webGLVersion > 1) ? "#version 300 es\n#define WEBGL2 \n" : "";
  14065. var vertexShader = compileShader(context, vertexCode, "vertex", defines, shaderVersion);
  14066. var fragmentShader = compileShader(context, fragmentCode, "fragment", defines, shaderVersion);
  14067. var program = this._createShaderProgram(vertexShader, fragmentShader, context, transformFeedbackVaryings);
  14068. this.onAfterShaderCompilationObservable.notifyObservers(this);
  14069. return program;
  14070. };
  14071. Engine.prototype._createShaderProgram = function (vertexShader, fragmentShader, context, transformFeedbackVaryings) {
  14072. if (transformFeedbackVaryings === void 0) { transformFeedbackVaryings = null; }
  14073. var shaderProgram = context.createProgram();
  14074. if (!shaderProgram) {
  14075. throw new Error("Unable to create program");
  14076. }
  14077. context.attachShader(shaderProgram, vertexShader);
  14078. context.attachShader(shaderProgram, fragmentShader);
  14079. if (this.webGLVersion > 1 && transformFeedbackVaryings) {
  14080. var transformFeedback = this.createTransformFeedback();
  14081. this.bindTransformFeedback(transformFeedback);
  14082. this.setTranformFeedbackVaryings(shaderProgram, transformFeedbackVaryings);
  14083. shaderProgram.transformFeedback = transformFeedback;
  14084. }
  14085. context.linkProgram(shaderProgram);
  14086. if (this.webGLVersion > 1 && transformFeedbackVaryings) {
  14087. this.bindTransformFeedback(null);
  14088. }
  14089. var linked = context.getProgramParameter(shaderProgram, context.LINK_STATUS);
  14090. if (!linked) {
  14091. context.validateProgram(shaderProgram);
  14092. var error = context.getProgramInfoLog(shaderProgram);
  14093. if (error) {
  14094. throw new Error(error);
  14095. }
  14096. }
  14097. context.deleteShader(vertexShader);
  14098. context.deleteShader(fragmentShader);
  14099. return shaderProgram;
  14100. };
  14101. /**
  14102. * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
  14103. * @param shaderProgram defines the webGL program to use
  14104. * @param uniformsNames defines the list of uniform names
  14105. * @returns an array of webGL uniform locations
  14106. */
  14107. Engine.prototype.getUniforms = function (shaderProgram, uniformsNames) {
  14108. var results = new Array();
  14109. for (var index = 0; index < uniformsNames.length; index++) {
  14110. results.push(this._gl.getUniformLocation(shaderProgram, uniformsNames[index]));
  14111. }
  14112. return results;
  14113. };
  14114. /**
  14115. * Gets the lsit of active attributes for a given webGL program
  14116. * @param shaderProgram defines the webGL program to use
  14117. * @param attributesNames defines the list of attribute names to get
  14118. * @returns an array of indices indicating the offset of each attribute
  14119. */
  14120. Engine.prototype.getAttributes = function (shaderProgram, attributesNames) {
  14121. var results = [];
  14122. for (var index = 0; index < attributesNames.length; index++) {
  14123. try {
  14124. results.push(this._gl.getAttribLocation(shaderProgram, attributesNames[index]));
  14125. }
  14126. catch (e) {
  14127. results.push(-1);
  14128. }
  14129. }
  14130. return results;
  14131. };
  14132. /**
  14133. * Activates an effect, mkaing it the current one (ie. the one used for rendering)
  14134. * @param effect defines the effect to activate
  14135. */
  14136. Engine.prototype.enableEffect = function (effect) {
  14137. if (!effect) {
  14138. return;
  14139. }
  14140. // Use program
  14141. this.bindSamplers(effect);
  14142. this._currentEffect = effect;
  14143. if (effect.onBind) {
  14144. effect.onBind(effect);
  14145. }
  14146. effect.onBindObservable.notifyObservers(effect);
  14147. };
  14148. /**
  14149. * Set the value of an uniform to an array of int32
  14150. * @param uniform defines the webGL uniform location where to store the value
  14151. * @param array defines the array of int32 to store
  14152. */
  14153. Engine.prototype.setIntArray = function (uniform, array) {
  14154. if (!uniform)
  14155. return;
  14156. this._gl.uniform1iv(uniform, array);
  14157. };
  14158. /**
  14159. * Set the value of an uniform to an array of int32 (stored as vec2)
  14160. * @param uniform defines the webGL uniform location where to store the value
  14161. * @param array defines the array of int32 to store
  14162. */
  14163. Engine.prototype.setIntArray2 = function (uniform, array) {
  14164. if (!uniform || array.length % 2 !== 0)
  14165. return;
  14166. this._gl.uniform2iv(uniform, array);
  14167. };
  14168. /**
  14169. * Set the value of an uniform to an array of int32 (stored as vec3)
  14170. * @param uniform defines the webGL uniform location where to store the value
  14171. * @param array defines the array of int32 to store
  14172. */
  14173. Engine.prototype.setIntArray3 = function (uniform, array) {
  14174. if (!uniform || array.length % 3 !== 0)
  14175. return;
  14176. this._gl.uniform3iv(uniform, array);
  14177. };
  14178. /**
  14179. * Set the value of an uniform to an array of int32 (stored as vec4)
  14180. * @param uniform defines the webGL uniform location where to store the value
  14181. * @param array defines the array of int32 to store
  14182. */
  14183. Engine.prototype.setIntArray4 = function (uniform, array) {
  14184. if (!uniform || array.length % 4 !== 0)
  14185. return;
  14186. this._gl.uniform4iv(uniform, array);
  14187. };
  14188. /**
  14189. * Set the value of an uniform to an array of float32
  14190. * @param uniform defines the webGL uniform location where to store the value
  14191. * @param array defines the array of float32 to store
  14192. */
  14193. Engine.prototype.setFloatArray = function (uniform, array) {
  14194. if (!uniform)
  14195. return;
  14196. this._gl.uniform1fv(uniform, array);
  14197. };
  14198. /**
  14199. * Set the value of an uniform to an array of float32 (stored as vec2)
  14200. * @param uniform defines the webGL uniform location where to store the value
  14201. * @param array defines the array of float32 to store
  14202. */
  14203. Engine.prototype.setFloatArray2 = function (uniform, array) {
  14204. if (!uniform || array.length % 2 !== 0)
  14205. return;
  14206. this._gl.uniform2fv(uniform, array);
  14207. };
  14208. /**
  14209. * Set the value of an uniform to an array of float32 (stored as vec3)
  14210. * @param uniform defines the webGL uniform location where to store the value
  14211. * @param array defines the array of float32 to store
  14212. */
  14213. Engine.prototype.setFloatArray3 = function (uniform, array) {
  14214. if (!uniform || array.length % 3 !== 0)
  14215. return;
  14216. this._gl.uniform3fv(uniform, array);
  14217. };
  14218. /**
  14219. * Set the value of an uniform to an array of float32 (stored as vec4)
  14220. * @param uniform defines the webGL uniform location where to store the value
  14221. * @param array defines the array of float32 to store
  14222. */
  14223. Engine.prototype.setFloatArray4 = function (uniform, array) {
  14224. if (!uniform || array.length % 4 !== 0)
  14225. return;
  14226. this._gl.uniform4fv(uniform, array);
  14227. };
  14228. /**
  14229. * Set the value of an uniform to an array of number
  14230. * @param uniform defines the webGL uniform location where to store the value
  14231. * @param array defines the array of number to store
  14232. */
  14233. Engine.prototype.setArray = function (uniform, array) {
  14234. if (!uniform)
  14235. return;
  14236. this._gl.uniform1fv(uniform, array);
  14237. };
  14238. /**
  14239. * Set the value of an uniform to an array of number (stored as vec2)
  14240. * @param uniform defines the webGL uniform location where to store the value
  14241. * @param array defines the array of number to store
  14242. */
  14243. Engine.prototype.setArray2 = function (uniform, array) {
  14244. if (!uniform || array.length % 2 !== 0)
  14245. return;
  14246. this._gl.uniform2fv(uniform, array);
  14247. };
  14248. /**
  14249. * Set the value of an uniform to an array of number (stored as vec3)
  14250. * @param uniform defines the webGL uniform location where to store the value
  14251. * @param array defines the array of number to store
  14252. */
  14253. Engine.prototype.setArray3 = function (uniform, array) {
  14254. if (!uniform || array.length % 3 !== 0)
  14255. return;
  14256. this._gl.uniform3fv(uniform, array);
  14257. };
  14258. /**
  14259. * Set the value of an uniform to an array of number (stored as vec4)
  14260. * @param uniform defines the webGL uniform location where to store the value
  14261. * @param array defines the array of number to store
  14262. */
  14263. Engine.prototype.setArray4 = function (uniform, array) {
  14264. if (!uniform || array.length % 4 !== 0)
  14265. return;
  14266. this._gl.uniform4fv(uniform, array);
  14267. };
  14268. /**
  14269. * Set the value of an uniform to an array of float32 (stored as matrices)
  14270. * @param uniform defines the webGL uniform location where to store the value
  14271. * @param matrices defines the array of float32 to store
  14272. */
  14273. Engine.prototype.setMatrices = function (uniform, matrices) {
  14274. if (!uniform)
  14275. return;
  14276. this._gl.uniformMatrix4fv(uniform, false, matrices);
  14277. };
  14278. /**
  14279. * Set the value of an uniform to a matrix
  14280. * @param uniform defines the webGL uniform location where to store the value
  14281. * @param matrix defines the matrix to store
  14282. */
  14283. Engine.prototype.setMatrix = function (uniform, matrix) {
  14284. if (!uniform)
  14285. return;
  14286. this._gl.uniformMatrix4fv(uniform, false, matrix.toArray());
  14287. };
  14288. /**
  14289. * Set the value of an uniform to a matrix (3x3)
  14290. * @param uniform defines the webGL uniform location where to store the value
  14291. * @param matrix defines the Float32Array representing the 3x3 matrix to store
  14292. */
  14293. Engine.prototype.setMatrix3x3 = function (uniform, matrix) {
  14294. if (!uniform)
  14295. return;
  14296. this._gl.uniformMatrix3fv(uniform, false, matrix);
  14297. };
  14298. /**
  14299. * Set the value of an uniform to a matrix (2x2)
  14300. * @param uniform defines the webGL uniform location where to store the value
  14301. * @param matrix defines the Float32Array representing the 2x2 matrix to store
  14302. */
  14303. Engine.prototype.setMatrix2x2 = function (uniform, matrix) {
  14304. if (!uniform)
  14305. return;
  14306. this._gl.uniformMatrix2fv(uniform, false, matrix);
  14307. };
  14308. /**
  14309. * Set the value of an uniform to a number (int)
  14310. * @param uniform defines the webGL uniform location where to store the value
  14311. * @param value defines the int number to store
  14312. */
  14313. Engine.prototype.setInt = function (uniform, value) {
  14314. if (!uniform)
  14315. return;
  14316. this._gl.uniform1i(uniform, value);
  14317. };
  14318. /**
  14319. * Set the value of an uniform to a number (float)
  14320. * @param uniform defines the webGL uniform location where to store the value
  14321. * @param value defines the float number to store
  14322. */
  14323. Engine.prototype.setFloat = function (uniform, value) {
  14324. if (!uniform)
  14325. return;
  14326. this._gl.uniform1f(uniform, value);
  14327. };
  14328. /**
  14329. * Set the value of an uniform to a vec2
  14330. * @param uniform defines the webGL uniform location where to store the value
  14331. * @param x defines the 1st component of the value
  14332. * @param y defines the 2nd component of the value
  14333. */
  14334. Engine.prototype.setFloat2 = function (uniform, x, y) {
  14335. if (!uniform)
  14336. return;
  14337. this._gl.uniform2f(uniform, x, y);
  14338. };
  14339. /**
  14340. * Set the value of an uniform to a vec3
  14341. * @param uniform defines the webGL uniform location where to store the value
  14342. * @param x defines the 1st component of the value
  14343. * @param y defines the 2nd component of the value
  14344. * @param z defines the 3rd component of the value
  14345. */
  14346. Engine.prototype.setFloat3 = function (uniform, x, y, z) {
  14347. if (!uniform)
  14348. return;
  14349. this._gl.uniform3f(uniform, x, y, z);
  14350. };
  14351. /**
  14352. * Set the value of an uniform to a boolean
  14353. * @param uniform defines the webGL uniform location where to store the value
  14354. * @param bool defines the boolean to store
  14355. */
  14356. Engine.prototype.setBool = function (uniform, bool) {
  14357. if (!uniform)
  14358. return;
  14359. this._gl.uniform1i(uniform, bool);
  14360. };
  14361. /**
  14362. * Set the value of an uniform to a vec4
  14363. * @param uniform defines the webGL uniform location where to store the value
  14364. * @param x defines the 1st component of the value
  14365. * @param y defines the 2nd component of the value
  14366. * @param z defines the 3rd component of the value
  14367. * @param w defines the 4th component of the value
  14368. */
  14369. Engine.prototype.setFloat4 = function (uniform, x, y, z, w) {
  14370. if (!uniform)
  14371. return;
  14372. this._gl.uniform4f(uniform, x, y, z, w);
  14373. };
  14374. /**
  14375. * Set the value of an uniform to a Color3
  14376. * @param uniform defines the webGL uniform location where to store the value
  14377. * @param color3 defines the color to store
  14378. */
  14379. Engine.prototype.setColor3 = function (uniform, color3) {
  14380. if (!uniform)
  14381. return;
  14382. this._gl.uniform3f(uniform, color3.r, color3.g, color3.b);
  14383. };
  14384. /**
  14385. * Set the value of an uniform to a Color3 and an alpha value
  14386. * @param uniform defines the webGL uniform location where to store the value
  14387. * @param color3 defines the color to store
  14388. * @param alpha defines the alpha component to store
  14389. */
  14390. Engine.prototype.setColor4 = function (uniform, color3, alpha) {
  14391. if (!uniform)
  14392. return;
  14393. this._gl.uniform4f(uniform, color3.r, color3.g, color3.b, alpha);
  14394. };
  14395. /**
  14396. * Sets a Color4 on a uniform variable
  14397. * @param uniform defines the uniform location
  14398. * @param color4 defines the value to be set
  14399. */
  14400. Engine.prototype.setDirectColor4 = function (uniform, color4) {
  14401. if (!uniform)
  14402. return;
  14403. this._gl.uniform4f(uniform, color4.r, color4.g, color4.b, color4.a);
  14404. };
  14405. // States
  14406. /**
  14407. * Set various states to the webGL context
  14408. * @param culling defines backface culling state
  14409. * @param zOffset defines the value to apply to zOffset (0 by default)
  14410. * @param force defines if states must be applied even if cache is up to date
  14411. * @param reverseSide defines if culling must be reversed (CCW instead of CW and CW instead of CCW)
  14412. */
  14413. Engine.prototype.setState = function (culling, zOffset, force, reverseSide) {
  14414. if (zOffset === void 0) { zOffset = 0; }
  14415. if (reverseSide === void 0) { reverseSide = false; }
  14416. // Culling
  14417. if (this._depthCullingState.cull !== culling || force) {
  14418. this._depthCullingState.cull = culling;
  14419. }
  14420. // Cull face
  14421. var cullFace = this.cullBackFaces ? this._gl.BACK : this._gl.FRONT;
  14422. if (this._depthCullingState.cullFace !== cullFace || force) {
  14423. this._depthCullingState.cullFace = cullFace;
  14424. }
  14425. // Z offset
  14426. this.setZOffset(zOffset);
  14427. // Front face
  14428. var frontFace = reverseSide ? this._gl.CW : this._gl.CCW;
  14429. if (this._depthCullingState.frontFace !== frontFace || force) {
  14430. this._depthCullingState.frontFace = frontFace;
  14431. }
  14432. };
  14433. /**
  14434. * Set the z offset to apply to current rendering
  14435. * @param value defines the offset to apply
  14436. */
  14437. Engine.prototype.setZOffset = function (value) {
  14438. this._depthCullingState.zOffset = value;
  14439. };
  14440. /**
  14441. * Gets the current value of the zOffset
  14442. * @returns the current zOffset state
  14443. */
  14444. Engine.prototype.getZOffset = function () {
  14445. return this._depthCullingState.zOffset;
  14446. };
  14447. /**
  14448. * Enable or disable depth buffering
  14449. * @param enable defines the state to set
  14450. */
  14451. Engine.prototype.setDepthBuffer = function (enable) {
  14452. this._depthCullingState.depthTest = enable;
  14453. };
  14454. /**
  14455. * Gets a boolean indicating if depth writing is enabled
  14456. * @returns the current depth writing state
  14457. */
  14458. Engine.prototype.getDepthWrite = function () {
  14459. return this._depthCullingState.depthMask;
  14460. };
  14461. /**
  14462. * Enable or disable depth writing
  14463. * @param enable defines the state to set
  14464. */
  14465. Engine.prototype.setDepthWrite = function (enable) {
  14466. this._depthCullingState.depthMask = enable;
  14467. };
  14468. /**
  14469. * Enable or disable color writing
  14470. * @param enable defines the state to set
  14471. */
  14472. Engine.prototype.setColorWrite = function (enable) {
  14473. this._gl.colorMask(enable, enable, enable, enable);
  14474. this._colorWrite = enable;
  14475. };
  14476. /**
  14477. * Gets a boolean indicating if color writing is enabled
  14478. * @returns the current color writing state
  14479. */
  14480. Engine.prototype.getColorWrite = function () {
  14481. return this._colorWrite;
  14482. };
  14483. /**
  14484. * Sets alpha constants used by some alpha blending modes
  14485. * @param r defines the red component
  14486. * @param g defines the green component
  14487. * @param b defines the blue component
  14488. * @param a defines the alpha component
  14489. */
  14490. Engine.prototype.setAlphaConstants = function (r, g, b, a) {
  14491. this._alphaState.setAlphaBlendConstants(r, g, b, a);
  14492. };
  14493. /**
  14494. * Sets the current alpha mode
  14495. * @param mode defines the mode to use (one of the BABYLON.Engine.ALPHA_XXX)
  14496. * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)
  14497. * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
  14498. */
  14499. Engine.prototype.setAlphaMode = function (mode, noDepthWriteChange) {
  14500. if (noDepthWriteChange === void 0) { noDepthWriteChange = false; }
  14501. if (this._alphaMode === mode) {
  14502. return;
  14503. }
  14504. switch (mode) {
  14505. case Engine.ALPHA_DISABLE:
  14506. this._alphaState.alphaBlend = false;
  14507. break;
  14508. case Engine.ALPHA_PREMULTIPLIED:
  14509. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  14510. this._alphaState.alphaBlend = true;
  14511. break;
  14512. case Engine.ALPHA_PREMULTIPLIED_PORTERDUFF:
  14513. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
  14514. this._alphaState.alphaBlend = true;
  14515. break;
  14516. case Engine.ALPHA_COMBINE:
  14517. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  14518. this._alphaState.alphaBlend = true;
  14519. break;
  14520. case Engine.ALPHA_ONEONE:
  14521. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  14522. this._alphaState.alphaBlend = true;
  14523. break;
  14524. case Engine.ALPHA_ADD:
  14525. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  14526. this._alphaState.alphaBlend = true;
  14527. break;
  14528. case Engine.ALPHA_SUBTRACT:
  14529. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);
  14530. this._alphaState.alphaBlend = true;
  14531. break;
  14532. case Engine.ALPHA_MULTIPLY:
  14533. this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR, this._gl.ZERO, this._gl.ONE, this._gl.ONE);
  14534. this._alphaState.alphaBlend = true;
  14535. break;
  14536. case Engine.ALPHA_MAXIMIZED:
  14537. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);
  14538. this._alphaState.alphaBlend = true;
  14539. break;
  14540. case Engine.ALPHA_INTERPOLATE:
  14541. this._alphaState.setAlphaBlendFunctionParameters(this._gl.CONSTANT_COLOR, this._gl.ONE_MINUS_CONSTANT_COLOR, this._gl.CONSTANT_ALPHA, this._gl.ONE_MINUS_CONSTANT_ALPHA);
  14542. this._alphaState.alphaBlend = true;
  14543. break;
  14544. case Engine.ALPHA_SCREENMODE:
  14545. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
  14546. this._alphaState.alphaBlend = true;
  14547. break;
  14548. }
  14549. if (!noDepthWriteChange) {
  14550. this.setDepthWrite(mode === Engine.ALPHA_DISABLE);
  14551. }
  14552. this._alphaMode = mode;
  14553. };
  14554. /**
  14555. * Gets the current alpha mode
  14556. * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
  14557. * @returns the current alpha mode
  14558. */
  14559. Engine.prototype.getAlphaMode = function () {
  14560. return this._alphaMode;
  14561. };
  14562. // Textures
  14563. /**
  14564. * Force the entire cache to be cleared
  14565. * You should not have to use this function unless your engine needs to share the webGL context with another engine
  14566. * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
  14567. */
  14568. Engine.prototype.wipeCaches = function (bruteForce) {
  14569. if (this.preventCacheWipeBetweenFrames && !bruteForce) {
  14570. return;
  14571. }
  14572. this._currentEffect = null;
  14573. if (bruteForce) {
  14574. this.resetTextureCache();
  14575. this._currentProgram = null;
  14576. this._stencilState.reset();
  14577. this._depthCullingState.reset();
  14578. this.setDepthFunctionToLessOrEqual();
  14579. this._alphaState.reset();
  14580. }
  14581. this._resetVertexBufferBinding();
  14582. this._cachedIndexBuffer = null;
  14583. this._cachedEffectForVertexBuffers = null;
  14584. this._unbindVertexArrayObject();
  14585. this.bindIndexBuffer(null);
  14586. };
  14587. /**
  14588. * Set the compressed texture format to use, based on the formats you have, and the formats
  14589. * supported by the hardware / browser.
  14590. *
  14591. * Khronos Texture Container (.ktx) files are used to support this. This format has the
  14592. * advantage of being specifically designed for OpenGL. Header elements directly correspond
  14593. * to API arguments needed to compressed textures. This puts the burden on the container
  14594. * generator to house the arcane code for determining these for current & future formats.
  14595. *
  14596. * for description see https://www.khronos.org/opengles/sdk/tools/KTX/
  14597. * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
  14598. *
  14599. * Note: The result of this call is not taken into account when a texture is base64.
  14600. *
  14601. * @param formatsAvailable defines the list of those format families you have created
  14602. * on your server. Syntax: '-' + format family + '.ktx'. (Case and order do not matter.)
  14603. *
  14604. * Current families are astc, dxt, pvrtc, etc2, & etc1.
  14605. * @returns The extension selected.
  14606. */
  14607. Engine.prototype.setTextureFormatToUse = function (formatsAvailable) {
  14608. for (var i = 0, len1 = this.texturesSupported.length; i < len1; i++) {
  14609. for (var j = 0, len2 = formatsAvailable.length; j < len2; j++) {
  14610. if (this._texturesSupported[i] === formatsAvailable[j].toLowerCase()) {
  14611. return this._textureFormatInUse = this._texturesSupported[i];
  14612. }
  14613. }
  14614. }
  14615. // actively set format to nothing, to allow this to be called more than once
  14616. // and possibly fail the 2nd time
  14617. this._textureFormatInUse = null;
  14618. return null;
  14619. };
  14620. /** @hidden */
  14621. Engine.prototype._createTexture = function () {
  14622. var texture = this._gl.createTexture();
  14623. if (!texture) {
  14624. throw new Error("Unable to create texture");
  14625. }
  14626. return texture;
  14627. };
  14628. /**
  14629. * Usually called from BABYLON.Texture.ts.
  14630. * Passed information to create a WebGLTexture
  14631. * @param urlArg defines a value which contains one of the following:
  14632. * * A conventional http URL, e.g. 'http://...' or 'file://...'
  14633. * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
  14634. * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
  14635. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
  14636. * @param invertY when true, image is flipped when loaded. You probably want true. Ignored for compressed textures. Must be flipped in the file
  14637. * @param scene needed for loading to the correct scene
  14638. * @param samplingMode mode with should be used sample / access the texture (Default: BABYLON.Texture.TRILINEAR_SAMPLINGMODE)
  14639. * @param onLoad optional callback to be called upon successful completion
  14640. * @param onError optional callback to be called upon failure
  14641. * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob
  14642. * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
  14643. * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
  14644. * @returns a InternalTexture for assignment back into BABYLON.Texture
  14645. */
  14646. Engine.prototype.createTexture = function (urlArg, noMipmap, invertY, scene, samplingMode, onLoad, onError, buffer, fallback, format) {
  14647. var _this = this;
  14648. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  14649. if (onLoad === void 0) { onLoad = null; }
  14650. if (onError === void 0) { onError = null; }
  14651. if (buffer === void 0) { buffer = null; }
  14652. if (fallback === void 0) { fallback = null; }
  14653. if (format === void 0) { format = null; }
  14654. var url = String(urlArg); // assign a new string, so that the original is still available in case of fallback
  14655. var fromData = url.substr(0, 5) === "data:";
  14656. var fromBlob = url.substr(0, 5) === "blob:";
  14657. var isBase64 = fromData && url.indexOf("base64") !== -1;
  14658. var texture = fallback ? fallback : new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_URL);
  14659. // establish the file extension, if possible
  14660. var lastDot = url.lastIndexOf('.');
  14661. var extension = (lastDot > 0) ? url.substring(lastDot).toLowerCase() : "";
  14662. var isDDS = this.getCaps().s3tc && (extension.indexOf(".dds") === 0);
  14663. var isTGA = (extension.indexOf(".tga") === 0);
  14664. // determine if a ktx file should be substituted
  14665. var isKTX = false;
  14666. if (this._textureFormatInUse && !isBase64 && !fallback) {
  14667. url = url.substring(0, lastDot) + this._textureFormatInUse;
  14668. isKTX = true;
  14669. }
  14670. if (scene) {
  14671. scene._addPendingData(texture);
  14672. }
  14673. texture.url = url;
  14674. texture.generateMipMaps = !noMipmap;
  14675. texture.samplingMode = samplingMode;
  14676. texture.invertY = invertY;
  14677. if (!this._doNotHandleContextLost) {
  14678. // Keep a link to the buffer only if we plan to handle context lost
  14679. texture._buffer = buffer;
  14680. }
  14681. var onLoadObserver = null;
  14682. if (onLoad && !fallback) {
  14683. onLoadObserver = texture.onLoadedObservable.add(onLoad);
  14684. }
  14685. if (!fallback)
  14686. this._internalTexturesCache.push(texture);
  14687. var onerror = function (message, exception) {
  14688. if (scene) {
  14689. scene._removePendingData(texture);
  14690. }
  14691. if (onLoadObserver) {
  14692. texture.onLoadedObservable.remove(onLoadObserver);
  14693. }
  14694. // fallback for when compressed file not found to try again. For instance, etc1 does not have an alpha capable type
  14695. if (isKTX) {
  14696. _this.createTexture(urlArg, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
  14697. }
  14698. else if (BABYLON.Tools.UseFallbackTexture) {
  14699. _this.createTexture(BABYLON.Tools.fallbackTexture, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
  14700. }
  14701. if (onError) {
  14702. onError(message || "Unknown error", exception);
  14703. }
  14704. };
  14705. var callback = null;
  14706. // processing for non-image formats
  14707. if (isKTX || isTGA || isDDS) {
  14708. if (isKTX) {
  14709. callback = function (data) {
  14710. var ktx = new BABYLON.KhronosTextureContainer(data, 1);
  14711. _this._prepareWebGLTexture(texture, scene, ktx.pixelWidth, ktx.pixelHeight, invertY, false, true, function () {
  14712. ktx.uploadLevels(_this._gl, !noMipmap);
  14713. return false;
  14714. }, samplingMode);
  14715. };
  14716. }
  14717. else if (isTGA) {
  14718. callback = function (arrayBuffer) {
  14719. var data = new Uint8Array(arrayBuffer);
  14720. var header = BABYLON.TGATools.GetTGAHeader(data);
  14721. _this._prepareWebGLTexture(texture, scene, header.width, header.height, invertY, noMipmap, false, function () {
  14722. BABYLON.TGATools.UploadContent(_this._gl, data);
  14723. return false;
  14724. }, samplingMode);
  14725. };
  14726. }
  14727. else if (isDDS) {
  14728. callback = function (data) {
  14729. var info = BABYLON.DDSTools.GetDDSInfo(data);
  14730. var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap && ((info.width >> (info.mipmapCount - 1)) === 1);
  14731. _this._prepareWebGLTexture(texture, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, function () {
  14732. BABYLON.DDSTools.UploadDDSLevels(_this, _this._gl, data, info, loadMipmap, 1);
  14733. return false;
  14734. }, samplingMode);
  14735. };
  14736. }
  14737. if (!buffer) {
  14738. this._loadFile(url, function (data) {
  14739. if (callback) {
  14740. callback(data);
  14741. }
  14742. }, undefined, scene ? scene.database : undefined, true, function (request, exception) {
  14743. onerror("Unable to load " + (request ? request.responseURL : url, exception));
  14744. });
  14745. }
  14746. else {
  14747. if (callback) {
  14748. callback(buffer);
  14749. }
  14750. }
  14751. // image format processing
  14752. }
  14753. else {
  14754. var onload = function (img) {
  14755. if (fromBlob && !_this._doNotHandleContextLost) {
  14756. // We need to store the image if we need to rebuild the texture
  14757. // in case of a webgl context lost
  14758. texture._buffer = img;
  14759. }
  14760. _this._prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight, continuationCallback) {
  14761. var gl = _this._gl;
  14762. var isPot = (img.width === potWidth && img.height === potHeight);
  14763. var internalFormat = format ? _this._getInternalFormat(format) : ((extension === ".jpg") ? gl.RGB : gl.RGBA);
  14764. if (isPot) {
  14765. gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, internalFormat, gl.UNSIGNED_BYTE, img);
  14766. return false;
  14767. }
  14768. // Using shaders to rescale because canvas.drawImage is lossy
  14769. var source = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_TEMP);
  14770. _this._bindTextureDirectly(gl.TEXTURE_2D, source, true);
  14771. gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, internalFormat, gl.UNSIGNED_BYTE, img);
  14772. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  14773. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  14774. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  14775. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  14776. _this._rescaleTexture(source, texture, scene, internalFormat, function () {
  14777. _this._releaseTexture(source);
  14778. _this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
  14779. continuationCallback();
  14780. });
  14781. return true;
  14782. }, samplingMode);
  14783. };
  14784. if (!fromData || isBase64) {
  14785. if (buffer instanceof HTMLImageElement) {
  14786. onload(buffer);
  14787. }
  14788. else {
  14789. BABYLON.Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
  14790. }
  14791. }
  14792. else if (typeof buffer === "string" || buffer instanceof ArrayBuffer || buffer instanceof Blob) {
  14793. BABYLON.Tools.LoadImage(buffer, onload, onerror, scene ? scene.database : null);
  14794. }
  14795. else {
  14796. onload(buffer);
  14797. }
  14798. }
  14799. return texture;
  14800. };
  14801. Engine.prototype._rescaleTexture = function (source, destination, scene, internalFormat, onComplete) {
  14802. var _this = this;
  14803. var rtt = this.createRenderTargetTexture({
  14804. width: destination.width,
  14805. height: destination.height,
  14806. }, {
  14807. generateMipMaps: false,
  14808. type: Engine.TEXTURETYPE_UNSIGNED_INT,
  14809. samplingMode: BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  14810. generateDepthBuffer: false,
  14811. generateStencilBuffer: false
  14812. });
  14813. if (!this._rescalePostProcess) {
  14814. this._rescalePostProcess = new BABYLON.PassPostProcess("rescale", 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this, false, Engine.TEXTURETYPE_UNSIGNED_INT);
  14815. }
  14816. this._rescalePostProcess.getEffect().executeWhenCompiled(function () {
  14817. _this._rescalePostProcess.onApply = function (effect) {
  14818. effect._bindTexture("textureSampler", source);
  14819. };
  14820. var hostingScene = scene;
  14821. if (!hostingScene) {
  14822. hostingScene = _this.scenes[_this.scenes.length - 1];
  14823. }
  14824. hostingScene.postProcessManager.directRender([_this._rescalePostProcess], rtt, true);
  14825. _this._bindTextureDirectly(_this._gl.TEXTURE_2D, destination, true);
  14826. _this._gl.copyTexImage2D(_this._gl.TEXTURE_2D, 0, internalFormat, 0, 0, destination.width, destination.height, 0);
  14827. _this.unBindFramebuffer(rtt);
  14828. _this._releaseTexture(rtt);
  14829. if (onComplete) {
  14830. onComplete();
  14831. }
  14832. });
  14833. };
  14834. /**
  14835. * Update a raw texture
  14836. * @param texture defines the texture to update
  14837. * @param data defines the data to store in the texture
  14838. * @param format defines the format of the data
  14839. * @param invertY defines if data must be stored with Y axis inverted
  14840. * @param compression defines the compression used (null by default)
  14841. * @param type defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
  14842. */
  14843. Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression, type) {
  14844. if (compression === void 0) { compression = null; }
  14845. if (type === void 0) { type = Engine.TEXTURETYPE_UNSIGNED_INT; }
  14846. if (!texture) {
  14847. return;
  14848. }
  14849. // babylon's internalSizedFomat but gl's texImage2D internalFormat
  14850. var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type, format);
  14851. // babylon's internalFormat but gl's texImage2D format
  14852. var internalFormat = this._getInternalFormat(format);
  14853. var textureType = this._getWebGLTextureType(type);
  14854. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
  14855. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  14856. if (!this._doNotHandleContextLost) {
  14857. texture._bufferView = data;
  14858. texture.format = format;
  14859. texture.type = type;
  14860. texture.invertY = invertY;
  14861. texture._compression = compression;
  14862. }
  14863. if (texture.width % 4 !== 0) {
  14864. this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);
  14865. }
  14866. if (compression && data) {
  14867. this._gl.compressedTexImage2D(this._gl.TEXTURE_2D, 0, this.getCaps().s3tc[compression], texture.width, texture.height, 0, data);
  14868. }
  14869. else {
  14870. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, data);
  14871. }
  14872. if (texture.generateMipMaps) {
  14873. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  14874. }
  14875. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  14876. // this.resetTextureCache();
  14877. texture.isReady = true;
  14878. };
  14879. /**
  14880. * Creates a raw texture
  14881. * @param data defines the data to store in the texture
  14882. * @param width defines the width of the texture
  14883. * @param height defines the height of the texture
  14884. * @param format defines the format of the data
  14885. * @param generateMipMaps defines if the engine should generate the mip levels
  14886. * @param invertY defines if data must be stored with Y axis inverted
  14887. * @param samplingMode defines the required sampling mode (BABYLON.Texture.NEAREST_SAMPLINGMODE by default)
  14888. * @param compression defines the compression used (null by default)
  14889. * @param type defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
  14890. * @returns the raw texture inside an InternalTexture
  14891. */
  14892. Engine.prototype.createRawTexture = function (data, width, height, format, generateMipMaps, invertY, samplingMode, compression, type) {
  14893. if (compression === void 0) { compression = null; }
  14894. if (type === void 0) { type = Engine.TEXTURETYPE_UNSIGNED_INT; }
  14895. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_RAW);
  14896. texture.baseWidth = width;
  14897. texture.baseHeight = height;
  14898. texture.width = width;
  14899. texture.height = height;
  14900. texture.format = format;
  14901. texture.generateMipMaps = generateMipMaps;
  14902. texture.samplingMode = samplingMode;
  14903. texture.invertY = invertY;
  14904. texture._compression = compression;
  14905. texture.type = type;
  14906. if (!this._doNotHandleContextLost) {
  14907. texture._bufferView = data;
  14908. }
  14909. this.updateRawTexture(texture, data, format, invertY, compression, type);
  14910. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
  14911. // Filters
  14912. var filters = getSamplingParameters(samplingMode, generateMipMaps, this._gl);
  14913. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
  14914. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  14915. if (generateMipMaps) {
  14916. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  14917. }
  14918. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  14919. this._internalTexturesCache.push(texture);
  14920. return texture;
  14921. };
  14922. /**
  14923. * Creates a dynamic texture
  14924. * @param width defines the width of the texture
  14925. * @param height defines the height of the texture
  14926. * @param generateMipMaps defines if the engine should generate the mip levels
  14927. * @param samplingMode defines the required sampling mode (BABYLON.Texture.NEAREST_SAMPLINGMODE by default)
  14928. * @returns the dynamic texture inside an InternalTexture
  14929. */
  14930. Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
  14931. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_DYNAMIC);
  14932. texture.baseWidth = width;
  14933. texture.baseHeight = height;
  14934. if (generateMipMaps) {
  14935. width = this.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(width, this._caps.maxTextureSize) : width;
  14936. height = this.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(height, this._caps.maxTextureSize) : height;
  14937. }
  14938. // this.resetTextureCache();
  14939. texture.width = width;
  14940. texture.height = height;
  14941. texture.isReady = false;
  14942. texture.generateMipMaps = generateMipMaps;
  14943. texture.samplingMode = samplingMode;
  14944. this.updateTextureSamplingMode(samplingMode, texture);
  14945. this._internalTexturesCache.push(texture);
  14946. return texture;
  14947. };
  14948. /**
  14949. * Update the sampling mode of a given texture
  14950. * @param samplingMode defines the required sampling mode
  14951. * @param texture defines the texture to update
  14952. */
  14953. Engine.prototype.updateTextureSamplingMode = function (samplingMode, texture) {
  14954. var filters = getSamplingParameters(samplingMode, texture.generateMipMaps, this._gl);
  14955. if (texture.isCube) {
  14956. this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
  14957. this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MIN_FILTER, filters.min);
  14958. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
  14959. }
  14960. else if (texture.is3D) {
  14961. this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
  14962. this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  14963. this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
  14964. }
  14965. else {
  14966. this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
  14967. this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  14968. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  14969. }
  14970. texture.samplingMode = samplingMode;
  14971. };
  14972. /**
  14973. * Update the content of a dynamic texture
  14974. * @param texture defines the texture to update
  14975. * @param canvas defines the canvas containing the source
  14976. * @param invertY defines if data must be stored with Y axis inverted
  14977. * @param premulAlpha defines if alpha is stored as premultiplied
  14978. * @param format defines the format of the data
  14979. */
  14980. Engine.prototype.updateDynamicTexture = function (texture, canvas, invertY, premulAlpha, format) {
  14981. if (premulAlpha === void 0) { premulAlpha = false; }
  14982. if (!texture) {
  14983. return;
  14984. }
  14985. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
  14986. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 1 : 0);
  14987. if (premulAlpha) {
  14988. this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
  14989. }
  14990. var internalFormat = format ? this._getInternalFormat(format) : this._gl.RGBA;
  14991. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, internalFormat, this._gl.UNSIGNED_BYTE, canvas);
  14992. if (texture.generateMipMaps) {
  14993. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  14994. }
  14995. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  14996. if (premulAlpha) {
  14997. this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
  14998. }
  14999. texture.isReady = true;
  15000. };
  15001. /**
  15002. * Update a video texture
  15003. * @param texture defines the texture to update
  15004. * @param video defines the video element to use
  15005. * @param invertY defines if data must be stored with Y axis inverted
  15006. */
  15007. Engine.prototype.updateVideoTexture = function (texture, video, invertY) {
  15008. if (!texture || texture._isDisabled) {
  15009. return;
  15010. }
  15011. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
  15012. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 0 : 1); // Video are upside down by default
  15013. try {
  15014. // Testing video texture support
  15015. if (this._videoTextureSupported === undefined) {
  15016. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
  15017. if (this._gl.getError() !== 0) {
  15018. this._videoTextureSupported = false;
  15019. }
  15020. else {
  15021. this._videoTextureSupported = true;
  15022. }
  15023. }
  15024. // Copy video through the current working canvas if video texture is not supported
  15025. if (!this._videoTextureSupported) {
  15026. if (!texture._workingCanvas) {
  15027. texture._workingCanvas = document.createElement("canvas");
  15028. var context = texture._workingCanvas.getContext("2d");
  15029. if (!context) {
  15030. throw new Error("Unable to get 2d context");
  15031. }
  15032. texture._workingContext = context;
  15033. texture._workingCanvas.width = texture.width;
  15034. texture._workingCanvas.height = texture.height;
  15035. }
  15036. texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);
  15037. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
  15038. }
  15039. else {
  15040. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
  15041. }
  15042. if (texture.generateMipMaps) {
  15043. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  15044. }
  15045. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  15046. // this.resetTextureCache();
  15047. texture.isReady = true;
  15048. }
  15049. catch (ex) {
  15050. // Something unexpected
  15051. // Let's disable the texture
  15052. texture._isDisabled = true;
  15053. }
  15054. };
  15055. /**
  15056. * Updates a depth texture Comparison Mode and Function.
  15057. * If the comparison Function is equal to 0, the mode will be set to none.
  15058. * Otherwise, this only works in webgl 2 and requires a shadow sampler in the shader.
  15059. * @param texture The texture to set the comparison function for
  15060. * @param comparisonFunction The comparison function to set, 0 if no comparison required
  15061. */
  15062. Engine.prototype.updateTextureComparisonFunction = function (texture, comparisonFunction) {
  15063. if (this.webGLVersion === 1) {
  15064. BABYLON.Tools.Error("WebGL 1 does not support texture comparison.");
  15065. return;
  15066. }
  15067. var gl = this._gl;
  15068. if (texture.isCube) {
  15069. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);
  15070. if (comparisonFunction === 0) {
  15071. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, Engine.LEQUAL);
  15072. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.NONE);
  15073. }
  15074. else {
  15075. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);
  15076. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
  15077. }
  15078. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
  15079. }
  15080. else {
  15081. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
  15082. if (comparisonFunction === 0) {
  15083. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, Engine.LEQUAL);
  15084. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.NONE);
  15085. }
  15086. else {
  15087. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);
  15088. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
  15089. }
  15090. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  15091. }
  15092. texture._comparisonFunction = comparisonFunction;
  15093. };
  15094. Engine.prototype._setupDepthStencilTexture = function (internalTexture, size, generateStencil, bilinearFiltering, comparisonFunction) {
  15095. var width = size.width || size;
  15096. var height = size.height || size;
  15097. internalTexture.baseWidth = width;
  15098. internalTexture.baseHeight = height;
  15099. internalTexture.width = width;
  15100. internalTexture.height = height;
  15101. internalTexture.isReady = true;
  15102. internalTexture.samples = 1;
  15103. internalTexture.generateMipMaps = false;
  15104. internalTexture._generateDepthBuffer = true;
  15105. internalTexture._generateStencilBuffer = generateStencil;
  15106. internalTexture.samplingMode = bilinearFiltering ? BABYLON.Texture.BILINEAR_SAMPLINGMODE : BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15107. internalTexture.type = Engine.TEXTURETYPE_UNSIGNED_INT;
  15108. internalTexture._comparisonFunction = comparisonFunction;
  15109. var gl = this._gl;
  15110. var target = internalTexture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
  15111. var samplingParameters = getSamplingParameters(internalTexture.samplingMode, false, gl);
  15112. gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, samplingParameters.mag);
  15113. gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, samplingParameters.min);
  15114. gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15115. gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15116. if (comparisonFunction === 0) {
  15117. gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, Engine.LEQUAL);
  15118. gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.NONE);
  15119. }
  15120. else {
  15121. gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);
  15122. gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
  15123. }
  15124. };
  15125. /**
  15126. * Creates a depth stencil texture.
  15127. * This is only available in WebGL 2 or with the depth texture extension available.
  15128. * @param size The size of face edge in the texture.
  15129. * @param options The options defining the texture.
  15130. * @returns The texture
  15131. */
  15132. Engine.prototype.createDepthStencilTexture = function (size, options) {
  15133. if (options.isCube) {
  15134. var width = size.width || size;
  15135. return this._createDepthStencilCubeTexture(width, options);
  15136. }
  15137. else {
  15138. return this._createDepthStencilTexture(size, options);
  15139. }
  15140. };
  15141. /**
  15142. * Creates a depth stencil texture.
  15143. * This is only available in WebGL 2 or with the depth texture extension available.
  15144. * @param size The size of face edge in the texture.
  15145. * @param options The options defining the texture.
  15146. * @returns The texture
  15147. */
  15148. Engine.prototype._createDepthStencilTexture = function (size, options) {
  15149. var internalTexture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_DEPTHTEXTURE);
  15150. if (!this._caps.depthTextureExtension) {
  15151. BABYLON.Tools.Error("Depth texture is not supported by your browser or hardware.");
  15152. return internalTexture;
  15153. }
  15154. var internalOptions = __assign({ bilinearFiltering: false, comparisonFunction: 0, generateStencil: false }, options);
  15155. var gl = this._gl;
  15156. this._bindTextureDirectly(gl.TEXTURE_2D, internalTexture, true);
  15157. this._setupDepthStencilTexture(internalTexture, size, internalOptions.generateStencil, internalOptions.bilinearFiltering, internalOptions.comparisonFunction);
  15158. if (this.webGLVersion > 1) {
  15159. if (internalOptions.generateStencil) {
  15160. gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH24_STENCIL8, internalTexture.width, internalTexture.height, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);
  15161. }
  15162. else {
  15163. gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT24, internalTexture.width, internalTexture.height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);
  15164. }
  15165. }
  15166. else {
  15167. if (internalOptions.generateStencil) {
  15168. gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_STENCIL, internalTexture.width, internalTexture.height, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);
  15169. }
  15170. else {
  15171. gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, internalTexture.width, internalTexture.height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);
  15172. }
  15173. }
  15174. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  15175. return internalTexture;
  15176. };
  15177. /**
  15178. * Creates a depth stencil cube texture.
  15179. * This is only available in WebGL 2.
  15180. * @param size The size of face edge in the cube texture.
  15181. * @param options The options defining the cube texture.
  15182. * @returns The cube texture
  15183. */
  15184. Engine.prototype._createDepthStencilCubeTexture = function (size, options) {
  15185. var internalTexture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_UNKNOWN);
  15186. internalTexture.isCube = true;
  15187. if (this.webGLVersion === 1) {
  15188. BABYLON.Tools.Error("Depth cube texture is not supported by WebGL 1.");
  15189. return internalTexture;
  15190. }
  15191. var internalOptions = __assign({ bilinearFiltering: false, comparisonFunction: 0, generateStencil: false }, options);
  15192. var gl = this._gl;
  15193. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, internalTexture, true);
  15194. this._setupDepthStencilTexture(internalTexture, size, internalOptions.generateStencil, internalOptions.bilinearFiltering, internalOptions.comparisonFunction);
  15195. // Create the depth/stencil buffer
  15196. for (var face = 0; face < 6; face++) {
  15197. if (internalOptions.generateStencil) {
  15198. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH24_STENCIL8, size, size, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);
  15199. }
  15200. else {
  15201. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH_COMPONENT24, size, size, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);
  15202. }
  15203. }
  15204. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  15205. return internalTexture;
  15206. };
  15207. /**
  15208. * Sets the frame buffer Depth / Stencil attachement of the render target to the defined depth stencil texture.
  15209. * @param renderTarget The render target to set the frame buffer for
  15210. */
  15211. Engine.prototype.setFrameBufferDepthStencilTexture = function (renderTarget) {
  15212. // Create the framebuffer
  15213. var internalTexture = renderTarget.getInternalTexture();
  15214. if (!internalTexture || !internalTexture._framebuffer || !renderTarget.depthStencilTexture) {
  15215. return;
  15216. }
  15217. var gl = this._gl;
  15218. var depthStencilTexture = renderTarget.depthStencilTexture;
  15219. this.bindUnboundFramebuffer(internalTexture._framebuffer);
  15220. if (depthStencilTexture.isCube) {
  15221. if (depthStencilTexture._generateStencilBuffer) {
  15222. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_CUBE_MAP_POSITIVE_X, depthStencilTexture._webGLTexture, 0);
  15223. }
  15224. else {
  15225. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_CUBE_MAP_POSITIVE_X, depthStencilTexture._webGLTexture, 0);
  15226. }
  15227. }
  15228. else {
  15229. if (depthStencilTexture._generateStencilBuffer) {
  15230. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, depthStencilTexture._webGLTexture, 0);
  15231. }
  15232. else {
  15233. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthStencilTexture._webGLTexture, 0);
  15234. }
  15235. }
  15236. this.bindUnboundFramebuffer(null);
  15237. };
  15238. /**
  15239. * Creates a new render target texture
  15240. * @param size defines the size of the texture
  15241. * @param options defines the options used to create the texture
  15242. * @returns a new render target texture stored in an InternalTexture
  15243. */
  15244. Engine.prototype.createRenderTargetTexture = function (size, options) {
  15245. var fullOptions = new RenderTargetCreationOptions();
  15246. if (options !== undefined && typeof options === "object") {
  15247. fullOptions.generateMipMaps = options.generateMipMaps;
  15248. fullOptions.generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
  15249. fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
  15250. fullOptions.type = options.type === undefined ? Engine.TEXTURETYPE_UNSIGNED_INT : options.type;
  15251. fullOptions.samplingMode = options.samplingMode === undefined ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : options.samplingMode;
  15252. fullOptions.format = options.format === undefined ? Engine.TEXTUREFORMAT_RGBA : options.format;
  15253. }
  15254. else {
  15255. fullOptions.generateMipMaps = options;
  15256. fullOptions.generateDepthBuffer = true;
  15257. fullOptions.generateStencilBuffer = false;
  15258. fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
  15259. fullOptions.samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  15260. fullOptions.format = Engine.TEXTUREFORMAT_RGBA;
  15261. }
  15262. if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
  15263. // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
  15264. fullOptions.samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15265. }
  15266. else if (fullOptions.type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
  15267. // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
  15268. fullOptions.samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15269. }
  15270. var gl = this._gl;
  15271. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_RENDERTARGET);
  15272. this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
  15273. var width = size.width || size;
  15274. var height = size.height || size;
  15275. var filters = getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps ? true : false, gl);
  15276. if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {
  15277. fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
  15278. BABYLON.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type");
  15279. }
  15280. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
  15281. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
  15282. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15283. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15284. gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), width, height, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
  15285. // Create the framebuffer
  15286. var currentFrameBuffer = this._currentFramebuffer;
  15287. var framebuffer = gl.createFramebuffer();
  15288. this.bindUnboundFramebuffer(framebuffer);
  15289. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._webGLTexture, 0);
  15290. texture._depthStencilBuffer = this._setupFramebufferDepthAttachments(fullOptions.generateStencilBuffer ? true : false, fullOptions.generateDepthBuffer, width, height);
  15291. if (fullOptions.generateMipMaps) {
  15292. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  15293. }
  15294. // Unbind
  15295. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  15296. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  15297. this.bindUnboundFramebuffer(currentFrameBuffer);
  15298. texture._framebuffer = framebuffer;
  15299. texture.baseWidth = width;
  15300. texture.baseHeight = height;
  15301. texture.width = width;
  15302. texture.height = height;
  15303. texture.isReady = true;
  15304. texture.samples = 1;
  15305. texture.generateMipMaps = fullOptions.generateMipMaps ? true : false;
  15306. texture.samplingMode = fullOptions.samplingMode;
  15307. texture.type = fullOptions.type;
  15308. texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
  15309. texture._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
  15310. // this.resetTextureCache();
  15311. this._internalTexturesCache.push(texture);
  15312. return texture;
  15313. };
  15314. /**
  15315. * Create a multi render target texture
  15316. * @see http://doc.babylonjs.com/features/webgl2#multiple-render-target
  15317. * @param size defines the size of the texture
  15318. * @param options defines the creation options
  15319. * @returns the cube texture as an InternalTexture
  15320. */
  15321. Engine.prototype.createMultipleRenderTarget = function (size, options) {
  15322. var generateMipMaps = false;
  15323. var generateDepthBuffer = true;
  15324. var generateStencilBuffer = false;
  15325. var generateDepthTexture = false;
  15326. var textureCount = 1;
  15327. var defaultType = Engine.TEXTURETYPE_UNSIGNED_INT;
  15328. var defaultSamplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  15329. var types = new Array();
  15330. var samplingModes = new Array();
  15331. if (options !== undefined) {
  15332. generateMipMaps = options.generateMipMaps === undefined ? false : options.generateMipMaps;
  15333. generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
  15334. generateStencilBuffer = options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;
  15335. generateDepthTexture = options.generateDepthTexture === undefined ? false : options.generateDepthTexture;
  15336. textureCount = options.textureCount || 1;
  15337. if (options.types) {
  15338. types = options.types;
  15339. }
  15340. if (options.samplingModes) {
  15341. samplingModes = options.samplingModes;
  15342. }
  15343. }
  15344. var gl = this._gl;
  15345. // Create the framebuffer
  15346. var framebuffer = gl.createFramebuffer();
  15347. this.bindUnboundFramebuffer(framebuffer);
  15348. var width = size.width || size;
  15349. var height = size.height || size;
  15350. var textures = [];
  15351. var attachments = [];
  15352. var depthStencilBuffer = this._setupFramebufferDepthAttachments(generateStencilBuffer, generateDepthBuffer, width, height);
  15353. for (var i = 0; i < textureCount; i++) {
  15354. var samplingMode = samplingModes[i] || defaultSamplingMode;
  15355. var type = types[i] || defaultType;
  15356. if (type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
  15357. // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
  15358. samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15359. }
  15360. else if (type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
  15361. // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
  15362. samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15363. }
  15364. var filters = getSamplingParameters(samplingMode, generateMipMaps, gl);
  15365. if (type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {
  15366. type = Engine.TEXTURETYPE_UNSIGNED_INT;
  15367. BABYLON.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type");
  15368. }
  15369. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_MULTIRENDERTARGET);
  15370. var attachment = gl[this.webGLVersion > 1 ? "COLOR_ATTACHMENT" + i : "COLOR_ATTACHMENT" + i + "_WEBGL"];
  15371. textures.push(texture);
  15372. attachments.push(attachment);
  15373. gl.activeTexture(gl["TEXTURE" + i]);
  15374. gl.bindTexture(gl.TEXTURE_2D, texture._webGLTexture);
  15375. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
  15376. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
  15377. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15378. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15379. gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(type), width, height, 0, gl.RGBA, this._getWebGLTextureType(type), null);
  15380. gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, texture._webGLTexture, 0);
  15381. if (generateMipMaps) {
  15382. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  15383. }
  15384. // Unbind
  15385. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  15386. texture._framebuffer = framebuffer;
  15387. texture._depthStencilBuffer = depthStencilBuffer;
  15388. texture.baseWidth = width;
  15389. texture.baseHeight = height;
  15390. texture.width = width;
  15391. texture.height = height;
  15392. texture.isReady = true;
  15393. texture.samples = 1;
  15394. texture.generateMipMaps = generateMipMaps;
  15395. texture.samplingMode = samplingMode;
  15396. texture.type = type;
  15397. texture._generateDepthBuffer = generateDepthBuffer;
  15398. texture._generateStencilBuffer = generateStencilBuffer;
  15399. texture._attachments = attachments;
  15400. this._internalTexturesCache.push(texture);
  15401. }
  15402. if (generateDepthTexture && this._caps.depthTextureExtension) {
  15403. // Depth texture
  15404. var depthTexture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_MULTIRENDERTARGET);
  15405. gl.activeTexture(gl.TEXTURE0);
  15406. gl.bindTexture(gl.TEXTURE_2D, depthTexture._webGLTexture);
  15407. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  15408. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  15409. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15410. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15411. gl.texImage2D(gl.TEXTURE_2D, 0, this.webGLVersion < 2 ? gl.DEPTH_COMPONENT : gl.DEPTH_COMPONENT16, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null);
  15412. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture._webGLTexture, 0);
  15413. depthTexture._framebuffer = framebuffer;
  15414. depthTexture.baseWidth = width;
  15415. depthTexture.baseHeight = height;
  15416. depthTexture.width = width;
  15417. depthTexture.height = height;
  15418. depthTexture.isReady = true;
  15419. depthTexture.samples = 1;
  15420. depthTexture.generateMipMaps = generateMipMaps;
  15421. depthTexture.samplingMode = gl.NEAREST;
  15422. depthTexture._generateDepthBuffer = generateDepthBuffer;
  15423. depthTexture._generateStencilBuffer = generateStencilBuffer;
  15424. textures.push(depthTexture);
  15425. this._internalTexturesCache.push(depthTexture);
  15426. }
  15427. gl.drawBuffers(attachments);
  15428. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  15429. this.bindUnboundFramebuffer(null);
  15430. this.resetTextureCache();
  15431. return textures;
  15432. };
  15433. Engine.prototype._setupFramebufferDepthAttachments = function (generateStencilBuffer, generateDepthBuffer, width, height, samples) {
  15434. if (samples === void 0) { samples = 1; }
  15435. var depthStencilBuffer = null;
  15436. var gl = this._gl;
  15437. // Create the depth/stencil buffer
  15438. if (generateStencilBuffer) {
  15439. depthStencilBuffer = gl.createRenderbuffer();
  15440. gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
  15441. if (samples > 1) {
  15442. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.DEPTH24_STENCIL8, width, height);
  15443. }
  15444. else {
  15445. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  15446. }
  15447. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
  15448. }
  15449. else if (generateDepthBuffer) {
  15450. depthStencilBuffer = gl.createRenderbuffer();
  15451. gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
  15452. if (samples > 1) {
  15453. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.DEPTH_COMPONENT16, width, height);
  15454. }
  15455. else {
  15456. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  15457. }
  15458. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
  15459. }
  15460. return depthStencilBuffer;
  15461. };
  15462. /**
  15463. * Updates the sample count of a render target texture
  15464. * @see http://doc.babylonjs.com/features/webgl2#multisample-render-targets
  15465. * @param texture defines the texture to update
  15466. * @param samples defines the sample count to set
  15467. * @returns the effective sample count (could be 0 if multisample render targets are not supported)
  15468. */
  15469. Engine.prototype.updateRenderTargetTextureSampleCount = function (texture, samples) {
  15470. if (this.webGLVersion < 2 || !texture) {
  15471. return 1;
  15472. }
  15473. if (texture.samples === samples) {
  15474. return samples;
  15475. }
  15476. var gl = this._gl;
  15477. samples = Math.min(samples, gl.getParameter(gl.MAX_SAMPLES));
  15478. // Dispose previous render buffers
  15479. if (texture._depthStencilBuffer) {
  15480. gl.deleteRenderbuffer(texture._depthStencilBuffer);
  15481. texture._depthStencilBuffer = null;
  15482. }
  15483. if (texture._MSAAFramebuffer) {
  15484. gl.deleteFramebuffer(texture._MSAAFramebuffer);
  15485. texture._MSAAFramebuffer = null;
  15486. }
  15487. if (texture._MSAARenderBuffer) {
  15488. gl.deleteRenderbuffer(texture._MSAARenderBuffer);
  15489. texture._MSAARenderBuffer = null;
  15490. }
  15491. if (samples > 1) {
  15492. var framebuffer = gl.createFramebuffer();
  15493. if (!framebuffer) {
  15494. throw new Error("Unable to create multi sampled framebuffer");
  15495. }
  15496. texture._MSAAFramebuffer = framebuffer;
  15497. this.bindUnboundFramebuffer(texture._MSAAFramebuffer);
  15498. var colorRenderbuffer = gl.createRenderbuffer();
  15499. if (!colorRenderbuffer) {
  15500. throw new Error("Unable to create multi sampled framebuffer");
  15501. }
  15502. gl.bindRenderbuffer(gl.RENDERBUFFER, colorRenderbuffer);
  15503. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, this._getRGBAMultiSampleBufferFormat(texture.type), texture.width, texture.height);
  15504. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRenderbuffer);
  15505. texture._MSAARenderBuffer = colorRenderbuffer;
  15506. }
  15507. else {
  15508. this.bindUnboundFramebuffer(texture._framebuffer);
  15509. }
  15510. texture.samples = samples;
  15511. texture._depthStencilBuffer = this._setupFramebufferDepthAttachments(texture._generateStencilBuffer, texture._generateDepthBuffer, texture.width, texture.height, samples);
  15512. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  15513. this.bindUnboundFramebuffer(null);
  15514. return samples;
  15515. };
  15516. /**
  15517. * Update the sample count for a given multiple render target texture
  15518. * @see http://doc.babylonjs.com/features/webgl2#multisample-render-targets
  15519. * @param textures defines the textures to update
  15520. * @param samples defines the sample count to set
  15521. * @returns the effective sample count (could be 0 if multisample render targets are not supported)
  15522. */
  15523. Engine.prototype.updateMultipleRenderTargetTextureSampleCount = function (textures, samples) {
  15524. if (this.webGLVersion < 2 || !textures || textures.length == 0) {
  15525. return 1;
  15526. }
  15527. if (textures[0].samples === samples) {
  15528. return samples;
  15529. }
  15530. var gl = this._gl;
  15531. samples = Math.min(samples, gl.getParameter(gl.MAX_SAMPLES));
  15532. // Dispose previous render buffers
  15533. if (textures[0]._depthStencilBuffer) {
  15534. gl.deleteRenderbuffer(textures[0]._depthStencilBuffer);
  15535. textures[0]._depthStencilBuffer = null;
  15536. }
  15537. if (textures[0]._MSAAFramebuffer) {
  15538. gl.deleteFramebuffer(textures[0]._MSAAFramebuffer);
  15539. textures[0]._MSAAFramebuffer = null;
  15540. }
  15541. for (var i = 0; i < textures.length; i++) {
  15542. if (textures[i]._MSAARenderBuffer) {
  15543. gl.deleteRenderbuffer(textures[i]._MSAARenderBuffer);
  15544. textures[i]._MSAARenderBuffer = null;
  15545. }
  15546. }
  15547. if (samples > 1) {
  15548. var framebuffer = gl.createFramebuffer();
  15549. if (!framebuffer) {
  15550. throw new Error("Unable to create multi sampled framebuffer");
  15551. }
  15552. this.bindUnboundFramebuffer(framebuffer);
  15553. var depthStencilBuffer = this._setupFramebufferDepthAttachments(textures[0]._generateStencilBuffer, textures[0]._generateDepthBuffer, textures[0].width, textures[0].height, samples);
  15554. var attachments = [];
  15555. for (var i = 0; i < textures.length; i++) {
  15556. var texture = textures[i];
  15557. var attachment = gl[this.webGLVersion > 1 ? "COLOR_ATTACHMENT" + i : "COLOR_ATTACHMENT" + i + "_WEBGL"];
  15558. var colorRenderbuffer = gl.createRenderbuffer();
  15559. if (!colorRenderbuffer) {
  15560. throw new Error("Unable to create multi sampled framebuffer");
  15561. }
  15562. gl.bindRenderbuffer(gl.RENDERBUFFER, colorRenderbuffer);
  15563. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, this._getRGBAMultiSampleBufferFormat(texture.type), texture.width, texture.height);
  15564. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, colorRenderbuffer);
  15565. texture._MSAAFramebuffer = framebuffer;
  15566. texture._MSAARenderBuffer = colorRenderbuffer;
  15567. texture.samples = samples;
  15568. texture._depthStencilBuffer = depthStencilBuffer;
  15569. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  15570. attachments.push(attachment);
  15571. }
  15572. gl.drawBuffers(attachments);
  15573. }
  15574. else {
  15575. this.bindUnboundFramebuffer(textures[0]._framebuffer);
  15576. }
  15577. this.bindUnboundFramebuffer(null);
  15578. return samples;
  15579. };
  15580. /** @hidden */
  15581. Engine.prototype._uploadDataToTexture = function (target, lod, internalFormat, width, height, format, type, data) {
  15582. this._gl.texImage2D(target, lod, internalFormat, width, height, 0, format, type, data);
  15583. };
  15584. /** @hidden */
  15585. Engine.prototype._uploadCompressedDataToTexture = function (target, lod, internalFormat, width, height, data) {
  15586. this._gl.compressedTexImage2D(target, lod, internalFormat, width, height, 0, data);
  15587. };
  15588. /** @hidden */
  15589. Engine.prototype._uploadImageToTexture = function (texture, faceIndex, lod, image) {
  15590. var gl = this._gl;
  15591. var textureType = this._getWebGLTextureType(texture.type);
  15592. var format = this._getInternalFormat(texture.format);
  15593. var internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, format);
  15594. var bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
  15595. this._bindTextureDirectly(bindTarget, texture, true);
  15596. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.invertY ? 1 : 0);
  15597. var target = gl.TEXTURE_2D;
  15598. if (texture.isCube) {
  15599. var target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;
  15600. }
  15601. gl.texImage2D(target, lod, internalFormat, format, textureType, image);
  15602. this._bindTextureDirectly(bindTarget, null, true);
  15603. };
  15604. /**
  15605. * Creates a new render target cube texture
  15606. * @param size defines the size of the texture
  15607. * @param options defines the options used to create the texture
  15608. * @returns a new render target cube texture stored in an InternalTexture
  15609. */
  15610. Engine.prototype.createRenderTargetCubeTexture = function (size, options) {
  15611. var fullOptions = __assign({ generateMipMaps: true, generateDepthBuffer: true, generateStencilBuffer: false, type: Engine.TEXTURETYPE_UNSIGNED_INT, samplingMode: BABYLON.Texture.TRILINEAR_SAMPLINGMODE, format: Engine.TEXTUREFORMAT_RGBA }, options);
  15612. fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
  15613. if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
  15614. // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
  15615. fullOptions.samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15616. }
  15617. else if (fullOptions.type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
  15618. // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
  15619. fullOptions.samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
  15620. }
  15621. var gl = this._gl;
  15622. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_RENDERTARGET);
  15623. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15624. var filters = getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps, gl);
  15625. if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {
  15626. fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
  15627. BABYLON.Tools.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type");
  15628. }
  15629. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);
  15630. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);
  15631. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15632. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15633. for (var face = 0; face < 6; face++) {
  15634. gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), size, size, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
  15635. }
  15636. // Create the framebuffer
  15637. var framebuffer = gl.createFramebuffer();
  15638. this.bindUnboundFramebuffer(framebuffer);
  15639. texture._depthStencilBuffer = this._setupFramebufferDepthAttachments(fullOptions.generateStencilBuffer, fullOptions.generateDepthBuffer, size, size);
  15640. // MipMaps
  15641. if (fullOptions.generateMipMaps) {
  15642. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  15643. }
  15644. // Unbind
  15645. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  15646. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  15647. this.bindUnboundFramebuffer(null);
  15648. texture._framebuffer = framebuffer;
  15649. texture.width = size;
  15650. texture.height = size;
  15651. texture.isReady = true;
  15652. texture.isCube = true;
  15653. texture.samples = 1;
  15654. texture.generateMipMaps = fullOptions.generateMipMaps;
  15655. texture.samplingMode = fullOptions.samplingMode;
  15656. texture.type = fullOptions.type;
  15657. texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
  15658. texture._generateStencilBuffer = fullOptions.generateStencilBuffer;
  15659. this._internalTexturesCache.push(texture);
  15660. return texture;
  15661. };
  15662. /**
  15663. * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)
  15664. * @param rootUrl defines the url where the file to load is located
  15665. * @param scene defines the current scene
  15666. * @param lodScale defines scale to apply to the mip map selection
  15667. * @param lodOffset defines offset to apply to the mip map selection
  15668. * @param onLoad defines an optional callback raised when the texture is loaded
  15669. * @param onError defines an optional callback raised if there is an issue to load the texture
  15670. * @param format defines the format of the data
  15671. * @param forcedExtension defines the extension to use to pick the right loader
  15672. * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture
  15673. * @returns the cube texture as an InternalTexture
  15674. */
  15675. Engine.prototype.createPrefilteredCubeTexture = function (rootUrl, scene, lodScale, lodOffset, onLoad, onError, format, forcedExtension, createPolynomials) {
  15676. var _this = this;
  15677. if (onLoad === void 0) { onLoad = null; }
  15678. if (onError === void 0) { onError = null; }
  15679. if (forcedExtension === void 0) { forcedExtension = null; }
  15680. if (createPolynomials === void 0) { createPolynomials = true; }
  15681. var callback = function (loadData) {
  15682. if (!loadData) {
  15683. if (onLoad) {
  15684. onLoad(null);
  15685. }
  15686. return;
  15687. }
  15688. var texture = loadData.texture;
  15689. if (!createPolynomials) {
  15690. texture._sphericalPolynomial = new BABYLON.SphericalPolynomial();
  15691. }
  15692. else if (loadData.info.sphericalPolynomial) {
  15693. texture._sphericalPolynomial = loadData.info.sphericalPolynomial;
  15694. }
  15695. texture._dataSource = BABYLON.InternalTexture.DATASOURCE_CUBEPREFILTERED;
  15696. if (_this._caps.textureLOD) {
  15697. // Do not add extra process if texture lod is supported.
  15698. if (onLoad) {
  15699. onLoad(texture);
  15700. }
  15701. return;
  15702. }
  15703. var mipSlices = 3;
  15704. var gl = _this._gl;
  15705. var width = loadData.width;
  15706. if (!width) {
  15707. return;
  15708. }
  15709. var textures = [];
  15710. for (var i = 0; i < mipSlices; i++) {
  15711. //compute LOD from even spacing in smoothness (matching shader calculation)
  15712. var smoothness = i / (mipSlices - 1);
  15713. var roughness = 1 - smoothness;
  15714. var minLODIndex = lodOffset; // roughness = 0
  15715. var maxLODIndex = BABYLON.Scalar.Log2(width) * lodScale + lodOffset; // roughness = 1
  15716. var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
  15717. var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
  15718. var glTextureFromLod = new BABYLON.InternalTexture(_this, BABYLON.InternalTexture.DATASOURCE_TEMP);
  15719. glTextureFromLod.isCube = true;
  15720. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod, true);
  15721. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  15722. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  15723. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15724. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15725. if (loadData.isDDS) {
  15726. var info = loadData.info;
  15727. var data = loadData.data;
  15728. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
  15729. BABYLON.DDSTools.UploadDDSLevels(_this, _this._gl, data, info, true, 6, mipmapIndex);
  15730. }
  15731. else {
  15732. BABYLON.Tools.Warn("DDS is the only prefiltered cube map supported so far.");
  15733. }
  15734. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  15735. // Wrap in a base texture for easy binding.
  15736. var lodTexture = new BABYLON.BaseTexture(scene);
  15737. lodTexture.isCube = true;
  15738. lodTexture._texture = glTextureFromLod;
  15739. glTextureFromLod.isReady = true;
  15740. textures.push(lodTexture);
  15741. }
  15742. texture._lodTextureHigh = textures[2];
  15743. texture._lodTextureMid = textures[1];
  15744. texture._lodTextureLow = textures[0];
  15745. if (onLoad) {
  15746. onLoad(texture);
  15747. }
  15748. };
  15749. return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset);
  15750. };
  15751. /**
  15752. * Creates a cube texture
  15753. * @param rootUrl defines the url where the files to load is located
  15754. * @param scene defines the current scene
  15755. * @param files defines the list of files to load (1 per face)
  15756. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
  15757. * @param onLoad defines an optional callback raised when the texture is loaded
  15758. * @param onError defines an optional callback raised if there is an issue to load the texture
  15759. * @param format defines the format of the data
  15760. * @param forcedExtension defines the extension to use to pick the right loader
  15761. * @param createPolynomials if a polynomial sphere should be created for the cube texture
  15762. * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness
  15763. * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
  15764. * @returns the cube texture as an InternalTexture
  15765. */
  15766. Engine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset) {
  15767. var _this = this;
  15768. if (onLoad === void 0) { onLoad = null; }
  15769. if (onError === void 0) { onError = null; }
  15770. if (forcedExtension === void 0) { forcedExtension = null; }
  15771. if (createPolynomials === void 0) { createPolynomials = false; }
  15772. if (lodScale === void 0) { lodScale = 0; }
  15773. if (lodOffset === void 0) { lodOffset = 0; }
  15774. var gl = this._gl;
  15775. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_CUBE);
  15776. texture.isCube = true;
  15777. texture.url = rootUrl;
  15778. texture.generateMipMaps = !noMipmap;
  15779. texture._lodGenerationScale = lodScale;
  15780. texture._lodGenerationOffset = lodOffset;
  15781. if (!this._doNotHandleContextLost) {
  15782. texture._extension = forcedExtension;
  15783. texture._files = files;
  15784. }
  15785. var isKTX = false;
  15786. var isDDS = false;
  15787. var isEnv = false;
  15788. var lastDot = rootUrl.lastIndexOf('.');
  15789. var extension = forcedExtension ? forcedExtension : (lastDot > -1 ? rootUrl.substring(lastDot).toLowerCase() : "");
  15790. if (this._textureFormatInUse) {
  15791. extension = this._textureFormatInUse;
  15792. rootUrl = (lastDot > -1 ? rootUrl.substring(0, lastDot) : rootUrl) + this._textureFormatInUse;
  15793. isKTX = true;
  15794. }
  15795. else {
  15796. isDDS = (extension === ".dds");
  15797. isEnv = (extension === ".env");
  15798. }
  15799. var onerror = function (request, exception) {
  15800. if (onError && request) {
  15801. onError(request.status + " " + request.statusText, exception);
  15802. }
  15803. };
  15804. if (isKTX) {
  15805. this._loadFile(rootUrl, function (data) {
  15806. var ktx = new BABYLON.KhronosTextureContainer(data, 6);
  15807. var loadMipmap = ktx.numberOfMipmapLevels > 1 && !noMipmap;
  15808. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15809. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
  15810. ktx.uploadLevels(_this._gl, !noMipmap);
  15811. _this.setCubeMapTextureParams(gl, loadMipmap);
  15812. texture.width = ktx.pixelWidth;
  15813. texture.height = ktx.pixelHeight;
  15814. texture.isReady = true;
  15815. }, undefined, undefined, true, onerror);
  15816. }
  15817. else if (isEnv) {
  15818. this._loadFile(rootUrl, function (data) {
  15819. data = data;
  15820. var info = BABYLON.EnvironmentTextureTools.GetEnvInfo(data);
  15821. if (info) {
  15822. texture.width = info.width;
  15823. texture.height = info.width;
  15824. BABYLON.EnvironmentTextureTools.UploadPolynomials(texture, data, info);
  15825. BABYLON.EnvironmentTextureTools.UploadLevelsAsync(texture, data, info).then(function () {
  15826. texture.isReady = true;
  15827. if (onLoad) {
  15828. onLoad();
  15829. }
  15830. });
  15831. }
  15832. else if (onError) {
  15833. onError("Can not parse the environment file", null);
  15834. }
  15835. }, undefined, undefined, true, onerror);
  15836. }
  15837. else if (isDDS) {
  15838. if (files && files.length === 6) {
  15839. this._cascadeLoadFiles(scene, function (imgs) {
  15840. var info;
  15841. var loadMipmap = false;
  15842. var width = 0;
  15843. for (var index = 0; index < imgs.length; index++) {
  15844. var data = imgs[index];
  15845. info = BABYLON.DDSTools.GetDDSInfo(data);
  15846. loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
  15847. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15848. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
  15849. BABYLON.DDSTools.UploadDDSLevels(_this, _this._gl, data, info, loadMipmap, 6, -1, index);
  15850. if (!noMipmap && !info.isFourCC && info.mipmapCount === 1) {
  15851. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  15852. }
  15853. texture.width = info.width;
  15854. texture.height = info.height;
  15855. texture.type = info.textureType;
  15856. width = info.width;
  15857. }
  15858. _this.setCubeMapTextureParams(gl, loadMipmap);
  15859. texture.isReady = true;
  15860. if (onLoad) {
  15861. onLoad({ isDDS: true, width: width, info: info, imgs: imgs, texture: texture });
  15862. }
  15863. }, files, onError);
  15864. }
  15865. else {
  15866. this._loadFile(rootUrl, function (data) {
  15867. var info = BABYLON.DDSTools.GetDDSInfo(data);
  15868. if (createPolynomials) {
  15869. info.sphericalPolynomial = new BABYLON.SphericalPolynomial();
  15870. }
  15871. var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
  15872. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15873. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
  15874. BABYLON.DDSTools.UploadDDSLevels(_this, _this._gl, data, info, loadMipmap, 6);
  15875. if (!noMipmap && !info.isFourCC && info.mipmapCount === 1) {
  15876. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  15877. }
  15878. _this.setCubeMapTextureParams(gl, loadMipmap);
  15879. texture.width = info.width;
  15880. texture.height = info.height;
  15881. texture.isReady = true;
  15882. texture.type = info.textureType;
  15883. if (onLoad) {
  15884. onLoad({ isDDS: true, width: info.width, info: info, data: data, texture: texture });
  15885. }
  15886. }, undefined, undefined, true, onerror);
  15887. }
  15888. }
  15889. else {
  15890. if (!files) {
  15891. throw new Error("Cannot load cubemap because files were not defined");
  15892. }
  15893. cascadeLoadImgs(rootUrl, scene, function (imgs) {
  15894. var width = _this.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize) : imgs[0].width;
  15895. var height = width;
  15896. _this._prepareWorkingCanvas();
  15897. if (!_this._workingCanvas || !_this._workingContext) {
  15898. return;
  15899. }
  15900. _this._workingCanvas.width = width;
  15901. _this._workingCanvas.height = height;
  15902. var faces = [
  15903. gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
  15904. gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
  15905. ];
  15906. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15907. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
  15908. var internalFormat = format ? _this._getInternalFormat(format) : _this._gl.RGBA;
  15909. for (var index = 0; index < faces.length; index++) {
  15910. _this._workingContext.drawImage(imgs[index], 0, 0, imgs[index].width, imgs[index].height, 0, 0, width, height);
  15911. gl.texImage2D(faces[index], 0, internalFormat, internalFormat, gl.UNSIGNED_BYTE, _this._workingCanvas);
  15912. }
  15913. if (!noMipmap) {
  15914. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  15915. }
  15916. _this.setCubeMapTextureParams(gl, !noMipmap);
  15917. texture.width = width;
  15918. texture.height = height;
  15919. texture.isReady = true;
  15920. if (format) {
  15921. texture.format = format;
  15922. }
  15923. texture.onLoadedObservable.notifyObservers(texture);
  15924. texture.onLoadedObservable.clear();
  15925. if (onLoad) {
  15926. onLoad();
  15927. }
  15928. }, files, onError);
  15929. }
  15930. this._internalTexturesCache.push(texture);
  15931. return texture;
  15932. };
  15933. Engine.prototype.setCubeMapTextureParams = function (gl, loadMipmap) {
  15934. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  15935. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, loadMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  15936. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  15937. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  15938. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  15939. // this.resetTextureCache();
  15940. };
  15941. /**
  15942. * Update a raw cube texture
  15943. * @param texture defines the texture to udpdate
  15944. * @param data defines the data to store
  15945. * @param format defines the data format
  15946. * @param type defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
  15947. * @param invertY defines if data must be stored with Y axis inverted
  15948. * @param compression defines the compression used (null by default)
  15949. * @param level defines which level of the texture to update
  15950. */
  15951. Engine.prototype.updateRawCubeTexture = function (texture, data, format, type, invertY, compression, level) {
  15952. if (compression === void 0) { compression = null; }
  15953. if (level === void 0) { level = 0; }
  15954. texture._bufferViewArray = data;
  15955. texture.format = format;
  15956. texture.type = type;
  15957. texture.invertY = invertY;
  15958. texture._compression = compression;
  15959. var gl = this._gl;
  15960. var textureType = this._getWebGLTextureType(type);
  15961. var internalFormat = this._getInternalFormat(format);
  15962. var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);
  15963. var needConversion = false;
  15964. if (internalFormat === gl.RGB) {
  15965. internalFormat = gl.RGBA;
  15966. needConversion = true;
  15967. }
  15968. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  15969. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  15970. if (texture.width % 4 !== 0) {
  15971. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  15972. }
  15973. // Data are known to be in +X +Y +Z -X -Y -Z
  15974. for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
  15975. var faceData = data[faceIndex];
  15976. if (compression) {
  15977. gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, (this.getCaps().s3tc)[compression], texture.width, texture.height, 0, faceData);
  15978. }
  15979. else {
  15980. if (needConversion) {
  15981. faceData = this._convertRGBtoRGBATextureData(faceData, texture.width, texture.height, type);
  15982. }
  15983. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, faceData);
  15984. }
  15985. }
  15986. var isPot = !this.needPOTTextures || (BABYLON.Tools.IsExponentOfTwo(texture.width) && BABYLON.Tools.IsExponentOfTwo(texture.height));
  15987. if (isPot && texture.generateMipMaps && level === 0) {
  15988. this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);
  15989. }
  15990. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
  15991. // this.resetTextureCache();
  15992. texture.isReady = true;
  15993. };
  15994. /**
  15995. * Creates a new raw cube texture
  15996. * @param data defines the array of data to use to create each face
  15997. * @param size defines the size of the textures
  15998. * @param format defines the format of the data
  15999. * @param type defines the type fo the data (like BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT)
  16000. * @param generateMipMaps defines if the engine should generate the mip levels
  16001. * @param invertY defines if data must be stored with Y axis inverted
  16002. * @param samplingMode defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)
  16003. * @param compression defines the compression used (null by default)
  16004. * @returns the cube texture as an InternalTexture
  16005. */
  16006. Engine.prototype.createRawCubeTexture = function (data, size, format, type, generateMipMaps, invertY, samplingMode, compression) {
  16007. if (compression === void 0) { compression = null; }
  16008. var gl = this._gl;
  16009. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_CUBERAW);
  16010. texture.isCube = true;
  16011. texture.generateMipMaps = generateMipMaps;
  16012. texture.format = format;
  16013. texture.type = type;
  16014. if (!this._doNotHandleContextLost) {
  16015. texture._bufferViewArray = data;
  16016. }
  16017. var textureType = this._getWebGLTextureType(type);
  16018. var internalFormat = this._getInternalFormat(format);
  16019. if (internalFormat === gl.RGB) {
  16020. internalFormat = gl.RGBA;
  16021. }
  16022. var width = size;
  16023. var height = width;
  16024. texture.width = width;
  16025. texture.height = height;
  16026. // Double check on POT to generate Mips.
  16027. var isPot = !this.needPOTTextures || (BABYLON.Tools.IsExponentOfTwo(texture.width) && BABYLON.Tools.IsExponentOfTwo(texture.height));
  16028. if (!isPot) {
  16029. generateMipMaps = false;
  16030. }
  16031. // Upload data if needed. The texture won't be ready until then.
  16032. if (data) {
  16033. this.updateRawCubeTexture(texture, data, format, type, invertY, compression);
  16034. }
  16035. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);
  16036. // Filters
  16037. if (data && generateMipMaps) {
  16038. this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);
  16039. }
  16040. if (textureType === gl.FLOAT && !this._caps.textureFloatLinearFiltering) {
  16041. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  16042. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  16043. }
  16044. else if (textureType === this._gl.HALF_FLOAT_OES && !this._caps.textureHalfFloatLinearFiltering) {
  16045. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  16046. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  16047. }
  16048. else {
  16049. var filters = getSamplingParameters(samplingMode, generateMipMaps, gl);
  16050. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);
  16051. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);
  16052. }
  16053. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  16054. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  16055. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  16056. return texture;
  16057. };
  16058. /**
  16059. * Creates a new raw cube texture from a specified url
  16060. * @param url defines the url where the data is located
  16061. * @param scene defines the current scene
  16062. * @param size defines the size of the textures
  16063. * @param format defines the format of the data
  16064. * @param type defines the type fo the data (like BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT)
  16065. * @param noMipmap defines if the engine should avoid generating the mip levels
  16066. * @param callback defines a callback used to extract texture data from loaded data
  16067. * @param mipmapGenerator defines to provide an optional tool to generate mip levels
  16068. * @param onLoad defines a callback called when texture is loaded
  16069. * @param onError defines a callback called if there is an error
  16070. * @param samplingMode defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)
  16071. * @param invertY defines if data must be stored with Y axis inverted
  16072. * @returns the cube texture as an InternalTexture
  16073. */
  16074. Engine.prototype.createRawCubeTextureFromUrl = function (url, scene, size, format, type, noMipmap, callback, mipmapGenerator, onLoad, onError, samplingMode, invertY) {
  16075. var _this = this;
  16076. if (onLoad === void 0) { onLoad = null; }
  16077. if (onError === void 0) { onError = null; }
  16078. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  16079. if (invertY === void 0) { invertY = false; }
  16080. var gl = this._gl;
  16081. var texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode);
  16082. scene._addPendingData(texture);
  16083. texture.url = url;
  16084. this._internalTexturesCache.push(texture);
  16085. var onerror = function (request, exception) {
  16086. scene._removePendingData(texture);
  16087. if (onError && request) {
  16088. onError(request.status + " " + request.statusText, exception);
  16089. }
  16090. };
  16091. var internalCallback = function (data) {
  16092. var width = texture.width;
  16093. var faceDataArrays = callback(data);
  16094. if (!faceDataArrays) {
  16095. return;
  16096. }
  16097. if (mipmapGenerator) {
  16098. var textureType = _this._getWebGLTextureType(type);
  16099. var internalFormat = _this._getInternalFormat(format);
  16100. var internalSizedFomat = _this._getRGBABufferInternalSizedFormat(type);
  16101. var needConversion = false;
  16102. if (internalFormat === gl.RGB) {
  16103. internalFormat = gl.RGBA;
  16104. needConversion = true;
  16105. }
  16106. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  16107. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
  16108. var mipData = mipmapGenerator(faceDataArrays);
  16109. for (var level = 0; level < mipData.length; level++) {
  16110. var mipSize = width >> level;
  16111. for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
  16112. var mipFaceData = mipData[level][faceIndex];
  16113. if (needConversion) {
  16114. mipFaceData = _this._convertRGBtoRGBATextureData(mipFaceData, mipSize, mipSize, type);
  16115. }
  16116. gl.texImage2D(faceIndex, level, internalSizedFomat, mipSize, mipSize, 0, internalFormat, textureType, mipFaceData);
  16117. }
  16118. }
  16119. _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  16120. }
  16121. else {
  16122. texture.generateMipMaps = !noMipmap;
  16123. _this.updateRawCubeTexture(texture, faceDataArrays, format, type, invertY);
  16124. }
  16125. texture.isReady = true;
  16126. // this.resetTextureCache();
  16127. scene._removePendingData(texture);
  16128. if (onLoad) {
  16129. onLoad();
  16130. }
  16131. };
  16132. this._loadFile(url, function (data) {
  16133. internalCallback(data);
  16134. }, undefined, scene.database, true, onerror);
  16135. return texture;
  16136. };
  16137. ;
  16138. /**
  16139. * Update a raw 3D texture
  16140. * @param texture defines the texture to update
  16141. * @param data defines the data to store
  16142. * @param format defines the data format
  16143. * @param invertY defines if data must be stored with Y axis inverted
  16144. * @param compression defines the used compression (can be null)
  16145. * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
  16146. */
  16147. Engine.prototype.updateRawTexture3D = function (texture, data, format, invertY, compression, textureType) {
  16148. if (compression === void 0) { compression = null; }
  16149. if (textureType === void 0) { textureType = Engine.TEXTURETYPE_UNSIGNED_INT; }
  16150. var internalType = this._getWebGLTextureType(textureType);
  16151. var internalFormat = this._getInternalFormat(format);
  16152. var internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);
  16153. this._bindTextureDirectly(this._gl.TEXTURE_3D, texture, true);
  16154. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  16155. if (!this._doNotHandleContextLost) {
  16156. texture._bufferView = data;
  16157. texture.format = format;
  16158. texture.invertY = invertY;
  16159. texture._compression = compression;
  16160. }
  16161. if (texture.width % 4 !== 0) {
  16162. this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);
  16163. }
  16164. if (compression && data) {
  16165. this._gl.compressedTexImage3D(this._gl.TEXTURE_3D, 0, this.getCaps().s3tc[compression], texture.width, texture.height, texture.depth, 0, data);
  16166. }
  16167. else {
  16168. this._gl.texImage3D(this._gl.TEXTURE_3D, 0, internalSizedFomat, texture.width, texture.height, texture.depth, 0, internalFormat, internalType, data);
  16169. }
  16170. if (texture.generateMipMaps) {
  16171. this._gl.generateMipmap(this._gl.TEXTURE_3D);
  16172. }
  16173. this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
  16174. // this.resetTextureCache();
  16175. texture.isReady = true;
  16176. };
  16177. /**
  16178. * Creates a new raw 3D texture
  16179. * @param data defines the data used to create the texture
  16180. * @param width defines the width of the texture
  16181. * @param height defines the height of the texture
  16182. * @param depth defines the depth of the texture
  16183. * @param format defines the format of the texture
  16184. * @param generateMipMaps defines if the engine must generate mip levels
  16185. * @param invertY defines if data must be stored with Y axis inverted
  16186. * @param samplingMode defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)
  16187. * @param compression defines the compressed used (can be null)
  16188. * @param textureType defines the compressed used (can be null)
  16189. * @returns a new raw 3D texture (stored in an InternalTexture)
  16190. */
  16191. Engine.prototype.createRawTexture3D = function (data, width, height, depth, format, generateMipMaps, invertY, samplingMode, compression, textureType) {
  16192. if (compression === void 0) { compression = null; }
  16193. if (textureType === void 0) { textureType = Engine.TEXTURETYPE_UNSIGNED_INT; }
  16194. var texture = new BABYLON.InternalTexture(this, BABYLON.InternalTexture.DATASOURCE_RAW3D);
  16195. texture.baseWidth = width;
  16196. texture.baseHeight = height;
  16197. texture.baseDepth = depth;
  16198. texture.width = width;
  16199. texture.height = height;
  16200. texture.depth = depth;
  16201. texture.format = format;
  16202. texture.type = textureType;
  16203. texture.generateMipMaps = generateMipMaps;
  16204. texture.samplingMode = samplingMode;
  16205. texture.is3D = true;
  16206. if (!this._doNotHandleContextLost) {
  16207. texture._bufferView = data;
  16208. }
  16209. this.updateRawTexture3D(texture, data, format, invertY, compression, textureType);
  16210. this._bindTextureDirectly(this._gl.TEXTURE_3D, texture, true);
  16211. // Filters
  16212. var filters = getSamplingParameters(samplingMode, generateMipMaps, this._gl);
  16213. this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
  16214. this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  16215. if (generateMipMaps) {
  16216. this._gl.generateMipmap(this._gl.TEXTURE_3D);
  16217. }
  16218. this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
  16219. this._internalTexturesCache.push(texture);
  16220. return texture;
  16221. };
  16222. Engine.prototype._prepareWebGLTextureContinuation = function (texture, scene, noMipmap, isCompressed, samplingMode) {
  16223. var gl = this._gl;
  16224. if (!gl) {
  16225. return;
  16226. }
  16227. var filters = getSamplingParameters(samplingMode, !noMipmap, gl);
  16228. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
  16229. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
  16230. if (!noMipmap && !isCompressed) {
  16231. gl.generateMipmap(gl.TEXTURE_2D);
  16232. }
  16233. this._bindTextureDirectly(gl.TEXTURE_2D, null);
  16234. // this.resetTextureCache();
  16235. if (scene) {
  16236. scene._removePendingData(texture);
  16237. }
  16238. texture.onLoadedObservable.notifyObservers(texture);
  16239. texture.onLoadedObservable.clear();
  16240. };
  16241. Engine.prototype._prepareWebGLTexture = function (texture, scene, width, height, invertY, noMipmap, isCompressed, processFunction, samplingMode) {
  16242. var _this = this;
  16243. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  16244. var potWidth = this.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(width, this.getCaps().maxTextureSize) : width;
  16245. var potHeight = this.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(height, this.getCaps().maxTextureSize) : height;
  16246. var gl = this._gl;
  16247. if (!gl) {
  16248. return;
  16249. }
  16250. if (!texture._webGLTexture) {
  16251. // this.resetTextureCache();
  16252. if (scene) {
  16253. scene._removePendingData(texture);
  16254. }
  16255. return;
  16256. }
  16257. this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
  16258. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  16259. texture.baseWidth = width;
  16260. texture.baseHeight = height;
  16261. texture.width = potWidth;
  16262. texture.height = potHeight;
  16263. texture.isReady = true;
  16264. if (processFunction(potWidth, potHeight, function () {
  16265. _this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
  16266. })) {
  16267. // Returning as texture needs extra async steps
  16268. return;
  16269. }
  16270. this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
  16271. };
  16272. Engine.prototype._convertRGBtoRGBATextureData = function (rgbData, width, height, textureType) {
  16273. // Create new RGBA data container.
  16274. var rgbaData;
  16275. if (textureType === Engine.TEXTURETYPE_FLOAT) {
  16276. rgbaData = new Float32Array(width * height * 4);
  16277. }
  16278. else {
  16279. rgbaData = new Uint32Array(width * height * 4);
  16280. }
  16281. // Convert each pixel.
  16282. for (var x = 0; x < width; x++) {
  16283. for (var y = 0; y < height; y++) {
  16284. var index = (y * width + x) * 3;
  16285. var newIndex = (y * width + x) * 4;
  16286. // Map Old Value to new value.
  16287. rgbaData[newIndex + 0] = rgbData[index + 0];
  16288. rgbaData[newIndex + 1] = rgbData[index + 1];
  16289. rgbaData[newIndex + 2] = rgbData[index + 2];
  16290. // Add fully opaque alpha channel.
  16291. rgbaData[newIndex + 3] = 1;
  16292. }
  16293. }
  16294. return rgbaData;
  16295. };
  16296. /** @hidden */
  16297. Engine.prototype._releaseFramebufferObjects = function (texture) {
  16298. var gl = this._gl;
  16299. if (texture._framebuffer) {
  16300. gl.deleteFramebuffer(texture._framebuffer);
  16301. texture._framebuffer = null;
  16302. }
  16303. if (texture._depthStencilBuffer) {
  16304. gl.deleteRenderbuffer(texture._depthStencilBuffer);
  16305. texture._depthStencilBuffer = null;
  16306. }
  16307. if (texture._MSAAFramebuffer) {
  16308. gl.deleteFramebuffer(texture._MSAAFramebuffer);
  16309. texture._MSAAFramebuffer = null;
  16310. }
  16311. if (texture._MSAARenderBuffer) {
  16312. gl.deleteRenderbuffer(texture._MSAARenderBuffer);
  16313. texture._MSAARenderBuffer = null;
  16314. }
  16315. };
  16316. /** @hidden */
  16317. Engine.prototype._releaseTexture = function (texture) {
  16318. var gl = this._gl;
  16319. this._releaseFramebufferObjects(texture);
  16320. gl.deleteTexture(texture._webGLTexture);
  16321. // Unbind channels
  16322. this.unbindAllTextures();
  16323. var index = this._internalTexturesCache.indexOf(texture);
  16324. if (index !== -1) {
  16325. this._internalTexturesCache.splice(index, 1);
  16326. }
  16327. // Integrated fixed lod samplers.
  16328. if (texture._lodTextureHigh) {
  16329. texture._lodTextureHigh.dispose();
  16330. }
  16331. if (texture._lodTextureMid) {
  16332. texture._lodTextureMid.dispose();
  16333. }
  16334. if (texture._lodTextureLow) {
  16335. texture._lodTextureLow.dispose();
  16336. }
  16337. // Set output texture of post process to null if the texture has been released/disposed
  16338. this.scenes.forEach(function (scene) {
  16339. scene.postProcesses.forEach(function (postProcess) {
  16340. if (postProcess._outputTexture == texture) {
  16341. postProcess._outputTexture = null;
  16342. }
  16343. });
  16344. scene.cameras.forEach(function (camera) {
  16345. camera._postProcesses.forEach(function (postProcess) {
  16346. if (postProcess) {
  16347. if (postProcess._outputTexture == texture) {
  16348. postProcess._outputTexture = null;
  16349. }
  16350. }
  16351. });
  16352. });
  16353. });
  16354. };
  16355. Engine.prototype.setProgram = function (program) {
  16356. if (this._currentProgram !== program) {
  16357. this._gl.useProgram(program);
  16358. this._currentProgram = program;
  16359. }
  16360. };
  16361. /**
  16362. * Binds an effect to the webGL context
  16363. * @param effect defines the effect to bind
  16364. */
  16365. Engine.prototype.bindSamplers = function (effect) {
  16366. this.setProgram(effect.getProgram());
  16367. var samplers = effect.getSamplers();
  16368. for (var index = 0; index < samplers.length; index++) {
  16369. var uniform = effect.getUniform(samplers[index]);
  16370. if (uniform) {
  16371. this._boundUniforms[index] = uniform;
  16372. }
  16373. }
  16374. this._currentEffect = null;
  16375. };
  16376. Engine.prototype._moveBoundTextureOnTop = function (internalTexture) {
  16377. if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
  16378. return;
  16379. }
  16380. // Remove
  16381. this._linkTrackers(internalTexture.previous, internalTexture.next);
  16382. // Bind last to it
  16383. this._linkTrackers(this._lastBoundInternalTextureTracker.previous, internalTexture);
  16384. // Bind to dummy
  16385. this._linkTrackers(internalTexture, this._lastBoundInternalTextureTracker);
  16386. };
  16387. Engine.prototype._getCorrectTextureChannel = function (channel, internalTexture) {
  16388. if (!internalTexture) {
  16389. return -1;
  16390. }
  16391. internalTexture._initialSlot = channel;
  16392. if (this.disableTextureBindingOptimization) { // We want texture sampler ID === texture channel
  16393. if (channel !== internalTexture._designatedSlot) {
  16394. this._textureCollisions.addCount(1, false);
  16395. }
  16396. }
  16397. else {
  16398. if (channel !== internalTexture._designatedSlot) {
  16399. if (internalTexture._designatedSlot > -1) { // Texture is already assigned to a slot
  16400. return internalTexture._designatedSlot;
  16401. }
  16402. else {
  16403. // No slot for this texture, let's pick a new one (if we find a free slot)
  16404. if (this._nextFreeTextureSlots.length) {
  16405. return this._nextFreeTextureSlots[0];
  16406. }
  16407. // We need to recycle the oldest bound texture, sorry.
  16408. this._textureCollisions.addCount(1, false);
  16409. return this._removeDesignatedSlot(this._firstBoundInternalTextureTracker.next);
  16410. }
  16411. }
  16412. }
  16413. return channel;
  16414. };
  16415. Engine.prototype._linkTrackers = function (previous, next) {
  16416. previous.next = next;
  16417. next.previous = previous;
  16418. };
  16419. Engine.prototype._removeDesignatedSlot = function (internalTexture) {
  16420. var currentSlot = internalTexture._designatedSlot;
  16421. if (currentSlot === -1) {
  16422. return -1;
  16423. }
  16424. internalTexture._designatedSlot = -1;
  16425. if (this.disableTextureBindingOptimization) {
  16426. return -1;
  16427. }
  16428. // Remove from bound list
  16429. this._linkTrackers(internalTexture.previous, internalTexture.next);
  16430. // Free the slot
  16431. this._boundTexturesCache[currentSlot] = null;
  16432. this._nextFreeTextureSlots.push(currentSlot);
  16433. return currentSlot;
  16434. };
  16435. Engine.prototype._activateCurrentTexture = function () {
  16436. if (this._currentTextureChannel !== this._activeChannel) {
  16437. this._gl.activeTexture(this._gl.TEXTURE0 + this._activeChannel);
  16438. this._currentTextureChannel = this._activeChannel;
  16439. }
  16440. };
  16441. /** @hidden */
  16442. Engine.prototype._bindTextureDirectly = function (target, texture, forTextureDataUpdate, force) {
  16443. if (forTextureDataUpdate === void 0) { forTextureDataUpdate = false; }
  16444. if (force === void 0) { force = false; }
  16445. if (forTextureDataUpdate && texture && texture._designatedSlot > -1) {
  16446. this._activeChannel = texture._designatedSlot;
  16447. }
  16448. var currentTextureBound = this._boundTexturesCache[this._activeChannel];
  16449. var isTextureForRendering = texture && texture._initialSlot > -1;
  16450. if (currentTextureBound !== texture || force) {
  16451. if (currentTextureBound) {
  16452. this._removeDesignatedSlot(currentTextureBound);
  16453. }
  16454. this._activateCurrentTexture();
  16455. this._gl.bindTexture(target, texture ? texture._webGLTexture : null);
  16456. this._boundTexturesCache[this._activeChannel] = texture;
  16457. if (texture) {
  16458. if (!this.disableTextureBindingOptimization) {
  16459. var slotIndex = this._nextFreeTextureSlots.indexOf(this._activeChannel);
  16460. if (slotIndex > -1) {
  16461. this._nextFreeTextureSlots.splice(slotIndex, 1);
  16462. }
  16463. this._linkTrackers(this._lastBoundInternalTextureTracker.previous, texture);
  16464. this._linkTrackers(texture, this._lastBoundInternalTextureTracker);
  16465. }
  16466. texture._designatedSlot = this._activeChannel;
  16467. }
  16468. }
  16469. else if (forTextureDataUpdate) {
  16470. this._activateCurrentTexture();
  16471. }
  16472. if (isTextureForRendering && !forTextureDataUpdate) {
  16473. this._bindSamplerUniformToChannel(texture._initialSlot, this._activeChannel);
  16474. }
  16475. };
  16476. /** @hidden */
  16477. Engine.prototype._bindTexture = function (channel, texture) {
  16478. if (channel < 0) {
  16479. return;
  16480. }
  16481. if (texture) {
  16482. channel = this._getCorrectTextureChannel(channel, texture);
  16483. }
  16484. this._activeChannel = channel;
  16485. this._bindTextureDirectly(this._gl.TEXTURE_2D, texture);
  16486. };
  16487. /**
  16488. * Sets a texture to the webGL context from a postprocess
  16489. * @param channel defines the channel to use
  16490. * @param postProcess defines the source postprocess
  16491. */
  16492. Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
  16493. this._bindTexture(channel, postProcess ? postProcess._textures.data[postProcess._currentRenderTextureInd] : null);
  16494. };
  16495. /**
  16496. * Binds the output of the passed in post process to the texture channel specified
  16497. * @param channel The channel the texture should be bound to
  16498. * @param postProcess The post process which's output should be bound
  16499. */
  16500. Engine.prototype.setTextureFromPostProcessOutput = function (channel, postProcess) {
  16501. this._bindTexture(channel, postProcess ? postProcess._outputTexture : null);
  16502. };
  16503. /**
  16504. * Unbind all textures from the webGL context
  16505. */
  16506. Engine.prototype.unbindAllTextures = function () {
  16507. for (var channel = 0; channel < this._maxSimultaneousTextures; channel++) {
  16508. this._activeChannel = channel;
  16509. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  16510. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
  16511. if (this.webGLVersion > 1) {
  16512. this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
  16513. }
  16514. }
  16515. };
  16516. /**
  16517. * Sets a texture to the according uniform.
  16518. * @param channel The texture channel
  16519. * @param uniform The uniform to set
  16520. * @param texture The texture to apply
  16521. */
  16522. Engine.prototype.setTexture = function (channel, uniform, texture) {
  16523. if (channel < 0) {
  16524. return;
  16525. }
  16526. if (uniform) {
  16527. this._boundUniforms[channel] = uniform;
  16528. }
  16529. this._setTexture(channel, texture);
  16530. };
  16531. /**
  16532. * Sets a depth stencil texture from a render target to the according uniform.
  16533. * @param channel The texture channel
  16534. * @param uniform The uniform to set
  16535. * @param texture The render target texture containing the depth stencil texture to apply
  16536. */
  16537. Engine.prototype.setDepthStencilTexture = function (channel, uniform, texture) {
  16538. if (channel < 0) {
  16539. return;
  16540. }
  16541. if (uniform) {
  16542. this._boundUniforms[channel] = uniform;
  16543. }
  16544. if (!texture || !texture.depthStencilTexture) {
  16545. this._setTexture(channel, null);
  16546. }
  16547. else {
  16548. this._setTexture(channel, texture, false, true);
  16549. }
  16550. };
  16551. Engine.prototype._bindSamplerUniformToChannel = function (sourceSlot, destination) {
  16552. var uniform = this._boundUniforms[sourceSlot];
  16553. if (uniform._currentState === destination) {
  16554. return;
  16555. }
  16556. this._gl.uniform1i(uniform, destination);
  16557. uniform._currentState = destination;
  16558. };
  16559. Engine.prototype._getTextureWrapMode = function (mode) {
  16560. switch (mode) {
  16561. case BABYLON.Texture.WRAP_ADDRESSMODE:
  16562. return this._gl.REPEAT;
  16563. case BABYLON.Texture.CLAMP_ADDRESSMODE:
  16564. return this._gl.CLAMP_TO_EDGE;
  16565. case BABYLON.Texture.MIRROR_ADDRESSMODE:
  16566. return this._gl.MIRRORED_REPEAT;
  16567. }
  16568. return this._gl.REPEAT;
  16569. };
  16570. Engine.prototype._setTexture = function (channel, texture, isPartOfTextureArray, depthStencilTexture) {
  16571. if (isPartOfTextureArray === void 0) { isPartOfTextureArray = false; }
  16572. if (depthStencilTexture === void 0) { depthStencilTexture = false; }
  16573. // Not ready?
  16574. if (!texture) {
  16575. if (this._boundTexturesCache[channel] != null) {
  16576. this._activeChannel = channel;
  16577. this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
  16578. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
  16579. if (this.webGLVersion > 1) {
  16580. this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
  16581. }
  16582. }
  16583. return false;
  16584. }
  16585. // Video
  16586. if (texture.video) {
  16587. this._activeChannel = channel;
  16588. texture.update();
  16589. }
  16590. else if (texture.delayLoadState === Engine.DELAYLOADSTATE_NOTLOADED) { // Delay loading
  16591. texture.delayLoad();
  16592. return false;
  16593. }
  16594. var internalTexture;
  16595. if (depthStencilTexture) {
  16596. internalTexture = texture.depthStencilTexture;
  16597. }
  16598. else if (texture.isReady()) {
  16599. internalTexture = texture.getInternalTexture();
  16600. }
  16601. else if (texture.isCube) {
  16602. internalTexture = this.emptyCubeTexture;
  16603. }
  16604. else if (texture.is3D) {
  16605. internalTexture = this.emptyTexture3D;
  16606. }
  16607. else {
  16608. internalTexture = this.emptyTexture;
  16609. }
  16610. if (!isPartOfTextureArray) {
  16611. channel = this._getCorrectTextureChannel(channel, internalTexture);
  16612. }
  16613. var needToBind = true;
  16614. if (this._boundTexturesCache[channel] === internalTexture) {
  16615. this._moveBoundTextureOnTop(internalTexture);
  16616. if (!isPartOfTextureArray) {
  16617. this._bindSamplerUniformToChannel(internalTexture._initialSlot, channel);
  16618. }
  16619. needToBind = false;
  16620. }
  16621. this._activeChannel = channel;
  16622. if (internalTexture && internalTexture.is3D) {
  16623. if (needToBind) {
  16624. this._bindTextureDirectly(this._gl.TEXTURE_3D, internalTexture, isPartOfTextureArray);
  16625. }
  16626. if (internalTexture && internalTexture._cachedWrapU !== texture.wrapU) {
  16627. internalTexture._cachedWrapU = texture.wrapU;
  16628. this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);
  16629. }
  16630. if (internalTexture && internalTexture._cachedWrapV !== texture.wrapV) {
  16631. internalTexture._cachedWrapV = texture.wrapV;
  16632. this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);
  16633. }
  16634. if (internalTexture && internalTexture._cachedWrapR !== texture.wrapR) {
  16635. internalTexture._cachedWrapR = texture.wrapR;
  16636. this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(texture.wrapR), internalTexture);
  16637. }
  16638. this._setAnisotropicLevel(this._gl.TEXTURE_3D, texture);
  16639. }
  16640. else if (internalTexture && internalTexture.isCube) {
  16641. if (needToBind) {
  16642. this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, internalTexture, isPartOfTextureArray);
  16643. }
  16644. if (internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {
  16645. internalTexture._cachedCoordinatesMode = texture.coordinatesMode;
  16646. // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.
  16647. var textureWrapMode = (texture.coordinatesMode !== BABYLON.Texture.CUBIC_MODE && texture.coordinatesMode !== BABYLON.Texture.SKYBOX_MODE) ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE;
  16648. this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, textureWrapMode, internalTexture);
  16649. this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, textureWrapMode);
  16650. }
  16651. this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture);
  16652. }
  16653. else {
  16654. if (needToBind) {
  16655. this._bindTextureDirectly(this._gl.TEXTURE_2D, internalTexture, isPartOfTextureArray);
  16656. }
  16657. if (internalTexture && internalTexture._cachedWrapU !== texture.wrapU) {
  16658. internalTexture._cachedWrapU = texture.wrapU;
  16659. this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);
  16660. }
  16661. if (internalTexture && internalTexture._cachedWrapV !== texture.wrapV) {
  16662. internalTexture._cachedWrapV = texture.wrapV;
  16663. this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);
  16664. }
  16665. this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
  16666. }
  16667. return true;
  16668. };
  16669. /**
  16670. * Sets an array of texture to the webGL context
  16671. * @param channel defines the channel where the texture array must be set
  16672. * @param uniform defines the associated uniform location
  16673. * @param textures defines the array of textures to bind
  16674. */
  16675. Engine.prototype.setTextureArray = function (channel, uniform, textures) {
  16676. if (channel < 0 || !uniform) {
  16677. return;
  16678. }
  16679. if (!this._textureUnits || this._textureUnits.length !== textures.length) {
  16680. this._textureUnits = new Int32Array(textures.length);
  16681. }
  16682. for (var i = 0; i < textures.length; i++) {
  16683. this._textureUnits[i] = this._getCorrectTextureChannel(channel + i, textures[i].getInternalTexture());
  16684. }
  16685. this._gl.uniform1iv(uniform, this._textureUnits);
  16686. for (var index = 0; index < textures.length; index++) {
  16687. this._setTexture(this._textureUnits[index], textures[index], true);
  16688. }
  16689. };
  16690. /** @hidden */
  16691. Engine.prototype._setAnisotropicLevel = function (target, texture) {
  16692. var internalTexture = texture.getInternalTexture();
  16693. if (!internalTexture) {
  16694. return;
  16695. }
  16696. var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
  16697. var value = texture.anisotropicFilteringLevel;
  16698. if (internalTexture.samplingMode !== BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST
  16699. && internalTexture.samplingMode !== BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR
  16700. && internalTexture.samplingMode !== BABYLON.Texture.LINEAR_LINEAR) {
  16701. value = 1; // Forcing the anisotropic to 1 because else webgl will force filters to linear
  16702. }
  16703. if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== value) {
  16704. this._setTextureParameterFloat(target, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy), internalTexture);
  16705. internalTexture._cachedAnisotropicFilteringLevel = value;
  16706. }
  16707. };
  16708. Engine.prototype._setTextureParameterFloat = function (target, parameter, value, texture) {
  16709. this._bindTextureDirectly(target, texture, true, true);
  16710. this._gl.texParameterf(target, parameter, value);
  16711. };
  16712. Engine.prototype._setTextureParameterInteger = function (target, parameter, value, texture) {
  16713. if (texture) {
  16714. this._bindTextureDirectly(target, texture, true, true);
  16715. }
  16716. this._gl.texParameteri(target, parameter, value);
  16717. };
  16718. /**
  16719. * Reads pixels from the current frame buffer. Please note that this function can be slow
  16720. * @param x defines the x coordinate of the rectangle where pixels must be read
  16721. * @param y defines the y coordinate of the rectangle where pixels must be read
  16722. * @param width defines the width of the rectangle where pixels must be read
  16723. * @param height defines the height of the rectangle where pixels must be read
  16724. * @returns a Uint8Array containing RGBA colors
  16725. */
  16726. Engine.prototype.readPixels = function (x, y, width, height) {
  16727. var data = new Uint8Array(height * width * 4);
  16728. this._gl.readPixels(x, y, width, height, this._gl.RGBA, this._gl.UNSIGNED_BYTE, data);
  16729. return data;
  16730. };
  16731. /**
  16732. * Add an externaly attached data from its key.
  16733. * This method call will fail and return false, if such key already exists.
  16734. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  16735. * @param key the unique key that identifies the data
  16736. * @param data the data object to associate to the key for this Engine instance
  16737. * @return true if no such key were already present and the data was added successfully, false otherwise
  16738. */
  16739. Engine.prototype.addExternalData = function (key, data) {
  16740. if (!this._externalData) {
  16741. this._externalData = new BABYLON.StringDictionary();
  16742. }
  16743. return this._externalData.add(key, data);
  16744. };
  16745. /**
  16746. * Get an externaly attached data from its key
  16747. * @param key the unique key that identifies the data
  16748. * @return the associated data, if present (can be null), or undefined if not present
  16749. */
  16750. Engine.prototype.getExternalData = function (key) {
  16751. if (!this._externalData) {
  16752. this._externalData = new BABYLON.StringDictionary();
  16753. }
  16754. return this._externalData.get(key);
  16755. };
  16756. /**
  16757. * Get an externaly attached data from its key, create it using a factory if it's not already present
  16758. * @param key the unique key that identifies the data
  16759. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  16760. * @return the associated data, can be null if the factory returned null.
  16761. */
  16762. Engine.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  16763. if (!this._externalData) {
  16764. this._externalData = new BABYLON.StringDictionary();
  16765. }
  16766. return this._externalData.getOrAddWithFactory(key, factory);
  16767. };
  16768. /**
  16769. * Remove an externaly attached data from the Engine instance
  16770. * @param key the unique key that identifies the data
  16771. * @return true if the data was successfully removed, false if it doesn't exist
  16772. */
  16773. Engine.prototype.removeExternalData = function (key) {
  16774. if (!this._externalData) {
  16775. this._externalData = new BABYLON.StringDictionary();
  16776. }
  16777. return this._externalData.remove(key);
  16778. };
  16779. /**
  16780. * Unbind all vertex attributes from the webGL context
  16781. */
  16782. Engine.prototype.unbindAllAttributes = function () {
  16783. if (this._mustWipeVertexAttributes) {
  16784. this._mustWipeVertexAttributes = false;
  16785. for (var i = 0; i < this._caps.maxVertexAttribs; i++) {
  16786. this._gl.disableVertexAttribArray(i);
  16787. this._vertexAttribArraysEnabled[i] = false;
  16788. this._currentBufferPointers[i].active = false;
  16789. }
  16790. return;
  16791. }
  16792. for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
  16793. if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
  16794. continue;
  16795. }
  16796. this._gl.disableVertexAttribArray(i);
  16797. this._vertexAttribArraysEnabled[i] = false;
  16798. this._currentBufferPointers[i].active = false;
  16799. }
  16800. };
  16801. /**
  16802. * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled
  16803. */
  16804. Engine.prototype.releaseEffects = function () {
  16805. for (var name in this._compiledEffects) {
  16806. this._deleteProgram(this._compiledEffects[name]._program);
  16807. }
  16808. this._compiledEffects = {};
  16809. };
  16810. /**
  16811. * Dispose and release all associated resources
  16812. */
  16813. Engine.prototype.dispose = function () {
  16814. this.hideLoadingUI();
  16815. this.stopRenderLoop();
  16816. // Release postProcesses
  16817. while (this.postProcesses.length) {
  16818. this.postProcesses[0].dispose();
  16819. }
  16820. // Empty texture
  16821. if (this._emptyTexture) {
  16822. this._releaseTexture(this._emptyTexture);
  16823. this._emptyTexture = null;
  16824. }
  16825. if (this._emptyCubeTexture) {
  16826. this._releaseTexture(this._emptyCubeTexture);
  16827. this._emptyCubeTexture = null;
  16828. }
  16829. // Rescale PP
  16830. if (this._rescalePostProcess) {
  16831. this._rescalePostProcess.dispose();
  16832. }
  16833. // Release scenes
  16834. while (this.scenes.length) {
  16835. this.scenes[0].dispose();
  16836. }
  16837. // Release audio engine
  16838. if (Engine.audioEngine) {
  16839. Engine.audioEngine.dispose();
  16840. }
  16841. // Release effects
  16842. this.releaseEffects();
  16843. // Unbind
  16844. this.unbindAllAttributes();
  16845. this._boundUniforms = [];
  16846. if (this._dummyFramebuffer) {
  16847. this._gl.deleteFramebuffer(this._dummyFramebuffer);
  16848. }
  16849. //WebVR
  16850. this.disableVR();
  16851. // Events
  16852. if (BABYLON.Tools.IsWindowObjectExist()) {
  16853. window.removeEventListener("blur", this._onBlur);
  16854. window.removeEventListener("focus", this._onFocus);
  16855. window.removeEventListener('vrdisplaypointerrestricted', this._onVRDisplayPointerRestricted);
  16856. window.removeEventListener('vrdisplaypointerunrestricted', this._onVRDisplayPointerUnrestricted);
  16857. if (this._renderingCanvas) {
  16858. this._renderingCanvas.removeEventListener("focus", this._onCanvasFocus);
  16859. this._renderingCanvas.removeEventListener("blur", this._onCanvasBlur);
  16860. this._renderingCanvas.removeEventListener("pointerout", this._onCanvasPointerOut);
  16861. if (!this._doNotHandleContextLost) {
  16862. this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
  16863. this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
  16864. }
  16865. }
  16866. document.removeEventListener("fullscreenchange", this._onFullscreenChange);
  16867. document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
  16868. document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
  16869. document.removeEventListener("msfullscreenchange", this._onFullscreenChange);
  16870. document.removeEventListener("pointerlockchange", this._onPointerLockChange);
  16871. document.removeEventListener("mspointerlockchange", this._onPointerLockChange);
  16872. document.removeEventListener("mozpointerlockchange", this._onPointerLockChange);
  16873. document.removeEventListener("webkitpointerlockchange", this._onPointerLockChange);
  16874. if (this._onVrDisplayConnect) {
  16875. window.removeEventListener('vrdisplayconnect', this._onVrDisplayConnect);
  16876. if (this._onVrDisplayDisconnect) {
  16877. window.removeEventListener('vrdisplaydisconnect', this._onVrDisplayDisconnect);
  16878. }
  16879. if (this._onVrDisplayPresentChange) {
  16880. window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
  16881. }
  16882. this._onVrDisplayConnect = null;
  16883. this._onVrDisplayDisconnect = null;
  16884. }
  16885. }
  16886. // Remove from Instances
  16887. var index = Engine.Instances.indexOf(this);
  16888. if (index >= 0) {
  16889. Engine.Instances.splice(index, 1);
  16890. }
  16891. this._workingCanvas = null;
  16892. this._workingContext = null;
  16893. this._currentBufferPointers = [];
  16894. this._renderingCanvas = null;
  16895. this._currentProgram = null;
  16896. this._bindedRenderFunction = null;
  16897. this.onResizeObservable.clear();
  16898. this.onCanvasBlurObservable.clear();
  16899. this.onCanvasFocusObservable.clear();
  16900. this.onCanvasPointerOutObservable.clear();
  16901. this.onBeginFrameObservable.clear();
  16902. this.onEndFrameObservable.clear();
  16903. BABYLON.Effect.ResetCache();
  16904. // Abort active requests
  16905. for (var _i = 0, _a = this._activeRequests; _i < _a.length; _i++) {
  16906. var request = _a[_i];
  16907. request.abort();
  16908. }
  16909. };
  16910. // Loading screen
  16911. /**
  16912. * Display the loading screen
  16913. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16914. */
  16915. Engine.prototype.displayLoadingUI = function () {
  16916. if (!BABYLON.Tools.IsWindowObjectExist()) {
  16917. return;
  16918. }
  16919. var loadingScreen = this.loadingScreen;
  16920. if (loadingScreen) {
  16921. loadingScreen.displayLoadingUI();
  16922. }
  16923. };
  16924. /**
  16925. * Hide the loading screen
  16926. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16927. */
  16928. Engine.prototype.hideLoadingUI = function () {
  16929. if (!BABYLON.Tools.IsWindowObjectExist()) {
  16930. return;
  16931. }
  16932. var loadingScreen = this.loadingScreen;
  16933. if (loadingScreen) {
  16934. loadingScreen.hideLoadingUI();
  16935. }
  16936. };
  16937. Object.defineProperty(Engine.prototype, "loadingScreen", {
  16938. /**
  16939. * Gets the current loading screen object
  16940. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16941. */
  16942. get: function () {
  16943. if (!this._loadingScreen && BABYLON.DefaultLoadingScreen && this._renderingCanvas)
  16944. this._loadingScreen = new BABYLON.DefaultLoadingScreen(this._renderingCanvas);
  16945. return this._loadingScreen;
  16946. },
  16947. /**
  16948. * Sets the current loading screen object
  16949. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16950. */
  16951. set: function (loadingScreen) {
  16952. this._loadingScreen = loadingScreen;
  16953. },
  16954. enumerable: true,
  16955. configurable: true
  16956. });
  16957. Object.defineProperty(Engine.prototype, "loadingUIText", {
  16958. /**
  16959. * Sets the current loading screen text
  16960. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16961. */
  16962. set: function (text) {
  16963. this.loadingScreen.loadingUIText = text;
  16964. },
  16965. enumerable: true,
  16966. configurable: true
  16967. });
  16968. Object.defineProperty(Engine.prototype, "loadingUIBackgroundColor", {
  16969. /**
  16970. * Sets the current loading screen background color
  16971. * @see http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen
  16972. */
  16973. set: function (color) {
  16974. this.loadingScreen.loadingUIBackgroundColor = color;
  16975. },
  16976. enumerable: true,
  16977. configurable: true
  16978. });
  16979. /**
  16980. * Attach a new callback raised when context lost event is fired
  16981. * @param callback defines the callback to call
  16982. */
  16983. Engine.prototype.attachContextLostEvent = function (callback) {
  16984. if (this._renderingCanvas) {
  16985. this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
  16986. }
  16987. };
  16988. /**
  16989. * Attach a new callback raised when context restored event is fired
  16990. * @param callback defines the callback to call
  16991. */
  16992. Engine.prototype.attachContextRestoredEvent = function (callback) {
  16993. if (this._renderingCanvas) {
  16994. this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
  16995. }
  16996. };
  16997. /**
  16998. * Gets the source code of the vertex shader associated with a specific webGL program
  16999. * @param program defines the program to use
  17000. * @returns a string containing the source code of the vertex shader associated with the program
  17001. */
  17002. Engine.prototype.getVertexShaderSource = function (program) {
  17003. var shaders = this._gl.getAttachedShaders(program);
  17004. if (!shaders) {
  17005. return null;
  17006. }
  17007. return this._gl.getShaderSource(shaders[0]);
  17008. };
  17009. /**
  17010. * Gets the source code of the fragment shader associated with a specific webGL program
  17011. * @param program defines the program to use
  17012. * @returns a string containing the source code of the fragment shader associated with the program
  17013. */
  17014. Engine.prototype.getFragmentShaderSource = function (program) {
  17015. var shaders = this._gl.getAttachedShaders(program);
  17016. if (!shaders) {
  17017. return null;
  17018. }
  17019. return this._gl.getShaderSource(shaders[1]);
  17020. };
  17021. /**
  17022. * Get the current error code of the webGL context
  17023. * @returns the error code
  17024. * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
  17025. */
  17026. Engine.prototype.getError = function () {
  17027. return this._gl.getError();
  17028. };
  17029. // FPS
  17030. /**
  17031. * Gets the current framerate
  17032. * @returns a number representing the framerate
  17033. */
  17034. Engine.prototype.getFps = function () {
  17035. return this._fps;
  17036. };
  17037. /**
  17038. * Gets the time spent between current and previous frame
  17039. * @returns a number representing the delta time in ms
  17040. */
  17041. Engine.prototype.getDeltaTime = function () {
  17042. return this._deltaTime;
  17043. };
  17044. Engine.prototype._measureFps = function () {
  17045. this._performanceMonitor.sampleFrame();
  17046. this._fps = this._performanceMonitor.averageFPS;
  17047. this._deltaTime = this._performanceMonitor.instantaneousFrameTime || 0;
  17048. };
  17049. /** @hidden */
  17050. Engine.prototype._readTexturePixels = function (texture, width, height, faceIndex, level) {
  17051. if (faceIndex === void 0) { faceIndex = -1; }
  17052. if (level === void 0) { level = 0; }
  17053. var gl = this._gl;
  17054. if (!this._dummyFramebuffer) {
  17055. var dummy = gl.createFramebuffer();
  17056. if (!dummy) {
  17057. throw new Error("Unable to create dummy framebuffer");
  17058. }
  17059. this._dummyFramebuffer = dummy;
  17060. }
  17061. gl.bindFramebuffer(gl.FRAMEBUFFER, this._dummyFramebuffer);
  17062. if (faceIndex > -1) {
  17063. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, texture._webGLTexture, level);
  17064. }
  17065. else {
  17066. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._webGLTexture, level);
  17067. }
  17068. var readType = (texture.type !== undefined) ? this._getWebGLTextureType(texture.type) : gl.UNSIGNED_BYTE;
  17069. var buffer;
  17070. switch (readType) {
  17071. case gl.UNSIGNED_BYTE:
  17072. buffer = new Uint8Array(4 * width * height);
  17073. readType = gl.UNSIGNED_BYTE;
  17074. break;
  17075. default:
  17076. buffer = new Float32Array(4 * width * height);
  17077. readType = gl.FLOAT;
  17078. break;
  17079. }
  17080. gl.readPixels(0, 0, width, height, gl.RGBA, readType, buffer);
  17081. gl.bindFramebuffer(gl.FRAMEBUFFER, this._currentFramebuffer);
  17082. return buffer;
  17083. };
  17084. Engine.prototype._canRenderToFloatFramebuffer = function () {
  17085. if (this._webGLVersion > 1) {
  17086. return this._caps.colorBufferFloat;
  17087. }
  17088. return this._canRenderToFramebuffer(Engine.TEXTURETYPE_FLOAT);
  17089. };
  17090. Engine.prototype._canRenderToHalfFloatFramebuffer = function () {
  17091. if (this._webGLVersion > 1) {
  17092. return this._caps.colorBufferFloat;
  17093. }
  17094. return this._canRenderToFramebuffer(Engine.TEXTURETYPE_HALF_FLOAT);
  17095. };
  17096. // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture
  17097. Engine.prototype._canRenderToFramebuffer = function (type) {
  17098. var gl = this._gl;
  17099. //clear existing errors
  17100. while (gl.getError() !== gl.NO_ERROR) { }
  17101. var successful = true;
  17102. var texture = gl.createTexture();
  17103. gl.bindTexture(gl.TEXTURE_2D, texture);
  17104. gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(type), 1, 1, 0, gl.RGBA, this._getWebGLTextureType(type), null);
  17105. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  17106. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  17107. var fb = gl.createFramebuffer();
  17108. gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
  17109. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
  17110. var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
  17111. successful = successful && (status === gl.FRAMEBUFFER_COMPLETE);
  17112. successful = successful && (gl.getError() === gl.NO_ERROR);
  17113. //try render by clearing frame buffer's color buffer
  17114. if (successful) {
  17115. gl.clear(gl.COLOR_BUFFER_BIT);
  17116. successful = successful && (gl.getError() === gl.NO_ERROR);
  17117. }
  17118. //try reading from frame to ensure render occurs (just creating the FBO is not sufficient to determine if rendering is supported)
  17119. if (successful) {
  17120. //in practice it's sufficient to just read from the backbuffer rather than handle potentially issues reading from the texture
  17121. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  17122. var readFormat = gl.RGBA;
  17123. var readType = gl.UNSIGNED_BYTE;
  17124. var buffer = new Uint8Array(4);
  17125. gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);
  17126. successful = successful && (gl.getError() === gl.NO_ERROR);
  17127. }
  17128. //clean up
  17129. gl.deleteTexture(texture);
  17130. gl.deleteFramebuffer(fb);
  17131. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  17132. //clear accumulated errors
  17133. while (!successful && (gl.getError() !== gl.NO_ERROR)) { }
  17134. return successful;
  17135. };
  17136. /** @hidden */
  17137. Engine.prototype._getWebGLTextureType = function (type) {
  17138. if (type === Engine.TEXTURETYPE_FLOAT) {
  17139. return this._gl.FLOAT;
  17140. }
  17141. else if (type === Engine.TEXTURETYPE_HALF_FLOAT) {
  17142. // Add Half Float Constant.
  17143. return this._gl.HALF_FLOAT_OES;
  17144. }
  17145. return this._gl.UNSIGNED_BYTE;
  17146. };
  17147. ;
  17148. Engine.prototype._getInternalFormat = function (format) {
  17149. var internalFormat = this._gl.RGBA;
  17150. switch (format) {
  17151. case Engine.TEXTUREFORMAT_ALPHA:
  17152. internalFormat = this._gl.ALPHA;
  17153. break;
  17154. case Engine.TEXTUREFORMAT_LUMINANCE:
  17155. internalFormat = this._gl.LUMINANCE;
  17156. break;
  17157. case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
  17158. internalFormat = this._gl.LUMINANCE_ALPHA;
  17159. break;
  17160. case Engine.TEXTUREFORMAT_RGB:
  17161. internalFormat = this._gl.RGB;
  17162. break;
  17163. case Engine.TEXTUREFORMAT_RGBA:
  17164. internalFormat = this._gl.RGBA;
  17165. break;
  17166. case Engine.TEXTUREFORMAT_R:
  17167. internalFormat = this._gl.RED;
  17168. break;
  17169. case Engine.TEXTUREFORMAT_RG:
  17170. internalFormat = this._gl.RG;
  17171. break;
  17172. }
  17173. return internalFormat;
  17174. };
  17175. /** @hidden */
  17176. Engine.prototype._getRGBABufferInternalSizedFormat = function (type, format) {
  17177. if (this._webGLVersion === 1) {
  17178. if (format !== undefined) {
  17179. switch (format) {
  17180. case Engine.TEXTUREFORMAT_LUMINANCE:
  17181. return this._gl.LUMINANCE;
  17182. case Engine.TEXTUREFORMAT_ALPHA:
  17183. return this._gl.ALPHA;
  17184. }
  17185. }
  17186. return this._gl.RGBA;
  17187. }
  17188. if (type === Engine.TEXTURETYPE_FLOAT) {
  17189. if (format !== undefined) {
  17190. switch (format) {
  17191. case Engine.TEXTUREFORMAT_R:
  17192. return this._gl.R32F;
  17193. case Engine.TEXTUREFORMAT_RG:
  17194. return this._gl.RG32F;
  17195. case Engine.TEXTUREFORMAT_RGB:
  17196. return this._gl.RGB32F;
  17197. }
  17198. }
  17199. return this._gl.RGBA32F;
  17200. }
  17201. if (type === Engine.TEXTURETYPE_HALF_FLOAT) {
  17202. if (format) {
  17203. switch (format) {
  17204. case Engine.TEXTUREFORMAT_R:
  17205. return this._gl.R16F;
  17206. case Engine.TEXTUREFORMAT_RG:
  17207. return this._gl.RG16F;
  17208. case Engine.TEXTUREFORMAT_RGB:
  17209. return this._gl.RGB16F;
  17210. }
  17211. }
  17212. return this._gl.RGBA16F;
  17213. }
  17214. if (format !== undefined) {
  17215. switch (format) {
  17216. case Engine.TEXTUREFORMAT_LUMINANCE:
  17217. return this._gl.LUMINANCE;
  17218. case Engine.TEXTUREFORMAT_RGB:
  17219. return this._gl.RGB;
  17220. case Engine.TEXTUREFORMAT_R:
  17221. return this._gl.R8;
  17222. case Engine.TEXTUREFORMAT_RG:
  17223. return this._gl.RG8;
  17224. case Engine.TEXTUREFORMAT_ALPHA:
  17225. return this._gl.ALPHA;
  17226. }
  17227. }
  17228. return this._gl.RGBA;
  17229. };
  17230. ;
  17231. /** @hidden */
  17232. Engine.prototype._getRGBAMultiSampleBufferFormat = function (type) {
  17233. if (type === Engine.TEXTURETYPE_FLOAT) {
  17234. return this._gl.RGBA32F;
  17235. }
  17236. else if (type === Engine.TEXTURETYPE_HALF_FLOAT) {
  17237. return this._gl.RGBA16F;
  17238. }
  17239. return this._gl.RGBA8;
  17240. };
  17241. ;
  17242. /**
  17243. * Create a new webGL query (you must be sure that queries are supported by checking getCaps() function)
  17244. * @return the new query
  17245. */
  17246. Engine.prototype.createQuery = function () {
  17247. return this._gl.createQuery();
  17248. };
  17249. /**
  17250. * Delete and release a webGL query
  17251. * @param query defines the query to delete
  17252. * @return the current engine
  17253. */
  17254. Engine.prototype.deleteQuery = function (query) {
  17255. this._gl.deleteQuery(query);
  17256. return this;
  17257. };
  17258. /**
  17259. * Check if a given query has resolved and got its value
  17260. * @param query defines the query to check
  17261. * @returns true if the query got its value
  17262. */
  17263. Engine.prototype.isQueryResultAvailable = function (query) {
  17264. return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT_AVAILABLE);
  17265. };
  17266. /**
  17267. * Gets the value of a given query
  17268. * @param query defines the query to check
  17269. * @returns the value of the query
  17270. */
  17271. Engine.prototype.getQueryResult = function (query) {
  17272. return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT);
  17273. };
  17274. /**
  17275. * Initiates an occlusion query
  17276. * @param algorithmType defines the algorithm to use
  17277. * @param query defines the query to use
  17278. * @returns the current engine
  17279. * @see http://doc.babylonjs.com/features/occlusionquery
  17280. */
  17281. Engine.prototype.beginOcclusionQuery = function (algorithmType, query) {
  17282. var glAlgorithm = this.getGlAlgorithmType(algorithmType);
  17283. this._gl.beginQuery(glAlgorithm, query);
  17284. return this;
  17285. };
  17286. /**
  17287. * Ends an occlusion query
  17288. * @see http://doc.babylonjs.com/features/occlusionquery
  17289. * @param algorithmType defines the algorithm to use
  17290. * @returns the current engine
  17291. */
  17292. Engine.prototype.endOcclusionQuery = function (algorithmType) {
  17293. var glAlgorithm = this.getGlAlgorithmType(algorithmType);
  17294. this._gl.endQuery(glAlgorithm);
  17295. return this;
  17296. };
  17297. /* Time queries */
  17298. Engine.prototype._createTimeQuery = function () {
  17299. var timerQuery = this._caps.timerQuery;
  17300. if (timerQuery.createQueryEXT) {
  17301. return timerQuery.createQueryEXT();
  17302. }
  17303. return this.createQuery();
  17304. };
  17305. Engine.prototype._deleteTimeQuery = function (query) {
  17306. var timerQuery = this._caps.timerQuery;
  17307. if (timerQuery.deleteQueryEXT) {
  17308. timerQuery.deleteQueryEXT(query);
  17309. return;
  17310. }
  17311. this.deleteQuery(query);
  17312. };
  17313. Engine.prototype._getTimeQueryResult = function (query) {
  17314. var timerQuery = this._caps.timerQuery;
  17315. if (timerQuery.getQueryObjectEXT) {
  17316. return timerQuery.getQueryObjectEXT(query, timerQuery.QUERY_RESULT_EXT);
  17317. }
  17318. return this.getQueryResult(query);
  17319. };
  17320. Engine.prototype._getTimeQueryAvailability = function (query) {
  17321. var timerQuery = this._caps.timerQuery;
  17322. if (timerQuery.getQueryObjectEXT) {
  17323. return timerQuery.getQueryObjectEXT(query, timerQuery.QUERY_RESULT_AVAILABLE_EXT);
  17324. }
  17325. return this.isQueryResultAvailable(query);
  17326. };
  17327. /**
  17328. * Starts a time query (used to measure time spent by the GPU on a specific frame)
  17329. * Please note that only one query can be issued at a time
  17330. * @returns a time token used to track the time span
  17331. */
  17332. Engine.prototype.startTimeQuery = function () {
  17333. var timerQuery = this._caps.timerQuery;
  17334. if (!timerQuery) {
  17335. return null;
  17336. }
  17337. var token = new BABYLON._TimeToken();
  17338. this._gl.getParameter(timerQuery.GPU_DISJOINT_EXT);
  17339. if (this._caps.canUseTimestampForTimerQuery) {
  17340. token._startTimeQuery = this._createTimeQuery();
  17341. timerQuery.queryCounterEXT(token._startTimeQuery, timerQuery.TIMESTAMP_EXT);
  17342. }
  17343. else {
  17344. if (this._currentNonTimestampToken) {
  17345. return this._currentNonTimestampToken;
  17346. }
  17347. token._timeElapsedQuery = this._createTimeQuery();
  17348. if (timerQuery.beginQueryEXT) {
  17349. timerQuery.beginQueryEXT(timerQuery.TIME_ELAPSED_EXT, token._timeElapsedQuery);
  17350. }
  17351. else {
  17352. this._gl.beginQuery(timerQuery.TIME_ELAPSED_EXT, token._timeElapsedQuery);
  17353. }
  17354. this._currentNonTimestampToken = token;
  17355. }
  17356. return token;
  17357. };
  17358. /**
  17359. * Ends a time query
  17360. * @param token defines the token used to measure the time span
  17361. * @returns the time spent (in ns)
  17362. */
  17363. Engine.prototype.endTimeQuery = function (token) {
  17364. var timerQuery = this._caps.timerQuery;
  17365. if (!timerQuery || !token) {
  17366. return -1;
  17367. }
  17368. if (this._caps.canUseTimestampForTimerQuery) {
  17369. if (!token._startTimeQuery) {
  17370. return -1;
  17371. }
  17372. if (!token._endTimeQuery) {
  17373. token._endTimeQuery = this._createTimeQuery();
  17374. timerQuery.queryCounterEXT(token._endTimeQuery, timerQuery.TIMESTAMP_EXT);
  17375. }
  17376. }
  17377. else if (!token._timeElapsedQueryEnded) {
  17378. if (!token._timeElapsedQuery) {
  17379. return -1;
  17380. }
  17381. if (timerQuery.endQueryEXT) {
  17382. timerQuery.endQueryEXT(timerQuery.TIME_ELAPSED_EXT);
  17383. }
  17384. else {
  17385. this._gl.endQuery(timerQuery.TIME_ELAPSED_EXT);
  17386. }
  17387. token._timeElapsedQueryEnded = true;
  17388. }
  17389. var disjoint = this._gl.getParameter(timerQuery.GPU_DISJOINT_EXT);
  17390. var available = false;
  17391. if (token._endTimeQuery) {
  17392. available = this._getTimeQueryAvailability(token._endTimeQuery);
  17393. }
  17394. else if (token._timeElapsedQuery) {
  17395. available = this._getTimeQueryAvailability(token._timeElapsedQuery);
  17396. }
  17397. if (available && !disjoint) {
  17398. var result = 0;
  17399. if (this._caps.canUseTimestampForTimerQuery) {
  17400. if (!token._startTimeQuery || !token._endTimeQuery) {
  17401. return -1;
  17402. }
  17403. var timeStart = this._getTimeQueryResult(token._startTimeQuery);
  17404. var timeEnd = this._getTimeQueryResult(token._endTimeQuery);
  17405. result = timeEnd - timeStart;
  17406. this._deleteTimeQuery(token._startTimeQuery);
  17407. this._deleteTimeQuery(token._endTimeQuery);
  17408. token._startTimeQuery = null;
  17409. token._endTimeQuery = null;
  17410. }
  17411. else {
  17412. if (!token._timeElapsedQuery) {
  17413. return -1;
  17414. }
  17415. result = this._getTimeQueryResult(token._timeElapsedQuery);
  17416. this._deleteTimeQuery(token._timeElapsedQuery);
  17417. token._timeElapsedQuery = null;
  17418. token._timeElapsedQueryEnded = false;
  17419. this._currentNonTimestampToken = null;
  17420. }
  17421. return result;
  17422. }
  17423. return -1;
  17424. };
  17425. Engine.prototype.getGlAlgorithmType = function (algorithmType) {
  17426. return algorithmType === BABYLON.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
  17427. };
  17428. // Transform feedback
  17429. /**
  17430. * Creates a webGL transform feedback object
  17431. * Please makes sure to check webGLVersion property to check if you are running webGL 2+
  17432. * @returns the webGL transform feedback object
  17433. */
  17434. Engine.prototype.createTransformFeedback = function () {
  17435. return this._gl.createTransformFeedback();
  17436. };
  17437. /**
  17438. * Delete a webGL transform feedback object
  17439. * @param value defines the webGL transform feedback object to delete
  17440. */
  17441. Engine.prototype.deleteTransformFeedback = function (value) {
  17442. this._gl.deleteTransformFeedback(value);
  17443. };
  17444. /**
  17445. * Bind a webGL transform feedback object to the webgl context
  17446. * @param value defines the webGL transform feedback object to bind
  17447. */
  17448. Engine.prototype.bindTransformFeedback = function (value) {
  17449. this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK, value);
  17450. };
  17451. /**
  17452. * Begins a transform feedback operation
  17453. * @param usePoints defines if points or triangles must be used
  17454. */
  17455. Engine.prototype.beginTransformFeedback = function (usePoints) {
  17456. if (usePoints === void 0) { usePoints = true; }
  17457. this._gl.beginTransformFeedback(usePoints ? this._gl.POINTS : this._gl.TRIANGLES);
  17458. };
  17459. /**
  17460. * Ends a transform feedback operation
  17461. */
  17462. Engine.prototype.endTransformFeedback = function () {
  17463. this._gl.endTransformFeedback();
  17464. };
  17465. /**
  17466. * Specify the varyings to use with transform feedback
  17467. * @param program defines the associated webGL program
  17468. * @param value defines the list of strings representing the varying names
  17469. */
  17470. Engine.prototype.setTranformFeedbackVaryings = function (program, value) {
  17471. this._gl.transformFeedbackVaryings(program, value, this._gl.INTERLEAVED_ATTRIBS);
  17472. };
  17473. /**
  17474. * Bind a webGL buffer for a transform feedback operation
  17475. * @param value defines the webGL buffer to bind
  17476. */
  17477. Engine.prototype.bindTransformFeedbackBuffer = function (value) {
  17478. this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER, 0, value);
  17479. };
  17480. /** @hidden */
  17481. Engine.prototype._loadFile = function (url, onSuccess, onProgress, database, useArrayBuffer, onError) {
  17482. var _this = this;
  17483. var request = BABYLON.Tools.LoadFile(url, onSuccess, onProgress, database, useArrayBuffer, onError);
  17484. this._activeRequests.push(request);
  17485. request.onCompleteObservable.add(function (request) {
  17486. _this._activeRequests.splice(_this._activeRequests.indexOf(request), 1);
  17487. });
  17488. return request;
  17489. };
  17490. /** @hidden */
  17491. Engine.prototype._loadFileAsync = function (url, database, useArrayBuffer) {
  17492. var _this = this;
  17493. return new Promise(function (resolve, reject) {
  17494. _this._loadFile(url, function (data) {
  17495. resolve(data);
  17496. }, undefined, database, useArrayBuffer, function (request, exception) {
  17497. reject(exception);
  17498. });
  17499. });
  17500. };
  17501. Engine.prototype._partialLoadFile = function (url, index, loadedFiles, scene, onfinish, onErrorCallBack) {
  17502. if (onErrorCallBack === void 0) { onErrorCallBack = null; }
  17503. var onload = function (data) {
  17504. loadedFiles[index] = data;
  17505. loadedFiles._internalCount++;
  17506. if (loadedFiles._internalCount === 6) {
  17507. onfinish(loadedFiles);
  17508. }
  17509. };
  17510. var onerror = function (request, exception) {
  17511. if (onErrorCallBack && request) {
  17512. onErrorCallBack(request.status + " " + request.statusText, exception);
  17513. }
  17514. };
  17515. this._loadFile(url, onload, undefined, undefined, true, onerror);
  17516. };
  17517. Engine.prototype._cascadeLoadFiles = function (scene, onfinish, files, onError) {
  17518. if (onError === void 0) { onError = null; }
  17519. var loadedFiles = [];
  17520. loadedFiles._internalCount = 0;
  17521. for (var index = 0; index < 6; index++) {
  17522. this._partialLoadFile(files[index], index, loadedFiles, scene, onfinish, onError);
  17523. }
  17524. };
  17525. // Statics
  17526. /**
  17527. * Gets a boolean indicating if the engine can be instanciated (ie. if a webGL context can be found)
  17528. * @returns true if the engine can be created
  17529. * @ignorenaming
  17530. */
  17531. Engine.isSupported = function () {
  17532. try {
  17533. var tempcanvas = document.createElement("canvas");
  17534. var gl = tempcanvas.getContext("webgl") || tempcanvas.getContext("experimental-webgl");
  17535. return gl != null && !!window.WebGLRenderingContext;
  17536. }
  17537. catch (e) {
  17538. return false;
  17539. }
  17540. };
  17541. /** Use this array to turn off some WebGL2 features on known buggy browsers version */
  17542. Engine.ExceptionList = [
  17543. { key: "Chrome/63.0", capture: "63\\.0\\.3239\\.(\\d+)", captureConstraint: 108, targets: ["uniformBuffer"] },
  17544. { key: "Firefox/58", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
  17545. { key: "Firefox/59", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
  17546. { key: "Macintosh", capture: null, captureConstraint: null, targets: ["textureBindingOptimization"] },
  17547. { key: "iPhone", capture: null, captureConstraint: null, targets: ["textureBindingOptimization"] },
  17548. { key: "iPad", capture: null, captureConstraint: null, targets: ["textureBindingOptimization"] }
  17549. ];
  17550. /** Gets the list of created engines */
  17551. Engine.Instances = new Array();
  17552. // Const statics
  17553. Engine._ALPHA_DISABLE = 0;
  17554. Engine._ALPHA_ADD = 1;
  17555. Engine._ALPHA_COMBINE = 2;
  17556. Engine._ALPHA_SUBTRACT = 3;
  17557. Engine._ALPHA_MULTIPLY = 4;
  17558. Engine._ALPHA_MAXIMIZED = 5;
  17559. Engine._ALPHA_ONEONE = 6;
  17560. Engine._ALPHA_PREMULTIPLIED = 7;
  17561. Engine._ALPHA_PREMULTIPLIED_PORTERDUFF = 8;
  17562. Engine._ALPHA_INTERPOLATE = 9;
  17563. Engine._ALPHA_SCREENMODE = 10;
  17564. Engine._DELAYLOADSTATE_NONE = 0;
  17565. Engine._DELAYLOADSTATE_LOADED = 1;
  17566. Engine._DELAYLOADSTATE_LOADING = 2;
  17567. Engine._DELAYLOADSTATE_NOTLOADED = 4;
  17568. Engine._TEXTUREFORMAT_ALPHA = 0;
  17569. Engine._TEXTUREFORMAT_LUMINANCE = 1;
  17570. Engine._TEXTUREFORMAT_LUMINANCE_ALPHA = 2;
  17571. Engine._TEXTUREFORMAT_RGB = 4;
  17572. Engine._TEXTUREFORMAT_RGBA = 5;
  17573. Engine._TEXTUREFORMAT_R = 6;
  17574. Engine._TEXTUREFORMAT_RG = 7;
  17575. Engine._TEXTURETYPE_UNSIGNED_INT = 0;
  17576. Engine._TEXTURETYPE_FLOAT = 1;
  17577. Engine._TEXTURETYPE_HALF_FLOAT = 2;
  17578. // Depht or Stencil test Constants.
  17579. Engine._NEVER = 0x0200; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn.
  17580. Engine._ALWAYS = 0x0207; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn.
  17581. Engine._LESS = 0x0201; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value.
  17582. Engine._EQUAL = 0x0202; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value.
  17583. Engine._LEQUAL = 0x0203; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value.
  17584. Engine._GREATER = 0x0204; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value.
  17585. Engine._GEQUAL = 0x0206; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value.
  17586. Engine._NOTEQUAL = 0x0205; // Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value.
  17587. // Stencil Actions Constants.
  17588. Engine._KEEP = 0x1E00;
  17589. Engine._REPLACE = 0x1E01;
  17590. Engine._INCR = 0x1E02;
  17591. Engine._DECR = 0x1E03;
  17592. Engine._INVERT = 0x150A;
  17593. Engine._INCR_WRAP = 0x8507;
  17594. Engine._DECR_WRAP = 0x8508;
  17595. // Texture rescaling mode
  17596. Engine._SCALEMODE_FLOOR = 1;
  17597. Engine._SCALEMODE_NEAREST = 2;
  17598. Engine._SCALEMODE_CEILING = 3;
  17599. // Updatable statics so stick with vars here
  17600. /**
  17601. * Gets or sets the epsilon value used by collision engine
  17602. */
  17603. Engine.CollisionsEpsilon = 0.001;
  17604. /**
  17605. * Gets or sets the relative url used to load code if using the engine in non-minified mode
  17606. */
  17607. Engine.CodeRepository = "src/";
  17608. /**
  17609. * Gets or sets the relative url used to load shaders if using the engine in non-minified mode
  17610. */
  17611. Engine.ShadersRepository = "src/Shaders/";
  17612. return Engine;
  17613. }());
  17614. BABYLON.Engine = Engine;
  17615. })(BABYLON || (BABYLON = {}));
  17616. //# sourceMappingURL=babylon.engine.js.map
  17617. var BABYLON;
  17618. (function (BABYLON) {
  17619. /**
  17620. * Node is the basic class for all scene objects (Mesh, Light Camera).
  17621. */
  17622. var Node = /** @class */ (function () {
  17623. /**
  17624. * Creates a new Node
  17625. * @param {string} name - the name and id to be given to this node
  17626. * @param {BABYLON.Scene} the scene this node will be added to
  17627. */
  17628. function Node(name, scene) {
  17629. if (scene === void 0) { scene = null; }
  17630. /**
  17631. * Gets or sets a string used to store user defined state for the node
  17632. */
  17633. this.state = "";
  17634. /**
  17635. * Gets or sets an object used to store user defined information for the node
  17636. */
  17637. this.metadata = null;
  17638. /**
  17639. * Gets or sets a boolean used to define if the node must be serialized
  17640. */
  17641. this.doNotSerialize = false;
  17642. /** @hidden */
  17643. this._isDisposed = false;
  17644. /**
  17645. * Gets a list of Animations associated with the node
  17646. */
  17647. this.animations = new Array();
  17648. this._ranges = {};
  17649. this._isEnabled = true;
  17650. this._isReady = true;
  17651. /** @hidden */
  17652. this._currentRenderId = -1;
  17653. this._parentRenderId = -1;
  17654. this._childRenderId = -1;
  17655. this._animationPropertiesOverride = null;
  17656. /**
  17657. * An event triggered when the mesh is disposed
  17658. */
  17659. this.onDisposeObservable = new BABYLON.Observable();
  17660. // Behaviors
  17661. this._behaviors = new Array();
  17662. this.name = name;
  17663. this.id = name;
  17664. this._scene = (scene || BABYLON.Engine.LastCreatedScene);
  17665. this.uniqueId = this._scene.getUniqueId();
  17666. this._initCache();
  17667. }
  17668. /**
  17669. * Gets a boolean indicating if the node has been disposed
  17670. * @returns true if the node was disposed
  17671. */
  17672. Node.prototype.isDisposed = function () {
  17673. return this._isDisposed;
  17674. };
  17675. Object.defineProperty(Node.prototype, "parent", {
  17676. get: function () {
  17677. return this._parentNode;
  17678. },
  17679. /**
  17680. * Gets or sets the parent of the node
  17681. */
  17682. set: function (parent) {
  17683. if (this._parentNode === parent) {
  17684. return;
  17685. }
  17686. // Remove self from list of children of parent
  17687. if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
  17688. var index = this._parentNode._children.indexOf(this);
  17689. if (index !== -1) {
  17690. this._parentNode._children.splice(index, 1);
  17691. }
  17692. }
  17693. // Store new parent
  17694. this._parentNode = parent;
  17695. // Add as child to new parent
  17696. if (this._parentNode) {
  17697. if (this._parentNode._children === undefined || this._parentNode._children === null) {
  17698. this._parentNode._children = new Array();
  17699. }
  17700. this._parentNode._children.push(this);
  17701. }
  17702. },
  17703. enumerable: true,
  17704. configurable: true
  17705. });
  17706. Object.defineProperty(Node.prototype, "animationPropertiesOverride", {
  17707. /**
  17708. * Gets or sets the animation properties override
  17709. */
  17710. get: function () {
  17711. if (!this._animationPropertiesOverride) {
  17712. return this._scene.animationPropertiesOverride;
  17713. }
  17714. return this._animationPropertiesOverride;
  17715. },
  17716. set: function (value) {
  17717. this._animationPropertiesOverride = value;
  17718. },
  17719. enumerable: true,
  17720. configurable: true
  17721. });
  17722. /**
  17723. * Gets a string idenfifying the name of the class
  17724. * @returns "Node" string
  17725. */
  17726. Node.prototype.getClassName = function () {
  17727. return "Node";
  17728. };
  17729. Object.defineProperty(Node.prototype, "onDispose", {
  17730. /**
  17731. * Sets a callback that will be raised when the node will be disposed
  17732. */
  17733. set: function (callback) {
  17734. if (this._onDisposeObserver) {
  17735. this.onDisposeObservable.remove(this._onDisposeObserver);
  17736. }
  17737. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  17738. },
  17739. enumerable: true,
  17740. configurable: true
  17741. });
  17742. /**
  17743. * Gets the scene of the node
  17744. * @returns a {BABYLON.Scene}
  17745. */
  17746. Node.prototype.getScene = function () {
  17747. return this._scene;
  17748. };
  17749. /**
  17750. * Gets the engine of the node
  17751. * @returns a {BABYLON.Engine}
  17752. */
  17753. Node.prototype.getEngine = function () {
  17754. return this._scene.getEngine();
  17755. };
  17756. /**
  17757. * Attach a behavior to the node
  17758. * @see http://doc.babylonjs.com/features/behaviour
  17759. * @param behavior defines the behavior to attach
  17760. * @returns the current Node
  17761. */
  17762. Node.prototype.addBehavior = function (behavior) {
  17763. var _this = this;
  17764. var index = this._behaviors.indexOf(behavior);
  17765. if (index !== -1) {
  17766. return this;
  17767. }
  17768. behavior.init();
  17769. if (this._scene.isLoading) {
  17770. // We defer the attach when the scene will be loaded
  17771. this._scene.onDataLoadedObservable.addOnce(function () {
  17772. behavior.attach(_this);
  17773. });
  17774. }
  17775. else {
  17776. behavior.attach(this);
  17777. }
  17778. this._behaviors.push(behavior);
  17779. return this;
  17780. };
  17781. /**
  17782. * Remove an attached behavior
  17783. * @see http://doc.babylonjs.com/features/behaviour
  17784. * @param behavior defines the behavior to attach
  17785. * @returns the current Node
  17786. */
  17787. Node.prototype.removeBehavior = function (behavior) {
  17788. var index = this._behaviors.indexOf(behavior);
  17789. if (index === -1) {
  17790. return this;
  17791. }
  17792. this._behaviors[index].detach();
  17793. this._behaviors.splice(index, 1);
  17794. return this;
  17795. };
  17796. Object.defineProperty(Node.prototype, "behaviors", {
  17797. /**
  17798. * Gets the list of attached behaviors
  17799. * @see http://doc.babylonjs.com/features/behaviour
  17800. */
  17801. get: function () {
  17802. return this._behaviors;
  17803. },
  17804. enumerable: true,
  17805. configurable: true
  17806. });
  17807. /**
  17808. * Gets an attached behavior by name
  17809. * @param name defines the name of the behavior to look for
  17810. * @see http://doc.babylonjs.com/features/behaviour
  17811. * @returns null if behavior was not found else the requested behavior
  17812. */
  17813. Node.prototype.getBehaviorByName = function (name) {
  17814. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  17815. var behavior = _a[_i];
  17816. if (behavior.name === name) {
  17817. return behavior;
  17818. }
  17819. }
  17820. return null;
  17821. };
  17822. /**
  17823. * Returns the world matrix of the node
  17824. * @returns a matrix containing the node's world matrix
  17825. */
  17826. Node.prototype.getWorldMatrix = function () {
  17827. return BABYLON.Matrix.Identity();
  17828. };
  17829. /** @hidden */
  17830. Node.prototype._getWorldMatrixDeterminant = function () {
  17831. return 1;
  17832. };
  17833. // override it in derived class if you add new variables to the cache
  17834. // and call the parent class method
  17835. /** @hidden */
  17836. Node.prototype._initCache = function () {
  17837. this._cache = {};
  17838. this._cache.parent = undefined;
  17839. };
  17840. /** @hidden */
  17841. Node.prototype.updateCache = function (force) {
  17842. if (!force && this.isSynchronized())
  17843. return;
  17844. this._cache.parent = this.parent;
  17845. this._updateCache();
  17846. };
  17847. // override it in derived class if you add new variables to the cache
  17848. // and call the parent class method if !ignoreParentClass
  17849. /** @hidden */
  17850. Node.prototype._updateCache = function (ignoreParentClass) {
  17851. };
  17852. // override it in derived class if you add new variables to the cache
  17853. /** @hidden */
  17854. Node.prototype._isSynchronized = function () {
  17855. return true;
  17856. };
  17857. /** @hidden */
  17858. Node.prototype._markSyncedWithParent = function () {
  17859. if (this.parent) {
  17860. this._parentRenderId = this.parent._childRenderId;
  17861. }
  17862. };
  17863. /** @hidden */
  17864. Node.prototype.isSynchronizedWithParent = function () {
  17865. if (!this.parent) {
  17866. return true;
  17867. }
  17868. if (this._parentRenderId !== this.parent._childRenderId) {
  17869. return false;
  17870. }
  17871. return this.parent.isSynchronized();
  17872. };
  17873. /** @hidden */
  17874. Node.prototype.isSynchronized = function (updateCache) {
  17875. var check = this.hasNewParent();
  17876. check = check || !this.isSynchronizedWithParent();
  17877. check = check || !this._isSynchronized();
  17878. if (updateCache)
  17879. this.updateCache(true);
  17880. return !check;
  17881. };
  17882. /** @hidden */
  17883. Node.prototype.hasNewParent = function (update) {
  17884. if (this._cache.parent === this.parent)
  17885. return false;
  17886. if (update)
  17887. this._cache.parent = this.parent;
  17888. return true;
  17889. };
  17890. /**
  17891. * Is this node ready to be used/rendered
  17892. * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
  17893. * @return true if the node is ready
  17894. */
  17895. Node.prototype.isReady = function (completeCheck) {
  17896. if (completeCheck === void 0) { completeCheck = false; }
  17897. return this._isReady;
  17898. };
  17899. /**
  17900. * Is this node enabled?
  17901. * If the node has a parent, all ancestors will be checked and false will be returned if any are false (not enabled), otherwise will return true
  17902. * @param checkAncestors indicates if this method should check the ancestors. The default is to check the ancestors. If set to false, the method will return the value of this node without checking ancestors
  17903. * @return whether this node (and its parent) is enabled
  17904. */
  17905. Node.prototype.isEnabled = function (checkAncestors) {
  17906. if (checkAncestors === void 0) { checkAncestors = true; }
  17907. if (checkAncestors === false) {
  17908. return this._isEnabled;
  17909. }
  17910. if (this._isEnabled === false) {
  17911. return false;
  17912. }
  17913. if (this.parent !== undefined && this.parent !== null) {
  17914. return this.parent.isEnabled(checkAncestors);
  17915. }
  17916. return true;
  17917. };
  17918. /**
  17919. * Set the enabled state of this node
  17920. * @param value defines the new enabled state
  17921. */
  17922. Node.prototype.setEnabled = function (value) {
  17923. this._isEnabled = value;
  17924. };
  17925. /**
  17926. * Is this node a descendant of the given node?
  17927. * The function will iterate up the hierarchy until the ancestor was found or no more parents defined
  17928. * @param ancestor defines the parent node to inspect
  17929. * @returns a boolean indicating if this node is a descendant of the given node
  17930. */
  17931. Node.prototype.isDescendantOf = function (ancestor) {
  17932. if (this.parent) {
  17933. if (this.parent === ancestor) {
  17934. return true;
  17935. }
  17936. return this.parent.isDescendantOf(ancestor);
  17937. }
  17938. return false;
  17939. };
  17940. /** @hidden */
  17941. Node.prototype._getDescendants = function (results, directDescendantsOnly, predicate) {
  17942. if (directDescendantsOnly === void 0) { directDescendantsOnly = false; }
  17943. if (!this._children) {
  17944. return;
  17945. }
  17946. for (var index = 0; index < this._children.length; index++) {
  17947. var item = this._children[index];
  17948. if (!predicate || predicate(item)) {
  17949. results.push(item);
  17950. }
  17951. if (!directDescendantsOnly) {
  17952. item._getDescendants(results, false, predicate);
  17953. }
  17954. }
  17955. };
  17956. /**
  17957. * Will return all nodes that have this node as ascendant
  17958. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  17959. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  17960. * @return all children nodes of all types
  17961. */
  17962. Node.prototype.getDescendants = function (directDescendantsOnly, predicate) {
  17963. var results = new Array();
  17964. this._getDescendants(results, directDescendantsOnly, predicate);
  17965. return results;
  17966. };
  17967. /**
  17968. * Get all child-meshes of this node
  17969. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  17970. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  17971. * @returns an array of {BABYLON.AbstractMesh}
  17972. */
  17973. Node.prototype.getChildMeshes = function (directDescendantsOnly, predicate) {
  17974. var results = [];
  17975. this._getDescendants(results, directDescendantsOnly, function (node) {
  17976. return ((!predicate || predicate(node)) && (node instanceof BABYLON.AbstractMesh));
  17977. });
  17978. return results;
  17979. };
  17980. /**
  17981. * Get all child-transformNodes of this node
  17982. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  17983. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  17984. * @returns an array of {BABYLON.TransformNode}
  17985. */
  17986. Node.prototype.getChildTransformNodes = function (directDescendantsOnly, predicate) {
  17987. var results = [];
  17988. this._getDescendants(results, directDescendantsOnly, function (node) {
  17989. return ((!predicate || predicate(node)) && (node instanceof BABYLON.TransformNode));
  17990. });
  17991. return results;
  17992. };
  17993. /**
  17994. * Get all direct children of this node
  17995. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  17996. * @returns an array of {BABYLON.Node}
  17997. */
  17998. Node.prototype.getChildren = function (predicate) {
  17999. return this.getDescendants(true, predicate);
  18000. };
  18001. /** @hidden */
  18002. Node.prototype._setReady = function (state) {
  18003. if (state === this._isReady) {
  18004. return;
  18005. }
  18006. if (!state) {
  18007. this._isReady = false;
  18008. return;
  18009. }
  18010. if (this.onReady) {
  18011. this.onReady(this);
  18012. }
  18013. this._isReady = true;
  18014. };
  18015. /**
  18016. * Get an animation by name
  18017. * @param name defines the name of the animation to look for
  18018. * @returns null if not found else the requested animation
  18019. */
  18020. Node.prototype.getAnimationByName = function (name) {
  18021. for (var i = 0; i < this.animations.length; i++) {
  18022. var animation = this.animations[i];
  18023. if (animation.name === name) {
  18024. return animation;
  18025. }
  18026. }
  18027. return null;
  18028. };
  18029. /**
  18030. * Creates an animation range for this node
  18031. * @param name defines the name of the range
  18032. * @param from defines the starting key
  18033. * @param to defines the end key
  18034. */
  18035. Node.prototype.createAnimationRange = function (name, from, to) {
  18036. // check name not already in use
  18037. if (!this._ranges[name]) {
  18038. this._ranges[name] = new BABYLON.AnimationRange(name, from, to);
  18039. for (var i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {
  18040. if (this.animations[i]) {
  18041. this.animations[i].createRange(name, from, to);
  18042. }
  18043. }
  18044. }
  18045. };
  18046. /**
  18047. * Delete a specific animation range
  18048. * @param name defines the name of the range to delete
  18049. * @param deleteFrames defines if animation frames from the range must be deleted as well
  18050. */
  18051. Node.prototype.deleteAnimationRange = function (name, deleteFrames) {
  18052. if (deleteFrames === void 0) { deleteFrames = true; }
  18053. for (var i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {
  18054. if (this.animations[i]) {
  18055. this.animations[i].deleteRange(name, deleteFrames);
  18056. }
  18057. }
  18058. this._ranges[name] = null; // said much faster than 'delete this._range[name]'
  18059. };
  18060. /**
  18061. * Get an animation range by name
  18062. * @param name defines the name of the animation range to look for
  18063. * @returns null if not found else the requested animation range
  18064. */
  18065. Node.prototype.getAnimationRange = function (name) {
  18066. return this._ranges[name];
  18067. };
  18068. /**
  18069. * Will start the animation sequence
  18070. * @param name defines the range frames for animation sequence
  18071. * @param loop defines if the animation should loop (false by default)
  18072. * @param speedRatio defines the speed factor in which to run the animation (1 by default)
  18073. * @param onAnimationEnd defines a function to be executed when the animation ended (undefined by default)
  18074. * @returns the object created for this animation. If range does not exist, it will return null
  18075. */
  18076. Node.prototype.beginAnimation = function (name, loop, speedRatio, onAnimationEnd) {
  18077. var range = this.getAnimationRange(name);
  18078. if (!range) {
  18079. return null;
  18080. }
  18081. return this._scene.beginAnimation(this, range.from, range.to, loop, speedRatio, onAnimationEnd);
  18082. };
  18083. /**
  18084. * Serialize animation ranges into a JSON compatible object
  18085. * @returns serialization object
  18086. */
  18087. Node.prototype.serializeAnimationRanges = function () {
  18088. var serializationRanges = [];
  18089. for (var name in this._ranges) {
  18090. var localRange = this._ranges[name];
  18091. if (!localRange) {
  18092. continue;
  18093. }
  18094. var range = {};
  18095. range.name = name;
  18096. range.from = localRange.from;
  18097. range.to = localRange.to;
  18098. serializationRanges.push(range);
  18099. }
  18100. return serializationRanges;
  18101. };
  18102. /**
  18103. * Computes the world matrix of the node
  18104. * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch
  18105. * @returns the world matrix
  18106. */
  18107. Node.prototype.computeWorldMatrix = function (force) {
  18108. return BABYLON.Matrix.Identity();
  18109. };
  18110. /**
  18111. * Releases resources associated with this node.
  18112. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  18113. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  18114. */
  18115. Node.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  18116. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  18117. if (!doNotRecurse) {
  18118. var nodes = this.getDescendants(true);
  18119. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  18120. var node = nodes_1[_i];
  18121. node.dispose(doNotRecurse, disposeMaterialAndTextures);
  18122. }
  18123. }
  18124. else {
  18125. var transformNodes = this.getChildTransformNodes(true);
  18126. for (var _a = 0, transformNodes_1 = transformNodes; _a < transformNodes_1.length; _a++) {
  18127. var transformNode = transformNodes_1[_a];
  18128. transformNode.parent = null;
  18129. transformNode.computeWorldMatrix(true);
  18130. }
  18131. }
  18132. this.parent = null;
  18133. // Callback
  18134. this.onDisposeObservable.notifyObservers(this);
  18135. this.onDisposeObservable.clear();
  18136. // Behaviors
  18137. for (var _b = 0, _c = this._behaviors; _b < _c.length; _b++) {
  18138. var behavior = _c[_b];
  18139. behavior.detach();
  18140. }
  18141. this._behaviors = [];
  18142. this._isDisposed = true;
  18143. };
  18144. /**
  18145. * Parse animation range data from a serialization object and store them into a given node
  18146. * @param node defines where to store the animation ranges
  18147. * @param parsedNode defines the serialization object to read data from
  18148. * @param scene defines the hosting scene
  18149. */
  18150. Node.ParseAnimationRanges = function (node, parsedNode, scene) {
  18151. if (parsedNode.ranges) {
  18152. for (var index = 0; index < parsedNode.ranges.length; index++) {
  18153. var data = parsedNode.ranges[index];
  18154. node.createAnimationRange(data.name, data.from, data.to);
  18155. }
  18156. }
  18157. };
  18158. __decorate([
  18159. BABYLON.serialize()
  18160. ], Node.prototype, "name", void 0);
  18161. __decorate([
  18162. BABYLON.serialize()
  18163. ], Node.prototype, "id", void 0);
  18164. __decorate([
  18165. BABYLON.serialize()
  18166. ], Node.prototype, "uniqueId", void 0);
  18167. __decorate([
  18168. BABYLON.serialize()
  18169. ], Node.prototype, "state", void 0);
  18170. __decorate([
  18171. BABYLON.serialize()
  18172. ], Node.prototype, "metadata", void 0);
  18173. return Node;
  18174. }());
  18175. BABYLON.Node = Node;
  18176. })(BABYLON || (BABYLON = {}));
  18177. //# sourceMappingURL=babylon.node.js.map
  18178. var BABYLON;
  18179. (function (BABYLON) {
  18180. var BoundingSphere = /** @class */ (function () {
  18181. /**
  18182. * Creates a new bounding sphere
  18183. * @param min defines the minimum vector (in local space)
  18184. * @param max defines the maximum vector (in local space)
  18185. */
  18186. function BoundingSphere(min, max) {
  18187. this._tempRadiusVector = BABYLON.Vector3.Zero();
  18188. this.reConstruct(min, max);
  18189. }
  18190. /**
  18191. * Recreates the entire bounding sphere from scratch
  18192. * @param min defines the new minimum vector (in local space)
  18193. * @param max defines the new maximum vector (in local space)
  18194. */
  18195. BoundingSphere.prototype.reConstruct = function (min, max) {
  18196. this.minimum = min.clone();
  18197. this.maximum = max.clone();
  18198. var distance = BABYLON.Vector3.Distance(min, max);
  18199. this.center = BABYLON.Vector3.Lerp(min, max, 0.5);
  18200. this.radius = distance * 0.5;
  18201. this.centerWorld = BABYLON.Vector3.Zero();
  18202. this._update(BABYLON.Matrix.Identity());
  18203. };
  18204. // Methods
  18205. BoundingSphere.prototype._update = function (world) {
  18206. BABYLON.Vector3.TransformCoordinatesToRef(this.center, world, this.centerWorld);
  18207. BABYLON.Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, world, this._tempRadiusVector);
  18208. this.radiusWorld = Math.max(Math.abs(this._tempRadiusVector.x), Math.abs(this._tempRadiusVector.y), Math.abs(this._tempRadiusVector.z)) * this.radius;
  18209. };
  18210. BoundingSphere.prototype.isInFrustum = function (frustumPlanes) {
  18211. for (var i = 0; i < 6; i++) {
  18212. if (frustumPlanes[i].dotCoordinate(this.centerWorld) <= -this.radiusWorld)
  18213. return false;
  18214. }
  18215. return true;
  18216. };
  18217. BoundingSphere.prototype.intersectsPoint = function (point) {
  18218. var x = this.centerWorld.x - point.x;
  18219. var y = this.centerWorld.y - point.y;
  18220. var z = this.centerWorld.z - point.z;
  18221. var distance = Math.sqrt((x * x) + (y * y) + (z * z));
  18222. if (Math.abs(this.radiusWorld - distance) < BABYLON.Epsilon)
  18223. return false;
  18224. return true;
  18225. };
  18226. // Statics
  18227. BoundingSphere.Intersects = function (sphere0, sphere1) {
  18228. var x = sphere0.centerWorld.x - sphere1.centerWorld.x;
  18229. var y = sphere0.centerWorld.y - sphere1.centerWorld.y;
  18230. var z = sphere0.centerWorld.z - sphere1.centerWorld.z;
  18231. var distance = Math.sqrt((x * x) + (y * y) + (z * z));
  18232. if (sphere0.radiusWorld + sphere1.radiusWorld < distance)
  18233. return false;
  18234. return true;
  18235. };
  18236. return BoundingSphere;
  18237. }());
  18238. BABYLON.BoundingSphere = BoundingSphere;
  18239. })(BABYLON || (BABYLON = {}));
  18240. //# sourceMappingURL=babylon.boundingSphere.js.map
  18241. var BABYLON;
  18242. (function (BABYLON) {
  18243. var BoundingBox = /** @class */ (function () {
  18244. /**
  18245. * Creates a new bounding box
  18246. * @param min defines the minimum vector (in local space)
  18247. * @param max defines the maximum vector (in local space)
  18248. */
  18249. function BoundingBox(min, max) {
  18250. this.vectorsWorld = new Array();
  18251. this.reConstruct(min, max);
  18252. }
  18253. // Methods
  18254. /**
  18255. * Recreates the entire bounding box from scratch
  18256. * @param min defines the new minimum vector (in local space)
  18257. * @param max defines the new maximum vector (in local space)
  18258. */
  18259. BoundingBox.prototype.reConstruct = function (min, max) {
  18260. this.minimum = min.clone();
  18261. this.maximum = max.clone();
  18262. // Bounding vectors
  18263. this.vectors = new Array();
  18264. this.vectors.push(this.minimum.clone());
  18265. this.vectors.push(this.maximum.clone());
  18266. this.vectors.push(this.minimum.clone());
  18267. this.vectors[2].x = this.maximum.x;
  18268. this.vectors.push(this.minimum.clone());
  18269. this.vectors[3].y = this.maximum.y;
  18270. this.vectors.push(this.minimum.clone());
  18271. this.vectors[4].z = this.maximum.z;
  18272. this.vectors.push(this.maximum.clone());
  18273. this.vectors[5].z = this.minimum.z;
  18274. this.vectors.push(this.maximum.clone());
  18275. this.vectors[6].x = this.minimum.x;
  18276. this.vectors.push(this.maximum.clone());
  18277. this.vectors[7].y = this.minimum.y;
  18278. // OBB
  18279. this.center = this.maximum.add(this.minimum).scale(0.5);
  18280. this.extendSize = this.maximum.subtract(this.minimum).scale(0.5);
  18281. this.directions = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
  18282. // World
  18283. for (var index = 0; index < this.vectors.length; index++) {
  18284. this.vectorsWorld[index] = BABYLON.Vector3.Zero();
  18285. }
  18286. this.minimumWorld = BABYLON.Vector3.Zero();
  18287. this.maximumWorld = BABYLON.Vector3.Zero();
  18288. this.centerWorld = BABYLON.Vector3.Zero();
  18289. this.extendSizeWorld = BABYLON.Vector3.Zero();
  18290. this._update(this._worldMatrix || BABYLON.Matrix.Identity());
  18291. };
  18292. BoundingBox.prototype.getWorldMatrix = function () {
  18293. return this._worldMatrix;
  18294. };
  18295. BoundingBox.prototype.setWorldMatrix = function (matrix) {
  18296. this._worldMatrix.copyFrom(matrix);
  18297. return this;
  18298. };
  18299. BoundingBox.prototype._update = function (world) {
  18300. BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this.minimumWorld);
  18301. BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, this.maximumWorld);
  18302. for (var index = 0; index < this.vectors.length; index++) {
  18303. var v = this.vectorsWorld[index];
  18304. BABYLON.Vector3.TransformCoordinatesToRef(this.vectors[index], world, v);
  18305. if (v.x < this.minimumWorld.x)
  18306. this.minimumWorld.x = v.x;
  18307. if (v.y < this.minimumWorld.y)
  18308. this.minimumWorld.y = v.y;
  18309. if (v.z < this.minimumWorld.z)
  18310. this.minimumWorld.z = v.z;
  18311. if (v.x > this.maximumWorld.x)
  18312. this.maximumWorld.x = v.x;
  18313. if (v.y > this.maximumWorld.y)
  18314. this.maximumWorld.y = v.y;
  18315. if (v.z > this.maximumWorld.z)
  18316. this.maximumWorld.z = v.z;
  18317. }
  18318. // Extend
  18319. this.maximumWorld.subtractToRef(this.minimumWorld, this.extendSizeWorld);
  18320. this.extendSizeWorld.scaleInPlace(0.5);
  18321. // OBB
  18322. this.maximumWorld.addToRef(this.minimumWorld, this.centerWorld);
  18323. this.centerWorld.scaleInPlace(0.5);
  18324. BABYLON.Vector3.FromFloatArrayToRef(world.m, 0, this.directions[0]);
  18325. BABYLON.Vector3.FromFloatArrayToRef(world.m, 4, this.directions[1]);
  18326. BABYLON.Vector3.FromFloatArrayToRef(world.m, 8, this.directions[2]);
  18327. this._worldMatrix = world;
  18328. };
  18329. BoundingBox.prototype.isInFrustum = function (frustumPlanes) {
  18330. return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);
  18331. };
  18332. BoundingBox.prototype.isCompletelyInFrustum = function (frustumPlanes) {
  18333. return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);
  18334. };
  18335. BoundingBox.prototype.intersectsPoint = function (point) {
  18336. var delta = -BABYLON.Epsilon;
  18337. if (this.maximumWorld.x - point.x < delta || delta > point.x - this.minimumWorld.x)
  18338. return false;
  18339. if (this.maximumWorld.y - point.y < delta || delta > point.y - this.minimumWorld.y)
  18340. return false;
  18341. if (this.maximumWorld.z - point.z < delta || delta > point.z - this.minimumWorld.z)
  18342. return false;
  18343. return true;
  18344. };
  18345. BoundingBox.prototype.intersectsSphere = function (sphere) {
  18346. return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);
  18347. };
  18348. BoundingBox.prototype.intersectsMinMax = function (min, max) {
  18349. if (this.maximumWorld.x < min.x || this.minimumWorld.x > max.x)
  18350. return false;
  18351. if (this.maximumWorld.y < min.y || this.minimumWorld.y > max.y)
  18352. return false;
  18353. if (this.maximumWorld.z < min.z || this.minimumWorld.z > max.z)
  18354. return false;
  18355. return true;
  18356. };
  18357. // Statics
  18358. BoundingBox.Intersects = function (box0, box1) {
  18359. if (box0.maximumWorld.x < box1.minimumWorld.x || box0.minimumWorld.x > box1.maximumWorld.x)
  18360. return false;
  18361. if (box0.maximumWorld.y < box1.minimumWorld.y || box0.minimumWorld.y > box1.maximumWorld.y)
  18362. return false;
  18363. if (box0.maximumWorld.z < box1.minimumWorld.z || box0.minimumWorld.z > box1.maximumWorld.z)
  18364. return false;
  18365. return true;
  18366. };
  18367. BoundingBox.IntersectsSphere = function (minPoint, maxPoint, sphereCenter, sphereRadius) {
  18368. var vector = BABYLON.Vector3.Clamp(sphereCenter, minPoint, maxPoint);
  18369. var num = BABYLON.Vector3.DistanceSquared(sphereCenter, vector);
  18370. return (num <= (sphereRadius * sphereRadius));
  18371. };
  18372. BoundingBox.IsCompletelyInFrustum = function (boundingVectors, frustumPlanes) {
  18373. for (var p = 0; p < 6; p++) {
  18374. for (var i = 0; i < 8; i++) {
  18375. if (frustumPlanes[p].dotCoordinate(boundingVectors[i]) < 0) {
  18376. return false;
  18377. }
  18378. }
  18379. }
  18380. return true;
  18381. };
  18382. BoundingBox.IsInFrustum = function (boundingVectors, frustumPlanes) {
  18383. for (var p = 0; p < 6; p++) {
  18384. var inCount = 8;
  18385. for (var i = 0; i < 8; i++) {
  18386. if (frustumPlanes[p].dotCoordinate(boundingVectors[i]) < 0) {
  18387. --inCount;
  18388. }
  18389. else {
  18390. break;
  18391. }
  18392. }
  18393. if (inCount === 0)
  18394. return false;
  18395. }
  18396. return true;
  18397. };
  18398. return BoundingBox;
  18399. }());
  18400. BABYLON.BoundingBox = BoundingBox;
  18401. })(BABYLON || (BABYLON = {}));
  18402. //# sourceMappingURL=babylon.boundingBox.js.map
  18403. var BABYLON;
  18404. (function (BABYLON) {
  18405. var computeBoxExtents = function (axis, box) {
  18406. var p = BABYLON.Vector3.Dot(box.centerWorld, axis);
  18407. var r0 = Math.abs(BABYLON.Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;
  18408. var r1 = Math.abs(BABYLON.Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;
  18409. var r2 = Math.abs(BABYLON.Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;
  18410. var r = r0 + r1 + r2;
  18411. return {
  18412. min: p - r,
  18413. max: p + r
  18414. };
  18415. };
  18416. var extentsOverlap = function (min0, max0, min1, max1) { return !(min0 > max1 || min1 > max0); };
  18417. var axisOverlap = function (axis, box0, box1) {
  18418. var result0 = computeBoxExtents(axis, box0);
  18419. var result1 = computeBoxExtents(axis, box1);
  18420. return extentsOverlap(result0.min, result0.max, result1.min, result1.max);
  18421. };
  18422. var BoundingInfo = /** @class */ (function () {
  18423. function BoundingInfo(minimum, maximum) {
  18424. this.minimum = minimum;
  18425. this.maximum = maximum;
  18426. this._isLocked = false;
  18427. this.boundingBox = new BABYLON.BoundingBox(minimum, maximum);
  18428. this.boundingSphere = new BABYLON.BoundingSphere(minimum, maximum);
  18429. }
  18430. Object.defineProperty(BoundingInfo.prototype, "isLocked", {
  18431. get: function () {
  18432. return this._isLocked;
  18433. },
  18434. set: function (value) {
  18435. this._isLocked = value;
  18436. },
  18437. enumerable: true,
  18438. configurable: true
  18439. });
  18440. // Methods
  18441. BoundingInfo.prototype.update = function (world) {
  18442. if (this._isLocked) {
  18443. return;
  18444. }
  18445. this.boundingBox._update(world);
  18446. this.boundingSphere._update(world);
  18447. };
  18448. /**
  18449. * Recreate the bounding info to be centered around a specific point given a specific extend.
  18450. * @param center New center of the bounding info
  18451. * @param extend New extend of the bounding info
  18452. */
  18453. BoundingInfo.prototype.centerOn = function (center, extend) {
  18454. this.minimum = center.subtract(extend);
  18455. this.maximum = center.add(extend);
  18456. this.boundingBox = new BABYLON.BoundingBox(this.minimum, this.maximum);
  18457. this.boundingSphere = new BABYLON.BoundingSphere(this.minimum, this.maximum);
  18458. return this;
  18459. };
  18460. BoundingInfo.prototype.isInFrustum = function (frustumPlanes) {
  18461. if (!this.boundingSphere.isInFrustum(frustumPlanes))
  18462. return false;
  18463. return this.boundingBox.isInFrustum(frustumPlanes);
  18464. };
  18465. Object.defineProperty(BoundingInfo.prototype, "diagonalLength", {
  18466. /**
  18467. * Gets the world distance between the min and max points of the bounding box
  18468. */
  18469. get: function () {
  18470. var boundingBox = this.boundingBox;
  18471. var size = boundingBox.maximumWorld.subtract(boundingBox.minimumWorld);
  18472. return size.length();
  18473. },
  18474. enumerable: true,
  18475. configurable: true
  18476. });
  18477. BoundingInfo.prototype.isCompletelyInFrustum = function (frustumPlanes) {
  18478. return this.boundingBox.isCompletelyInFrustum(frustumPlanes);
  18479. };
  18480. BoundingInfo.prototype._checkCollision = function (collider) {
  18481. return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);
  18482. };
  18483. BoundingInfo.prototype.intersectsPoint = function (point) {
  18484. if (!this.boundingSphere.centerWorld) {
  18485. return false;
  18486. }
  18487. if (!this.boundingSphere.intersectsPoint(point)) {
  18488. return false;
  18489. }
  18490. if (!this.boundingBox.intersectsPoint(point)) {
  18491. return false;
  18492. }
  18493. return true;
  18494. };
  18495. BoundingInfo.prototype.intersects = function (boundingInfo, precise) {
  18496. if (!this.boundingSphere.centerWorld || !boundingInfo.boundingSphere.centerWorld) {
  18497. return false;
  18498. }
  18499. if (!BABYLON.BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {
  18500. return false;
  18501. }
  18502. if (!BABYLON.BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {
  18503. return false;
  18504. }
  18505. if (!precise) {
  18506. return true;
  18507. }
  18508. var box0 = this.boundingBox;
  18509. var box1 = boundingInfo.boundingBox;
  18510. if (!axisOverlap(box0.directions[0], box0, box1))
  18511. return false;
  18512. if (!axisOverlap(box0.directions[1], box0, box1))
  18513. return false;
  18514. if (!axisOverlap(box0.directions[2], box0, box1))
  18515. return false;
  18516. if (!axisOverlap(box1.directions[0], box0, box1))
  18517. return false;
  18518. if (!axisOverlap(box1.directions[1], box0, box1))
  18519. return false;
  18520. if (!axisOverlap(box1.directions[2], box0, box1))
  18521. return false;
  18522. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0], box1.directions[0]), box0, box1))
  18523. return false;
  18524. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0], box1.directions[1]), box0, box1))
  18525. return false;
  18526. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0], box1.directions[2]), box0, box1))
  18527. return false;
  18528. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1], box1.directions[0]), box0, box1))
  18529. return false;
  18530. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1], box1.directions[1]), box0, box1))
  18531. return false;
  18532. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1], box1.directions[2]), box0, box1))
  18533. return false;
  18534. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2], box1.directions[0]), box0, box1))
  18535. return false;
  18536. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2], box1.directions[1]), box0, box1))
  18537. return false;
  18538. if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1))
  18539. return false;
  18540. return true;
  18541. };
  18542. return BoundingInfo;
  18543. }());
  18544. BABYLON.BoundingInfo = BoundingInfo;
  18545. })(BABYLON || (BABYLON = {}));
  18546. //# sourceMappingURL=babylon.boundingInfo.js.map
  18547. var BABYLON;
  18548. (function (BABYLON) {
  18549. var TransformNode = /** @class */ (function (_super) {
  18550. __extends(TransformNode, _super);
  18551. function TransformNode(name, scene, isPure) {
  18552. if (scene === void 0) { scene = null; }
  18553. if (isPure === void 0) { isPure = true; }
  18554. var _this = _super.call(this, name, scene) || this;
  18555. _this._forward = new BABYLON.Vector3(0, 0, 1);
  18556. _this._forwardInverted = new BABYLON.Vector3(0, 0, -1);
  18557. _this._up = new BABYLON.Vector3(0, 1, 0);
  18558. _this._right = new BABYLON.Vector3(1, 0, 0);
  18559. _this._rightInverted = new BABYLON.Vector3(-1, 0, 0);
  18560. // Properties
  18561. _this._rotation = BABYLON.Vector3.Zero();
  18562. _this._scaling = BABYLON.Vector3.One();
  18563. _this._isDirty = false;
  18564. /**
  18565. * Set the billboard mode. Default is 0.
  18566. *
  18567. * | Value | Type | Description |
  18568. * | --- | --- | --- |
  18569. * | 0 | BILLBOARDMODE_NONE | |
  18570. * | 1 | BILLBOARDMODE_X | |
  18571. * | 2 | BILLBOARDMODE_Y | |
  18572. * | 4 | BILLBOARDMODE_Z | |
  18573. * | 7 | BILLBOARDMODE_ALL | |
  18574. *
  18575. */
  18576. _this.billboardMode = TransformNode.BILLBOARDMODE_NONE;
  18577. _this.scalingDeterminant = 1;
  18578. _this.infiniteDistance = false;
  18579. /**
  18580. * Gets or sets a boolean indicating that non uniform scaling (when at least one component is different from others) should be ignored.
  18581. * By default the system will update normals to compensate
  18582. */
  18583. _this.ignoreNonUniformScaling = false;
  18584. _this.position = BABYLON.Vector3.Zero();
  18585. _this._localWorld = BABYLON.Matrix.Zero();
  18586. _this._worldMatrix = BABYLON.Matrix.Zero();
  18587. _this._worldMatrixDeterminant = 0;
  18588. _this._absolutePosition = BABYLON.Vector3.Zero();
  18589. _this._pivotMatrix = BABYLON.Matrix.Identity();
  18590. _this._postMultiplyPivotMatrix = false;
  18591. _this._isWorldMatrixFrozen = false;
  18592. /**
  18593. * An event triggered after the world matrix is updated
  18594. */
  18595. _this.onAfterWorldMatrixUpdateObservable = new BABYLON.Observable();
  18596. _this._nonUniformScaling = false;
  18597. if (isPure) {
  18598. _this.getScene().addTransformNode(_this);
  18599. }
  18600. return _this;
  18601. }
  18602. /**
  18603. * Gets a string idenfifying the name of the class
  18604. * @returns "TransformNode" string
  18605. */
  18606. TransformNode.prototype.getClassName = function () {
  18607. return "TransformNode";
  18608. };
  18609. Object.defineProperty(TransformNode.prototype, "rotation", {
  18610. /**
  18611. * Rotation property : a Vector3 depicting the rotation value in radians around each local axis X, Y, Z.
  18612. * If rotation quaternion is set, this Vector3 will (almost always) be the Zero vector!
  18613. * Default : (0.0, 0.0, 0.0)
  18614. */
  18615. get: function () {
  18616. return this._rotation;
  18617. },
  18618. set: function (newRotation) {
  18619. this._rotation = newRotation;
  18620. },
  18621. enumerable: true,
  18622. configurable: true
  18623. });
  18624. Object.defineProperty(TransformNode.prototype, "scaling", {
  18625. /**
  18626. * Scaling property : a Vector3 depicting the mesh scaling along each local axis X, Y, Z.
  18627. * Default : (1.0, 1.0, 1.0)
  18628. */
  18629. get: function () {
  18630. return this._scaling;
  18631. },
  18632. /**
  18633. * Scaling property : a Vector3 depicting the mesh scaling along each local axis X, Y, Z.
  18634. * Default : (1.0, 1.0, 1.0)
  18635. */
  18636. set: function (newScaling) {
  18637. this._scaling = newScaling;
  18638. },
  18639. enumerable: true,
  18640. configurable: true
  18641. });
  18642. Object.defineProperty(TransformNode.prototype, "rotationQuaternion", {
  18643. /**
  18644. * Rotation Quaternion property : this a Quaternion object depicting the mesh rotation by using a unit quaternion.
  18645. * It's null by default.
  18646. * If set, only the rotationQuaternion is then used to compute the mesh rotation and its property `.rotation\ is then ignored and set to (0.0, 0.0, 0.0)
  18647. */
  18648. get: function () {
  18649. return this._rotationQuaternion;
  18650. },
  18651. set: function (quaternion) {
  18652. this._rotationQuaternion = quaternion;
  18653. //reset the rotation vector.
  18654. if (quaternion && this.rotation.length()) {
  18655. this.rotation.copyFromFloats(0.0, 0.0, 0.0);
  18656. }
  18657. },
  18658. enumerable: true,
  18659. configurable: true
  18660. });
  18661. Object.defineProperty(TransformNode.prototype, "forward", {
  18662. /**
  18663. * The forward direction of that transform in world space.
  18664. */
  18665. get: function () {
  18666. return BABYLON.Vector3.Normalize(BABYLON.Vector3.TransformNormal(this.getScene().useRightHandedSystem ? this._forwardInverted : this._forward, this.getWorldMatrix()));
  18667. },
  18668. enumerable: true,
  18669. configurable: true
  18670. });
  18671. Object.defineProperty(TransformNode.prototype, "up", {
  18672. /**
  18673. * The up direction of that transform in world space.
  18674. */
  18675. get: function () {
  18676. return BABYLON.Vector3.Normalize(BABYLON.Vector3.TransformNormal(this._up, this.getWorldMatrix()));
  18677. },
  18678. enumerable: true,
  18679. configurable: true
  18680. });
  18681. Object.defineProperty(TransformNode.prototype, "right", {
  18682. /**
  18683. * The right direction of that transform in world space.
  18684. */
  18685. get: function () {
  18686. return BABYLON.Vector3.Normalize(BABYLON.Vector3.TransformNormal(this.getScene().useRightHandedSystem ? this._rightInverted : this._right, this.getWorldMatrix()));
  18687. },
  18688. enumerable: true,
  18689. configurable: true
  18690. });
  18691. /**
  18692. * Returns the latest update of the World matrix
  18693. * Returns a Matrix.
  18694. */
  18695. TransformNode.prototype.getWorldMatrix = function () {
  18696. if (this._currentRenderId !== this.getScene().getRenderId()) {
  18697. this.computeWorldMatrix();
  18698. }
  18699. return this._worldMatrix;
  18700. };
  18701. /** @hidden */
  18702. TransformNode.prototype._getWorldMatrixDeterminant = function () {
  18703. return this._worldMatrixDeterminant;
  18704. };
  18705. Object.defineProperty(TransformNode.prototype, "worldMatrixFromCache", {
  18706. /**
  18707. * Returns directly the latest state of the mesh World matrix.
  18708. * A Matrix is returned.
  18709. */
  18710. get: function () {
  18711. return this._worldMatrix;
  18712. },
  18713. enumerable: true,
  18714. configurable: true
  18715. });
  18716. /**
  18717. * Copies the paramater passed Matrix into the mesh Pose matrix.
  18718. * Returns the TransformNode.
  18719. */
  18720. TransformNode.prototype.updatePoseMatrix = function (matrix) {
  18721. this._poseMatrix.copyFrom(matrix);
  18722. return this;
  18723. };
  18724. /**
  18725. * Returns the mesh Pose matrix.
  18726. * Returned object : Matrix
  18727. */
  18728. TransformNode.prototype.getPoseMatrix = function () {
  18729. return this._poseMatrix;
  18730. };
  18731. TransformNode.prototype._isSynchronized = function () {
  18732. if (this._isDirty) {
  18733. return false;
  18734. }
  18735. if (this.billboardMode !== this._cache.billboardMode || this.billboardMode !== TransformNode.BILLBOARDMODE_NONE)
  18736. return false;
  18737. if (this._cache.pivotMatrixUpdated) {
  18738. return false;
  18739. }
  18740. if (this.infiniteDistance) {
  18741. return false;
  18742. }
  18743. if (!this._cache.position.equals(this.position))
  18744. return false;
  18745. if (this.rotationQuaternion) {
  18746. if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
  18747. return false;
  18748. }
  18749. if (!this._cache.rotation.equals(this.rotation))
  18750. return false;
  18751. if (!this._cache.scaling.equals(this.scaling))
  18752. return false;
  18753. return true;
  18754. };
  18755. TransformNode.prototype._initCache = function () {
  18756. _super.prototype._initCache.call(this);
  18757. this._cache.localMatrixUpdated = false;
  18758. this._cache.position = BABYLON.Vector3.Zero();
  18759. this._cache.scaling = BABYLON.Vector3.Zero();
  18760. this._cache.rotation = BABYLON.Vector3.Zero();
  18761. this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
  18762. this._cache.billboardMode = -1;
  18763. };
  18764. TransformNode.prototype.markAsDirty = function (property) {
  18765. if (property === "rotation") {
  18766. this.rotationQuaternion = null;
  18767. }
  18768. this._currentRenderId = Number.MAX_VALUE;
  18769. this._isDirty = true;
  18770. return this;
  18771. };
  18772. Object.defineProperty(TransformNode.prototype, "absolutePosition", {
  18773. /**
  18774. * Returns the current mesh absolute position.
  18775. * Retuns a Vector3.
  18776. */
  18777. get: function () {
  18778. return this._absolutePosition;
  18779. },
  18780. enumerable: true,
  18781. configurable: true
  18782. });
  18783. /**
  18784. * Sets a new matrix to apply before all other transformation
  18785. * @param matrix defines the transform matrix
  18786. * @returns the current TransformNode
  18787. */
  18788. TransformNode.prototype.setPreTransformMatrix = function (matrix) {
  18789. return this.setPivotMatrix(matrix, false);
  18790. };
  18791. /**
  18792. * Sets a new pivot matrix to the current node
  18793. * @param matrix defines the new pivot matrix to use
  18794. * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect
  18795. * @returns the current TransformNode
  18796. */
  18797. TransformNode.prototype.setPivotMatrix = function (matrix, postMultiplyPivotMatrix) {
  18798. if (postMultiplyPivotMatrix === void 0) { postMultiplyPivotMatrix = true; }
  18799. this._pivotMatrix = matrix.clone();
  18800. this._cache.pivotMatrixUpdated = true;
  18801. this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;
  18802. if (this._postMultiplyPivotMatrix) {
  18803. if (!this._pivotMatrixInverse) {
  18804. this._pivotMatrixInverse = BABYLON.Matrix.Invert(this._pivotMatrix);
  18805. }
  18806. else {
  18807. this._pivotMatrix.invertToRef(this._pivotMatrixInverse);
  18808. }
  18809. }
  18810. return this;
  18811. };
  18812. /**
  18813. * Returns the mesh pivot matrix.
  18814. * Default : Identity.
  18815. * A Matrix is returned.
  18816. */
  18817. TransformNode.prototype.getPivotMatrix = function () {
  18818. return this._pivotMatrix;
  18819. };
  18820. /**
  18821. * Prevents the World matrix to be computed any longer.
  18822. * Returns the TransformNode.
  18823. */
  18824. TransformNode.prototype.freezeWorldMatrix = function () {
  18825. this._isWorldMatrixFrozen = false; // no guarantee world is not already frozen, switch off temporarily
  18826. this.computeWorldMatrix(true);
  18827. this._isWorldMatrixFrozen = true;
  18828. return this;
  18829. };
  18830. /**
  18831. * Allows back the World matrix computation.
  18832. * Returns the TransformNode.
  18833. */
  18834. TransformNode.prototype.unfreezeWorldMatrix = function () {
  18835. this._isWorldMatrixFrozen = false;
  18836. this.computeWorldMatrix(true);
  18837. return this;
  18838. };
  18839. Object.defineProperty(TransformNode.prototype, "isWorldMatrixFrozen", {
  18840. /**
  18841. * True if the World matrix has been frozen.
  18842. * Returns a boolean.
  18843. */
  18844. get: function () {
  18845. return this._isWorldMatrixFrozen;
  18846. },
  18847. enumerable: true,
  18848. configurable: true
  18849. });
  18850. /**
  18851. * Retuns the mesh absolute position in the World.
  18852. * Returns a Vector3.
  18853. */
  18854. TransformNode.prototype.getAbsolutePosition = function () {
  18855. this.computeWorldMatrix();
  18856. return this._absolutePosition;
  18857. };
  18858. /**
  18859. * Sets the mesh absolute position in the World from a Vector3 or an Array(3).
  18860. * Returns the TransformNode.
  18861. */
  18862. TransformNode.prototype.setAbsolutePosition = function (absolutePosition) {
  18863. if (!absolutePosition) {
  18864. return this;
  18865. }
  18866. var absolutePositionX;
  18867. var absolutePositionY;
  18868. var absolutePositionZ;
  18869. if (absolutePosition.x === undefined) {
  18870. if (arguments.length < 3) {
  18871. return this;
  18872. }
  18873. absolutePositionX = arguments[0];
  18874. absolutePositionY = arguments[1];
  18875. absolutePositionZ = arguments[2];
  18876. }
  18877. else {
  18878. absolutePositionX = absolutePosition.x;
  18879. absolutePositionY = absolutePosition.y;
  18880. absolutePositionZ = absolutePosition.z;
  18881. }
  18882. if (this.parent) {
  18883. var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
  18884. invertParentWorldMatrix.invert();
  18885. var worldPosition = new BABYLON.Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
  18886. this.position = BABYLON.Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
  18887. }
  18888. else {
  18889. this.position.x = absolutePositionX;
  18890. this.position.y = absolutePositionY;
  18891. this.position.z = absolutePositionZ;
  18892. }
  18893. return this;
  18894. };
  18895. /**
  18896. * Sets the mesh position in its local space.
  18897. * Returns the TransformNode.
  18898. */
  18899. TransformNode.prototype.setPositionWithLocalVector = function (vector3) {
  18900. this.computeWorldMatrix();
  18901. this.position = BABYLON.Vector3.TransformNormal(vector3, this._localWorld);
  18902. return this;
  18903. };
  18904. /**
  18905. * Returns the mesh position in the local space from the current World matrix values.
  18906. * Returns a new Vector3.
  18907. */
  18908. TransformNode.prototype.getPositionExpressedInLocalSpace = function () {
  18909. this.computeWorldMatrix();
  18910. var invLocalWorldMatrix = this._localWorld.clone();
  18911. invLocalWorldMatrix.invert();
  18912. return BABYLON.Vector3.TransformNormal(this.position, invLocalWorldMatrix);
  18913. };
  18914. /**
  18915. * Translates the mesh along the passed Vector3 in its local space.
  18916. * Returns the TransformNode.
  18917. */
  18918. TransformNode.prototype.locallyTranslate = function (vector3) {
  18919. this.computeWorldMatrix(true);
  18920. this.position = BABYLON.Vector3.TransformCoordinates(vector3, this._localWorld);
  18921. return this;
  18922. };
  18923. /**
  18924. * Orients a mesh towards a target point. Mesh must be drawn facing user.
  18925. * @param targetPoint the position (must be in same space as current mesh) to look at
  18926. * @param yawCor optional yaw (y-axis) correction in radians
  18927. * @param pitchCor optional pitch (x-axis) correction in radians
  18928. * @param rollCor optional roll (z-axis) correction in radians
  18929. * @param space the choosen space of the target
  18930. * @returns the TransformNode.
  18931. */
  18932. TransformNode.prototype.lookAt = function (targetPoint, yawCor, pitchCor, rollCor, space) {
  18933. if (yawCor === void 0) { yawCor = 0; }
  18934. if (pitchCor === void 0) { pitchCor = 0; }
  18935. if (rollCor === void 0) { rollCor = 0; }
  18936. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  18937. var dv = TransformNode._lookAtVectorCache;
  18938. var pos = space === BABYLON.Space.LOCAL ? this.position : this.getAbsolutePosition();
  18939. targetPoint.subtractToRef(pos, dv);
  18940. var yaw = -Math.atan2(dv.z, dv.x) - Math.PI / 2;
  18941. var len = Math.sqrt(dv.x * dv.x + dv.z * dv.z);
  18942. var pitch = Math.atan2(dv.y, len);
  18943. if (this.rotationQuaternion) {
  18944. BABYLON.Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);
  18945. }
  18946. else {
  18947. this.rotation.x = pitch + pitchCor;
  18948. this.rotation.y = yaw + yawCor;
  18949. this.rotation.z = rollCor;
  18950. }
  18951. return this;
  18952. };
  18953. /**
  18954. * Returns a new Vector3 what is the localAxis, expressed in the mesh local space, rotated like the mesh.
  18955. * This Vector3 is expressed in the World space.
  18956. */
  18957. TransformNode.prototype.getDirection = function (localAxis) {
  18958. var result = BABYLON.Vector3.Zero();
  18959. this.getDirectionToRef(localAxis, result);
  18960. return result;
  18961. };
  18962. /**
  18963. * Sets the Vector3 "result" as the rotated Vector3 "localAxis" in the same rotation than the mesh.
  18964. * localAxis is expressed in the mesh local space.
  18965. * result is computed in the Wordl space from the mesh World matrix.
  18966. * Returns the TransformNode.
  18967. */
  18968. TransformNode.prototype.getDirectionToRef = function (localAxis, result) {
  18969. BABYLON.Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);
  18970. return this;
  18971. };
  18972. /**
  18973. * Sets a new pivot point to the current node
  18974. * @param point defines the new pivot point to use
  18975. * @param space defines if the point is in world or local space (local by default)
  18976. * @returns the current TransformNode
  18977. */
  18978. TransformNode.prototype.setPivotPoint = function (point, space) {
  18979. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  18980. if (this.getScene().getRenderId() == 0) {
  18981. this.computeWorldMatrix(true);
  18982. }
  18983. var wm = this.getWorldMatrix();
  18984. if (space == BABYLON.Space.WORLD) {
  18985. var tmat = BABYLON.Tmp.Matrix[0];
  18986. wm.invertToRef(tmat);
  18987. point = BABYLON.Vector3.TransformCoordinates(point, tmat);
  18988. }
  18989. return this.setPivotMatrix(BABYLON.Matrix.Translation(-point.x, -point.y, -point.z), true);
  18990. };
  18991. /**
  18992. * Returns a new Vector3 set with the mesh pivot point coordinates in the local space.
  18993. */
  18994. TransformNode.prototype.getPivotPoint = function () {
  18995. var point = BABYLON.Vector3.Zero();
  18996. this.getPivotPointToRef(point);
  18997. return point;
  18998. };
  18999. /**
  19000. * Sets the passed Vector3 "result" with the coordinates of the mesh pivot point in the local space.
  19001. * Returns the TransformNode.
  19002. */
  19003. TransformNode.prototype.getPivotPointToRef = function (result) {
  19004. result.x = -this._pivotMatrix.m[12];
  19005. result.y = -this._pivotMatrix.m[13];
  19006. result.z = -this._pivotMatrix.m[14];
  19007. return this;
  19008. };
  19009. /**
  19010. * Returns a new Vector3 set with the mesh pivot point World coordinates.
  19011. */
  19012. TransformNode.prototype.getAbsolutePivotPoint = function () {
  19013. var point = BABYLON.Vector3.Zero();
  19014. this.getAbsolutePivotPointToRef(point);
  19015. return point;
  19016. };
  19017. /**
  19018. * Sets the Vector3 "result" coordinates with the mesh pivot point World coordinates.
  19019. * Returns the TransformNode.
  19020. */
  19021. TransformNode.prototype.getAbsolutePivotPointToRef = function (result) {
  19022. result.x = this._pivotMatrix.m[12];
  19023. result.y = this._pivotMatrix.m[13];
  19024. result.z = this._pivotMatrix.m[14];
  19025. this.getPivotPointToRef(result);
  19026. BABYLON.Vector3.TransformCoordinatesToRef(result, this.getWorldMatrix(), result);
  19027. return this;
  19028. };
  19029. /**
  19030. * Defines the passed node as the parent of the current node.
  19031. * The node will remain exactly where it is and its position / rotation will be updated accordingly
  19032. * Returns the TransformNode.
  19033. */
  19034. TransformNode.prototype.setParent = function (node) {
  19035. if (node === null) {
  19036. var rotation = BABYLON.Tmp.Quaternion[0];
  19037. var position = BABYLON.Tmp.Vector3[0];
  19038. var scale = BABYLON.Tmp.Vector3[1];
  19039. if (this.parent && this.parent.computeWorldMatrix) {
  19040. this.parent.computeWorldMatrix(true);
  19041. }
  19042. this.computeWorldMatrix(true);
  19043. this.getWorldMatrix().decompose(scale, rotation, position);
  19044. if (this.rotationQuaternion) {
  19045. this.rotationQuaternion.copyFrom(rotation);
  19046. }
  19047. else {
  19048. rotation.toEulerAnglesToRef(this.rotation);
  19049. }
  19050. this.scaling.x = scale.x;
  19051. this.scaling.y = scale.y;
  19052. this.scaling.z = scale.z;
  19053. this.position.x = position.x;
  19054. this.position.y = position.y;
  19055. this.position.z = position.z;
  19056. }
  19057. else {
  19058. var rotation = BABYLON.Tmp.Quaternion[0];
  19059. var position = BABYLON.Tmp.Vector3[0];
  19060. var scale = BABYLON.Tmp.Vector3[1];
  19061. var diffMatrix = BABYLON.Tmp.Matrix[0];
  19062. var invParentMatrix = BABYLON.Tmp.Matrix[1];
  19063. this.computeWorldMatrix(true);
  19064. node.computeWorldMatrix(true);
  19065. node.getWorldMatrix().invertToRef(invParentMatrix);
  19066. this.getWorldMatrix().multiplyToRef(invParentMatrix, diffMatrix);
  19067. diffMatrix.decompose(scale, rotation, position);
  19068. if (this.rotationQuaternion) {
  19069. this.rotationQuaternion.copyFrom(rotation);
  19070. }
  19071. else {
  19072. rotation.toEulerAnglesToRef(this.rotation);
  19073. }
  19074. this.position.x = position.x;
  19075. this.position.y = position.y;
  19076. this.position.z = position.z;
  19077. this.scaling.x = scale.x;
  19078. this.scaling.y = scale.y;
  19079. this.scaling.z = scale.z;
  19080. }
  19081. this.parent = node;
  19082. return this;
  19083. };
  19084. Object.defineProperty(TransformNode.prototype, "nonUniformScaling", {
  19085. get: function () {
  19086. return this._nonUniformScaling;
  19087. },
  19088. enumerable: true,
  19089. configurable: true
  19090. });
  19091. TransformNode.prototype._updateNonUniformScalingState = function (value) {
  19092. if (this._nonUniformScaling === value) {
  19093. return false;
  19094. }
  19095. this._nonUniformScaling = value;
  19096. return true;
  19097. };
  19098. /**
  19099. * Attach the current TransformNode to another TransformNode associated with a bone
  19100. * @param bone Bone affecting the TransformNode
  19101. * @param affectedTransformNode TransformNode associated with the bone
  19102. */
  19103. TransformNode.prototype.attachToBone = function (bone, affectedTransformNode) {
  19104. this._transformToBoneReferal = affectedTransformNode;
  19105. this.parent = bone;
  19106. if (bone.getWorldMatrix().determinant() < 0) {
  19107. this.scalingDeterminant *= -1;
  19108. }
  19109. return this;
  19110. };
  19111. TransformNode.prototype.detachFromBone = function () {
  19112. if (!this.parent) {
  19113. return this;
  19114. }
  19115. if (this.parent.getWorldMatrix().determinant() < 0) {
  19116. this.scalingDeterminant *= -1;
  19117. }
  19118. this._transformToBoneReferal = null;
  19119. this.parent = null;
  19120. return this;
  19121. };
  19122. /**
  19123. * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.
  19124. * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD.
  19125. * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.
  19126. * The passed axis is also normalized.
  19127. * Returns the TransformNode.
  19128. */
  19129. TransformNode.prototype.rotate = function (axis, amount, space) {
  19130. axis.normalize();
  19131. if (!this.rotationQuaternion) {
  19132. this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
  19133. this.rotation = BABYLON.Vector3.Zero();
  19134. }
  19135. var rotationQuaternion;
  19136. if (!space || space === BABYLON.Space.LOCAL) {
  19137. rotationQuaternion = BABYLON.Quaternion.RotationAxisToRef(axis, amount, TransformNode._rotationAxisCache);
  19138. this.rotationQuaternion.multiplyToRef(rotationQuaternion, this.rotationQuaternion);
  19139. }
  19140. else {
  19141. if (this.parent) {
  19142. var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
  19143. invertParentWorldMatrix.invert();
  19144. axis = BABYLON.Vector3.TransformNormal(axis, invertParentWorldMatrix);
  19145. }
  19146. rotationQuaternion = BABYLON.Quaternion.RotationAxisToRef(axis, amount, TransformNode._rotationAxisCache);
  19147. rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
  19148. }
  19149. return this;
  19150. };
  19151. /**
  19152. * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.
  19153. * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.
  19154. * The passed axis is also normalized.
  19155. * Returns the TransformNode.
  19156. * Method is based on http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm
  19157. */
  19158. TransformNode.prototype.rotateAround = function (point, axis, amount) {
  19159. axis.normalize();
  19160. if (!this.rotationQuaternion) {
  19161. this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
  19162. this.rotation.copyFromFloats(0, 0, 0);
  19163. }
  19164. point.subtractToRef(this.position, BABYLON.Tmp.Vector3[0]);
  19165. BABYLON.Matrix.TranslationToRef(BABYLON.Tmp.Vector3[0].x, BABYLON.Tmp.Vector3[0].y, BABYLON.Tmp.Vector3[0].z, BABYLON.Tmp.Matrix[0]);
  19166. BABYLON.Tmp.Matrix[0].invertToRef(BABYLON.Tmp.Matrix[2]);
  19167. BABYLON.Matrix.RotationAxisToRef(axis, amount, BABYLON.Tmp.Matrix[1]);
  19168. BABYLON.Tmp.Matrix[2].multiplyToRef(BABYLON.Tmp.Matrix[1], BABYLON.Tmp.Matrix[2]);
  19169. BABYLON.Tmp.Matrix[2].multiplyToRef(BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Matrix[2]);
  19170. BABYLON.Tmp.Matrix[2].decompose(BABYLON.Tmp.Vector3[0], BABYLON.Tmp.Quaternion[0], BABYLON.Tmp.Vector3[1]);
  19171. this.position.addInPlace(BABYLON.Tmp.Vector3[1]);
  19172. BABYLON.Tmp.Quaternion[0].multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
  19173. return this;
  19174. };
  19175. /**
  19176. * Translates the mesh along the axis vector for the passed distance in the given space.
  19177. * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD.
  19178. * Returns the TransformNode.
  19179. */
  19180. TransformNode.prototype.translate = function (axis, distance, space) {
  19181. var displacementVector = axis.scale(distance);
  19182. if (!space || space === BABYLON.Space.LOCAL) {
  19183. var tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);
  19184. this.setPositionWithLocalVector(tempV3);
  19185. }
  19186. else {
  19187. this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));
  19188. }
  19189. return this;
  19190. };
  19191. /**
  19192. * Adds a rotation step to the mesh current rotation.
  19193. * x, y, z are Euler angles expressed in radians.
  19194. * This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.
  19195. * This means this rotation is made in the mesh local space only.
  19196. * It's useful to set a custom rotation order different from the BJS standard one YXZ.
  19197. * Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.
  19198. * ```javascript
  19199. * mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);
  19200. * ```
  19201. * Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.
  19202. * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.
  19203. * Returns the TransformNode.
  19204. */
  19205. TransformNode.prototype.addRotation = function (x, y, z) {
  19206. var rotationQuaternion;
  19207. if (this.rotationQuaternion) {
  19208. rotationQuaternion = this.rotationQuaternion;
  19209. }
  19210. else {
  19211. rotationQuaternion = BABYLON.Tmp.Quaternion[1];
  19212. BABYLON.Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, rotationQuaternion);
  19213. }
  19214. var accumulation = BABYLON.Tmp.Quaternion[0];
  19215. BABYLON.Quaternion.RotationYawPitchRollToRef(y, x, z, accumulation);
  19216. rotationQuaternion.multiplyInPlace(accumulation);
  19217. if (!this.rotationQuaternion) {
  19218. rotationQuaternion.toEulerAnglesToRef(this.rotation);
  19219. }
  19220. return this;
  19221. };
  19222. /**
  19223. * Computes the mesh World matrix and returns it.
  19224. * If the mesh world matrix is frozen, this computation does nothing more than returning the last frozen values.
  19225. * If the parameter `force` is let to `false` (default), the current cached World matrix is returned.
  19226. * If the parameter `force`is set to `true`, the actual computation is done.
  19227. * Returns the mesh World Matrix.
  19228. */
  19229. TransformNode.prototype.computeWorldMatrix = function (force) {
  19230. if (this._isWorldMatrixFrozen) {
  19231. return this._worldMatrix;
  19232. }
  19233. if (!force && this.isSynchronized(true)) {
  19234. this._currentRenderId = this.getScene().getRenderId();
  19235. return this._worldMatrix;
  19236. }
  19237. this._cache.position.copyFrom(this.position);
  19238. this._cache.scaling.copyFrom(this.scaling);
  19239. this._cache.pivotMatrixUpdated = false;
  19240. this._cache.billboardMode = this.billboardMode;
  19241. this._currentRenderId = this.getScene().getRenderId();
  19242. this._childRenderId = this.getScene().getRenderId();
  19243. this._isDirty = false;
  19244. // Scaling
  19245. BABYLON.Matrix.ScalingToRef(this.scaling.x * this.scalingDeterminant, this.scaling.y * this.scalingDeterminant, this.scaling.z * this.scalingDeterminant, BABYLON.Tmp.Matrix[1]);
  19246. // Rotation
  19247. //rotate, if quaternion is set and rotation was used
  19248. if (this.rotationQuaternion) {
  19249. var len = this.rotation.length();
  19250. if (len) {
  19251. this.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z));
  19252. this.rotation.copyFromFloats(0, 0, 0);
  19253. }
  19254. }
  19255. if (this.rotationQuaternion) {
  19256. this.rotationQuaternion.toRotationMatrix(BABYLON.Tmp.Matrix[0]);
  19257. this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
  19258. }
  19259. else {
  19260. BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, BABYLON.Tmp.Matrix[0]);
  19261. this._cache.rotation.copyFrom(this.rotation);
  19262. }
  19263. // Translation
  19264. var camera = this.getScene().activeCamera;
  19265. if (this.infiniteDistance && !this.parent && camera) {
  19266. var cameraWorldMatrix = camera.getWorldMatrix();
  19267. var cameraGlobalPosition = new BABYLON.Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);
  19268. BABYLON.Matrix.TranslationToRef(this.position.x + cameraGlobalPosition.x, this.position.y + cameraGlobalPosition.y, this.position.z + cameraGlobalPosition.z, BABYLON.Tmp.Matrix[2]);
  19269. }
  19270. else {
  19271. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, BABYLON.Tmp.Matrix[2]);
  19272. }
  19273. // Composing transformations
  19274. this._pivotMatrix.multiplyToRef(BABYLON.Tmp.Matrix[1], BABYLON.Tmp.Matrix[4]);
  19275. BABYLON.Tmp.Matrix[4].multiplyToRef(BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Matrix[5]);
  19276. // Billboarding (testing PG:http://www.babylonjs-playground.com/#UJEIL#13)
  19277. if (this.billboardMode !== TransformNode.BILLBOARDMODE_NONE && camera) {
  19278. if ((this.billboardMode & TransformNode.BILLBOARDMODE_ALL) !== TransformNode.BILLBOARDMODE_ALL) {
  19279. // Need to decompose each rotation here
  19280. var currentPosition = BABYLON.Tmp.Vector3[3];
  19281. if (this.parent && this.parent.getWorldMatrix) {
  19282. if (this._transformToBoneReferal) {
  19283. this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), BABYLON.Tmp.Matrix[6]);
  19284. BABYLON.Vector3.TransformCoordinatesToRef(this.position, BABYLON.Tmp.Matrix[6], currentPosition);
  19285. }
  19286. else {
  19287. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), currentPosition);
  19288. }
  19289. }
  19290. else {
  19291. currentPosition.copyFrom(this.position);
  19292. }
  19293. currentPosition.subtractInPlace(camera.globalPosition);
  19294. var finalEuler = BABYLON.Tmp.Vector3[4].copyFromFloats(0, 0, 0);
  19295. if ((this.billboardMode & TransformNode.BILLBOARDMODE_X) === TransformNode.BILLBOARDMODE_X) {
  19296. finalEuler.x = Math.atan2(-currentPosition.y, currentPosition.z);
  19297. }
  19298. if ((this.billboardMode & TransformNode.BILLBOARDMODE_Y) === TransformNode.BILLBOARDMODE_Y) {
  19299. finalEuler.y = Math.atan2(currentPosition.x, currentPosition.z);
  19300. }
  19301. if ((this.billboardMode & TransformNode.BILLBOARDMODE_Z) === TransformNode.BILLBOARDMODE_Z) {
  19302. finalEuler.z = Math.atan2(currentPosition.y, currentPosition.x);
  19303. }
  19304. BABYLON.Matrix.RotationYawPitchRollToRef(finalEuler.y, finalEuler.x, finalEuler.z, BABYLON.Tmp.Matrix[0]);
  19305. }
  19306. else {
  19307. BABYLON.Tmp.Matrix[1].copyFrom(camera.getViewMatrix());
  19308. BABYLON.Tmp.Matrix[1].setTranslationFromFloats(0, 0, 0);
  19309. BABYLON.Tmp.Matrix[1].invertToRef(BABYLON.Tmp.Matrix[0]);
  19310. }
  19311. BABYLON.Tmp.Matrix[1].copyFrom(BABYLON.Tmp.Matrix[5]);
  19312. BABYLON.Tmp.Matrix[1].multiplyToRef(BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Matrix[5]);
  19313. }
  19314. // Local world
  19315. BABYLON.Tmp.Matrix[5].multiplyToRef(BABYLON.Tmp.Matrix[2], this._localWorld);
  19316. // Parent
  19317. if (this.parent && this.parent.getWorldMatrix) {
  19318. if (this.billboardMode !== TransformNode.BILLBOARDMODE_NONE) {
  19319. if (this._transformToBoneReferal) {
  19320. this.parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), BABYLON.Tmp.Matrix[6]);
  19321. BABYLON.Tmp.Matrix[5].copyFrom(BABYLON.Tmp.Matrix[6]);
  19322. }
  19323. else {
  19324. BABYLON.Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix());
  19325. }
  19326. this._localWorld.getTranslationToRef(BABYLON.Tmp.Vector3[5]);
  19327. BABYLON.Vector3.TransformCoordinatesToRef(BABYLON.Tmp.Vector3[5], BABYLON.Tmp.Matrix[5], BABYLON.Tmp.Vector3[5]);
  19328. this._worldMatrix.copyFrom(this._localWorld);
  19329. this._worldMatrix.setTranslation(BABYLON.Tmp.Vector3[5]);
  19330. }
  19331. else {
  19332. if (this._transformToBoneReferal) {
  19333. this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), BABYLON.Tmp.Matrix[6]);
  19334. BABYLON.Tmp.Matrix[6].multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), this._worldMatrix);
  19335. }
  19336. else {
  19337. this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
  19338. }
  19339. }
  19340. this._markSyncedWithParent();
  19341. }
  19342. else {
  19343. this._worldMatrix.copyFrom(this._localWorld);
  19344. }
  19345. // Post multiply inverse of pivotMatrix
  19346. if (this._postMultiplyPivotMatrix) {
  19347. this._worldMatrix.multiplyToRef(this._pivotMatrixInverse, this._worldMatrix);
  19348. }
  19349. // Normal matrix
  19350. if (!this.ignoreNonUniformScaling) {
  19351. if (this.scaling.isNonUniform) {
  19352. this._updateNonUniformScalingState(true);
  19353. }
  19354. else if (this.parent && this.parent._nonUniformScaling) {
  19355. this._updateNonUniformScalingState(this.parent._nonUniformScaling);
  19356. }
  19357. else {
  19358. this._updateNonUniformScalingState(false);
  19359. }
  19360. }
  19361. else {
  19362. this._updateNonUniformScalingState(false);
  19363. }
  19364. this._afterComputeWorldMatrix();
  19365. // Absolute position
  19366. this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
  19367. // Callbacks
  19368. this.onAfterWorldMatrixUpdateObservable.notifyObservers(this);
  19369. if (!this._poseMatrix) {
  19370. this._poseMatrix = BABYLON.Matrix.Invert(this._worldMatrix);
  19371. }
  19372. // Cache the determinant
  19373. this._worldMatrixDeterminant = this._worldMatrix.determinant();
  19374. return this._worldMatrix;
  19375. };
  19376. TransformNode.prototype._afterComputeWorldMatrix = function () {
  19377. };
  19378. /**
  19379. * If you'd like to be called back after the mesh position, rotation or scaling has been updated.
  19380. * @param func: callback function to add
  19381. *
  19382. * Returns the TransformNode.
  19383. */
  19384. TransformNode.prototype.registerAfterWorldMatrixUpdate = function (func) {
  19385. this.onAfterWorldMatrixUpdateObservable.add(func);
  19386. return this;
  19387. };
  19388. /**
  19389. * Removes a registered callback function.
  19390. * Returns the TransformNode.
  19391. */
  19392. TransformNode.prototype.unregisterAfterWorldMatrixUpdate = function (func) {
  19393. this.onAfterWorldMatrixUpdateObservable.removeCallback(func);
  19394. return this;
  19395. };
  19396. /**
  19397. * Clone the current transform node
  19398. * Returns the new transform node
  19399. * @param name Name of the new clone
  19400. * @param newParent New parent for the clone
  19401. * @param doNotCloneChildren Do not clone children hierarchy
  19402. */
  19403. TransformNode.prototype.clone = function (name, newParent, doNotCloneChildren) {
  19404. var _this = this;
  19405. var result = BABYLON.SerializationHelper.Clone(function () { return new TransformNode(name, _this.getScene()); }, this);
  19406. result.name = name;
  19407. result.id = name;
  19408. if (newParent) {
  19409. result.parent = newParent;
  19410. }
  19411. if (!doNotCloneChildren) {
  19412. // Children
  19413. var directDescendants = this.getDescendants(true);
  19414. for (var index = 0; index < directDescendants.length; index++) {
  19415. var child = directDescendants[index];
  19416. if (child.clone) {
  19417. child.clone(name + "." + child.name, result);
  19418. }
  19419. }
  19420. }
  19421. return result;
  19422. };
  19423. TransformNode.prototype.serialize = function (currentSerializationObject) {
  19424. var serializationObject = BABYLON.SerializationHelper.Serialize(this, currentSerializationObject);
  19425. serializationObject.type = this.getClassName();
  19426. // Parent
  19427. if (this.parent) {
  19428. serializationObject.parentId = this.parent.id;
  19429. }
  19430. if (BABYLON.Tags && BABYLON.Tags.HasTags(this)) {
  19431. serializationObject.tags = BABYLON.Tags.GetTags(this);
  19432. }
  19433. serializationObject.localMatrix = this.getPivotMatrix().asArray();
  19434. serializationObject.isEnabled = this.isEnabled();
  19435. // Parent
  19436. if (this.parent) {
  19437. serializationObject.parentId = this.parent.id;
  19438. }
  19439. return serializationObject;
  19440. };
  19441. // Statics
  19442. /**
  19443. * Returns a new TransformNode object parsed from the source provided.
  19444. * The parameter `parsedMesh` is the source.
  19445. * The parameter `rootUrl` is a string, it's the root URL to prefix the `delayLoadingFile` property with
  19446. */
  19447. TransformNode.Parse = function (parsedTransformNode, scene, rootUrl) {
  19448. var transformNode = BABYLON.SerializationHelper.Parse(function () { return new TransformNode(parsedTransformNode.name, scene); }, parsedTransformNode, scene, rootUrl);
  19449. if (BABYLON.Tags) {
  19450. BABYLON.Tags.AddTagsTo(transformNode, parsedTransformNode.tags);
  19451. }
  19452. if (parsedTransformNode.localMatrix) {
  19453. transformNode.setPreTransformMatrix(BABYLON.Matrix.FromArray(parsedTransformNode.localMatrix));
  19454. }
  19455. else if (parsedTransformNode.pivotMatrix) {
  19456. transformNode.setPivotMatrix(BABYLON.Matrix.FromArray(parsedTransformNode.pivotMatrix));
  19457. }
  19458. transformNode.setEnabled(parsedTransformNode.isEnabled);
  19459. // Parent
  19460. if (parsedTransformNode.parentId) {
  19461. transformNode._waitingParentId = parsedTransformNode.parentId;
  19462. }
  19463. return transformNode;
  19464. };
  19465. /**
  19466. * Releases resources associated with this transform node.
  19467. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  19468. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  19469. */
  19470. TransformNode.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  19471. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  19472. // Animations
  19473. this.getScene().stopAnimation(this);
  19474. // Remove from scene
  19475. this.getScene().removeTransformNode(this);
  19476. this.onAfterWorldMatrixUpdateObservable.clear();
  19477. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  19478. };
  19479. // Statics
  19480. TransformNode.BILLBOARDMODE_NONE = 0;
  19481. TransformNode.BILLBOARDMODE_X = 1;
  19482. TransformNode.BILLBOARDMODE_Y = 2;
  19483. TransformNode.BILLBOARDMODE_Z = 4;
  19484. TransformNode.BILLBOARDMODE_ALL = 7;
  19485. TransformNode._lookAtVectorCache = new BABYLON.Vector3(0, 0, 0);
  19486. TransformNode._rotationAxisCache = new BABYLON.Quaternion();
  19487. __decorate([
  19488. BABYLON.serializeAsVector3()
  19489. ], TransformNode.prototype, "_rotation", void 0);
  19490. __decorate([
  19491. BABYLON.serializeAsQuaternion()
  19492. ], TransformNode.prototype, "_rotationQuaternion", void 0);
  19493. __decorate([
  19494. BABYLON.serializeAsVector3()
  19495. ], TransformNode.prototype, "_scaling", void 0);
  19496. __decorate([
  19497. BABYLON.serialize()
  19498. ], TransformNode.prototype, "billboardMode", void 0);
  19499. __decorate([
  19500. BABYLON.serialize()
  19501. ], TransformNode.prototype, "scalingDeterminant", void 0);
  19502. __decorate([
  19503. BABYLON.serialize()
  19504. ], TransformNode.prototype, "infiniteDistance", void 0);
  19505. __decorate([
  19506. BABYLON.serialize()
  19507. ], TransformNode.prototype, "ignoreNonUniformScaling", void 0);
  19508. __decorate([
  19509. BABYLON.serializeAsVector3()
  19510. ], TransformNode.prototype, "position", void 0);
  19511. return TransformNode;
  19512. }(BABYLON.Node));
  19513. BABYLON.TransformNode = TransformNode;
  19514. })(BABYLON || (BABYLON = {}));
  19515. //# sourceMappingURL=babylon.transformNode.js.map
  19516. var BABYLON;
  19517. (function (BABYLON) {
  19518. /**
  19519. * Class used to store all common mesh properties
  19520. */
  19521. var AbstractMesh = /** @class */ (function (_super) {
  19522. __extends(AbstractMesh, _super);
  19523. // Constructor
  19524. /**
  19525. * Creates a new AbstractMesh
  19526. * @param name defines the name of the mesh
  19527. * @param scene defines the hosting scene
  19528. */
  19529. function AbstractMesh(name, scene) {
  19530. if (scene === void 0) { scene = null; }
  19531. var _this = _super.call(this, name, scene, false) || this;
  19532. _this._facetNb = 0; // facet number
  19533. _this._partitioningSubdivisions = 10; // number of subdivisions per axis in the partioning space
  19534. _this._partitioningBBoxRatio = 1.01; // the partioning array space is by default 1% bigger than the bounding box
  19535. _this._facetDataEnabled = false; // is the facet data feature enabled on this mesh ?
  19536. _this._facetParameters = {}; // keep a reference to the object parameters to avoid memory re-allocation
  19537. _this._bbSize = BABYLON.Vector3.Zero(); // bbox size approximated for facet data
  19538. _this._subDiv = {
  19539. max: 1,
  19540. X: 1,
  19541. Y: 1,
  19542. Z: 1
  19543. };
  19544. _this._facetDepthSort = false; // is the facet depth sort to be computed
  19545. _this._facetDepthSortEnabled = false; // is the facet depth sort initialized
  19546. // Events
  19547. /**
  19548. * An event triggered when this mesh collides with another one
  19549. */
  19550. _this.onCollideObservable = new BABYLON.Observable();
  19551. /**
  19552. * An event triggered when the collision's position changes
  19553. */
  19554. _this.onCollisionPositionChangeObservable = new BABYLON.Observable();
  19555. /**
  19556. * An event triggered when material is changed
  19557. */
  19558. _this.onMaterialChangedObservable = new BABYLON.Observable();
  19559. // Properties
  19560. /**
  19561. * Gets or sets the orientation for POV movement & rotation
  19562. */
  19563. _this.definedFacingForward = true;
  19564. /**
  19565. * This property determines the type of occlusion query algorithm to run in WebGl, you can use:
  19566. * * AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE which is mapped to GL_ANY_SAMPLES_PASSED.
  19567. * * AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE (Default Value) which is mapped to GL_ANY_SAMPLES_PASSED_CONSERVATIVE which is a false positive algorithm that is faster than GL_ANY_SAMPLES_PASSED but less accurate.
  19568. * @see http://doc.babylonjs.com/features/occlusionquery
  19569. */
  19570. _this.occlusionQueryAlgorithmType = AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
  19571. /**
  19572. * This property is responsible for starting the occlusion query within the Mesh or not, this property is also used to determine what should happen when the occlusionRetryCount is reached. It has supports 3 values:
  19573. * * OCCLUSION_TYPE_NONE (Default Value): this option means no occlusion query whith the Mesh.
  19574. * * OCCLUSION_TYPE_OPTIMISTIC: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken show the mesh.
  19575. * * OCCLUSION_TYPE_STRICT: this option is means use occlusion query and if occlusionRetryCount is reached and the query is broken restore the last state of the mesh occlusion if the mesh was visible then show the mesh if was hidden then hide don't show.
  19576. * @see http://doc.babylonjs.com/features/occlusionquery
  19577. */
  19578. _this.occlusionType = AbstractMesh.OCCLUSION_TYPE_NONE;
  19579. /**
  19580. * This number indicates the number of allowed retries before stop the occlusion query, this is useful if the occlusion query is taking long time before to the query result is retireved, the query result indicates if the object is visible within the scene or not and based on that Babylon.Js engine decideds to show or hide the object.
  19581. * The default value is -1 which means don't break the query and wait till the result
  19582. * @see http://doc.babylonjs.com/features/occlusionquery
  19583. */
  19584. _this.occlusionRetryCount = -1;
  19585. _this._occlusionInternalRetryCounter = 0;
  19586. _this._isOccluded = false;
  19587. _this._isOcclusionQueryInProgress = false;
  19588. _this._visibility = 1.0;
  19589. /** Gets or sets the alpha index used to sort transparent meshes
  19590. * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered#alpha-index
  19591. */
  19592. _this.alphaIndex = Number.MAX_VALUE;
  19593. /**
  19594. * Gets or sets a boolean indicating if the mesh is visible (renderable). Default is true
  19595. */
  19596. _this.isVisible = true;
  19597. /**
  19598. * Gets or sets a boolean indicating if the mesh can be picked (by scene.pick for instance or through actions). Default is true
  19599. */
  19600. _this.isPickable = true;
  19601. /**
  19602. * Gets or sets a boolean indicating if the bounding box must be rendered as well (false by default)
  19603. */
  19604. _this.showBoundingBox = false;
  19605. /** Gets or sets a boolean indicating that bounding boxes of subMeshes must be rendered as well (false by default) */
  19606. _this.showSubMeshesBoundingBox = false;
  19607. /** Gets or sets a boolean indicating if the mesh must be considered as a ray blocker for lens flares (false by default)
  19608. * @see http://doc.babylonjs.com/how_to/how_to_use_lens_flares
  19609. */
  19610. _this.isBlocker = false;
  19611. /**
  19612. * Gets or sets a boolean indicating that pointer move events must be supported on this mesh (false by default)
  19613. */
  19614. _this.enablePointerMoveEvents = false;
  19615. /**
  19616. * Specifies the rendering group id for this mesh (0 by default)
  19617. * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered#rendering-groups
  19618. */
  19619. _this.renderingGroupId = 0;
  19620. _this._receiveShadows = false;
  19621. /**
  19622. * Gets or sets a boolean indicating if the outline must be rendered as well
  19623. * @see https://www.babylonjs-playground.com/#10WJ5S#3
  19624. */
  19625. _this.renderOutline = false;
  19626. /** Defines color to use when rendering outline */
  19627. _this.outlineColor = BABYLON.Color3.Red();
  19628. /** Define width to use when rendering outline */
  19629. _this.outlineWidth = 0.02;
  19630. /**
  19631. * Gets or sets a boolean indicating if the overlay must be rendered as well
  19632. * @see https://www.babylonjs-playground.com/#10WJ5S#2
  19633. */
  19634. _this.renderOverlay = false;
  19635. /** Defines color to use when rendering overlay */
  19636. _this.overlayColor = BABYLON.Color3.Red();
  19637. /** Defines alpha to use when rendering overlay */
  19638. _this.overlayAlpha = 0.5;
  19639. _this._hasVertexAlpha = false;
  19640. _this._useVertexColors = true;
  19641. _this._computeBonesUsingShaders = true;
  19642. _this._numBoneInfluencers = 4;
  19643. _this._applyFog = true;
  19644. /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes selection (true by default) */
  19645. _this.useOctreeForRenderingSelection = true;
  19646. /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes picking (true by default) */
  19647. _this.useOctreeForPicking = true;
  19648. /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes collision (true by default) */
  19649. _this.useOctreeForCollisions = true;
  19650. _this._layerMask = 0x0FFFFFFF;
  19651. /**
  19652. * True if the mesh must be rendered in any case (this will shortcut the frustum clipping phase)
  19653. */
  19654. _this.alwaysSelectAsActiveMesh = false;
  19655. /**
  19656. * Gets or sets the current action manager
  19657. * @see http://doc.babylonjs.com/how_to/how_to_use_actions
  19658. */
  19659. _this.actionManager = null;
  19660. /**
  19661. * Gets or sets impostor used for physic simulation
  19662. * @see http://doc.babylonjs.com/features/physics_engine
  19663. */
  19664. _this.physicsImpostor = null;
  19665. // Collisions
  19666. _this._checkCollisions = false;
  19667. _this._collisionMask = -1;
  19668. _this._collisionGroup = -1;
  19669. /**
  19670. * Gets or sets the ellipsoid used to impersonate this mesh when using collision engine (default is (0.5, 1, 0.5))
  19671. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  19672. */
  19673. _this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
  19674. /**
  19675. * Gets or sets the ellipsoid offset used to impersonate this mesh when using collision engine (default is (0, 0, 0))
  19676. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  19677. */
  19678. _this.ellipsoidOffset = new BABYLON.Vector3(0, 0, 0);
  19679. _this._oldPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
  19680. _this._diffPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
  19681. // Edges
  19682. /**
  19683. * Defines edge width used when edgesRenderer is enabled
  19684. * @see https://www.babylonjs-playground.com/#10OJSG#13
  19685. */
  19686. _this.edgesWidth = 1;
  19687. /**
  19688. * Defines edge color used when edgesRenderer is enabled
  19689. * @see https://www.babylonjs-playground.com/#10OJSG#13
  19690. */
  19691. _this.edgesColor = new BABYLON.Color4(1, 0, 0, 1);
  19692. // Cache
  19693. _this._collisionsTransformMatrix = BABYLON.Matrix.Zero();
  19694. _this._collisionsScalingMatrix = BABYLON.Matrix.Zero();
  19695. /** @hidden */
  19696. _this._renderId = 0;
  19697. /** @hidden */
  19698. _this._intersectionsInProgress = new Array();
  19699. /** @hidden */
  19700. _this._unIndexed = false;
  19701. /** @hidden */
  19702. _this._lightSources = new Array();
  19703. _this._onCollisionPositionChange = function (collisionId, newPosition, collidedMesh) {
  19704. if (collidedMesh === void 0) { collidedMesh = null; }
  19705. //TODO move this to the collision coordinator!
  19706. if (_this.getScene().workerCollisions)
  19707. newPosition.multiplyInPlace(_this._collider._radius);
  19708. newPosition.subtractToRef(_this._oldPositionForCollisions, _this._diffPositionForCollisions);
  19709. if (_this._diffPositionForCollisions.length() > BABYLON.Engine.CollisionsEpsilon) {
  19710. _this.position.addInPlace(_this._diffPositionForCollisions);
  19711. }
  19712. if (collidedMesh) {
  19713. _this.onCollideObservable.notifyObservers(collidedMesh);
  19714. }
  19715. _this.onCollisionPositionChangeObservable.notifyObservers(_this.position);
  19716. };
  19717. _this.getScene().addMesh(_this);
  19718. _this._resyncLightSources();
  19719. return _this;
  19720. }
  19721. Object.defineProperty(AbstractMesh, "BILLBOARDMODE_NONE", {
  19722. /**
  19723. * No billboard
  19724. */
  19725. get: function () {
  19726. return BABYLON.TransformNode.BILLBOARDMODE_NONE;
  19727. },
  19728. enumerable: true,
  19729. configurable: true
  19730. });
  19731. Object.defineProperty(AbstractMesh, "BILLBOARDMODE_X", {
  19732. /** Billboard on X axis */
  19733. get: function () {
  19734. return BABYLON.TransformNode.BILLBOARDMODE_X;
  19735. },
  19736. enumerable: true,
  19737. configurable: true
  19738. });
  19739. Object.defineProperty(AbstractMesh, "BILLBOARDMODE_Y", {
  19740. /** Billboard on Y axis */
  19741. get: function () {
  19742. return BABYLON.TransformNode.BILLBOARDMODE_Y;
  19743. },
  19744. enumerable: true,
  19745. configurable: true
  19746. });
  19747. Object.defineProperty(AbstractMesh, "BILLBOARDMODE_Z", {
  19748. /** Billboard on Z axis */
  19749. get: function () {
  19750. return BABYLON.TransformNode.BILLBOARDMODE_Z;
  19751. },
  19752. enumerable: true,
  19753. configurable: true
  19754. });
  19755. Object.defineProperty(AbstractMesh, "BILLBOARDMODE_ALL", {
  19756. /** Billboard on all axes */
  19757. get: function () {
  19758. return BABYLON.TransformNode.BILLBOARDMODE_ALL;
  19759. },
  19760. enumerable: true,
  19761. configurable: true
  19762. });
  19763. Object.defineProperty(AbstractMesh.prototype, "facetNb", {
  19764. /**
  19765. * Gets the number of facets in the mesh
  19766. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#what-is-a-mesh-facet
  19767. */
  19768. get: function () {
  19769. return this._facetNb;
  19770. },
  19771. enumerable: true,
  19772. configurable: true
  19773. });
  19774. Object.defineProperty(AbstractMesh.prototype, "partitioningSubdivisions", {
  19775. /**
  19776. * Gets or set the number (integer) of subdivisions per axis in the partioning space
  19777. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#tweaking-the-partitioning
  19778. */
  19779. get: function () {
  19780. return this._partitioningSubdivisions;
  19781. },
  19782. set: function (nb) {
  19783. this._partitioningSubdivisions = nb;
  19784. },
  19785. enumerable: true,
  19786. configurable: true
  19787. });
  19788. Object.defineProperty(AbstractMesh.prototype, "partitioningBBoxRatio", {
  19789. /**
  19790. * The ratio (float) to apply to the bouding box size to set to the partioning space.
  19791. * Ex : 1.01 (default) the partioning space is 1% bigger than the bounding box
  19792. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#tweaking-the-partitioning
  19793. */
  19794. get: function () {
  19795. return this._partitioningBBoxRatio;
  19796. },
  19797. set: function (ratio) {
  19798. this._partitioningBBoxRatio = ratio;
  19799. },
  19800. enumerable: true,
  19801. configurable: true
  19802. });
  19803. Object.defineProperty(AbstractMesh.prototype, "mustDepthSortFacets", {
  19804. /**
  19805. * Gets or sets a boolean indicating that the facets must be depth sorted on next call to `updateFacetData()`.
  19806. * Works only for updatable meshes.
  19807. * Doesn't work with multi-materials
  19808. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#facet-depth-sort
  19809. */
  19810. get: function () {
  19811. return this._facetDepthSort;
  19812. },
  19813. set: function (sort) {
  19814. this._facetDepthSort = sort;
  19815. },
  19816. enumerable: true,
  19817. configurable: true
  19818. });
  19819. Object.defineProperty(AbstractMesh.prototype, "facetDepthSortFrom", {
  19820. /**
  19821. * The location (Vector3) where the facet depth sort must be computed from.
  19822. * By default, the active camera position.
  19823. * Used only when facet depth sort is enabled
  19824. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#facet-depth-sort
  19825. */
  19826. get: function () {
  19827. return this._facetDepthSortFrom;
  19828. },
  19829. set: function (location) {
  19830. this._facetDepthSortFrom = location;
  19831. },
  19832. enumerable: true,
  19833. configurable: true
  19834. });
  19835. Object.defineProperty(AbstractMesh.prototype, "isFacetDataEnabled", {
  19836. /**
  19837. * gets a boolean indicating if facetData is enabled
  19838. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata#what-is-a-mesh-facet
  19839. */
  19840. get: function () {
  19841. return this._facetDataEnabled;
  19842. },
  19843. enumerable: true,
  19844. configurable: true
  19845. });
  19846. /** @hidden */
  19847. AbstractMesh.prototype._updateNonUniformScalingState = function (value) {
  19848. if (!_super.prototype._updateNonUniformScalingState.call(this, value)) {
  19849. return false;
  19850. }
  19851. this._markSubMeshesAsMiscDirty();
  19852. return true;
  19853. };
  19854. Object.defineProperty(AbstractMesh.prototype, "onCollide", {
  19855. /** Set a function to call when this mesh collides with another one */
  19856. set: function (callback) {
  19857. if (this._onCollideObserver) {
  19858. this.onCollideObservable.remove(this._onCollideObserver);
  19859. }
  19860. this._onCollideObserver = this.onCollideObservable.add(callback);
  19861. },
  19862. enumerable: true,
  19863. configurable: true
  19864. });
  19865. Object.defineProperty(AbstractMesh.prototype, "onCollisionPositionChange", {
  19866. /** Set a function to call when the collision's position changes */
  19867. set: function (callback) {
  19868. if (this._onCollisionPositionChangeObserver) {
  19869. this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver);
  19870. }
  19871. this._onCollisionPositionChangeObserver = this.onCollisionPositionChangeObservable.add(callback);
  19872. },
  19873. enumerable: true,
  19874. configurable: true
  19875. });
  19876. Object.defineProperty(AbstractMesh.prototype, "isOccluded", {
  19877. /**
  19878. * Gets or sets whether the mesh is occluded or not, it is used also to set the intial state of the mesh to be occluded or not
  19879. * @see http://doc.babylonjs.com/features/occlusionquery
  19880. */
  19881. get: function () {
  19882. return this._isOccluded;
  19883. },
  19884. set: function (value) {
  19885. this._isOccluded = value;
  19886. },
  19887. enumerable: true,
  19888. configurable: true
  19889. });
  19890. Object.defineProperty(AbstractMesh.prototype, "isOcclusionQueryInProgress", {
  19891. /**
  19892. * Flag to check the progress status of the query
  19893. * @see http://doc.babylonjs.com/features/occlusionquery
  19894. */
  19895. get: function () {
  19896. return this._isOcclusionQueryInProgress;
  19897. },
  19898. enumerable: true,
  19899. configurable: true
  19900. });
  19901. Object.defineProperty(AbstractMesh.prototype, "visibility", {
  19902. /**
  19903. * Gets or sets mesh visibility between 0 and 1 (default is 1)
  19904. */
  19905. get: function () {
  19906. return this._visibility;
  19907. },
  19908. /**
  19909. * Gets or sets mesh visibility between 0 and 1 (default is 1)
  19910. */
  19911. set: function (value) {
  19912. if (this._visibility === value) {
  19913. return;
  19914. }
  19915. this._visibility = value;
  19916. this._markSubMeshesAsMiscDirty();
  19917. },
  19918. enumerable: true,
  19919. configurable: true
  19920. });
  19921. Object.defineProperty(AbstractMesh.prototype, "material", {
  19922. /** Gets or sets current material */
  19923. get: function () {
  19924. return this._material;
  19925. },
  19926. set: function (value) {
  19927. if (this._material === value) {
  19928. return;
  19929. }
  19930. this._material = value;
  19931. if (this.onMaterialChangedObservable.hasObservers) {
  19932. this.onMaterialChangedObservable.notifyObservers(this);
  19933. }
  19934. if (!this.subMeshes) {
  19935. return;
  19936. }
  19937. this._unBindEffect();
  19938. },
  19939. enumerable: true,
  19940. configurable: true
  19941. });
  19942. Object.defineProperty(AbstractMesh.prototype, "receiveShadows", {
  19943. /**
  19944. * Gets or sets a boolean indicating that this mesh can receive realtime shadows
  19945. * @see http://doc.babylonjs.com/babylon101/shadows
  19946. */
  19947. get: function () {
  19948. return this._receiveShadows;
  19949. },
  19950. set: function (value) {
  19951. if (this._receiveShadows === value) {
  19952. return;
  19953. }
  19954. this._receiveShadows = value;
  19955. this._markSubMeshesAsLightDirty();
  19956. },
  19957. enumerable: true,
  19958. configurable: true
  19959. });
  19960. Object.defineProperty(AbstractMesh.prototype, "hasVertexAlpha", {
  19961. /** Gets or sets a boolean indicating that this mesh contains vertex color data with alpha values */
  19962. get: function () {
  19963. return this._hasVertexAlpha;
  19964. },
  19965. set: function (value) {
  19966. if (this._hasVertexAlpha === value) {
  19967. return;
  19968. }
  19969. this._hasVertexAlpha = value;
  19970. this._markSubMeshesAsAttributesDirty();
  19971. this._markSubMeshesAsMiscDirty();
  19972. },
  19973. enumerable: true,
  19974. configurable: true
  19975. });
  19976. Object.defineProperty(AbstractMesh.prototype, "useVertexColors", {
  19977. /** Gets or sets a boolean indicating that this mesh needs to use vertex color data to render (if this kind of vertex data is available in the geometry) */
  19978. get: function () {
  19979. return this._useVertexColors;
  19980. },
  19981. set: function (value) {
  19982. if (this._useVertexColors === value) {
  19983. return;
  19984. }
  19985. this._useVertexColors = value;
  19986. this._markSubMeshesAsAttributesDirty();
  19987. },
  19988. enumerable: true,
  19989. configurable: true
  19990. });
  19991. Object.defineProperty(AbstractMesh.prototype, "computeBonesUsingShaders", {
  19992. /**
  19993. * Gets or sets a boolean indicating that bone animations must be computed by the CPU (false by default)
  19994. */
  19995. get: function () {
  19996. return this._computeBonesUsingShaders;
  19997. },
  19998. set: function (value) {
  19999. if (this._computeBonesUsingShaders === value) {
  20000. return;
  20001. }
  20002. this._computeBonesUsingShaders = value;
  20003. this._markSubMeshesAsAttributesDirty();
  20004. },
  20005. enumerable: true,
  20006. configurable: true
  20007. });
  20008. Object.defineProperty(AbstractMesh.prototype, "numBoneInfluencers", {
  20009. /** Gets or sets the number of allowed bone influences per vertex (4 by default) */
  20010. get: function () {
  20011. return this._numBoneInfluencers;
  20012. },
  20013. set: function (value) {
  20014. if (this._numBoneInfluencers === value) {
  20015. return;
  20016. }
  20017. this._numBoneInfluencers = value;
  20018. this._markSubMeshesAsAttributesDirty();
  20019. },
  20020. enumerable: true,
  20021. configurable: true
  20022. });
  20023. Object.defineProperty(AbstractMesh.prototype, "applyFog", {
  20024. /** Gets or sets a boolean indicating that this mesh will allow fog to be rendered on it (true by default) */
  20025. get: function () {
  20026. return this._applyFog;
  20027. },
  20028. set: function (value) {
  20029. if (this._applyFog === value) {
  20030. return;
  20031. }
  20032. this._applyFog = value;
  20033. this._markSubMeshesAsMiscDirty();
  20034. },
  20035. enumerable: true,
  20036. configurable: true
  20037. });
  20038. Object.defineProperty(AbstractMesh.prototype, "layerMask", {
  20039. /**
  20040. * Gets or sets the current layer mask (default is 0x0FFFFFFF)
  20041. * @see http://doc.babylonjs.com/how_to/layermasks_and_multi-cam_textures
  20042. */
  20043. get: function () {
  20044. return this._layerMask;
  20045. },
  20046. set: function (value) {
  20047. if (value === this._layerMask) {
  20048. return;
  20049. }
  20050. this._layerMask = value;
  20051. this._resyncLightSources();
  20052. },
  20053. enumerable: true,
  20054. configurable: true
  20055. });
  20056. Object.defineProperty(AbstractMesh.prototype, "collisionMask", {
  20057. /**
  20058. * Gets or sets a collision mask used to mask collisions (default is -1).
  20059. * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0
  20060. */
  20061. get: function () {
  20062. return this._collisionMask;
  20063. },
  20064. set: function (mask) {
  20065. this._collisionMask = !isNaN(mask) ? mask : -1;
  20066. },
  20067. enumerable: true,
  20068. configurable: true
  20069. });
  20070. Object.defineProperty(AbstractMesh.prototype, "collisionGroup", {
  20071. /**
  20072. * Gets or sets the current collision group mask (-1 by default).
  20073. * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0
  20074. */
  20075. get: function () {
  20076. return this._collisionGroup;
  20077. },
  20078. set: function (mask) {
  20079. this._collisionGroup = !isNaN(mask) ? mask : -1;
  20080. },
  20081. enumerable: true,
  20082. configurable: true
  20083. });
  20084. Object.defineProperty(AbstractMesh.prototype, "_positions", {
  20085. /** @hidden */
  20086. get: function () {
  20087. return null;
  20088. },
  20089. enumerable: true,
  20090. configurable: true
  20091. });
  20092. Object.defineProperty(AbstractMesh.prototype, "skeleton", {
  20093. get: function () {
  20094. return this._skeleton;
  20095. },
  20096. /**
  20097. * Gets or sets a skeleton to apply skining transformations
  20098. * @see http://doc.babylonjs.com/how_to/how_to_use_bones_and_skeletons
  20099. */
  20100. set: function (value) {
  20101. if (this._skeleton && this._skeleton.needInitialSkinMatrix) {
  20102. this._skeleton._unregisterMeshWithPoseMatrix(this);
  20103. }
  20104. if (value && value.needInitialSkinMatrix) {
  20105. value._registerMeshWithPoseMatrix(this);
  20106. }
  20107. this._skeleton = value;
  20108. if (!this._skeleton) {
  20109. this._bonesTransformMatrices = null;
  20110. }
  20111. this._markSubMeshesAsAttributesDirty();
  20112. },
  20113. enumerable: true,
  20114. configurable: true
  20115. });
  20116. /**
  20117. * Returns the string "AbstractMesh"
  20118. * @returns "AbstractMesh"
  20119. */
  20120. AbstractMesh.prototype.getClassName = function () {
  20121. return "AbstractMesh";
  20122. };
  20123. /**
  20124. * Gets a string representation of the current mesh
  20125. * @param fullDetails defines a boolean indicating if full details must be included
  20126. * @returns a string representation of the current mesh
  20127. */
  20128. AbstractMesh.prototype.toString = function (fullDetails) {
  20129. var ret = "Name: " + this.name + ", isInstance: " + (this instanceof BABYLON.InstancedMesh ? "YES" : "NO");
  20130. ret += ", # of submeshes: " + (this.subMeshes ? this.subMeshes.length : 0);
  20131. if (this._skeleton) {
  20132. ret += ", skeleton: " + this._skeleton.name;
  20133. }
  20134. if (fullDetails) {
  20135. ret += ", billboard mode: " + (["NONE", "X", "Y", null, "Z", null, null, "ALL"])[this.billboardMode];
  20136. ret += ", freeze wrld mat: " + (this._isWorldMatrixFrozen || this._waitingFreezeWorldMatrix ? "YES" : "NO");
  20137. }
  20138. return ret;
  20139. };
  20140. /** @hidden */
  20141. AbstractMesh.prototype._rebuild = function () {
  20142. if (this._occlusionQuery) {
  20143. this._occlusionQuery = null;
  20144. }
  20145. if (this._edgesRenderer) {
  20146. this._edgesRenderer._rebuild();
  20147. }
  20148. if (!this.subMeshes) {
  20149. return;
  20150. }
  20151. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  20152. var subMesh = _a[_i];
  20153. subMesh._rebuild();
  20154. }
  20155. };
  20156. /** @hidden */
  20157. AbstractMesh.prototype._resyncLightSources = function () {
  20158. this._lightSources.length = 0;
  20159. for (var _i = 0, _a = this.getScene().lights; _i < _a.length; _i++) {
  20160. var light = _a[_i];
  20161. if (!light.isEnabled()) {
  20162. continue;
  20163. }
  20164. if (light.canAffectMesh(this)) {
  20165. this._lightSources.push(light);
  20166. }
  20167. }
  20168. this._markSubMeshesAsLightDirty();
  20169. };
  20170. /** @hidden */
  20171. AbstractMesh.prototype._resyncLighSource = function (light) {
  20172. var isIn = light.isEnabled() && light.canAffectMesh(this);
  20173. var index = this._lightSources.indexOf(light);
  20174. if (index === -1) {
  20175. if (!isIn) {
  20176. return;
  20177. }
  20178. this._lightSources.push(light);
  20179. }
  20180. else {
  20181. if (isIn) {
  20182. return;
  20183. }
  20184. this._lightSources.splice(index, 1);
  20185. }
  20186. this._markSubMeshesAsLightDirty();
  20187. };
  20188. /** @hidden */
  20189. AbstractMesh.prototype._unBindEffect = function () {
  20190. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  20191. var subMesh = _a[_i];
  20192. subMesh.setEffect(null);
  20193. }
  20194. };
  20195. /** @hidden */
  20196. AbstractMesh.prototype._removeLightSource = function (light) {
  20197. var index = this._lightSources.indexOf(light);
  20198. if (index === -1) {
  20199. return;
  20200. }
  20201. this._lightSources.splice(index, 1);
  20202. this._markSubMeshesAsLightDirty();
  20203. };
  20204. AbstractMesh.prototype._markSubMeshesAsDirty = function (func) {
  20205. if (!this.subMeshes) {
  20206. return;
  20207. }
  20208. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  20209. var subMesh = _a[_i];
  20210. if (subMesh._materialDefines) {
  20211. func(subMesh._materialDefines);
  20212. }
  20213. }
  20214. };
  20215. /** @hidden */
  20216. AbstractMesh.prototype._markSubMeshesAsLightDirty = function () {
  20217. this._markSubMeshesAsDirty(function (defines) { return defines.markAsLightDirty(); });
  20218. };
  20219. /** @hidden */
  20220. AbstractMesh.prototype._markSubMeshesAsAttributesDirty = function () {
  20221. this._markSubMeshesAsDirty(function (defines) { return defines.markAsAttributesDirty(); });
  20222. };
  20223. /** @hidden */
  20224. AbstractMesh.prototype._markSubMeshesAsMiscDirty = function () {
  20225. if (!this.subMeshes) {
  20226. return;
  20227. }
  20228. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  20229. var subMesh = _a[_i];
  20230. var material = subMesh.getMaterial();
  20231. if (material) {
  20232. material.markAsDirty(BABYLON.Material.MiscDirtyFlag);
  20233. }
  20234. }
  20235. };
  20236. Object.defineProperty(AbstractMesh.prototype, "scaling", {
  20237. /**
  20238. * Gets or sets a Vector3 depicting the mesh scaling along each local axis X, Y, Z. Default is (1.0, 1.0, 1.0)
  20239. */
  20240. get: function () {
  20241. return this._scaling;
  20242. },
  20243. set: function (newScaling) {
  20244. this._scaling = newScaling;
  20245. if (this.physicsImpostor) {
  20246. this.physicsImpostor.forceUpdate();
  20247. }
  20248. },
  20249. enumerable: true,
  20250. configurable: true
  20251. });
  20252. // Methods
  20253. /**
  20254. * Disables the mesh edge rendering mode
  20255. * @returns the currentAbstractMesh
  20256. */
  20257. AbstractMesh.prototype.disableEdgesRendering = function () {
  20258. if (this._edgesRenderer) {
  20259. this._edgesRenderer.dispose();
  20260. this._edgesRenderer = null;
  20261. }
  20262. return this;
  20263. };
  20264. /**
  20265. * Enables the edge rendering mode on the mesh.
  20266. * This mode makes the mesh edges visible
  20267. * @param epsilon defines the maximal distance between two angles to detect a face
  20268. * @param checkVerticesInsteadOfIndices indicates that we should check vertex list directly instead of faces
  20269. * @returns the currentAbstractMesh
  20270. * @see https://www.babylonjs-playground.com/#19O9TU#0
  20271. */
  20272. AbstractMesh.prototype.enableEdgesRendering = function (epsilon, checkVerticesInsteadOfIndices) {
  20273. if (epsilon === void 0) { epsilon = 0.95; }
  20274. if (checkVerticesInsteadOfIndices === void 0) { checkVerticesInsteadOfIndices = false; }
  20275. this.disableEdgesRendering();
  20276. this._edgesRenderer = new BABYLON.EdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices);
  20277. return this;
  20278. };
  20279. Object.defineProperty(AbstractMesh.prototype, "edgesRenderer", {
  20280. /**
  20281. * Gets the edgesRenderer associated with the mesh
  20282. */
  20283. get: function () {
  20284. return this._edgesRenderer;
  20285. },
  20286. enumerable: true,
  20287. configurable: true
  20288. });
  20289. Object.defineProperty(AbstractMesh.prototype, "isBlocked", {
  20290. /**
  20291. * Returns true if the mesh is blocked. Implemented by child classes
  20292. */
  20293. get: function () {
  20294. return false;
  20295. },
  20296. enumerable: true,
  20297. configurable: true
  20298. });
  20299. /**
  20300. * Returns the mesh itself by default. Implemented by child classes
  20301. * @param camera defines the camera to use to pick the right LOD level
  20302. * @returns the currentAbstractMesh
  20303. */
  20304. AbstractMesh.prototype.getLOD = function (camera) {
  20305. return this;
  20306. };
  20307. /**
  20308. * Returns 0 by default. Implemented by child classes
  20309. * @returns an integer
  20310. */
  20311. AbstractMesh.prototype.getTotalVertices = function () {
  20312. return 0;
  20313. };
  20314. /**
  20315. * Returns null by default. Implemented by child classes
  20316. * @returns null
  20317. */
  20318. AbstractMesh.prototype.getIndices = function () {
  20319. return null;
  20320. };
  20321. /**
  20322. * Returns the array of the requested vertex data kind. Implemented by child classes
  20323. * @param kind defines the vertex data kind to use
  20324. * @returns null
  20325. */
  20326. AbstractMesh.prototype.getVerticesData = function (kind) {
  20327. return null;
  20328. };
  20329. /**
  20330. * Sets the vertex data of the mesh geometry for the requested `kind`.
  20331. * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.
  20332. * Note that a new underlying VertexBuffer object is created each call.
  20333. * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
  20334. * @param kind defines vertex data kind:
  20335. * * BABYLON.VertexBuffer.PositionKind
  20336. * * BABYLON.VertexBuffer.UVKind
  20337. * * BABYLON.VertexBuffer.UV2Kind
  20338. * * BABYLON.VertexBuffer.UV3Kind
  20339. * * BABYLON.VertexBuffer.UV4Kind
  20340. * * BABYLON.VertexBuffer.UV5Kind
  20341. * * BABYLON.VertexBuffer.UV6Kind
  20342. * * BABYLON.VertexBuffer.ColorKind
  20343. * * BABYLON.VertexBuffer.MatricesIndicesKind
  20344. * * BABYLON.VertexBuffer.MatricesIndicesExtraKind
  20345. * * BABYLON.VertexBuffer.MatricesWeightsKind
  20346. * * BABYLON.VertexBuffer.MatricesWeightsExtraKind
  20347. * @param data defines the data source
  20348. * @param updatable defines if the data must be flagged as updatable (or static)
  20349. * @param stride defines the vertex stride (size of an entire vertex). Can be null and in this case will be deduced from vertex data kind
  20350. * @returns the current mesh
  20351. */
  20352. AbstractMesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
  20353. return this;
  20354. };
  20355. /**
  20356. * Updates the existing vertex data of the mesh geometry for the requested `kind`.
  20357. * If the mesh has no geometry, it is simply returned as it is.
  20358. * @param kind defines vertex data kind:
  20359. * * BABYLON.VertexBuffer.PositionKind
  20360. * * BABYLON.VertexBuffer.UVKind
  20361. * * BABYLON.VertexBuffer.UV2Kind
  20362. * * BABYLON.VertexBuffer.UV3Kind
  20363. * * BABYLON.VertexBuffer.UV4Kind
  20364. * * BABYLON.VertexBuffer.UV5Kind
  20365. * * BABYLON.VertexBuffer.UV6Kind
  20366. * * BABYLON.VertexBuffer.ColorKind
  20367. * * BABYLON.VertexBuffer.MatricesIndicesKind
  20368. * * BABYLON.VertexBuffer.MatricesIndicesExtraKind
  20369. * * BABYLON.VertexBuffer.MatricesWeightsKind
  20370. * * BABYLON.VertexBuffer.MatricesWeightsExtraKind
  20371. * @param data defines the data source
  20372. * @param updateExtends If `kind` is `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed
  20373. * @param makeItUnique If true, a new global geometry is created from this data and is set to the mesh
  20374. * @returns the current mesh
  20375. */
  20376. AbstractMesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
  20377. return this;
  20378. };
  20379. /**
  20380. * Sets the mesh indices,
  20381. * If the mesh has no geometry, a new Geometry object is created and set to the mesh.
  20382. * @param indices Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array)
  20383. * @param totalVertices Defines the total number of vertices
  20384. * @returns the current mesh
  20385. */
  20386. AbstractMesh.prototype.setIndices = function (indices, totalVertices) {
  20387. return this;
  20388. };
  20389. /**
  20390. * Gets a boolean indicating if specific vertex data is present
  20391. * @param kind defines the vertex data kind to use
  20392. * @returns true is data kind is present
  20393. */
  20394. AbstractMesh.prototype.isVerticesDataPresent = function (kind) {
  20395. return false;
  20396. };
  20397. /**
  20398. * Returns the mesh BoundingInfo object or creates a new one and returns if it was undefined
  20399. * @returns a BoundingInfo
  20400. */
  20401. AbstractMesh.prototype.getBoundingInfo = function () {
  20402. if (this._masterMesh) {
  20403. return this._masterMesh.getBoundingInfo();
  20404. }
  20405. if (!this._boundingInfo) {
  20406. // this._boundingInfo is being created here
  20407. this._updateBoundingInfo();
  20408. }
  20409. // cannot be null.
  20410. return this._boundingInfo;
  20411. };
  20412. /**
  20413. * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units)
  20414. * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box
  20415. * @returns the current mesh
  20416. */
  20417. AbstractMesh.prototype.normalizeToUnitCube = function (includeDescendants) {
  20418. if (includeDescendants === void 0) { includeDescendants = true; }
  20419. var boundingVectors = this.getHierarchyBoundingVectors(includeDescendants);
  20420. var sizeVec = boundingVectors.max.subtract(boundingVectors.min);
  20421. var maxDimension = Math.max(sizeVec.x, sizeVec.y, sizeVec.z);
  20422. if (maxDimension === 0) {
  20423. return this;
  20424. }
  20425. var scale = 1 / maxDimension;
  20426. this.scaling.scaleInPlace(scale);
  20427. return this;
  20428. };
  20429. /**
  20430. * Overwrite the current bounding info
  20431. * @param boundingInfo defines the new bounding info
  20432. * @returns the current mesh
  20433. */
  20434. AbstractMesh.prototype.setBoundingInfo = function (boundingInfo) {
  20435. this._boundingInfo = boundingInfo;
  20436. return this;
  20437. };
  20438. Object.defineProperty(AbstractMesh.prototype, "useBones", {
  20439. /** Gets a boolean indicating if this mesh has skinning data and an attached skeleton */
  20440. get: function () {
  20441. return (this.skeleton && this.getScene().skeletonsEnabled && this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind));
  20442. },
  20443. enumerable: true,
  20444. configurable: true
  20445. });
  20446. /** @hidden */
  20447. AbstractMesh.prototype._preActivate = function () {
  20448. };
  20449. /** @hidden */
  20450. AbstractMesh.prototype._preActivateForIntermediateRendering = function (renderId) {
  20451. };
  20452. /** @hidden */
  20453. AbstractMesh.prototype._activate = function (renderId) {
  20454. this._renderId = renderId;
  20455. };
  20456. /**
  20457. * Gets the current world matrix
  20458. * @returns a Matrix
  20459. */
  20460. AbstractMesh.prototype.getWorldMatrix = function () {
  20461. if (this._masterMesh) {
  20462. return this._masterMesh.getWorldMatrix();
  20463. }
  20464. return _super.prototype.getWorldMatrix.call(this);
  20465. };
  20466. /** @hidden */
  20467. AbstractMesh.prototype._getWorldMatrixDeterminant = function () {
  20468. if (this._masterMesh) {
  20469. return this._masterMesh._getWorldMatrixDeterminant();
  20470. }
  20471. return _super.prototype._getWorldMatrixDeterminant.call(this);
  20472. };
  20473. // ================================== Point of View Movement =================================
  20474. /**
  20475. * Perform relative position change from the point of view of behind the front of the mesh.
  20476. * This is performed taking into account the meshes current rotation, so you do not have to care.
  20477. * Supports definition of mesh facing forward or backward
  20478. * @param amountRight defines the distance on the right axis
  20479. * @param amountUp defines the distance on the up axis
  20480. * @param amountForward defines the distance on the forward axis
  20481. * @returns the current mesh
  20482. */
  20483. AbstractMesh.prototype.movePOV = function (amountRight, amountUp, amountForward) {
  20484. this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));
  20485. return this;
  20486. };
  20487. /**
  20488. * Calculate relative position change from the point of view of behind the front of the mesh.
  20489. * This is performed taking into account the meshes current rotation, so you do not have to care.
  20490. * Supports definition of mesh facing forward or backward
  20491. * @param amountRight defines the distance on the right axis
  20492. * @param amountUp defines the distance on the up axis
  20493. * @param amountForward defines the distance on the forward axis
  20494. * @returns the new displacement vector
  20495. */
  20496. AbstractMesh.prototype.calcMovePOV = function (amountRight, amountUp, amountForward) {
  20497. var rotMatrix = new BABYLON.Matrix();
  20498. var rotQuaternion = (this.rotationQuaternion) ? this.rotationQuaternion : BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
  20499. rotQuaternion.toRotationMatrix(rotMatrix);
  20500. var translationDelta = BABYLON.Vector3.Zero();
  20501. var defForwardMult = this.definedFacingForward ? -1 : 1;
  20502. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(amountRight * defForwardMult, amountUp, amountForward * defForwardMult, rotMatrix, translationDelta);
  20503. return translationDelta;
  20504. };
  20505. // ================================== Point of View Rotation =================================
  20506. /**
  20507. * Perform relative rotation change from the point of view of behind the front of the mesh.
  20508. * Supports definition of mesh facing forward or backward
  20509. * @param flipBack defines the flip
  20510. * @param twirlClockwise defines the twirl
  20511. * @param tiltRight defines the tilt
  20512. * @returns the current mesh
  20513. */
  20514. AbstractMesh.prototype.rotatePOV = function (flipBack, twirlClockwise, tiltRight) {
  20515. this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));
  20516. return this;
  20517. };
  20518. /**
  20519. * Calculate relative rotation change from the point of view of behind the front of the mesh.
  20520. * Supports definition of mesh facing forward or backward.
  20521. * @param flipBack defines the flip
  20522. * @param twirlClockwise defines the twirl
  20523. * @param tiltRight defines the tilt
  20524. * @returns the new rotation vector
  20525. */
  20526. AbstractMesh.prototype.calcRotatePOV = function (flipBack, twirlClockwise, tiltRight) {
  20527. var defForwardMult = this.definedFacingForward ? 1 : -1;
  20528. return new BABYLON.Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);
  20529. };
  20530. /**
  20531. * Return the minimum and maximum world vectors of the entire hierarchy under current mesh
  20532. * @param includeDescendants Include bounding info from descendants as well (true by default)
  20533. * @param predicate defines a callback function that can be customize to filter what meshes should be included in the list used to compute the bounding vectors
  20534. * @returns the new bounding vectors
  20535. */
  20536. AbstractMesh.prototype.getHierarchyBoundingVectors = function (includeDescendants, predicate) {
  20537. if (includeDescendants === void 0) { includeDescendants = true; }
  20538. if (predicate === void 0) { predicate = null; }
  20539. // Ensures that all world matrix will be recomputed.
  20540. this.getScene().incrementRenderId();
  20541. this.computeWorldMatrix(true);
  20542. var min;
  20543. var max;
  20544. var boundingInfo = this.getBoundingInfo();
  20545. if (!this.subMeshes) {
  20546. min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  20547. max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  20548. }
  20549. else {
  20550. min = boundingInfo.boundingBox.minimumWorld;
  20551. max = boundingInfo.boundingBox.maximumWorld;
  20552. }
  20553. if (includeDescendants) {
  20554. var descendants = this.getDescendants(false);
  20555. for (var _i = 0, descendants_1 = descendants; _i < descendants_1.length; _i++) {
  20556. var descendant = descendants_1[_i];
  20557. var childMesh = descendant;
  20558. childMesh.computeWorldMatrix(true);
  20559. // Filters meshes based on custom predicate function.
  20560. if (predicate && !predicate(childMesh)) {
  20561. continue;
  20562. }
  20563. //make sure we have the needed params to get mix and max
  20564. if (!childMesh.getBoundingInfo || childMesh.getTotalVertices() === 0) {
  20565. continue;
  20566. }
  20567. var childBoundingInfo = childMesh.getBoundingInfo();
  20568. var boundingBox = childBoundingInfo.boundingBox;
  20569. var minBox = boundingBox.minimumWorld;
  20570. var maxBox = boundingBox.maximumWorld;
  20571. BABYLON.Tools.CheckExtends(minBox, min, max);
  20572. BABYLON.Tools.CheckExtends(maxBox, min, max);
  20573. }
  20574. }
  20575. return {
  20576. min: min,
  20577. max: max
  20578. };
  20579. };
  20580. /** @hidden */
  20581. AbstractMesh.prototype._updateBoundingInfo = function () {
  20582. this._boundingInfo = this._boundingInfo || new BABYLON.BoundingInfo(this.absolutePosition, this.absolutePosition);
  20583. this._boundingInfo.update(this.worldMatrixFromCache);
  20584. this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
  20585. return this;
  20586. };
  20587. /** @hidden */
  20588. AbstractMesh.prototype._updateSubMeshesBoundingInfo = function (matrix) {
  20589. if (!this.subMeshes) {
  20590. return this;
  20591. }
  20592. for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
  20593. var subMesh = this.subMeshes[subIndex];
  20594. if (!subMesh.IsGlobal) {
  20595. subMesh.updateBoundingInfo(matrix);
  20596. }
  20597. }
  20598. return this;
  20599. };
  20600. /** @hidden */
  20601. AbstractMesh.prototype._afterComputeWorldMatrix = function () {
  20602. // Bounding info
  20603. this._updateBoundingInfo();
  20604. };
  20605. /**
  20606. * Returns `true` if the mesh is within the frustum defined by the passed array of planes.
  20607. * A mesh is in the frustum if its bounding box intersects the frustum
  20608. * @param frustumPlanes defines the frustum to test
  20609. * @returns true if the mesh is in the frustum planes
  20610. */
  20611. AbstractMesh.prototype.isInFrustum = function (frustumPlanes) {
  20612. return this._boundingInfo !== null && this._boundingInfo.isInFrustum(frustumPlanes);
  20613. };
  20614. /**
  20615. * Returns `true` if the mesh is completely in the frustum defined be the passed array of planes.
  20616. * A mesh is completely in the frustum if its bounding box it completely inside the frustum.
  20617. * @param frustumPlanes defines the frustum to test
  20618. * @returns true if the mesh is completely in the frustum planes
  20619. */
  20620. AbstractMesh.prototype.isCompletelyInFrustum = function (frustumPlanes) {
  20621. return this._boundingInfo !== null && this._boundingInfo.isCompletelyInFrustum(frustumPlanes);
  20622. };
  20623. /**
  20624. * True if the mesh intersects another mesh or a SolidParticle object
  20625. * @param mesh defines a target mesh or SolidParticle to test
  20626. * @param precise Unless the parameter `precise` is set to `true` the intersection is computed according to Axis Aligned Bounding Boxes (AABB), else according to OBB (Oriented BBoxes)
  20627. * @param includeDescendants Can be set to true to test if the mesh defined in parameters intersects with the current mesh or any child meshes
  20628. * @returns true if there is an intersection
  20629. */
  20630. AbstractMesh.prototype.intersectsMesh = function (mesh, precise, includeDescendants) {
  20631. if (precise === void 0) { precise = false; }
  20632. if (!this._boundingInfo || !mesh._boundingInfo) {
  20633. return false;
  20634. }
  20635. if (this._boundingInfo.intersects(mesh._boundingInfo, precise)) {
  20636. return true;
  20637. }
  20638. if (includeDescendants) {
  20639. for (var _i = 0, _a = this.getChildMeshes(); _i < _a.length; _i++) {
  20640. var child = _a[_i];
  20641. if (child.intersectsMesh(mesh, precise, true)) {
  20642. return true;
  20643. }
  20644. }
  20645. }
  20646. return false;
  20647. };
  20648. /**
  20649. * Returns true if the passed point (Vector3) is inside the mesh bounding box
  20650. * @param point defines the point to test
  20651. * @returns true if there is an intersection
  20652. */
  20653. AbstractMesh.prototype.intersectsPoint = function (point) {
  20654. if (!this._boundingInfo) {
  20655. return false;
  20656. }
  20657. return this._boundingInfo.intersectsPoint(point);
  20658. };
  20659. /**
  20660. * Gets the current physics impostor
  20661. * @see http://doc.babylonjs.com/features/physics_engine
  20662. * @returns a physics impostor or null
  20663. */
  20664. AbstractMesh.prototype.getPhysicsImpostor = function () {
  20665. return this.physicsImpostor;
  20666. };
  20667. /**
  20668. * Gets the position of the current mesh in camera space
  20669. * @param camera defines the camera to use
  20670. * @returns a position
  20671. */
  20672. AbstractMesh.prototype.getPositionInCameraSpace = function (camera) {
  20673. if (camera === void 0) { camera = null; }
  20674. if (!camera) {
  20675. camera = this.getScene().activeCamera;
  20676. }
  20677. return BABYLON.Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
  20678. };
  20679. /**
  20680. * Returns the distance from the mesh to the active camera
  20681. * @param camera defines the camera to use
  20682. * @returns the distance
  20683. */
  20684. AbstractMesh.prototype.getDistanceToCamera = function (camera) {
  20685. if (camera === void 0) { camera = null; }
  20686. if (!camera) {
  20687. camera = this.getScene().activeCamera;
  20688. }
  20689. return this.absolutePosition.subtract(camera.position).length();
  20690. };
  20691. /**
  20692. * Apply a physic impulse to the mesh
  20693. * @param force defines the force to apply
  20694. * @param contactPoint defines where to apply the force
  20695. * @returns the current mesh
  20696. * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
  20697. */
  20698. AbstractMesh.prototype.applyImpulse = function (force, contactPoint) {
  20699. if (!this.physicsImpostor) {
  20700. return this;
  20701. }
  20702. this.physicsImpostor.applyImpulse(force, contactPoint);
  20703. return this;
  20704. };
  20705. /**
  20706. * Creates a physic joint between two meshes
  20707. * @param otherMesh defines the other mesh to use
  20708. * @param pivot1 defines the pivot to use on this mesh
  20709. * @param pivot2 defines the pivot to use on the other mesh
  20710. * @param options defines additional options (can be plugin dependent)
  20711. * @returns the current mesh
  20712. * @see https://www.babylonjs-playground.com/#0BS5U0#0
  20713. */
  20714. AbstractMesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2, options) {
  20715. if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
  20716. return this;
  20717. }
  20718. this.physicsImpostor.createJoint(otherMesh.physicsImpostor, BABYLON.PhysicsJoint.HingeJoint, {
  20719. mainPivot: pivot1,
  20720. connectedPivot: pivot2,
  20721. nativeParams: options
  20722. });
  20723. return this;
  20724. };
  20725. Object.defineProperty(AbstractMesh.prototype, "checkCollisions", {
  20726. // Collisions
  20727. /**
  20728. * Gets or sets a boolean indicating that this mesh can be used in the collision engine
  20729. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  20730. */
  20731. get: function () {
  20732. return this._checkCollisions;
  20733. },
  20734. set: function (collisionEnabled) {
  20735. this._checkCollisions = collisionEnabled;
  20736. if (this.getScene().workerCollisions) {
  20737. this.getScene().collisionCoordinator.onMeshUpdated(this);
  20738. }
  20739. },
  20740. enumerable: true,
  20741. configurable: true
  20742. });
  20743. Object.defineProperty(AbstractMesh.prototype, "collider", {
  20744. /**
  20745. * Gets Collider object used to compute collisions (not physics)
  20746. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  20747. */
  20748. get: function () {
  20749. return this._collider;
  20750. },
  20751. enumerable: true,
  20752. configurable: true
  20753. });
  20754. /**
  20755. * Move the mesh using collision engine
  20756. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  20757. * @param displacement defines the requested displacement vector
  20758. * @returns the current mesh
  20759. */
  20760. AbstractMesh.prototype.moveWithCollisions = function (displacement) {
  20761. var globalPosition = this.getAbsolutePosition();
  20762. globalPosition.addToRef(this.ellipsoidOffset, this._oldPositionForCollisions);
  20763. if (!this._collider) {
  20764. this._collider = new BABYLON.Collider();
  20765. }
  20766. this._collider._radius = this.ellipsoid;
  20767. this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions, displacement, this._collider, 3, this, this._onCollisionPositionChange, this.uniqueId);
  20768. return this;
  20769. };
  20770. // Submeshes octree
  20771. /**
  20772. * This function will create an octree to help to select the right submeshes for rendering, picking and collision computations.
  20773. * Please note that you must have a decent number of submeshes to get performance improvements when using an octree
  20774. * @param maxCapacity defines the maximum size of each block (64 by default)
  20775. * @param maxDepth defines the maximum depth to use (no more than 2 levels by default)
  20776. * @returns the new octree
  20777. * @see https://www.babylonjs-playground.com/#NA4OQ#12
  20778. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene_with_octrees
  20779. */
  20780. AbstractMesh.prototype.createOrUpdateSubmeshesOctree = function (maxCapacity, maxDepth) {
  20781. if (maxCapacity === void 0) { maxCapacity = 64; }
  20782. if (maxDepth === void 0) { maxDepth = 2; }
  20783. if (!this._submeshesOctree) {
  20784. this._submeshesOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForSubMeshes, maxCapacity, maxDepth);
  20785. }
  20786. this.computeWorldMatrix(true);
  20787. var boundingInfo = this.getBoundingInfo();
  20788. // Update octree
  20789. var bbox = boundingInfo.boundingBox;
  20790. this._submeshesOctree.update(bbox.minimumWorld, bbox.maximumWorld, this.subMeshes);
  20791. return this._submeshesOctree;
  20792. };
  20793. // Collisions
  20794. /** @hidden */
  20795. AbstractMesh.prototype._collideForSubMesh = function (subMesh, transformMatrix, collider) {
  20796. this._generatePointsArray();
  20797. if (!this._positions) {
  20798. return this;
  20799. }
  20800. // Transformation
  20801. if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
  20802. subMesh._lastColliderTransformMatrix = transformMatrix.clone();
  20803. subMesh._lastColliderWorldVertices = [];
  20804. subMesh._trianglePlanes = [];
  20805. var start = subMesh.verticesStart;
  20806. var end = (subMesh.verticesStart + subMesh.verticesCount);
  20807. for (var i = start; i < end; i++) {
  20808. subMesh._lastColliderWorldVertices.push(BABYLON.Vector3.TransformCoordinates(this._positions[i], transformMatrix));
  20809. }
  20810. }
  20811. // Collide
  20812. collider._collide(subMesh._trianglePlanes, subMesh._lastColliderWorldVertices, this.getIndices(), subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart, !!subMesh.getMaterial());
  20813. if (collider.collisionFound) {
  20814. collider.collidedMesh = this;
  20815. }
  20816. return this;
  20817. };
  20818. /** @hidden */
  20819. AbstractMesh.prototype._processCollisionsForSubMeshes = function (collider, transformMatrix) {
  20820. var subMeshes;
  20821. var len;
  20822. // Octrees
  20823. if (this._submeshesOctree && this.useOctreeForCollisions) {
  20824. var radius = collider._velocityWorldLength + Math.max(collider._radius.x, collider._radius.y, collider._radius.z);
  20825. var intersections = this._submeshesOctree.intersects(collider._basePointWorld, radius);
  20826. len = intersections.length;
  20827. subMeshes = intersections.data;
  20828. }
  20829. else {
  20830. subMeshes = this.subMeshes;
  20831. len = subMeshes.length;
  20832. }
  20833. for (var index = 0; index < len; index++) {
  20834. var subMesh = subMeshes[index];
  20835. // Bounding test
  20836. if (len > 1 && !subMesh._checkCollision(collider))
  20837. continue;
  20838. this._collideForSubMesh(subMesh, transformMatrix, collider);
  20839. }
  20840. return this;
  20841. };
  20842. /** @hidden */
  20843. AbstractMesh.prototype._checkCollision = function (collider) {
  20844. // Bounding box test
  20845. if (!this._boundingInfo || !this._boundingInfo._checkCollision(collider))
  20846. return this;
  20847. // Transformation matrix
  20848. BABYLON.Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, this._collisionsScalingMatrix);
  20849. this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
  20850. this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
  20851. return this;
  20852. };
  20853. // Picking
  20854. /** @hidden */
  20855. AbstractMesh.prototype._generatePointsArray = function () {
  20856. return false;
  20857. };
  20858. /**
  20859. * Checks if the passed Ray intersects with the mesh
  20860. * @param ray defines the ray to use
  20861. * @param fastCheck defines if fast mode (but less precise) must be used (false by default)
  20862. * @returns the picking info
  20863. * @see http://doc.babylonjs.com/babylon101/intersect_collisions_-_mesh
  20864. */
  20865. AbstractMesh.prototype.intersects = function (ray, fastCheck) {
  20866. var pickingInfo = new BABYLON.PickingInfo();
  20867. if (!this.subMeshes || !this._boundingInfo || !ray.intersectsSphere(this._boundingInfo.boundingSphere) || !ray.intersectsBox(this._boundingInfo.boundingBox)) {
  20868. return pickingInfo;
  20869. }
  20870. if (!this._generatePointsArray()) {
  20871. return pickingInfo;
  20872. }
  20873. var intersectInfo = null;
  20874. // Octrees
  20875. var subMeshes;
  20876. var len;
  20877. if (this._submeshesOctree && this.useOctreeForPicking) {
  20878. var worldRay = BABYLON.Ray.Transform(ray, this.getWorldMatrix());
  20879. var intersections = this._submeshesOctree.intersectsRay(worldRay);
  20880. len = intersections.length;
  20881. subMeshes = intersections.data;
  20882. }
  20883. else {
  20884. subMeshes = this.subMeshes;
  20885. len = subMeshes.length;
  20886. }
  20887. for (var index = 0; index < len; index++) {
  20888. var subMesh = subMeshes[index];
  20889. // Bounding test
  20890. if (len > 1 && !subMesh.canIntersects(ray))
  20891. continue;
  20892. var currentIntersectInfo = subMesh.intersects(ray, this._positions, this.getIndices(), fastCheck);
  20893. if (currentIntersectInfo) {
  20894. if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
  20895. intersectInfo = currentIntersectInfo;
  20896. intersectInfo.subMeshId = index;
  20897. if (fastCheck) {
  20898. break;
  20899. }
  20900. }
  20901. }
  20902. }
  20903. if (intersectInfo) {
  20904. // Get picked point
  20905. var world = this.getWorldMatrix();
  20906. var worldOrigin = BABYLON.Vector3.TransformCoordinates(ray.origin, world);
  20907. var direction = ray.direction.clone();
  20908. direction = direction.scale(intersectInfo.distance);
  20909. var worldDirection = BABYLON.Vector3.TransformNormal(direction, world);
  20910. var pickedPoint = worldOrigin.add(worldDirection);
  20911. // Return result
  20912. pickingInfo.hit = true;
  20913. pickingInfo.distance = BABYLON.Vector3.Distance(worldOrigin, pickedPoint);
  20914. pickingInfo.pickedPoint = pickedPoint;
  20915. pickingInfo.pickedMesh = this;
  20916. pickingInfo.bu = intersectInfo.bu || 0;
  20917. pickingInfo.bv = intersectInfo.bv || 0;
  20918. pickingInfo.faceId = intersectInfo.faceId;
  20919. pickingInfo.subMeshId = intersectInfo.subMeshId;
  20920. return pickingInfo;
  20921. }
  20922. return pickingInfo;
  20923. };
  20924. /**
  20925. * Clones the current mesh
  20926. * @param name defines the mesh name
  20927. * @param newParent defines the new mesh parent
  20928. * @param doNotCloneChildren defines a boolean indicating that children must not be cloned (false by default)
  20929. * @returns the new mesh
  20930. */
  20931. AbstractMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  20932. return null;
  20933. };
  20934. /**
  20935. * Disposes all the submeshes of the current meshnp
  20936. * @returns the current mesh
  20937. */
  20938. AbstractMesh.prototype.releaseSubMeshes = function () {
  20939. if (this.subMeshes) {
  20940. while (this.subMeshes.length) {
  20941. this.subMeshes[0].dispose();
  20942. }
  20943. }
  20944. else {
  20945. this.subMeshes = new Array();
  20946. }
  20947. return this;
  20948. };
  20949. /**
  20950. * Releases resources associated with this abstract mesh.
  20951. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  20952. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  20953. */
  20954. AbstractMesh.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  20955. var _this = this;
  20956. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  20957. var index;
  20958. // Smart Array Retainers.
  20959. this.getScene().freeActiveMeshes();
  20960. this.getScene().freeRenderingGroups();
  20961. // Action manager
  20962. if (this.actionManager !== undefined && this.actionManager !== null) {
  20963. this.actionManager.dispose();
  20964. this.actionManager = null;
  20965. }
  20966. // Skeleton
  20967. this._skeleton = null;
  20968. // Physics
  20969. if (this.physicsImpostor) {
  20970. this.physicsImpostor.dispose( /*!doNotRecurse*/);
  20971. }
  20972. // Intersections in progress
  20973. for (index = 0; index < this._intersectionsInProgress.length; index++) {
  20974. var other = this._intersectionsInProgress[index];
  20975. var pos = other._intersectionsInProgress.indexOf(this);
  20976. other._intersectionsInProgress.splice(pos, 1);
  20977. }
  20978. this._intersectionsInProgress = [];
  20979. // Lights
  20980. var lights = this.getScene().lights;
  20981. lights.forEach(function (light) {
  20982. var meshIndex = light.includedOnlyMeshes.indexOf(_this);
  20983. if (meshIndex !== -1) {
  20984. light.includedOnlyMeshes.splice(meshIndex, 1);
  20985. }
  20986. meshIndex = light.excludedMeshes.indexOf(_this);
  20987. if (meshIndex !== -1) {
  20988. light.excludedMeshes.splice(meshIndex, 1);
  20989. }
  20990. // Shadow generators
  20991. var generator = light.getShadowGenerator();
  20992. if (generator) {
  20993. var shadowMap = generator.getShadowMap();
  20994. if (shadowMap && shadowMap.renderList) {
  20995. meshIndex = shadowMap.renderList.indexOf(_this);
  20996. if (meshIndex !== -1) {
  20997. shadowMap.renderList.splice(meshIndex, 1);
  20998. }
  20999. }
  21000. }
  21001. });
  21002. // Edges
  21003. if (this._edgesRenderer) {
  21004. this._edgesRenderer.dispose();
  21005. this._edgesRenderer = null;
  21006. }
  21007. // SubMeshes
  21008. if (this.getClassName() !== "InstancedMesh") {
  21009. this.releaseSubMeshes();
  21010. }
  21011. // Octree
  21012. var sceneOctree = this.getScene().selectionOctree;
  21013. if (sceneOctree !== undefined && sceneOctree !== null) {
  21014. var index = sceneOctree.dynamicContent.indexOf(this);
  21015. if (index !== -1) {
  21016. sceneOctree.dynamicContent.splice(index, 1);
  21017. }
  21018. }
  21019. // Query
  21020. var engine = this.getScene().getEngine();
  21021. if (this._occlusionQuery) {
  21022. this._isOcclusionQueryInProgress = false;
  21023. engine.deleteQuery(this._occlusionQuery);
  21024. this._occlusionQuery = null;
  21025. }
  21026. // Engine
  21027. engine.wipeCaches();
  21028. // Remove from scene
  21029. this.getScene().removeMesh(this);
  21030. if (disposeMaterialAndTextures) {
  21031. if (this.material) {
  21032. this.material.dispose(false, true);
  21033. }
  21034. }
  21035. if (!doNotRecurse) {
  21036. // Particles
  21037. for (index = 0; index < this.getScene().particleSystems.length; index++) {
  21038. if (this.getScene().particleSystems[index].emitter === this) {
  21039. this.getScene().particleSystems[index].dispose();
  21040. index--;
  21041. }
  21042. }
  21043. }
  21044. // facet data
  21045. if (this._facetDataEnabled) {
  21046. this.disableFacetData();
  21047. }
  21048. this.onAfterWorldMatrixUpdateObservable.clear();
  21049. this.onCollideObservable.clear();
  21050. this.onCollisionPositionChangeObservable.clear();
  21051. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  21052. };
  21053. /**
  21054. * Adds the passed mesh as a child to the current mesh
  21055. * @param mesh defines the child mesh
  21056. * @returns the current mesh
  21057. */
  21058. AbstractMesh.prototype.addChild = function (mesh) {
  21059. mesh.setParent(this);
  21060. return this;
  21061. };
  21062. /**
  21063. * Removes the passed mesh from the current mesh children list
  21064. * @param mesh defines the child mesh
  21065. * @returns the current mesh
  21066. */
  21067. AbstractMesh.prototype.removeChild = function (mesh) {
  21068. mesh.setParent(null);
  21069. return this;
  21070. };
  21071. // Facet data
  21072. /** @hidden */
  21073. AbstractMesh.prototype._initFacetData = function () {
  21074. if (!this._facetNormals) {
  21075. this._facetNormals = new Array();
  21076. }
  21077. if (!this._facetPositions) {
  21078. this._facetPositions = new Array();
  21079. }
  21080. if (!this._facetPartitioning) {
  21081. this._facetPartitioning = new Array();
  21082. }
  21083. this._facetNb = (this.getIndices().length / 3) | 0;
  21084. this._partitioningSubdivisions = (this._partitioningSubdivisions) ? this._partitioningSubdivisions : 10; // default nb of partitioning subdivisions = 10
  21085. this._partitioningBBoxRatio = (this._partitioningBBoxRatio) ? this._partitioningBBoxRatio : 1.01; // default ratio 1.01 = the partitioning is 1% bigger than the bounding box
  21086. for (var f = 0; f < this._facetNb; f++) {
  21087. this._facetNormals[f] = BABYLON.Vector3.Zero();
  21088. this._facetPositions[f] = BABYLON.Vector3.Zero();
  21089. }
  21090. this._facetDataEnabled = true;
  21091. return this;
  21092. };
  21093. /**
  21094. * Updates the mesh facetData arrays and the internal partitioning when the mesh is morphed or updated.
  21095. * This method can be called within the render loop.
  21096. * You don't need to call this method by yourself in the render loop when you update/morph a mesh with the methods CreateXXX() as they automatically manage this computation
  21097. * @returns the current mesh
  21098. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21099. */
  21100. AbstractMesh.prototype.updateFacetData = function () {
  21101. if (!this._facetDataEnabled) {
  21102. this._initFacetData();
  21103. }
  21104. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  21105. var indices = this.getIndices();
  21106. var normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  21107. var bInfo = this.getBoundingInfo();
  21108. if (this._facetDepthSort && !this._facetDepthSortEnabled) {
  21109. // init arrays, matrix and sort function on first call
  21110. this._facetDepthSortEnabled = true;
  21111. if (indices instanceof Uint16Array) {
  21112. this._depthSortedIndices = new Uint16Array(indices);
  21113. }
  21114. else if (indices instanceof Uint32Array) {
  21115. this._depthSortedIndices = new Uint32Array(indices);
  21116. }
  21117. else {
  21118. var needs32bits = false;
  21119. for (var i = 0; i < indices.length; i++) {
  21120. if (indices[i] > 65535) {
  21121. needs32bits = true;
  21122. break;
  21123. }
  21124. }
  21125. if (needs32bits) {
  21126. this._depthSortedIndices = new Uint32Array(indices);
  21127. }
  21128. else {
  21129. this._depthSortedIndices = new Uint16Array(indices);
  21130. }
  21131. }
  21132. this._facetDepthSortFunction = function (f1, f2) {
  21133. return (f2.sqDistance - f1.sqDistance);
  21134. };
  21135. if (!this._facetDepthSortFrom) {
  21136. var camera = this.getScene().activeCamera;
  21137. this._facetDepthSortFrom = (camera) ? camera.position : BABYLON.Vector3.Zero();
  21138. }
  21139. this._depthSortedFacets = [];
  21140. for (var f = 0; f < this._facetNb; f++) {
  21141. var depthSortedFacet = { ind: f * 3, sqDistance: 0.0 };
  21142. this._depthSortedFacets.push(depthSortedFacet);
  21143. }
  21144. this._invertedMatrix = BABYLON.Matrix.Identity();
  21145. this._facetDepthSortOrigin = BABYLON.Vector3.Zero();
  21146. }
  21147. this._bbSize.x = (bInfo.maximum.x - bInfo.minimum.x > BABYLON.Epsilon) ? bInfo.maximum.x - bInfo.minimum.x : BABYLON.Epsilon;
  21148. this._bbSize.y = (bInfo.maximum.y - bInfo.minimum.y > BABYLON.Epsilon) ? bInfo.maximum.y - bInfo.minimum.y : BABYLON.Epsilon;
  21149. this._bbSize.z = (bInfo.maximum.z - bInfo.minimum.z > BABYLON.Epsilon) ? bInfo.maximum.z - bInfo.minimum.z : BABYLON.Epsilon;
  21150. var bbSizeMax = (this._bbSize.x > this._bbSize.y) ? this._bbSize.x : this._bbSize.y;
  21151. bbSizeMax = (bbSizeMax > this._bbSize.z) ? bbSizeMax : this._bbSize.z;
  21152. this._subDiv.max = this._partitioningSubdivisions;
  21153. this._subDiv.X = Math.floor(this._subDiv.max * this._bbSize.x / bbSizeMax); // adjust the number of subdivisions per axis
  21154. this._subDiv.Y = Math.floor(this._subDiv.max * this._bbSize.y / bbSizeMax); // according to each bbox size per axis
  21155. this._subDiv.Z = Math.floor(this._subDiv.max * this._bbSize.z / bbSizeMax);
  21156. this._subDiv.X = this._subDiv.X < 1 ? 1 : this._subDiv.X; // at least one subdivision
  21157. this._subDiv.Y = this._subDiv.Y < 1 ? 1 : this._subDiv.Y;
  21158. this._subDiv.Z = this._subDiv.Z < 1 ? 1 : this._subDiv.Z;
  21159. // set the parameters for ComputeNormals()
  21160. this._facetParameters.facetNormals = this.getFacetLocalNormals();
  21161. this._facetParameters.facetPositions = this.getFacetLocalPositions();
  21162. this._facetParameters.facetPartitioning = this.getFacetLocalPartitioning();
  21163. this._facetParameters.bInfo = bInfo;
  21164. this._facetParameters.bbSize = this._bbSize;
  21165. this._facetParameters.subDiv = this._subDiv;
  21166. this._facetParameters.ratio = this.partitioningBBoxRatio;
  21167. this._facetParameters.depthSort = this._facetDepthSort;
  21168. if (this._facetDepthSort && this._facetDepthSortEnabled) {
  21169. this.computeWorldMatrix(true);
  21170. this._worldMatrix.invertToRef(this._invertedMatrix);
  21171. BABYLON.Vector3.TransformCoordinatesToRef(this._facetDepthSortFrom, this._invertedMatrix, this._facetDepthSortOrigin);
  21172. this._facetParameters.distanceTo = this._facetDepthSortOrigin;
  21173. }
  21174. this._facetParameters.depthSortedFacets = this._depthSortedFacets;
  21175. BABYLON.VertexData.ComputeNormals(positions, indices, normals, this._facetParameters);
  21176. if (this._facetDepthSort && this._facetDepthSortEnabled) {
  21177. this._depthSortedFacets.sort(this._facetDepthSortFunction);
  21178. var l = (this._depthSortedIndices.length / 3) | 0;
  21179. for (var f = 0; f < l; f++) {
  21180. var sind = this._depthSortedFacets[f].ind;
  21181. this._depthSortedIndices[f * 3] = indices[sind];
  21182. this._depthSortedIndices[f * 3 + 1] = indices[sind + 1];
  21183. this._depthSortedIndices[f * 3 + 2] = indices[sind + 2];
  21184. }
  21185. this.updateIndices(this._depthSortedIndices);
  21186. }
  21187. return this;
  21188. };
  21189. /**
  21190. * Returns the facetLocalNormals array.
  21191. * The normals are expressed in the mesh local spac
  21192. * @returns an array of Vector3
  21193. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21194. */
  21195. AbstractMesh.prototype.getFacetLocalNormals = function () {
  21196. if (!this._facetNormals) {
  21197. this.updateFacetData();
  21198. }
  21199. return this._facetNormals;
  21200. };
  21201. /**
  21202. * Returns the facetLocalPositions array.
  21203. * The facet positions are expressed in the mesh local space
  21204. * @returns an array of Vector3
  21205. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21206. */
  21207. AbstractMesh.prototype.getFacetLocalPositions = function () {
  21208. if (!this._facetPositions) {
  21209. this.updateFacetData();
  21210. }
  21211. return this._facetPositions;
  21212. };
  21213. /**
  21214. * Returns the facetLocalPartioning array
  21215. * @returns an array of array of numbers
  21216. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21217. */
  21218. AbstractMesh.prototype.getFacetLocalPartitioning = function () {
  21219. if (!this._facetPartitioning) {
  21220. this.updateFacetData();
  21221. }
  21222. return this._facetPartitioning;
  21223. };
  21224. /**
  21225. * Returns the i-th facet position in the world system.
  21226. * This method allocates a new Vector3 per call
  21227. * @param i defines the facet index
  21228. * @returns a new Vector3
  21229. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21230. */
  21231. AbstractMesh.prototype.getFacetPosition = function (i) {
  21232. var pos = BABYLON.Vector3.Zero();
  21233. this.getFacetPositionToRef(i, pos);
  21234. return pos;
  21235. };
  21236. /**
  21237. * Sets the reference Vector3 with the i-th facet position in the world system
  21238. * @param i defines the facet index
  21239. * @param ref defines the target vector
  21240. * @returns the current mesh
  21241. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21242. */
  21243. AbstractMesh.prototype.getFacetPositionToRef = function (i, ref) {
  21244. var localPos = (this.getFacetLocalPositions())[i];
  21245. var world = this.getWorldMatrix();
  21246. BABYLON.Vector3.TransformCoordinatesToRef(localPos, world, ref);
  21247. return this;
  21248. };
  21249. /**
  21250. * Returns the i-th facet normal in the world system.
  21251. * This method allocates a new Vector3 per call
  21252. * @param i defines the facet index
  21253. * @returns a new Vector3
  21254. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21255. */
  21256. AbstractMesh.prototype.getFacetNormal = function (i) {
  21257. var norm = BABYLON.Vector3.Zero();
  21258. this.getFacetNormalToRef(i, norm);
  21259. return norm;
  21260. };
  21261. /**
  21262. * Sets the reference Vector3 with the i-th facet normal in the world system
  21263. * @param i defines the facet index
  21264. * @param ref defines the target vector
  21265. * @returns the current mesh
  21266. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21267. */
  21268. AbstractMesh.prototype.getFacetNormalToRef = function (i, ref) {
  21269. var localNorm = (this.getFacetLocalNormals())[i];
  21270. BABYLON.Vector3.TransformNormalToRef(localNorm, this.getWorldMatrix(), ref);
  21271. return this;
  21272. };
  21273. /**
  21274. * Returns the facets (in an array) in the same partitioning block than the one the passed coordinates are located (expressed in the mesh local system)
  21275. * @param x defines x coordinate
  21276. * @param y defines y coordinate
  21277. * @param z defines z coordinate
  21278. * @returns the array of facet indexes
  21279. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21280. */
  21281. AbstractMesh.prototype.getFacetsAtLocalCoordinates = function (x, y, z) {
  21282. var bInfo = this.getBoundingInfo();
  21283. var ox = Math.floor((x - bInfo.minimum.x * this._partitioningBBoxRatio) * this._subDiv.X * this._partitioningBBoxRatio / this._bbSize.x);
  21284. var oy = Math.floor((y - bInfo.minimum.y * this._partitioningBBoxRatio) * this._subDiv.Y * this._partitioningBBoxRatio / this._bbSize.y);
  21285. var oz = Math.floor((z - bInfo.minimum.z * this._partitioningBBoxRatio) * this._subDiv.Z * this._partitioningBBoxRatio / this._bbSize.z);
  21286. if (ox < 0 || ox > this._subDiv.max || oy < 0 || oy > this._subDiv.max || oz < 0 || oz > this._subDiv.max) {
  21287. return null;
  21288. }
  21289. return this._facetPartitioning[ox + this._subDiv.max * oy + this._subDiv.max * this._subDiv.max * oz];
  21290. };
  21291. /**
  21292. * Returns the closest mesh facet index at (x,y,z) World coordinates, null if not found
  21293. * @param projected sets as the (x,y,z) world projection on the facet
  21294. * @param checkFace if true (default false), only the facet "facing" to (x,y,z) or only the ones "turning their backs", according to the parameter "facing" are returned
  21295. * @param facing if facing and checkFace are true, only the facet "facing" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet "turning their backs" to (x, y, z) are returned : negative dot (x, y, z) * facet position
  21296. * @param x defines x coordinate
  21297. * @param y defines y coordinate
  21298. * @param z defines z coordinate
  21299. * @returns the face index if found (or null instead)
  21300. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21301. */
  21302. AbstractMesh.prototype.getClosestFacetAtCoordinates = function (x, y, z, projected, checkFace, facing) {
  21303. if (checkFace === void 0) { checkFace = false; }
  21304. if (facing === void 0) { facing = true; }
  21305. var world = this.getWorldMatrix();
  21306. var invMat = BABYLON.Tmp.Matrix[5];
  21307. world.invertToRef(invMat);
  21308. var invVect = BABYLON.Tmp.Vector3[8];
  21309. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, invMat, invVect); // transform (x,y,z) to coordinates in the mesh local space
  21310. var closest = this.getClosestFacetAtLocalCoordinates(invVect.x, invVect.y, invVect.z, projected, checkFace, facing);
  21311. if (projected) {
  21312. // tranform the local computed projected vector to world coordinates
  21313. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(projected.x, projected.y, projected.z, world, projected);
  21314. }
  21315. return closest;
  21316. };
  21317. /**
  21318. * Returns the closest mesh facet index at (x,y,z) local coordinates, null if not found
  21319. * @param projected sets as the (x,y,z) local projection on the facet
  21320. * @param checkFace if true (default false), only the facet "facing" to (x,y,z) or only the ones "turning their backs", according to the parameter "facing" are returned
  21321. * @param facing if facing and checkFace are true, only the facet "facing" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet "turning their backs" to (x, y, z) are returned : negative dot (x, y, z) * facet position
  21322. * @param x defines x coordinate
  21323. * @param y defines y coordinate
  21324. * @param z defines z coordinate
  21325. * @returns the face index if found (or null instead)
  21326. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21327. */
  21328. AbstractMesh.prototype.getClosestFacetAtLocalCoordinates = function (x, y, z, projected, checkFace, facing) {
  21329. if (checkFace === void 0) { checkFace = false; }
  21330. if (facing === void 0) { facing = true; }
  21331. var closest = null;
  21332. var tmpx = 0.0;
  21333. var tmpy = 0.0;
  21334. var tmpz = 0.0;
  21335. var d = 0.0; // tmp dot facet normal * facet position
  21336. var t0 = 0.0;
  21337. var projx = 0.0;
  21338. var projy = 0.0;
  21339. var projz = 0.0;
  21340. // Get all the facets in the same partitioning block than (x, y, z)
  21341. var facetPositions = this.getFacetLocalPositions();
  21342. var facetNormals = this.getFacetLocalNormals();
  21343. var facetsInBlock = this.getFacetsAtLocalCoordinates(x, y, z);
  21344. if (!facetsInBlock) {
  21345. return null;
  21346. }
  21347. // Get the closest facet to (x, y, z)
  21348. var shortest = Number.MAX_VALUE; // init distance vars
  21349. var tmpDistance = shortest;
  21350. var fib; // current facet in the block
  21351. var norm; // current facet normal
  21352. var p0; // current facet barycenter position
  21353. // loop on all the facets in the current partitioning block
  21354. for (var idx = 0; idx < facetsInBlock.length; idx++) {
  21355. fib = facetsInBlock[idx];
  21356. norm = facetNormals[fib];
  21357. p0 = facetPositions[fib];
  21358. d = (x - p0.x) * norm.x + (y - p0.y) * norm.y + (z - p0.z) * norm.z;
  21359. if (!checkFace || (checkFace && facing && d >= 0.0) || (checkFace && !facing && d <= 0.0)) {
  21360. // compute (x,y,z) projection on the facet = (projx, projy, projz)
  21361. d = norm.x * p0.x + norm.y * p0.y + norm.z * p0.z;
  21362. t0 = -(norm.x * x + norm.y * y + norm.z * z - d) / (norm.x * norm.x + norm.y * norm.y + norm.z * norm.z);
  21363. projx = x + norm.x * t0;
  21364. projy = y + norm.y * t0;
  21365. projz = z + norm.z * t0;
  21366. tmpx = projx - x;
  21367. tmpy = projy - y;
  21368. tmpz = projz - z;
  21369. tmpDistance = tmpx * tmpx + tmpy * tmpy + tmpz * tmpz; // compute length between (x, y, z) and its projection on the facet
  21370. if (tmpDistance < shortest) { // just keep the closest facet to (x, y, z)
  21371. shortest = tmpDistance;
  21372. closest = fib;
  21373. if (projected) {
  21374. projected.x = projx;
  21375. projected.y = projy;
  21376. projected.z = projz;
  21377. }
  21378. }
  21379. }
  21380. }
  21381. return closest;
  21382. };
  21383. /**
  21384. * Returns the object "parameter" set with all the expected parameters for facetData computation by ComputeNormals()
  21385. * @returns the parameters
  21386. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21387. */
  21388. AbstractMesh.prototype.getFacetDataParameters = function () {
  21389. return this._facetParameters;
  21390. };
  21391. /**
  21392. * Disables the feature FacetData and frees the related memory
  21393. * @returns the current mesh
  21394. * @see http://doc.babylonjs.com/how_to/how_to_use_facetdata
  21395. */
  21396. AbstractMesh.prototype.disableFacetData = function () {
  21397. if (this._facetDataEnabled) {
  21398. this._facetDataEnabled = false;
  21399. this._facetPositions = new Array();
  21400. this._facetNormals = new Array();
  21401. this._facetPartitioning = new Array();
  21402. this._facetParameters = null;
  21403. this._depthSortedIndices = new Uint32Array(0);
  21404. }
  21405. return this;
  21406. };
  21407. /**
  21408. * Updates the AbstractMesh indices array
  21409. * @param indices defines the data source
  21410. * @returns the current mesh
  21411. */
  21412. AbstractMesh.prototype.updateIndices = function (indices) {
  21413. return this;
  21414. };
  21415. /**
  21416. * Creates new normals data for the mesh
  21417. * @param updatable defines if the normal vertex buffer must be flagged as updatable
  21418. * @returns the current mesh
  21419. */
  21420. AbstractMesh.prototype.createNormals = function (updatable) {
  21421. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  21422. var indices = this.getIndices();
  21423. var normals;
  21424. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  21425. normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  21426. }
  21427. else {
  21428. normals = [];
  21429. }
  21430. BABYLON.VertexData.ComputeNormals(positions, indices, normals, { useRightHandedSystem: this.getScene().useRightHandedSystem });
  21431. this.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatable);
  21432. return this;
  21433. };
  21434. /**
  21435. * Align the mesh with a normal
  21436. * @param normal defines the normal to use
  21437. * @param upDirection can be used to redefined the up vector to use (will use the (0, 1, 0) by default)
  21438. * @returns the current mesh
  21439. */
  21440. AbstractMesh.prototype.alignWithNormal = function (normal, upDirection) {
  21441. if (!upDirection) {
  21442. upDirection = BABYLON.Axis.Y;
  21443. }
  21444. var axisX = BABYLON.Tmp.Vector3[0];
  21445. var axisZ = BABYLON.Tmp.Vector3[1];
  21446. BABYLON.Vector3.CrossToRef(upDirection, normal, axisZ);
  21447. BABYLON.Vector3.CrossToRef(normal, axisZ, axisX);
  21448. if (this.rotationQuaternion) {
  21449. BABYLON.Quaternion.RotationQuaternionFromAxisToRef(axisX, normal, axisZ, this.rotationQuaternion);
  21450. }
  21451. else {
  21452. BABYLON.Vector3.RotationFromAxisToRef(axisX, normal, axisZ, this.rotation);
  21453. }
  21454. return this;
  21455. };
  21456. /** @hidden */
  21457. AbstractMesh.prototype._checkOcclusionQuery = function () {
  21458. var engine = this.getEngine();
  21459. if (engine.webGLVersion < 2 || this.occlusionType === AbstractMesh.OCCLUSION_TYPE_NONE) {
  21460. this._isOccluded = false;
  21461. return;
  21462. }
  21463. if (this.isOcclusionQueryInProgress && this._occlusionQuery) {
  21464. var isOcclusionQueryAvailable = engine.isQueryResultAvailable(this._occlusionQuery);
  21465. if (isOcclusionQueryAvailable) {
  21466. var occlusionQueryResult = engine.getQueryResult(this._occlusionQuery);
  21467. this._isOcclusionQueryInProgress = false;
  21468. this._occlusionInternalRetryCounter = 0;
  21469. this._isOccluded = occlusionQueryResult === 1 ? false : true;
  21470. }
  21471. else {
  21472. this._occlusionInternalRetryCounter++;
  21473. if (this.occlusionRetryCount !== -1 && this._occlusionInternalRetryCounter > this.occlusionRetryCount) {
  21474. this._isOcclusionQueryInProgress = false;
  21475. this._occlusionInternalRetryCounter = 0;
  21476. // if optimistic set isOccluded to false regardless of the status of isOccluded. (Render in the current render loop)
  21477. // if strict continue the last state of the object.
  21478. this._isOccluded = this.occlusionType === AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC ? false : this._isOccluded;
  21479. }
  21480. else {
  21481. return;
  21482. }
  21483. }
  21484. }
  21485. var scene = this.getScene();
  21486. var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
  21487. if (!this._occlusionQuery) {
  21488. this._occlusionQuery = engine.createQuery();
  21489. }
  21490. engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
  21491. occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
  21492. engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
  21493. this._isOcclusionQueryInProgress = true;
  21494. };
  21495. /** No occlusion */
  21496. AbstractMesh.OCCLUSION_TYPE_NONE = 0;
  21497. /** Occlusion set to optimisitic */
  21498. AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC = 1;
  21499. /** Occlusion set to strict */
  21500. AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
  21501. /** Use an accurante occlusion algorithm */
  21502. AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
  21503. /** Use a conservative occlusion algorithm */
  21504. AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
  21505. return AbstractMesh;
  21506. }(BABYLON.TransformNode));
  21507. BABYLON.AbstractMesh = AbstractMesh;
  21508. })(BABYLON || (BABYLON = {}));
  21509. //# sourceMappingURL=babylon.abstractMesh.js.map
  21510. var BABYLON;
  21511. (function (BABYLON) {
  21512. /**
  21513. * Base class of all the lights in Babylon. It groups all the generic information about lights.
  21514. * Lights are used, as you would expect, to affect how meshes are seen, in terms of both illumination and colour.
  21515. * All meshes allow light to pass through them unless shadow generation is activated. The default number of lights allowed is four but this can be increased.
  21516. */
  21517. var Light = /** @class */ (function (_super) {
  21518. __extends(Light, _super);
  21519. /**
  21520. * Creates a Light object in the scene.
  21521. * Documentation : http://doc.babylonjs.com/tutorials/lights
  21522. * @param name The firendly name of the light
  21523. * @param scene The scene the light belongs too
  21524. */
  21525. function Light(name, scene) {
  21526. var _this = _super.call(this, name, scene) || this;
  21527. /**
  21528. * Diffuse gives the basic color to an object.
  21529. */
  21530. _this.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
  21531. /**
  21532. * Specular produces a highlight color on an object.
  21533. * Note: This is note affecting PBR materials.
  21534. */
  21535. _this.specular = new BABYLON.Color3(1.0, 1.0, 1.0);
  21536. /**
  21537. * Strength of the light.
  21538. * Note: By default it is define in the framework own unit.
  21539. * Note: In PBR materials the intensityMode can be use to chose what unit the intensity is defined in.
  21540. */
  21541. _this.intensity = 1.0;
  21542. /**
  21543. * Defines how far from the source the light is impacting in scene units.
  21544. * Note: Unused in PBR material as the distance light falloff is defined following the inverse squared falloff.
  21545. */
  21546. _this.range = Number.MAX_VALUE;
  21547. /**
  21548. * Cached photometric scale default to 1.0 as the automatic intensity mode defaults to 1.0 for every type
  21549. * of light.
  21550. */
  21551. _this._photometricScale = 1.0;
  21552. _this._intensityMode = Light.INTENSITYMODE_AUTOMATIC;
  21553. _this._radius = 0.00001;
  21554. /**
  21555. * Defines the rendering priority of the lights. It can help in case of fallback or number of lights
  21556. * exceeding the number allowed of the materials.
  21557. */
  21558. _this.renderPriority = 0;
  21559. _this._shadowEnabled = true;
  21560. _this._excludeWithLayerMask = 0;
  21561. _this._includeOnlyWithLayerMask = 0;
  21562. _this._lightmapMode = 0;
  21563. /**
  21564. * @hidden Internal use only.
  21565. */
  21566. _this._excludedMeshesIds = new Array();
  21567. /**
  21568. * @hidden Internal use only.
  21569. */
  21570. _this._includedOnlyMeshesIds = new Array();
  21571. _this.getScene().addLight(_this);
  21572. _this._uniformBuffer = new BABYLON.UniformBuffer(_this.getScene().getEngine());
  21573. _this._buildUniformLayout();
  21574. _this.includedOnlyMeshes = new Array();
  21575. _this.excludedMeshes = new Array();
  21576. _this._resyncMeshes();
  21577. return _this;
  21578. }
  21579. Object.defineProperty(Light, "LIGHTMAP_DEFAULT", {
  21580. /**
  21581. * If every light affecting the material is in this lightmapMode,
  21582. * material.lightmapTexture adds or multiplies
  21583. * (depends on material.useLightmapAsShadowmap)
  21584. * after every other light calculations.
  21585. */
  21586. get: function () {
  21587. return Light._LIGHTMAP_DEFAULT;
  21588. },
  21589. enumerable: true,
  21590. configurable: true
  21591. });
  21592. Object.defineProperty(Light, "LIGHTMAP_SPECULAR", {
  21593. /**
  21594. * material.lightmapTexture as only diffuse lighting from this light
  21595. * adds only specular lighting from this light
  21596. * adds dynamic shadows
  21597. */
  21598. get: function () {
  21599. return Light._LIGHTMAP_SPECULAR;
  21600. },
  21601. enumerable: true,
  21602. configurable: true
  21603. });
  21604. Object.defineProperty(Light, "LIGHTMAP_SHADOWSONLY", {
  21605. /**
  21606. * material.lightmapTexture as only lighting
  21607. * no light calculation from this light
  21608. * only adds dynamic shadows from this light
  21609. */
  21610. get: function () {
  21611. return Light._LIGHTMAP_SHADOWSONLY;
  21612. },
  21613. enumerable: true,
  21614. configurable: true
  21615. });
  21616. Object.defineProperty(Light, "INTENSITYMODE_AUTOMATIC", {
  21617. /**
  21618. * Each light type uses the default quantity according to its type:
  21619. * point/spot lights use luminous intensity
  21620. * directional lights use illuminance
  21621. */
  21622. get: function () {
  21623. return Light._INTENSITYMODE_AUTOMATIC;
  21624. },
  21625. enumerable: true,
  21626. configurable: true
  21627. });
  21628. Object.defineProperty(Light, "INTENSITYMODE_LUMINOUSPOWER", {
  21629. /**
  21630. * lumen (lm)
  21631. */
  21632. get: function () {
  21633. return Light._INTENSITYMODE_LUMINOUSPOWER;
  21634. },
  21635. enumerable: true,
  21636. configurable: true
  21637. });
  21638. Object.defineProperty(Light, "INTENSITYMODE_LUMINOUSINTENSITY", {
  21639. /**
  21640. * candela (lm/sr)
  21641. */
  21642. get: function () {
  21643. return Light._INTENSITYMODE_LUMINOUSINTENSITY;
  21644. },
  21645. enumerable: true,
  21646. configurable: true
  21647. });
  21648. Object.defineProperty(Light, "INTENSITYMODE_ILLUMINANCE", {
  21649. /**
  21650. * lux (lm/m^2)
  21651. */
  21652. get: function () {
  21653. return Light._INTENSITYMODE_ILLUMINANCE;
  21654. },
  21655. enumerable: true,
  21656. configurable: true
  21657. });
  21658. Object.defineProperty(Light, "INTENSITYMODE_LUMINANCE", {
  21659. /**
  21660. * nit (cd/m^2)
  21661. */
  21662. get: function () {
  21663. return Light._INTENSITYMODE_LUMINANCE;
  21664. },
  21665. enumerable: true,
  21666. configurable: true
  21667. });
  21668. Object.defineProperty(Light, "LIGHTTYPEID_POINTLIGHT", {
  21669. /**
  21670. * Light type const id of the point light.
  21671. */
  21672. get: function () {
  21673. return Light._LIGHTTYPEID_POINTLIGHT;
  21674. },
  21675. enumerable: true,
  21676. configurable: true
  21677. });
  21678. Object.defineProperty(Light, "LIGHTTYPEID_DIRECTIONALLIGHT", {
  21679. /**
  21680. * Light type const id of the directional light.
  21681. */
  21682. get: function () {
  21683. return Light._LIGHTTYPEID_DIRECTIONALLIGHT;
  21684. },
  21685. enumerable: true,
  21686. configurable: true
  21687. });
  21688. Object.defineProperty(Light, "LIGHTTYPEID_SPOTLIGHT", {
  21689. /**
  21690. * Light type const id of the spot light.
  21691. */
  21692. get: function () {
  21693. return Light._LIGHTTYPEID_SPOTLIGHT;
  21694. },
  21695. enumerable: true,
  21696. configurable: true
  21697. });
  21698. Object.defineProperty(Light, "LIGHTTYPEID_HEMISPHERICLIGHT", {
  21699. /**
  21700. * Light type const id of the hemispheric light.
  21701. */
  21702. get: function () {
  21703. return Light._LIGHTTYPEID_HEMISPHERICLIGHT;
  21704. },
  21705. enumerable: true,
  21706. configurable: true
  21707. });
  21708. Object.defineProperty(Light.prototype, "intensityMode", {
  21709. /**
  21710. * Gets the photometric scale used to interpret the intensity.
  21711. * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.
  21712. */
  21713. get: function () {
  21714. return this._intensityMode;
  21715. },
  21716. /**
  21717. * Sets the photometric scale used to interpret the intensity.
  21718. * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.
  21719. */
  21720. set: function (value) {
  21721. this._intensityMode = value;
  21722. this._computePhotometricScale();
  21723. },
  21724. enumerable: true,
  21725. configurable: true
  21726. });
  21727. ;
  21728. ;
  21729. Object.defineProperty(Light.prototype, "radius", {
  21730. /**
  21731. * Gets the light radius used by PBR Materials to simulate soft area lights.
  21732. */
  21733. get: function () {
  21734. return this._radius;
  21735. },
  21736. /**
  21737. * sets the light radius used by PBR Materials to simulate soft area lights.
  21738. */
  21739. set: function (value) {
  21740. this._radius = value;
  21741. this._computePhotometricScale();
  21742. },
  21743. enumerable: true,
  21744. configurable: true
  21745. });
  21746. ;
  21747. ;
  21748. Object.defineProperty(Light.prototype, "shadowEnabled", {
  21749. /**
  21750. * Gets wether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching
  21751. * the current shadow generator.
  21752. */
  21753. get: function () {
  21754. return this._shadowEnabled;
  21755. },
  21756. /**
  21757. * Sets wether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching
  21758. * the current shadow generator.
  21759. */
  21760. set: function (value) {
  21761. if (this._shadowEnabled === value) {
  21762. return;
  21763. }
  21764. this._shadowEnabled = value;
  21765. this._markMeshesAsLightDirty();
  21766. },
  21767. enumerable: true,
  21768. configurable: true
  21769. });
  21770. Object.defineProperty(Light.prototype, "includedOnlyMeshes", {
  21771. /**
  21772. * Gets the only meshes impacted by this light.
  21773. */
  21774. get: function () {
  21775. return this._includedOnlyMeshes;
  21776. },
  21777. /**
  21778. * Sets the only meshes impacted by this light.
  21779. */
  21780. set: function (value) {
  21781. this._includedOnlyMeshes = value;
  21782. this._hookArrayForIncludedOnly(value);
  21783. },
  21784. enumerable: true,
  21785. configurable: true
  21786. });
  21787. Object.defineProperty(Light.prototype, "excludedMeshes", {
  21788. /**
  21789. * Gets the meshes not impacted by this light.
  21790. */
  21791. get: function () {
  21792. return this._excludedMeshes;
  21793. },
  21794. /**
  21795. * Sets the meshes not impacted by this light.
  21796. */
  21797. set: function (value) {
  21798. this._excludedMeshes = value;
  21799. this._hookArrayForExcluded(value);
  21800. },
  21801. enumerable: true,
  21802. configurable: true
  21803. });
  21804. Object.defineProperty(Light.prototype, "excludeWithLayerMask", {
  21805. /**
  21806. * Gets the layer id use to find what meshes are not impacted by the light.
  21807. * Inactive if 0
  21808. */
  21809. get: function () {
  21810. return this._excludeWithLayerMask;
  21811. },
  21812. /**
  21813. * Sets the layer id use to find what meshes are not impacted by the light.
  21814. * Inactive if 0
  21815. */
  21816. set: function (value) {
  21817. this._excludeWithLayerMask = value;
  21818. this._resyncMeshes();
  21819. },
  21820. enumerable: true,
  21821. configurable: true
  21822. });
  21823. Object.defineProperty(Light.prototype, "includeOnlyWithLayerMask", {
  21824. /**
  21825. * Gets the layer id use to find what meshes are impacted by the light.
  21826. * Inactive if 0
  21827. */
  21828. get: function () {
  21829. return this._includeOnlyWithLayerMask;
  21830. },
  21831. /**
  21832. * Sets the layer id use to find what meshes are impacted by the light.
  21833. * Inactive if 0
  21834. */
  21835. set: function (value) {
  21836. this._includeOnlyWithLayerMask = value;
  21837. this._resyncMeshes();
  21838. },
  21839. enumerable: true,
  21840. configurable: true
  21841. });
  21842. Object.defineProperty(Light.prototype, "lightmapMode", {
  21843. /**
  21844. * Gets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)
  21845. */
  21846. get: function () {
  21847. return this._lightmapMode;
  21848. },
  21849. /**
  21850. * Sets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)
  21851. */
  21852. set: function (value) {
  21853. if (this._lightmapMode === value) {
  21854. return;
  21855. }
  21856. this._lightmapMode = value;
  21857. this._markMeshesAsLightDirty();
  21858. },
  21859. enumerable: true,
  21860. configurable: true
  21861. });
  21862. /**
  21863. * Returns the string "Light".
  21864. * @returns the class name
  21865. */
  21866. Light.prototype.getClassName = function () {
  21867. return "Light";
  21868. };
  21869. /**
  21870. * Converts the light information to a readable string for debug purpose.
  21871. * @param fullDetails Supports for multiple levels of logging within scene loading
  21872. * @returns the human readable light info
  21873. */
  21874. Light.prototype.toString = function (fullDetails) {
  21875. var ret = "Name: " + this.name;
  21876. ret += ", type: " + (["Point", "Directional", "Spot", "Hemispheric"])[this.getTypeID()];
  21877. if (this.animations) {
  21878. for (var i = 0; i < this.animations.length; i++) {
  21879. ret += ", animation[0]: " + this.animations[i].toString(fullDetails);
  21880. }
  21881. }
  21882. if (fullDetails) {
  21883. }
  21884. return ret;
  21885. };
  21886. /**
  21887. * Set the enabled state of this node.
  21888. * @param value - the new enabled state
  21889. */
  21890. Light.prototype.setEnabled = function (value) {
  21891. _super.prototype.setEnabled.call(this, value);
  21892. this._resyncMeshes();
  21893. };
  21894. /**
  21895. * Returns the Light associated shadow generator if any.
  21896. * @return the associated shadow generator.
  21897. */
  21898. Light.prototype.getShadowGenerator = function () {
  21899. return this._shadowGenerator;
  21900. };
  21901. /**
  21902. * Returns a Vector3, the absolute light position in the World.
  21903. * @returns the world space position of the light
  21904. */
  21905. Light.prototype.getAbsolutePosition = function () {
  21906. return BABYLON.Vector3.Zero();
  21907. };
  21908. /**
  21909. * Specifies if the light will affect the passed mesh.
  21910. * @param mesh The mesh to test against the light
  21911. * @return true the mesh is affected otherwise, false.
  21912. */
  21913. Light.prototype.canAffectMesh = function (mesh) {
  21914. if (!mesh) {
  21915. return true;
  21916. }
  21917. if (this.includedOnlyMeshes && this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
  21918. return false;
  21919. }
  21920. if (this.excludedMeshes && this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
  21921. return false;
  21922. }
  21923. if (this.includeOnlyWithLayerMask !== 0 && (this.includeOnlyWithLayerMask & mesh.layerMask) === 0) {
  21924. return false;
  21925. }
  21926. if (this.excludeWithLayerMask !== 0 && this.excludeWithLayerMask & mesh.layerMask) {
  21927. return false;
  21928. }
  21929. return true;
  21930. };
  21931. /**
  21932. * Computes and Returns the light World matrix.
  21933. * @returns the world matrix
  21934. */
  21935. Light.prototype.getWorldMatrix = function () {
  21936. this._currentRenderId = this.getScene().getRenderId();
  21937. this._childRenderId = this._currentRenderId;
  21938. var worldMatrix = this._getWorldMatrix();
  21939. if (this.parent && this.parent.getWorldMatrix) {
  21940. if (!this._parentedWorldMatrix) {
  21941. this._parentedWorldMatrix = BABYLON.Matrix.Identity();
  21942. }
  21943. worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._parentedWorldMatrix);
  21944. this._markSyncedWithParent();
  21945. return this._parentedWorldMatrix;
  21946. }
  21947. return worldMatrix;
  21948. };
  21949. /**
  21950. * Sort function to order lights for rendering.
  21951. * @param a First Light object to compare to second.
  21952. * @param b Second Light object to compare first.
  21953. * @return -1 to reduce's a's index relative to be, 0 for no change, 1 to increase a's index relative to b.
  21954. */
  21955. Light.CompareLightsPriority = function (a, b) {
  21956. //shadow-casting lights have priority over non-shadow-casting lights
  21957. //the renderPrioirty is a secondary sort criterion
  21958. if (a.shadowEnabled !== b.shadowEnabled) {
  21959. return (b.shadowEnabled ? 1 : 0) - (a.shadowEnabled ? 1 : 0);
  21960. }
  21961. return b.renderPriority - a.renderPriority;
  21962. };
  21963. /**
  21964. * Releases resources associated with this node.
  21965. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  21966. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  21967. */
  21968. Light.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  21969. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  21970. if (this._shadowGenerator) {
  21971. this._shadowGenerator.dispose();
  21972. this._shadowGenerator = null;
  21973. }
  21974. // Animations
  21975. this.getScene().stopAnimation(this);
  21976. // Remove from meshes
  21977. for (var _i = 0, _a = this.getScene().meshes; _i < _a.length; _i++) {
  21978. var mesh = _a[_i];
  21979. mesh._removeLightSource(this);
  21980. }
  21981. this._uniformBuffer.dispose();
  21982. // Remove from scene
  21983. this.getScene().removeLight(this);
  21984. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  21985. };
  21986. /**
  21987. * Returns the light type ID (integer).
  21988. * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x
  21989. */
  21990. Light.prototype.getTypeID = function () {
  21991. return 0;
  21992. };
  21993. /**
  21994. * Returns the intensity scaled by the Photometric Scale according to the light type and intensity mode.
  21995. * @returns the scaled intensity in intensity mode unit
  21996. */
  21997. Light.prototype.getScaledIntensity = function () {
  21998. return this._photometricScale * this.intensity;
  21999. };
  22000. /**
  22001. * Returns a new Light object, named "name", from the current one.
  22002. * @param name The name of the cloned light
  22003. * @returns the new created light
  22004. */
  22005. Light.prototype.clone = function (name) {
  22006. var constructor = Light.GetConstructorFromName(this.getTypeID(), name, this.getScene());
  22007. if (!constructor) {
  22008. return null;
  22009. }
  22010. return BABYLON.SerializationHelper.Clone(constructor, this);
  22011. };
  22012. /**
  22013. * Serializes the current light into a Serialization object.
  22014. * @returns the serialized object.
  22015. */
  22016. Light.prototype.serialize = function () {
  22017. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  22018. // Type
  22019. serializationObject.type = this.getTypeID();
  22020. // Parent
  22021. if (this.parent) {
  22022. serializationObject.parentId = this.parent.id;
  22023. }
  22024. // Inclusion / exclusions
  22025. if (this.excludedMeshes.length > 0) {
  22026. serializationObject.excludedMeshesIds = [];
  22027. this.excludedMeshes.forEach(function (mesh) {
  22028. serializationObject.excludedMeshesIds.push(mesh.id);
  22029. });
  22030. }
  22031. if (this.includedOnlyMeshes.length > 0) {
  22032. serializationObject.includedOnlyMeshesIds = [];
  22033. this.includedOnlyMeshes.forEach(function (mesh) {
  22034. serializationObject.includedOnlyMeshesIds.push(mesh.id);
  22035. });
  22036. }
  22037. // Animations
  22038. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  22039. serializationObject.ranges = this.serializeAnimationRanges();
  22040. return serializationObject;
  22041. };
  22042. /**
  22043. * Creates a new typed light from the passed type (integer) : point light = 0, directional light = 1, spot light = 2, hemispheric light = 3.
  22044. * This new light is named "name" and added to the passed scene.
  22045. * @param type Type according to the types available in Light.LIGHTTYPEID_x
  22046. * @param name The friendly name of the light
  22047. * @param scene The scene the new light will belong to
  22048. * @returns the constructor function
  22049. */
  22050. Light.GetConstructorFromName = function (type, name, scene) {
  22051. switch (type) {
  22052. case 0:
  22053. return function () { return new BABYLON.PointLight(name, BABYLON.Vector3.Zero(), scene); };
  22054. case 1:
  22055. return function () { return new BABYLON.DirectionalLight(name, BABYLON.Vector3.Zero(), scene); };
  22056. case 2:
  22057. return function () { return new BABYLON.SpotLight(name, BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 0, 0, scene); };
  22058. case 3:
  22059. return function () { return new BABYLON.HemisphericLight(name, BABYLON.Vector3.Zero(), scene); };
  22060. }
  22061. return null;
  22062. };
  22063. /**
  22064. * Parses the passed "parsedLight" and returns a new instanced Light from this parsing.
  22065. * @param parsedLight The JSON representation of the light
  22066. * @param scene The scene to create the parsed light in
  22067. * @returns the created light after parsing
  22068. */
  22069. Light.Parse = function (parsedLight, scene) {
  22070. var constructor = Light.GetConstructorFromName(parsedLight.type, parsedLight.name, scene);
  22071. if (!constructor) {
  22072. return null;
  22073. }
  22074. var light = BABYLON.SerializationHelper.Parse(constructor, parsedLight, scene);
  22075. // Inclusion / exclusions
  22076. if (parsedLight.excludedMeshesIds) {
  22077. light._excludedMeshesIds = parsedLight.excludedMeshesIds;
  22078. }
  22079. if (parsedLight.includedOnlyMeshesIds) {
  22080. light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;
  22081. }
  22082. // Parent
  22083. if (parsedLight.parentId) {
  22084. light._waitingParentId = parsedLight.parentId;
  22085. }
  22086. // Animations
  22087. if (parsedLight.animations) {
  22088. for (var animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {
  22089. var parsedAnimation = parsedLight.animations[animationIndex];
  22090. light.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  22091. }
  22092. BABYLON.Node.ParseAnimationRanges(light, parsedLight, scene);
  22093. }
  22094. if (parsedLight.autoAnimate) {
  22095. scene.beginAnimation(light, parsedLight.autoAnimateFrom, parsedLight.autoAnimateTo, parsedLight.autoAnimateLoop, parsedLight.autoAnimateSpeed || 1.0);
  22096. }
  22097. return light;
  22098. };
  22099. Light.prototype._hookArrayForExcluded = function (array) {
  22100. var _this = this;
  22101. var oldPush = array.push;
  22102. array.push = function () {
  22103. var items = [];
  22104. for (var _i = 0; _i < arguments.length; _i++) {
  22105. items[_i] = arguments[_i];
  22106. }
  22107. var result = oldPush.apply(array, items);
  22108. for (var _a = 0, items_1 = items; _a < items_1.length; _a++) {
  22109. var item = items_1[_a];
  22110. item._resyncLighSource(_this);
  22111. }
  22112. return result;
  22113. };
  22114. var oldSplice = array.splice;
  22115. array.splice = function (index, deleteCount) {
  22116. var deleted = oldSplice.apply(array, [index, deleteCount]);
  22117. for (var _i = 0, deleted_1 = deleted; _i < deleted_1.length; _i++) {
  22118. var item = deleted_1[_i];
  22119. item._resyncLighSource(_this);
  22120. }
  22121. return deleted;
  22122. };
  22123. for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
  22124. var item = array_1[_i];
  22125. item._resyncLighSource(this);
  22126. }
  22127. };
  22128. Light.prototype._hookArrayForIncludedOnly = function (array) {
  22129. var _this = this;
  22130. var oldPush = array.push;
  22131. array.push = function () {
  22132. var items = [];
  22133. for (var _i = 0; _i < arguments.length; _i++) {
  22134. items[_i] = arguments[_i];
  22135. }
  22136. var result = oldPush.apply(array, items);
  22137. _this._resyncMeshes();
  22138. return result;
  22139. };
  22140. var oldSplice = array.splice;
  22141. array.splice = function (index, deleteCount) {
  22142. var deleted = oldSplice.apply(array, [index, deleteCount]);
  22143. _this._resyncMeshes();
  22144. return deleted;
  22145. };
  22146. this._resyncMeshes();
  22147. };
  22148. Light.prototype._resyncMeshes = function () {
  22149. for (var _i = 0, _a = this.getScene().meshes; _i < _a.length; _i++) {
  22150. var mesh = _a[_i];
  22151. mesh._resyncLighSource(this);
  22152. }
  22153. };
  22154. /**
  22155. * Forces the meshes to update their light related information in their rendering used effects
  22156. * @hidden Internal Use Only
  22157. */
  22158. Light.prototype._markMeshesAsLightDirty = function () {
  22159. for (var _i = 0, _a = this.getScene().meshes; _i < _a.length; _i++) {
  22160. var mesh = _a[_i];
  22161. if (mesh._lightSources.indexOf(this) !== -1) {
  22162. mesh._markSubMeshesAsLightDirty();
  22163. }
  22164. }
  22165. };
  22166. /**
  22167. * Recomputes the cached photometric scale if needed.
  22168. */
  22169. Light.prototype._computePhotometricScale = function () {
  22170. this._photometricScale = this._getPhotometricScale();
  22171. this.getScene().resetCachedMaterial();
  22172. };
  22173. /**
  22174. * Returns the Photometric Scale according to the light type and intensity mode.
  22175. */
  22176. Light.prototype._getPhotometricScale = function () {
  22177. var photometricScale = 0.0;
  22178. var lightTypeID = this.getTypeID();
  22179. //get photometric mode
  22180. var photometricMode = this.intensityMode;
  22181. if (photometricMode === Light.INTENSITYMODE_AUTOMATIC) {
  22182. if (lightTypeID === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {
  22183. photometricMode = Light.INTENSITYMODE_ILLUMINANCE;
  22184. }
  22185. else {
  22186. photometricMode = Light.INTENSITYMODE_LUMINOUSINTENSITY;
  22187. }
  22188. }
  22189. //compute photometric scale
  22190. switch (lightTypeID) {
  22191. case Light.LIGHTTYPEID_POINTLIGHT:
  22192. case Light.LIGHTTYPEID_SPOTLIGHT:
  22193. switch (photometricMode) {
  22194. case Light.INTENSITYMODE_LUMINOUSPOWER:
  22195. photometricScale = 1.0 / (4.0 * Math.PI);
  22196. break;
  22197. case Light.INTENSITYMODE_LUMINOUSINTENSITY:
  22198. photometricScale = 1.0;
  22199. break;
  22200. case Light.INTENSITYMODE_LUMINANCE:
  22201. photometricScale = this.radius * this.radius;
  22202. break;
  22203. }
  22204. break;
  22205. case Light.LIGHTTYPEID_DIRECTIONALLIGHT:
  22206. switch (photometricMode) {
  22207. case Light.INTENSITYMODE_ILLUMINANCE:
  22208. photometricScale = 1.0;
  22209. break;
  22210. case Light.INTENSITYMODE_LUMINANCE:
  22211. // When radius (and therefore solid angle) is non-zero a directional lights brightness can be specified via central (peak) luminance.
  22212. // For a directional light the 'radius' defines the angular radius (in radians) rather than world-space radius (e.g. in metres).
  22213. var apexAngleRadians = this.radius;
  22214. // Impose a minimum light angular size to avoid the light becoming an infinitely small angular light source (i.e. a dirac delta function).
  22215. apexAngleRadians = Math.max(apexAngleRadians, 0.001);
  22216. var solidAngle = 2.0 * Math.PI * (1.0 - Math.cos(apexAngleRadians));
  22217. photometricScale = solidAngle;
  22218. break;
  22219. }
  22220. break;
  22221. case Light.LIGHTTYPEID_HEMISPHERICLIGHT:
  22222. // No fall off in hemisperic light.
  22223. photometricScale = 1.0;
  22224. break;
  22225. }
  22226. return photometricScale;
  22227. };
  22228. /**
  22229. * Reorder the light in the scene according to their defined priority.
  22230. * @hidden Internal Use Only
  22231. */
  22232. Light.prototype._reorderLightsInScene = function () {
  22233. var scene = this.getScene();
  22234. if (this._renderPriority != 0) {
  22235. scene.requireLightSorting = true;
  22236. }
  22237. this.getScene().sortLightsByPriority();
  22238. };
  22239. //lightmapMode Consts
  22240. Light._LIGHTMAP_DEFAULT = 0;
  22241. Light._LIGHTMAP_SPECULAR = 1;
  22242. Light._LIGHTMAP_SHADOWSONLY = 2;
  22243. // Intensity Mode Consts
  22244. Light._INTENSITYMODE_AUTOMATIC = 0;
  22245. Light._INTENSITYMODE_LUMINOUSPOWER = 1;
  22246. Light._INTENSITYMODE_LUMINOUSINTENSITY = 2;
  22247. Light._INTENSITYMODE_ILLUMINANCE = 3;
  22248. Light._INTENSITYMODE_LUMINANCE = 4;
  22249. // Light types ids const.
  22250. Light._LIGHTTYPEID_POINTLIGHT = 0;
  22251. Light._LIGHTTYPEID_DIRECTIONALLIGHT = 1;
  22252. Light._LIGHTTYPEID_SPOTLIGHT = 2;
  22253. Light._LIGHTTYPEID_HEMISPHERICLIGHT = 3;
  22254. __decorate([
  22255. BABYLON.serializeAsColor3()
  22256. ], Light.prototype, "diffuse", void 0);
  22257. __decorate([
  22258. BABYLON.serializeAsColor3()
  22259. ], Light.prototype, "specular", void 0);
  22260. __decorate([
  22261. BABYLON.serialize()
  22262. ], Light.prototype, "intensity", void 0);
  22263. __decorate([
  22264. BABYLON.serialize()
  22265. ], Light.prototype, "range", void 0);
  22266. __decorate([
  22267. BABYLON.serialize()
  22268. ], Light.prototype, "intensityMode", null);
  22269. __decorate([
  22270. BABYLON.serialize()
  22271. ], Light.prototype, "radius", null);
  22272. __decorate([
  22273. BABYLON.serialize()
  22274. ], Light.prototype, "_renderPriority", void 0);
  22275. __decorate([
  22276. BABYLON.expandToProperty("_reorderLightsInScene")
  22277. ], Light.prototype, "renderPriority", void 0);
  22278. __decorate([
  22279. BABYLON.serialize("shadowEnabled")
  22280. ], Light.prototype, "_shadowEnabled", void 0);
  22281. __decorate([
  22282. BABYLON.serialize("excludeWithLayerMask")
  22283. ], Light.prototype, "_excludeWithLayerMask", void 0);
  22284. __decorate([
  22285. BABYLON.serialize("includeOnlyWithLayerMask")
  22286. ], Light.prototype, "_includeOnlyWithLayerMask", void 0);
  22287. __decorate([
  22288. BABYLON.serialize("lightmapMode")
  22289. ], Light.prototype, "_lightmapMode", void 0);
  22290. return Light;
  22291. }(BABYLON.Node));
  22292. BABYLON.Light = Light;
  22293. })(BABYLON || (BABYLON = {}));
  22294. //# sourceMappingURL=babylon.light.js.map
  22295. var BABYLON;
  22296. (function (BABYLON) {
  22297. var Camera = /** @class */ (function (_super) {
  22298. __extends(Camera, _super);
  22299. function Camera(name, position, scene, setActiveOnSceneIfNoneActive) {
  22300. if (setActiveOnSceneIfNoneActive === void 0) { setActiveOnSceneIfNoneActive = true; }
  22301. var _this = _super.call(this, name, scene) || this;
  22302. /**
  22303. * The vector the camera should consider as up.
  22304. * (default is Vector3(0, 1, 0) aka Vector3.Up())
  22305. */
  22306. _this.upVector = BABYLON.Vector3.Up();
  22307. _this.orthoLeft = null;
  22308. _this.orthoRight = null;
  22309. _this.orthoBottom = null;
  22310. _this.orthoTop = null;
  22311. /**
  22312. * FOV is set in Radians. (default is 0.8)
  22313. */
  22314. _this.fov = 0.8;
  22315. _this.minZ = 1;
  22316. _this.maxZ = 10000.0;
  22317. _this.inertia = 0.9;
  22318. _this.mode = Camera.PERSPECTIVE_CAMERA;
  22319. _this.isIntermediate = false;
  22320. _this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
  22321. /**
  22322. * Restricts the camera to viewing objects with the same layerMask.
  22323. * A camera with a layerMask of 1 will render mesh.layerMask & camera.layerMask!== 0
  22324. */
  22325. _this.layerMask = 0x0FFFFFFF;
  22326. /**
  22327. * fovMode sets the camera frustum bounds to the viewport bounds. (default is FOVMODE_VERTICAL_FIXED)
  22328. */
  22329. _this.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
  22330. // Camera rig members
  22331. _this.cameraRigMode = Camera.RIG_MODE_NONE;
  22332. _this._rigCameras = new Array();
  22333. _this._webvrViewMatrix = BABYLON.Matrix.Identity();
  22334. _this._skipRendering = false;
  22335. _this.customRenderTargets = new Array();
  22336. // Observables
  22337. _this.onViewMatrixChangedObservable = new BABYLON.Observable();
  22338. _this.onProjectionMatrixChangedObservable = new BABYLON.Observable();
  22339. _this.onAfterCheckInputsObservable = new BABYLON.Observable();
  22340. _this.onRestoreStateObservable = new BABYLON.Observable();
  22341. // Cache
  22342. _this._computedViewMatrix = BABYLON.Matrix.Identity();
  22343. _this._projectionMatrix = new BABYLON.Matrix();
  22344. _this._doNotComputeProjectionMatrix = false;
  22345. _this._worldMatrix = BABYLON.Matrix.Identity();
  22346. _this._postProcesses = new Array();
  22347. _this._transformMatrix = BABYLON.Matrix.Zero();
  22348. _this._activeMeshes = new BABYLON.SmartArray(256);
  22349. _this._globalPosition = BABYLON.Vector3.Zero();
  22350. _this._refreshFrustumPlanes = true;
  22351. _this.getScene().addCamera(_this);
  22352. if (setActiveOnSceneIfNoneActive && !_this.getScene().activeCamera) {
  22353. _this.getScene().activeCamera = _this;
  22354. }
  22355. _this.position = position;
  22356. return _this;
  22357. }
  22358. Object.defineProperty(Camera, "PERSPECTIVE_CAMERA", {
  22359. get: function () {
  22360. return Camera._PERSPECTIVE_CAMERA;
  22361. },
  22362. enumerable: true,
  22363. configurable: true
  22364. });
  22365. Object.defineProperty(Camera, "ORTHOGRAPHIC_CAMERA", {
  22366. get: function () {
  22367. return Camera._ORTHOGRAPHIC_CAMERA;
  22368. },
  22369. enumerable: true,
  22370. configurable: true
  22371. });
  22372. Object.defineProperty(Camera, "FOVMODE_VERTICAL_FIXED", {
  22373. /**
  22374. * This is the default FOV mode for perspective cameras.
  22375. * This setting aligns the upper and lower bounds of the viewport to the upper and lower bounds of the camera frustum.
  22376. *
  22377. */
  22378. get: function () {
  22379. return Camera._FOVMODE_VERTICAL_FIXED;
  22380. },
  22381. enumerable: true,
  22382. configurable: true
  22383. });
  22384. Object.defineProperty(Camera, "FOVMODE_HORIZONTAL_FIXED", {
  22385. /**
  22386. * This setting aligns the left and right bounds of the viewport to the left and right bounds of the camera frustum.
  22387. *
  22388. */
  22389. get: function () {
  22390. return Camera._FOVMODE_HORIZONTAL_FIXED;
  22391. },
  22392. enumerable: true,
  22393. configurable: true
  22394. });
  22395. Object.defineProperty(Camera, "RIG_MODE_NONE", {
  22396. get: function () {
  22397. return Camera._RIG_MODE_NONE;
  22398. },
  22399. enumerable: true,
  22400. configurable: true
  22401. });
  22402. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_ANAGLYPH", {
  22403. get: function () {
  22404. return Camera._RIG_MODE_STEREOSCOPIC_ANAGLYPH;
  22405. },
  22406. enumerable: true,
  22407. configurable: true
  22408. });
  22409. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL", {
  22410. get: function () {
  22411. return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL;
  22412. },
  22413. enumerable: true,
  22414. configurable: true
  22415. });
  22416. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED", {
  22417. get: function () {
  22418. return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;
  22419. },
  22420. enumerable: true,
  22421. configurable: true
  22422. });
  22423. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_OVERUNDER", {
  22424. get: function () {
  22425. return Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER;
  22426. },
  22427. enumerable: true,
  22428. configurable: true
  22429. });
  22430. Object.defineProperty(Camera, "RIG_MODE_VR", {
  22431. get: function () {
  22432. return Camera._RIG_MODE_VR;
  22433. },
  22434. enumerable: true,
  22435. configurable: true
  22436. });
  22437. Object.defineProperty(Camera, "RIG_MODE_WEBVR", {
  22438. get: function () {
  22439. return Camera._RIG_MODE_WEBVR;
  22440. },
  22441. enumerable: true,
  22442. configurable: true
  22443. });
  22444. /**
  22445. * Store current camera state (fov, position, etc..)
  22446. */
  22447. Camera.prototype.storeState = function () {
  22448. this._stateStored = true;
  22449. this._storedFov = this.fov;
  22450. return this;
  22451. };
  22452. /**
  22453. * Restores the camera state values if it has been stored. You must call storeState() first
  22454. */
  22455. Camera.prototype._restoreStateValues = function () {
  22456. if (!this._stateStored) {
  22457. return false;
  22458. }
  22459. this.fov = this._storedFov;
  22460. return true;
  22461. };
  22462. /**
  22463. * Restored camera state. You must call storeState() first
  22464. */
  22465. Camera.prototype.restoreState = function () {
  22466. if (this._restoreStateValues()) {
  22467. this.onRestoreStateObservable.notifyObservers(this);
  22468. return true;
  22469. }
  22470. return false;
  22471. };
  22472. Camera.prototype.getClassName = function () {
  22473. return "Camera";
  22474. };
  22475. /**
  22476. * @param {boolean} fullDetails - support for multiple levels of logging within scene loading
  22477. */
  22478. Camera.prototype.toString = function (fullDetails) {
  22479. var ret = "Name: " + this.name;
  22480. ret += ", type: " + this.getClassName();
  22481. if (this.animations) {
  22482. for (var i = 0; i < this.animations.length; i++) {
  22483. ret += ", animation[0]: " + this.animations[i].toString(fullDetails);
  22484. }
  22485. }
  22486. if (fullDetails) {
  22487. }
  22488. return ret;
  22489. };
  22490. Object.defineProperty(Camera.prototype, "globalPosition", {
  22491. get: function () {
  22492. return this._globalPosition;
  22493. },
  22494. enumerable: true,
  22495. configurable: true
  22496. });
  22497. Camera.prototype.getActiveMeshes = function () {
  22498. return this._activeMeshes;
  22499. };
  22500. Camera.prototype.isActiveMesh = function (mesh) {
  22501. return (this._activeMeshes.indexOf(mesh) !== -1);
  22502. };
  22503. /**
  22504. * Is this camera ready to be used/rendered
  22505. * @param completeCheck defines if a complete check (including post processes) has to be done (false by default)
  22506. * @return true if the camera is ready
  22507. */
  22508. Camera.prototype.isReady = function (completeCheck) {
  22509. if (completeCheck === void 0) { completeCheck = false; }
  22510. if (completeCheck) {
  22511. for (var _i = 0, _a = this._postProcesses; _i < _a.length; _i++) {
  22512. var pp = _a[_i];
  22513. if (pp && !pp.isReady()) {
  22514. return false;
  22515. }
  22516. }
  22517. }
  22518. return _super.prototype.isReady.call(this, completeCheck);
  22519. };
  22520. //Cache
  22521. Camera.prototype._initCache = function () {
  22522. _super.prototype._initCache.call(this);
  22523. this._cache.position = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  22524. this._cache.upVector = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  22525. this._cache.mode = undefined;
  22526. this._cache.minZ = undefined;
  22527. this._cache.maxZ = undefined;
  22528. this._cache.fov = undefined;
  22529. this._cache.fovMode = undefined;
  22530. this._cache.aspectRatio = undefined;
  22531. this._cache.orthoLeft = undefined;
  22532. this._cache.orthoRight = undefined;
  22533. this._cache.orthoBottom = undefined;
  22534. this._cache.orthoTop = undefined;
  22535. this._cache.renderWidth = undefined;
  22536. this._cache.renderHeight = undefined;
  22537. };
  22538. Camera.prototype._updateCache = function (ignoreParentClass) {
  22539. if (!ignoreParentClass) {
  22540. _super.prototype._updateCache.call(this);
  22541. }
  22542. this._cache.position.copyFrom(this.position);
  22543. this._cache.upVector.copyFrom(this.upVector);
  22544. };
  22545. // Synchronized
  22546. Camera.prototype._isSynchronized = function () {
  22547. return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();
  22548. };
  22549. Camera.prototype._isSynchronizedViewMatrix = function () {
  22550. if (!_super.prototype._isSynchronized.call(this))
  22551. return false;
  22552. return this._cache.position.equals(this.position)
  22553. && this._cache.upVector.equals(this.upVector)
  22554. && this.isSynchronizedWithParent();
  22555. };
  22556. Camera.prototype._isSynchronizedProjectionMatrix = function () {
  22557. var check = this._cache.mode === this.mode
  22558. && this._cache.minZ === this.minZ
  22559. && this._cache.maxZ === this.maxZ;
  22560. if (!check) {
  22561. return false;
  22562. }
  22563. var engine = this.getEngine();
  22564. if (this.mode === Camera.PERSPECTIVE_CAMERA) {
  22565. check = this._cache.fov === this.fov
  22566. && this._cache.fovMode === this.fovMode
  22567. && this._cache.aspectRatio === engine.getAspectRatio(this);
  22568. }
  22569. else {
  22570. check = this._cache.orthoLeft === this.orthoLeft
  22571. && this._cache.orthoRight === this.orthoRight
  22572. && this._cache.orthoBottom === this.orthoBottom
  22573. && this._cache.orthoTop === this.orthoTop
  22574. && this._cache.renderWidth === engine.getRenderWidth()
  22575. && this._cache.renderHeight === engine.getRenderHeight();
  22576. }
  22577. return check;
  22578. };
  22579. // Controls
  22580. Camera.prototype.attachControl = function (element, noPreventDefault) {
  22581. };
  22582. Camera.prototype.detachControl = function (element) {
  22583. };
  22584. Camera.prototype.update = function () {
  22585. this._checkInputs();
  22586. if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
  22587. this._updateRigCameras();
  22588. }
  22589. };
  22590. Camera.prototype._checkInputs = function () {
  22591. this.onAfterCheckInputsObservable.notifyObservers(this);
  22592. };
  22593. Object.defineProperty(Camera.prototype, "rigCameras", {
  22594. get: function () {
  22595. return this._rigCameras;
  22596. },
  22597. enumerable: true,
  22598. configurable: true
  22599. });
  22600. Object.defineProperty(Camera.prototype, "rigPostProcess", {
  22601. get: function () {
  22602. return this._rigPostProcess;
  22603. },
  22604. enumerable: true,
  22605. configurable: true
  22606. });
  22607. /**
  22608. * Internal, gets the first post proces.
  22609. * @returns the first post process to be run on this camera.
  22610. */
  22611. Camera.prototype._getFirstPostProcess = function () {
  22612. for (var ppIndex = 0; ppIndex < this._postProcesses.length; ppIndex++) {
  22613. if (this._postProcesses[ppIndex] !== null) {
  22614. return this._postProcesses[ppIndex];
  22615. }
  22616. }
  22617. return null;
  22618. };
  22619. Camera.prototype._cascadePostProcessesToRigCams = function () {
  22620. // invalidate framebuffer
  22621. var firstPostProcess = this._getFirstPostProcess();
  22622. if (firstPostProcess) {
  22623. firstPostProcess.markTextureDirty();
  22624. }
  22625. // glue the rigPostProcess to the end of the user postprocesses & assign to each sub-camera
  22626. for (var i = 0, len = this._rigCameras.length; i < len; i++) {
  22627. var cam = this._rigCameras[i];
  22628. var rigPostProcess = cam._rigPostProcess;
  22629. // for VR rig, there does not have to be a post process
  22630. if (rigPostProcess) {
  22631. var isPass = rigPostProcess instanceof BABYLON.PassPostProcess;
  22632. if (isPass) {
  22633. // any rig which has a PassPostProcess for rig[0], cannot be isIntermediate when there are also user postProcesses
  22634. cam.isIntermediate = this._postProcesses.length === 0;
  22635. }
  22636. cam._postProcesses = this._postProcesses.slice(0).concat(rigPostProcess);
  22637. rigPostProcess.markTextureDirty();
  22638. }
  22639. else {
  22640. cam._postProcesses = this._postProcesses.slice(0);
  22641. }
  22642. }
  22643. };
  22644. Camera.prototype.attachPostProcess = function (postProcess, insertAt) {
  22645. if (insertAt === void 0) { insertAt = null; }
  22646. if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
  22647. BABYLON.Tools.Error("You're trying to reuse a post process not defined as reusable.");
  22648. return 0;
  22649. }
  22650. if (insertAt == null || insertAt < 0) {
  22651. this._postProcesses.push(postProcess);
  22652. }
  22653. else if (this._postProcesses[insertAt] === null) {
  22654. this._postProcesses[insertAt] = postProcess;
  22655. }
  22656. else {
  22657. this._postProcesses.splice(insertAt, 0, postProcess);
  22658. }
  22659. this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated
  22660. return this._postProcesses.indexOf(postProcess);
  22661. };
  22662. Camera.prototype.detachPostProcess = function (postProcess) {
  22663. var idx = this._postProcesses.indexOf(postProcess);
  22664. if (idx !== -1) {
  22665. this._postProcesses[idx] = null;
  22666. }
  22667. this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated
  22668. };
  22669. Camera.prototype.getWorldMatrix = function () {
  22670. if (this._isSynchronizedViewMatrix()) {
  22671. return this._worldMatrix;
  22672. }
  22673. // Getting the the view matrix will also compute the world matrix.
  22674. this.getViewMatrix();
  22675. return this._worldMatrix;
  22676. };
  22677. Camera.prototype._getViewMatrix = function () {
  22678. return BABYLON.Matrix.Identity();
  22679. };
  22680. Camera.prototype.getViewMatrix = function (force) {
  22681. if (!force && this._isSynchronizedViewMatrix()) {
  22682. return this._computedViewMatrix;
  22683. }
  22684. this.updateCache();
  22685. this._computedViewMatrix = this._getViewMatrix();
  22686. this._currentRenderId = this.getScene().getRenderId();
  22687. this._childRenderId = this._currentRenderId;
  22688. this._refreshFrustumPlanes = true;
  22689. if (this._cameraRigParams && this._cameraRigParams.vrPreViewMatrix) {
  22690. this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);
  22691. }
  22692. this.onViewMatrixChangedObservable.notifyObservers(this);
  22693. this._computedViewMatrix.invertToRef(this._worldMatrix);
  22694. return this._computedViewMatrix;
  22695. };
  22696. Camera.prototype.freezeProjectionMatrix = function (projection) {
  22697. this._doNotComputeProjectionMatrix = true;
  22698. if (projection !== undefined) {
  22699. this._projectionMatrix = projection;
  22700. }
  22701. };
  22702. ;
  22703. Camera.prototype.unfreezeProjectionMatrix = function () {
  22704. this._doNotComputeProjectionMatrix = false;
  22705. };
  22706. ;
  22707. Camera.prototype.getProjectionMatrix = function (force) {
  22708. if (this._doNotComputeProjectionMatrix || (!force && this._isSynchronizedProjectionMatrix())) {
  22709. return this._projectionMatrix;
  22710. }
  22711. // Cache
  22712. this._cache.mode = this.mode;
  22713. this._cache.minZ = this.minZ;
  22714. this._cache.maxZ = this.maxZ;
  22715. // Matrix
  22716. this._refreshFrustumPlanes = true;
  22717. var engine = this.getEngine();
  22718. var scene = this.getScene();
  22719. if (this.mode === Camera.PERSPECTIVE_CAMERA) {
  22720. this._cache.fov = this.fov;
  22721. this._cache.fovMode = this.fovMode;
  22722. this._cache.aspectRatio = engine.getAspectRatio(this);
  22723. if (this.minZ <= 0) {
  22724. this.minZ = 0.1;
  22725. }
  22726. if (scene.useRightHandedSystem) {
  22727. BABYLON.Matrix.PerspectiveFovRHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode === Camera.FOVMODE_VERTICAL_FIXED);
  22728. }
  22729. else {
  22730. BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode === Camera.FOVMODE_VERTICAL_FIXED);
  22731. }
  22732. }
  22733. else {
  22734. var halfWidth = engine.getRenderWidth() / 2.0;
  22735. var halfHeight = engine.getRenderHeight() / 2.0;
  22736. if (scene.useRightHandedSystem) {
  22737. BABYLON.Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
  22738. }
  22739. else {
  22740. BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
  22741. }
  22742. this._cache.orthoLeft = this.orthoLeft;
  22743. this._cache.orthoRight = this.orthoRight;
  22744. this._cache.orthoBottom = this.orthoBottom;
  22745. this._cache.orthoTop = this.orthoTop;
  22746. this._cache.renderWidth = engine.getRenderWidth();
  22747. this._cache.renderHeight = engine.getRenderHeight();
  22748. }
  22749. this.onProjectionMatrixChangedObservable.notifyObservers(this);
  22750. return this._projectionMatrix;
  22751. };
  22752. Camera.prototype.getTranformationMatrix = function () {
  22753. this._computedViewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  22754. return this._transformMatrix;
  22755. };
  22756. Camera.prototype.updateFrustumPlanes = function () {
  22757. if (!this._refreshFrustumPlanes) {
  22758. return;
  22759. }
  22760. this.getTranformationMatrix();
  22761. if (!this._frustumPlanes) {
  22762. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  22763. }
  22764. else {
  22765. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  22766. }
  22767. this._refreshFrustumPlanes = false;
  22768. };
  22769. Camera.prototype.isInFrustum = function (target) {
  22770. this.updateFrustumPlanes();
  22771. return target.isInFrustum(this._frustumPlanes);
  22772. };
  22773. Camera.prototype.isCompletelyInFrustum = function (target) {
  22774. this.updateFrustumPlanes();
  22775. return target.isCompletelyInFrustum(this._frustumPlanes);
  22776. };
  22777. Camera.prototype.getForwardRay = function (length, transform, origin) {
  22778. if (length === void 0) { length = 100; }
  22779. if (!transform) {
  22780. transform = this.getWorldMatrix();
  22781. }
  22782. if (!origin) {
  22783. origin = this.position;
  22784. }
  22785. var forward = new BABYLON.Vector3(0, 0, 1);
  22786. var forwardWorld = BABYLON.Vector3.TransformNormal(forward, transform);
  22787. var direction = BABYLON.Vector3.Normalize(forwardWorld);
  22788. return new BABYLON.Ray(origin, direction, length);
  22789. };
  22790. /**
  22791. * Releases resources associated with this node.
  22792. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  22793. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  22794. */
  22795. Camera.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  22796. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  22797. // Observables
  22798. this.onViewMatrixChangedObservable.clear();
  22799. this.onProjectionMatrixChangedObservable.clear();
  22800. this.onAfterCheckInputsObservable.clear();
  22801. this.onRestoreStateObservable.clear();
  22802. // Inputs
  22803. if (this.inputs) {
  22804. this.inputs.clear();
  22805. }
  22806. // Animations
  22807. this.getScene().stopAnimation(this);
  22808. // Remove from scene
  22809. this.getScene().removeCamera(this);
  22810. while (this._rigCameras.length > 0) {
  22811. var camera = this._rigCameras.pop();
  22812. if (camera) {
  22813. camera.dispose();
  22814. }
  22815. }
  22816. // Postprocesses
  22817. if (this._rigPostProcess) {
  22818. this._rigPostProcess.dispose(this);
  22819. this._rigPostProcess = null;
  22820. this._postProcesses = [];
  22821. }
  22822. else if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
  22823. this._rigPostProcess = null;
  22824. this._postProcesses = [];
  22825. }
  22826. else {
  22827. var i = this._postProcesses.length;
  22828. while (--i >= 0) {
  22829. var postProcess = this._postProcesses[i];
  22830. if (postProcess) {
  22831. postProcess.dispose(this);
  22832. }
  22833. }
  22834. }
  22835. // Render targets
  22836. var i = this.customRenderTargets.length;
  22837. while (--i >= 0) {
  22838. this.customRenderTargets[i].dispose();
  22839. }
  22840. this.customRenderTargets = [];
  22841. // Active Meshes
  22842. this._activeMeshes.dispose();
  22843. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  22844. };
  22845. Object.defineProperty(Camera.prototype, "leftCamera", {
  22846. // ---- Camera rigs section ----
  22847. get: function () {
  22848. if (this._rigCameras.length < 1) {
  22849. return null;
  22850. }
  22851. return this._rigCameras[0];
  22852. },
  22853. enumerable: true,
  22854. configurable: true
  22855. });
  22856. Object.defineProperty(Camera.prototype, "rightCamera", {
  22857. get: function () {
  22858. if (this._rigCameras.length < 2) {
  22859. return null;
  22860. }
  22861. return this._rigCameras[1];
  22862. },
  22863. enumerable: true,
  22864. configurable: true
  22865. });
  22866. Camera.prototype.getLeftTarget = function () {
  22867. if (this._rigCameras.length < 1) {
  22868. return null;
  22869. }
  22870. return this._rigCameras[0].getTarget();
  22871. };
  22872. Camera.prototype.getRightTarget = function () {
  22873. if (this._rigCameras.length < 2) {
  22874. return null;
  22875. }
  22876. return this._rigCameras[1].getTarget();
  22877. };
  22878. Camera.prototype.setCameraRigMode = function (mode, rigParams) {
  22879. if (this.cameraRigMode === mode) {
  22880. return;
  22881. }
  22882. while (this._rigCameras.length > 0) {
  22883. var camera = this._rigCameras.pop();
  22884. if (camera) {
  22885. camera.dispose();
  22886. }
  22887. }
  22888. this.cameraRigMode = mode;
  22889. this._cameraRigParams = {};
  22890. //we have to implement stereo camera calcultating left and right viewpoints from interaxialDistance and target,
  22891. //not from a given angle as it is now, but until that complete code rewriting provisional stereoHalfAngle value is introduced
  22892. this._cameraRigParams.interaxialDistance = rigParams.interaxialDistance || 0.0637;
  22893. this._cameraRigParams.stereoHalfAngle = BABYLON.Tools.ToRadians(this._cameraRigParams.interaxialDistance / 0.0637);
  22894. // create the rig cameras, unless none
  22895. if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
  22896. var leftCamera = this.createRigCamera(this.name + "_L", 0);
  22897. var rightCamera = this.createRigCamera(this.name + "_R", 1);
  22898. if (leftCamera && rightCamera) {
  22899. this._rigCameras.push(leftCamera);
  22900. this._rigCameras.push(rightCamera);
  22901. }
  22902. }
  22903. switch (this.cameraRigMode) {
  22904. case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  22905. this._rigCameras[0]._rigPostProcess = new BABYLON.PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[0]);
  22906. this._rigCameras[1]._rigPostProcess = new BABYLON.AnaglyphPostProcess(this.name + "_anaglyph", 1.0, this._rigCameras);
  22907. break;
  22908. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  22909. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  22910. case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  22911. var isStereoscopicHoriz = this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL || this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;
  22912. this._rigCameras[0]._rigPostProcess = new BABYLON.PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[0]);
  22913. this._rigCameras[1]._rigPostProcess = new BABYLON.StereoscopicInterlacePostProcess(this.name + "_stereoInterlace", this._rigCameras, isStereoscopicHoriz);
  22914. break;
  22915. case Camera.RIG_MODE_VR:
  22916. var metrics = rigParams.vrCameraMetrics || BABYLON.VRCameraMetrics.GetDefault();
  22917. this._rigCameras[0]._cameraRigParams.vrMetrics = metrics;
  22918. this._rigCameras[0].viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
  22919. this._rigCameras[0]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  22920. this._rigCameras[0]._cameraRigParams.vrHMatrix = metrics.leftHMatrix;
  22921. this._rigCameras[0]._cameraRigParams.vrPreViewMatrix = metrics.leftPreViewMatrix;
  22922. this._rigCameras[0].getProjectionMatrix = this._rigCameras[0]._getVRProjectionMatrix;
  22923. this._rigCameras[1]._cameraRigParams.vrMetrics = metrics;
  22924. this._rigCameras[1].viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
  22925. this._rigCameras[1]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  22926. this._rigCameras[1]._cameraRigParams.vrHMatrix = metrics.rightHMatrix;
  22927. this._rigCameras[1]._cameraRigParams.vrPreViewMatrix = metrics.rightPreViewMatrix;
  22928. this._rigCameras[1].getProjectionMatrix = this._rigCameras[1]._getVRProjectionMatrix;
  22929. if (metrics.compensateDistortion) {
  22930. this._rigCameras[0]._rigPostProcess = new BABYLON.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left", this._rigCameras[0], false, metrics);
  22931. this._rigCameras[1]._rigPostProcess = new BABYLON.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right", this._rigCameras[1], true, metrics);
  22932. }
  22933. break;
  22934. case Camera.RIG_MODE_WEBVR:
  22935. if (rigParams.vrDisplay) {
  22936. var leftEye = rigParams.vrDisplay.getEyeParameters('left');
  22937. var rightEye = rigParams.vrDisplay.getEyeParameters('right');
  22938. //Left eye
  22939. this._rigCameras[0].viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
  22940. this._rigCameras[0].setCameraRigParameter("left", true);
  22941. //leaving this for future reference
  22942. this._rigCameras[0].setCameraRigParameter("specs", rigParams.specs);
  22943. this._rigCameras[0].setCameraRigParameter("eyeParameters", leftEye);
  22944. this._rigCameras[0].setCameraRigParameter("frameData", rigParams.frameData);
  22945. this._rigCameras[0].setCameraRigParameter("parentCamera", rigParams.parentCamera);
  22946. this._rigCameras[0]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  22947. this._rigCameras[0].getProjectionMatrix = this._getWebVRProjectionMatrix;
  22948. this._rigCameras[0].parent = this;
  22949. this._rigCameras[0]._getViewMatrix = this._getWebVRViewMatrix;
  22950. //Right eye
  22951. this._rigCameras[1].viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
  22952. this._rigCameras[1].setCameraRigParameter('eyeParameters', rightEye);
  22953. this._rigCameras[1].setCameraRigParameter("specs", rigParams.specs);
  22954. this._rigCameras[1].setCameraRigParameter("frameData", rigParams.frameData);
  22955. this._rigCameras[1].setCameraRigParameter("parentCamera", rigParams.parentCamera);
  22956. this._rigCameras[1]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  22957. this._rigCameras[1].getProjectionMatrix = this._getWebVRProjectionMatrix;
  22958. this._rigCameras[1].parent = this;
  22959. this._rigCameras[1]._getViewMatrix = this._getWebVRViewMatrix;
  22960. if (Camera.UseAlternateWebVRRendering) {
  22961. this._rigCameras[1]._skipRendering = true;
  22962. this._rigCameras[0]._alternateCamera = this._rigCameras[1];
  22963. }
  22964. }
  22965. break;
  22966. }
  22967. this._cascadePostProcessesToRigCams();
  22968. this.update();
  22969. };
  22970. Camera.prototype._getVRProjectionMatrix = function () {
  22971. BABYLON.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov, this._cameraRigParams.vrMetrics.aspectRatio, this.minZ, this.maxZ, this._cameraRigParams.vrWorkMatrix);
  22972. this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix, this._projectionMatrix);
  22973. return this._projectionMatrix;
  22974. };
  22975. Camera.prototype._updateCameraRotationMatrix = function () {
  22976. //Here for WebVR
  22977. };
  22978. Camera.prototype._updateWebVRCameraRotationMatrix = function () {
  22979. //Here for WebVR
  22980. };
  22981. /**
  22982. * This function MUST be overwritten by the different WebVR cameras available.
  22983. * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.
  22984. */
  22985. Camera.prototype._getWebVRProjectionMatrix = function () {
  22986. return BABYLON.Matrix.Identity();
  22987. };
  22988. /**
  22989. * This function MUST be overwritten by the different WebVR cameras available.
  22990. * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.
  22991. */
  22992. Camera.prototype._getWebVRViewMatrix = function () {
  22993. return BABYLON.Matrix.Identity();
  22994. };
  22995. Camera.prototype.setCameraRigParameter = function (name, value) {
  22996. if (!this._cameraRigParams) {
  22997. this._cameraRigParams = {};
  22998. }
  22999. this._cameraRigParams[name] = value;
  23000. //provisionnally:
  23001. if (name === "interaxialDistance") {
  23002. this._cameraRigParams.stereoHalfAngle = BABYLON.Tools.ToRadians(value / 0.0637);
  23003. }
  23004. };
  23005. /**
  23006. * needs to be overridden by children so sub has required properties to be copied
  23007. */
  23008. Camera.prototype.createRigCamera = function (name, cameraIndex) {
  23009. return null;
  23010. };
  23011. /**
  23012. * May need to be overridden by children
  23013. */
  23014. Camera.prototype._updateRigCameras = function () {
  23015. for (var i = 0; i < this._rigCameras.length; i++) {
  23016. this._rigCameras[i].minZ = this.minZ;
  23017. this._rigCameras[i].maxZ = this.maxZ;
  23018. this._rigCameras[i].fov = this.fov;
  23019. }
  23020. // only update viewport when ANAGLYPH
  23021. if (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH) {
  23022. this._rigCameras[0].viewport = this._rigCameras[1].viewport = this.viewport;
  23023. }
  23024. };
  23025. Camera.prototype._setupInputs = function () {
  23026. };
  23027. Camera.prototype.serialize = function () {
  23028. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  23029. // Type
  23030. serializationObject.type = this.getClassName();
  23031. // Parent
  23032. if (this.parent) {
  23033. serializationObject.parentId = this.parent.id;
  23034. }
  23035. if (this.inputs) {
  23036. this.inputs.serialize(serializationObject);
  23037. }
  23038. // Animations
  23039. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  23040. serializationObject.ranges = this.serializeAnimationRanges();
  23041. return serializationObject;
  23042. };
  23043. Camera.prototype.clone = function (name) {
  23044. return BABYLON.SerializationHelper.Clone(Camera.GetConstructorFromName(this.getClassName(), name, this.getScene(), this.interaxialDistance, this.isStereoscopicSideBySide), this);
  23045. };
  23046. Camera.prototype.getDirection = function (localAxis) {
  23047. var result = BABYLON.Vector3.Zero();
  23048. this.getDirectionToRef(localAxis, result);
  23049. return result;
  23050. };
  23051. Camera.prototype.getDirectionToRef = function (localAxis, result) {
  23052. BABYLON.Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);
  23053. };
  23054. Camera.GetConstructorFromName = function (type, name, scene, interaxial_distance, isStereoscopicSideBySide) {
  23055. if (interaxial_distance === void 0) { interaxial_distance = 0; }
  23056. if (isStereoscopicSideBySide === void 0) { isStereoscopicSideBySide = true; }
  23057. switch (type) {
  23058. case "ArcRotateCamera":
  23059. return function () { return new BABYLON.ArcRotateCamera(name, 0, 0, 1.0, BABYLON.Vector3.Zero(), scene); };
  23060. case "DeviceOrientationCamera":
  23061. return function () { return new BABYLON.DeviceOrientationCamera(name, BABYLON.Vector3.Zero(), scene); };
  23062. case "FollowCamera":
  23063. return function () { return new BABYLON.FollowCamera(name, BABYLON.Vector3.Zero(), scene); };
  23064. case "ArcFollowCamera":
  23065. return function () { return new BABYLON.ArcFollowCamera(name, 0, 0, 1.0, null, scene); };
  23066. case "GamepadCamera":
  23067. return function () { return new BABYLON.GamepadCamera(name, BABYLON.Vector3.Zero(), scene); };
  23068. case "TouchCamera":
  23069. return function () { return new BABYLON.TouchCamera(name, BABYLON.Vector3.Zero(), scene); };
  23070. case "VirtualJoysticksCamera":
  23071. return function () { return new BABYLON.VirtualJoysticksCamera(name, BABYLON.Vector3.Zero(), scene); };
  23072. case "WebVRFreeCamera":
  23073. return function () { return new BABYLON.WebVRFreeCamera(name, BABYLON.Vector3.Zero(), scene); };
  23074. case "WebVRGamepadCamera":
  23075. return function () { return new BABYLON.WebVRFreeCamera(name, BABYLON.Vector3.Zero(), scene); };
  23076. case "VRDeviceOrientationFreeCamera":
  23077. return function () { return new BABYLON.VRDeviceOrientationFreeCamera(name, BABYLON.Vector3.Zero(), scene); };
  23078. case "VRDeviceOrientationGamepadCamera":
  23079. return function () { return new BABYLON.VRDeviceOrientationGamepadCamera(name, BABYLON.Vector3.Zero(), scene); };
  23080. case "AnaglyphArcRotateCamera":
  23081. return function () { return new BABYLON.AnaglyphArcRotateCamera(name, 0, 0, 1.0, BABYLON.Vector3.Zero(), interaxial_distance, scene); };
  23082. case "AnaglyphFreeCamera":
  23083. return function () { return new BABYLON.AnaglyphFreeCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, scene); };
  23084. case "AnaglyphGamepadCamera":
  23085. return function () { return new BABYLON.AnaglyphGamepadCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, scene); };
  23086. case "AnaglyphUniversalCamera":
  23087. return function () { return new BABYLON.AnaglyphUniversalCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, scene); };
  23088. case "StereoscopicArcRotateCamera":
  23089. return function () { return new BABYLON.StereoscopicArcRotateCamera(name, 0, 0, 1.0, BABYLON.Vector3.Zero(), interaxial_distance, isStereoscopicSideBySide, scene); };
  23090. case "StereoscopicFreeCamera":
  23091. return function () { return new BABYLON.StereoscopicFreeCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, isStereoscopicSideBySide, scene); };
  23092. case "StereoscopicGamepadCamera":
  23093. return function () { return new BABYLON.StereoscopicGamepadCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, isStereoscopicSideBySide, scene); };
  23094. case "StereoscopicUniversalCamera":
  23095. return function () { return new BABYLON.StereoscopicUniversalCamera(name, BABYLON.Vector3.Zero(), interaxial_distance, isStereoscopicSideBySide, scene); };
  23096. case "FreeCamera": // Forcing Universal here
  23097. return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
  23098. default: // Universal Camera is the default value
  23099. return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
  23100. }
  23101. };
  23102. Camera.prototype.computeWorldMatrix = function () {
  23103. return this.getWorldMatrix();
  23104. };
  23105. Camera.Parse = function (parsedCamera, scene) {
  23106. var type = parsedCamera.type;
  23107. var construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);
  23108. var camera = BABYLON.SerializationHelper.Parse(construct, parsedCamera, scene);
  23109. // Parent
  23110. if (parsedCamera.parentId) {
  23111. camera._waitingParentId = parsedCamera.parentId;
  23112. }
  23113. //If camera has an input manager, let it parse inputs settings
  23114. if (camera.inputs) {
  23115. camera.inputs.parse(parsedCamera);
  23116. camera._setupInputs();
  23117. }
  23118. if (camera.setPosition) { // need to force position
  23119. camera.position.copyFromFloats(0, 0, 0);
  23120. camera.setPosition(BABYLON.Vector3.FromArray(parsedCamera.position));
  23121. }
  23122. // Target
  23123. if (parsedCamera.target) {
  23124. if (camera.setTarget) {
  23125. camera.setTarget(BABYLON.Vector3.FromArray(parsedCamera.target));
  23126. }
  23127. }
  23128. // Apply 3d rig, when found
  23129. if (parsedCamera.cameraRigMode) {
  23130. var rigParams = (parsedCamera.interaxial_distance) ? { interaxialDistance: parsedCamera.interaxial_distance } : {};
  23131. camera.setCameraRigMode(parsedCamera.cameraRigMode, rigParams);
  23132. }
  23133. // Animations
  23134. if (parsedCamera.animations) {
  23135. for (var animationIndex = 0; animationIndex < parsedCamera.animations.length; animationIndex++) {
  23136. var parsedAnimation = parsedCamera.animations[animationIndex];
  23137. camera.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  23138. }
  23139. BABYLON.Node.ParseAnimationRanges(camera, parsedCamera, scene);
  23140. }
  23141. if (parsedCamera.autoAnimate) {
  23142. scene.beginAnimation(camera, parsedCamera.autoAnimateFrom, parsedCamera.autoAnimateTo, parsedCamera.autoAnimateLoop, parsedCamera.autoAnimateSpeed || 1.0);
  23143. }
  23144. return camera;
  23145. };
  23146. // Statics
  23147. Camera._PERSPECTIVE_CAMERA = 0;
  23148. Camera._ORTHOGRAPHIC_CAMERA = 1;
  23149. Camera._FOVMODE_VERTICAL_FIXED = 0;
  23150. Camera._FOVMODE_HORIZONTAL_FIXED = 1;
  23151. Camera._RIG_MODE_NONE = 0;
  23152. Camera._RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;
  23153. Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;
  23154. Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;
  23155. Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;
  23156. Camera._RIG_MODE_VR = 20;
  23157. Camera._RIG_MODE_WEBVR = 21;
  23158. Camera.ForceAttachControlToAlwaysPreventDefault = false;
  23159. Camera.UseAlternateWebVRRendering = false;
  23160. __decorate([
  23161. BABYLON.serializeAsVector3()
  23162. ], Camera.prototype, "position", void 0);
  23163. __decorate([
  23164. BABYLON.serializeAsVector3()
  23165. ], Camera.prototype, "upVector", void 0);
  23166. __decorate([
  23167. BABYLON.serialize()
  23168. ], Camera.prototype, "orthoLeft", void 0);
  23169. __decorate([
  23170. BABYLON.serialize()
  23171. ], Camera.prototype, "orthoRight", void 0);
  23172. __decorate([
  23173. BABYLON.serialize()
  23174. ], Camera.prototype, "orthoBottom", void 0);
  23175. __decorate([
  23176. BABYLON.serialize()
  23177. ], Camera.prototype, "orthoTop", void 0);
  23178. __decorate([
  23179. BABYLON.serialize()
  23180. ], Camera.prototype, "fov", void 0);
  23181. __decorate([
  23182. BABYLON.serialize()
  23183. ], Camera.prototype, "minZ", void 0);
  23184. __decorate([
  23185. BABYLON.serialize()
  23186. ], Camera.prototype, "maxZ", void 0);
  23187. __decorate([
  23188. BABYLON.serialize()
  23189. ], Camera.prototype, "inertia", void 0);
  23190. __decorate([
  23191. BABYLON.serialize()
  23192. ], Camera.prototype, "mode", void 0);
  23193. __decorate([
  23194. BABYLON.serialize()
  23195. ], Camera.prototype, "layerMask", void 0);
  23196. __decorate([
  23197. BABYLON.serialize()
  23198. ], Camera.prototype, "fovMode", void 0);
  23199. __decorate([
  23200. BABYLON.serialize()
  23201. ], Camera.prototype, "cameraRigMode", void 0);
  23202. __decorate([
  23203. BABYLON.serialize()
  23204. ], Camera.prototype, "interaxialDistance", void 0);
  23205. __decorate([
  23206. BABYLON.serialize()
  23207. ], Camera.prototype, "isStereoscopicSideBySide", void 0);
  23208. return Camera;
  23209. }(BABYLON.Node));
  23210. BABYLON.Camera = Camera;
  23211. })(BABYLON || (BABYLON = {}));
  23212. //# sourceMappingURL=babylon.camera.js.map
  23213. var BABYLON;
  23214. (function (BABYLON) {
  23215. var RenderingManager = /** @class */ (function () {
  23216. function RenderingManager(scene) {
  23217. this._renderingGroups = new Array();
  23218. this._autoClearDepthStencil = {};
  23219. this._customOpaqueSortCompareFn = {};
  23220. this._customAlphaTestSortCompareFn = {};
  23221. this._customTransparentSortCompareFn = {};
  23222. this._renderinGroupInfo = null;
  23223. this._scene = scene;
  23224. for (var i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {
  23225. this._autoClearDepthStencil[i] = { autoClear: true, depth: true, stencil: true };
  23226. }
  23227. }
  23228. RenderingManager.prototype._clearDepthStencilBuffer = function (depth, stencil) {
  23229. if (depth === void 0) { depth = true; }
  23230. if (stencil === void 0) { stencil = true; }
  23231. if (this._depthStencilBufferAlreadyCleaned) {
  23232. return;
  23233. }
  23234. this._scene.getEngine().clear(null, false, depth, stencil);
  23235. this._depthStencilBufferAlreadyCleaned = true;
  23236. };
  23237. RenderingManager.prototype.render = function (customRenderFunction, activeMeshes, renderParticles, renderSprites) {
  23238. // Check if there's at least on observer on the onRenderingGroupObservable and initialize things to fire it
  23239. var observable = this._scene.onRenderingGroupObservable.hasObservers() ? this._scene.onRenderingGroupObservable : null;
  23240. var info = null;
  23241. if (observable) {
  23242. if (!this._renderinGroupInfo) {
  23243. this._renderinGroupInfo = new BABYLON.RenderingGroupInfo();
  23244. }
  23245. info = this._renderinGroupInfo;
  23246. info.scene = this._scene;
  23247. info.camera = this._scene.activeCamera;
  23248. }
  23249. // Dispatch sprites
  23250. if (renderSprites) {
  23251. for (var index = 0; index < this._scene.spriteManagers.length; index++) {
  23252. var manager = this._scene.spriteManagers[index];
  23253. this.dispatchSprites(manager);
  23254. }
  23255. }
  23256. // Render
  23257. for (var index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
  23258. this._depthStencilBufferAlreadyCleaned = index === RenderingManager.MIN_RENDERINGGROUPS;
  23259. var renderingGroup = this._renderingGroups[index];
  23260. if (!renderingGroup && !observable)
  23261. continue;
  23262. var renderingGroupMask = 0;
  23263. // Fire PRECLEAR stage
  23264. if (observable && info) {
  23265. renderingGroupMask = Math.pow(2, index);
  23266. info.renderStage = BABYLON.RenderingGroupInfo.STAGE_PRECLEAR;
  23267. info.renderingGroupId = index;
  23268. observable.notifyObservers(info, renderingGroupMask);
  23269. }
  23270. // Clear depth/stencil if needed
  23271. if (RenderingManager.AUTOCLEAR) {
  23272. var autoClear = this._autoClearDepthStencil[index];
  23273. if (autoClear && autoClear.autoClear) {
  23274. this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
  23275. }
  23276. }
  23277. if (observable && info) {
  23278. // Fire PREOPAQUE stage
  23279. info.renderStage = BABYLON.RenderingGroupInfo.STAGE_PREOPAQUE;
  23280. observable.notifyObservers(info, renderingGroupMask);
  23281. // Fire PRETRANSPARENT stage
  23282. info.renderStage = BABYLON.RenderingGroupInfo.STAGE_PRETRANSPARENT;
  23283. observable.notifyObservers(info, renderingGroupMask);
  23284. }
  23285. if (renderingGroup)
  23286. renderingGroup.render(customRenderFunction, renderSprites, renderParticles, activeMeshes);
  23287. // Fire POSTTRANSPARENT stage
  23288. if (observable && info) {
  23289. info.renderStage = BABYLON.RenderingGroupInfo.STAGE_POSTTRANSPARENT;
  23290. observable.notifyObservers(info, renderingGroupMask);
  23291. }
  23292. }
  23293. };
  23294. RenderingManager.prototype.reset = function () {
  23295. for (var index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
  23296. var renderingGroup = this._renderingGroups[index];
  23297. if (renderingGroup) {
  23298. renderingGroup.prepare();
  23299. }
  23300. }
  23301. };
  23302. RenderingManager.prototype.dispose = function () {
  23303. this.freeRenderingGroups();
  23304. this._renderingGroups.length = 0;
  23305. };
  23306. /**
  23307. * Clear the info related to rendering groups preventing retention points during dispose.
  23308. */
  23309. RenderingManager.prototype.freeRenderingGroups = function () {
  23310. for (var index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
  23311. var renderingGroup = this._renderingGroups[index];
  23312. if (renderingGroup) {
  23313. renderingGroup.dispose();
  23314. }
  23315. }
  23316. };
  23317. RenderingManager.prototype._prepareRenderingGroup = function (renderingGroupId) {
  23318. if (this._renderingGroups[renderingGroupId] === undefined) {
  23319. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene, this._customOpaqueSortCompareFn[renderingGroupId], this._customAlphaTestSortCompareFn[renderingGroupId], this._customTransparentSortCompareFn[renderingGroupId]);
  23320. }
  23321. };
  23322. RenderingManager.prototype.dispatchSprites = function (spriteManager) {
  23323. var renderingGroupId = spriteManager.renderingGroupId || 0;
  23324. this._prepareRenderingGroup(renderingGroupId);
  23325. this._renderingGroups[renderingGroupId].dispatchSprites(spriteManager);
  23326. };
  23327. RenderingManager.prototype.dispatchParticles = function (particleSystem) {
  23328. var renderingGroupId = particleSystem.renderingGroupId || 0;
  23329. this._prepareRenderingGroup(renderingGroupId);
  23330. this._renderingGroups[renderingGroupId].dispatchParticles(particleSystem);
  23331. };
  23332. /**
  23333. * @param subMesh The submesh to dispatch
  23334. * @param [mesh] Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.
  23335. * @param [material] Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.
  23336. */
  23337. RenderingManager.prototype.dispatch = function (subMesh, mesh, material) {
  23338. if (mesh === undefined) {
  23339. mesh = subMesh.getMesh();
  23340. }
  23341. var renderingGroupId = mesh.renderingGroupId || 0;
  23342. this._prepareRenderingGroup(renderingGroupId);
  23343. this._renderingGroups[renderingGroupId].dispatch(subMesh, mesh, material);
  23344. };
  23345. /**
  23346. * Overrides the default sort function applied in the renderging group to prepare the meshes.
  23347. * This allowed control for front to back rendering or reversly depending of the special needs.
  23348. *
  23349. * @param renderingGroupId The rendering group id corresponding to its index
  23350. * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
  23351. * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
  23352. * @param transparentSortCompareFn The transparent queue comparison function use to sort.
  23353. */
  23354. RenderingManager.prototype.setRenderingOrder = function (renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn) {
  23355. if (opaqueSortCompareFn === void 0) { opaqueSortCompareFn = null; }
  23356. if (alphaTestSortCompareFn === void 0) { alphaTestSortCompareFn = null; }
  23357. if (transparentSortCompareFn === void 0) { transparentSortCompareFn = null; }
  23358. this._customOpaqueSortCompareFn[renderingGroupId] = opaqueSortCompareFn;
  23359. this._customAlphaTestSortCompareFn[renderingGroupId] = alphaTestSortCompareFn;
  23360. this._customTransparentSortCompareFn[renderingGroupId] = transparentSortCompareFn;
  23361. if (this._renderingGroups[renderingGroupId]) {
  23362. var group = this._renderingGroups[renderingGroupId];
  23363. group.opaqueSortCompareFn = this._customOpaqueSortCompareFn[renderingGroupId];
  23364. group.alphaTestSortCompareFn = this._customAlphaTestSortCompareFn[renderingGroupId];
  23365. group.transparentSortCompareFn = this._customTransparentSortCompareFn[renderingGroupId];
  23366. }
  23367. };
  23368. /**
  23369. * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
  23370. *
  23371. * @param renderingGroupId The rendering group id corresponding to its index
  23372. * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
  23373. * @param depth Automatically clears depth between groups if true and autoClear is true.
  23374. * @param stencil Automatically clears stencil between groups if true and autoClear is true.
  23375. */
  23376. RenderingManager.prototype.setRenderingAutoClearDepthStencil = function (renderingGroupId, autoClearDepthStencil, depth, stencil) {
  23377. if (depth === void 0) { depth = true; }
  23378. if (stencil === void 0) { stencil = true; }
  23379. this._autoClearDepthStencil[renderingGroupId] = {
  23380. autoClear: autoClearDepthStencil,
  23381. depth: depth,
  23382. stencil: stencil
  23383. };
  23384. };
  23385. /**
  23386. * The max id used for rendering groups (not included)
  23387. */
  23388. RenderingManager.MAX_RENDERINGGROUPS = 4;
  23389. /**
  23390. * The min id used for rendering groups (included)
  23391. */
  23392. RenderingManager.MIN_RENDERINGGROUPS = 0;
  23393. /**
  23394. * Used to globally prevent autoclearing scenes.
  23395. */
  23396. RenderingManager.AUTOCLEAR = true;
  23397. return RenderingManager;
  23398. }());
  23399. BABYLON.RenderingManager = RenderingManager;
  23400. })(BABYLON || (BABYLON = {}));
  23401. //# sourceMappingURL=babylon.renderingManager.js.map
  23402. var BABYLON;
  23403. (function (BABYLON) {
  23404. var RenderingGroup = /** @class */ (function () {
  23405. /**
  23406. * Creates a new rendering group.
  23407. * @param index The rendering group index
  23408. * @param opaqueSortCompareFn The opaque sort comparison function. If null no order is applied
  23409. * @param alphaTestSortCompareFn The alpha test sort comparison function. If null no order is applied
  23410. * @param transparentSortCompareFn The transparent sort comparison function. If null back to front + alpha index sort is applied
  23411. */
  23412. function RenderingGroup(index, scene, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn) {
  23413. if (opaqueSortCompareFn === void 0) { opaqueSortCompareFn = null; }
  23414. if (alphaTestSortCompareFn === void 0) { alphaTestSortCompareFn = null; }
  23415. if (transparentSortCompareFn === void 0) { transparentSortCompareFn = null; }
  23416. this.index = index;
  23417. this._opaqueSubMeshes = new BABYLON.SmartArray(256);
  23418. this._transparentSubMeshes = new BABYLON.SmartArray(256);
  23419. this._alphaTestSubMeshes = new BABYLON.SmartArray(256);
  23420. this._depthOnlySubMeshes = new BABYLON.SmartArray(256);
  23421. this._particleSystems = new BABYLON.SmartArray(256);
  23422. this._spriteManagers = new BABYLON.SmartArray(256);
  23423. this._edgesRenderers = new BABYLON.SmartArray(16);
  23424. this._scene = scene;
  23425. this.opaqueSortCompareFn = opaqueSortCompareFn;
  23426. this.alphaTestSortCompareFn = alphaTestSortCompareFn;
  23427. this.transparentSortCompareFn = transparentSortCompareFn;
  23428. }
  23429. Object.defineProperty(RenderingGroup.prototype, "opaqueSortCompareFn", {
  23430. /**
  23431. * Set the opaque sort comparison function.
  23432. * If null the sub meshes will be render in the order they were created
  23433. */
  23434. set: function (value) {
  23435. this._opaqueSortCompareFn = value;
  23436. if (value) {
  23437. this._renderOpaque = this.renderOpaqueSorted;
  23438. }
  23439. else {
  23440. this._renderOpaque = RenderingGroup.renderUnsorted;
  23441. }
  23442. },
  23443. enumerable: true,
  23444. configurable: true
  23445. });
  23446. Object.defineProperty(RenderingGroup.prototype, "alphaTestSortCompareFn", {
  23447. /**
  23448. * Set the alpha test sort comparison function.
  23449. * If null the sub meshes will be render in the order they were created
  23450. */
  23451. set: function (value) {
  23452. this._alphaTestSortCompareFn = value;
  23453. if (value) {
  23454. this._renderAlphaTest = this.renderAlphaTestSorted;
  23455. }
  23456. else {
  23457. this._renderAlphaTest = RenderingGroup.renderUnsorted;
  23458. }
  23459. },
  23460. enumerable: true,
  23461. configurable: true
  23462. });
  23463. Object.defineProperty(RenderingGroup.prototype, "transparentSortCompareFn", {
  23464. /**
  23465. * Set the transparent sort comparison function.
  23466. * If null the sub meshes will be render in the order they were created
  23467. */
  23468. set: function (value) {
  23469. if (value) {
  23470. this._transparentSortCompareFn = value;
  23471. }
  23472. else {
  23473. this._transparentSortCompareFn = RenderingGroup.defaultTransparentSortCompare;
  23474. }
  23475. this._renderTransparent = this.renderTransparentSorted;
  23476. },
  23477. enumerable: true,
  23478. configurable: true
  23479. });
  23480. /**
  23481. * Render all the sub meshes contained in the group.
  23482. * @param customRenderFunction Used to override the default render behaviour of the group.
  23483. * @returns true if rendered some submeshes.
  23484. */
  23485. RenderingGroup.prototype.render = function (customRenderFunction, renderSprites, renderParticles, activeMeshes) {
  23486. if (customRenderFunction) {
  23487. customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes, this._depthOnlySubMeshes);
  23488. return;
  23489. }
  23490. var engine = this._scene.getEngine();
  23491. // Depth only
  23492. if (this._depthOnlySubMeshes.length !== 0) {
  23493. engine.setColorWrite(false);
  23494. this._renderAlphaTest(this._depthOnlySubMeshes);
  23495. engine.setColorWrite(true);
  23496. }
  23497. // Opaque
  23498. if (this._opaqueSubMeshes.length !== 0) {
  23499. this._renderOpaque(this._opaqueSubMeshes);
  23500. }
  23501. // Alpha test
  23502. if (this._alphaTestSubMeshes.length !== 0) {
  23503. this._renderAlphaTest(this._alphaTestSubMeshes);
  23504. }
  23505. var stencilState = engine.getStencilBuffer();
  23506. engine.setStencilBuffer(false);
  23507. // Sprites
  23508. if (renderSprites) {
  23509. this._renderSprites();
  23510. }
  23511. // Particles
  23512. if (renderParticles) {
  23513. this._renderParticles(activeMeshes);
  23514. }
  23515. if (this.onBeforeTransparentRendering) {
  23516. this.onBeforeTransparentRendering();
  23517. }
  23518. // Transparent
  23519. if (this._transparentSubMeshes.length !== 0) {
  23520. this._renderTransparent(this._transparentSubMeshes);
  23521. engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
  23522. }
  23523. // Set back stencil to false in case it changes before the edge renderer.
  23524. engine.setStencilBuffer(false);
  23525. // Edges
  23526. for (var edgesRendererIndex = 0; edgesRendererIndex < this._edgesRenderers.length; edgesRendererIndex++) {
  23527. this._edgesRenderers.data[edgesRendererIndex].render();
  23528. }
  23529. // Restore Stencil state.
  23530. engine.setStencilBuffer(stencilState);
  23531. };
  23532. /**
  23533. * Renders the opaque submeshes in the order from the opaqueSortCompareFn.
  23534. * @param subMeshes The submeshes to render
  23535. */
  23536. RenderingGroup.prototype.renderOpaqueSorted = function (subMeshes) {
  23537. return RenderingGroup.renderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false);
  23538. };
  23539. /**
  23540. * Renders the opaque submeshes in the order from the alphatestSortCompareFn.
  23541. * @param subMeshes The submeshes to render
  23542. */
  23543. RenderingGroup.prototype.renderAlphaTestSorted = function (subMeshes) {
  23544. return RenderingGroup.renderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false);
  23545. };
  23546. /**
  23547. * Renders the opaque submeshes in the order from the transparentSortCompareFn.
  23548. * @param subMeshes The submeshes to render
  23549. */
  23550. RenderingGroup.prototype.renderTransparentSorted = function (subMeshes) {
  23551. return RenderingGroup.renderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true);
  23552. };
  23553. /**
  23554. * Renders the submeshes in a specified order.
  23555. * @param subMeshes The submeshes to sort before render
  23556. * @param sortCompareFn The comparison function use to sort
  23557. * @param cameraPosition The camera position use to preprocess the submeshes to help sorting
  23558. * @param transparent Specifies to activate blending if true
  23559. */
  23560. RenderingGroup.renderSorted = function (subMeshes, sortCompareFn, camera, transparent) {
  23561. var subIndex = 0;
  23562. var subMesh;
  23563. var cameraPosition = camera ? camera.globalPosition : BABYLON.Vector3.Zero();
  23564. for (; subIndex < subMeshes.length; subIndex++) {
  23565. subMesh = subMeshes.data[subIndex];
  23566. subMesh._alphaIndex = subMesh.getMesh().alphaIndex;
  23567. subMesh._distanceToCamera = subMesh.getBoundingInfo().boundingSphere.centerWorld.subtract(cameraPosition).length();
  23568. }
  23569. var sortedArray = subMeshes.data.slice(0, subMeshes.length);
  23570. if (sortCompareFn) {
  23571. sortedArray.sort(sortCompareFn);
  23572. }
  23573. for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {
  23574. subMesh = sortedArray[subIndex];
  23575. if (transparent) {
  23576. var material = subMesh.getMaterial();
  23577. if (material && material.needDepthPrePass) {
  23578. var engine = material.getScene().getEngine();
  23579. engine.setColorWrite(false);
  23580. engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
  23581. subMesh.render(false);
  23582. engine.setColorWrite(true);
  23583. }
  23584. }
  23585. subMesh.render(transparent);
  23586. }
  23587. };
  23588. /**
  23589. * Renders the submeshes in the order they were dispatched (no sort applied).
  23590. * @param subMeshes The submeshes to render
  23591. */
  23592. RenderingGroup.renderUnsorted = function (subMeshes) {
  23593. for (var subIndex = 0; subIndex < subMeshes.length; subIndex++) {
  23594. var submesh = subMeshes.data[subIndex];
  23595. submesh.render(false);
  23596. }
  23597. };
  23598. /**
  23599. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  23600. * are rendered back to front if in the same alpha index.
  23601. *
  23602. * @param a The first submesh
  23603. * @param b The second submesh
  23604. * @returns The result of the comparison
  23605. */
  23606. RenderingGroup.defaultTransparentSortCompare = function (a, b) {
  23607. // Alpha index first
  23608. if (a._alphaIndex > b._alphaIndex) {
  23609. return 1;
  23610. }
  23611. if (a._alphaIndex < b._alphaIndex) {
  23612. return -1;
  23613. }
  23614. // Then distance to camera
  23615. return RenderingGroup.backToFrontSortCompare(a, b);
  23616. };
  23617. /**
  23618. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  23619. * are rendered back to front.
  23620. *
  23621. * @param a The first submesh
  23622. * @param b The second submesh
  23623. * @returns The result of the comparison
  23624. */
  23625. RenderingGroup.backToFrontSortCompare = function (a, b) {
  23626. // Then distance to camera
  23627. if (a._distanceToCamera < b._distanceToCamera) {
  23628. return 1;
  23629. }
  23630. if (a._distanceToCamera > b._distanceToCamera) {
  23631. return -1;
  23632. }
  23633. return 0;
  23634. };
  23635. /**
  23636. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  23637. * are rendered front to back (prevent overdraw).
  23638. *
  23639. * @param a The first submesh
  23640. * @param b The second submesh
  23641. * @returns The result of the comparison
  23642. */
  23643. RenderingGroup.frontToBackSortCompare = function (a, b) {
  23644. // Then distance to camera
  23645. if (a._distanceToCamera < b._distanceToCamera) {
  23646. return -1;
  23647. }
  23648. if (a._distanceToCamera > b._distanceToCamera) {
  23649. return 1;
  23650. }
  23651. return 0;
  23652. };
  23653. /**
  23654. * Resets the different lists of submeshes to prepare a new frame.
  23655. */
  23656. RenderingGroup.prototype.prepare = function () {
  23657. this._opaqueSubMeshes.reset();
  23658. this._transparentSubMeshes.reset();
  23659. this._alphaTestSubMeshes.reset();
  23660. this._depthOnlySubMeshes.reset();
  23661. this._particleSystems.reset();
  23662. this._spriteManagers.reset();
  23663. this._edgesRenderers.reset();
  23664. };
  23665. RenderingGroup.prototype.dispose = function () {
  23666. this._opaqueSubMeshes.dispose();
  23667. this._transparentSubMeshes.dispose();
  23668. this._alphaTestSubMeshes.dispose();
  23669. this._depthOnlySubMeshes.dispose();
  23670. this._particleSystems.dispose();
  23671. this._spriteManagers.dispose();
  23672. this._edgesRenderers.dispose();
  23673. };
  23674. /**
  23675. * Inserts the submesh in its correct queue depending on its material.
  23676. * @param subMesh The submesh to dispatch
  23677. * @param [mesh] Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.
  23678. * @param [material] Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.
  23679. */
  23680. RenderingGroup.prototype.dispatch = function (subMesh, mesh, material) {
  23681. // Get mesh and materials if not provided
  23682. if (mesh === undefined) {
  23683. mesh = subMesh.getMesh();
  23684. }
  23685. if (material === undefined) {
  23686. material = subMesh.getMaterial();
  23687. }
  23688. if (material === null || material === undefined) {
  23689. return;
  23690. }
  23691. if (material.needAlphaBlendingForMesh(mesh)) { // Transparent
  23692. this._transparentSubMeshes.push(subMesh);
  23693. }
  23694. else if (material.needAlphaTesting()) { // Alpha test
  23695. if (material.needDepthPrePass) {
  23696. this._depthOnlySubMeshes.push(subMesh);
  23697. }
  23698. this._alphaTestSubMeshes.push(subMesh);
  23699. }
  23700. else {
  23701. if (material.needDepthPrePass) {
  23702. this._depthOnlySubMeshes.push(subMesh);
  23703. }
  23704. this._opaqueSubMeshes.push(subMesh); // Opaque
  23705. }
  23706. if (mesh._edgesRenderer !== null && mesh._edgesRenderer !== undefined && mesh._edgesRenderer.isEnabled) {
  23707. this._edgesRenderers.push(mesh._edgesRenderer);
  23708. }
  23709. };
  23710. RenderingGroup.prototype.dispatchSprites = function (spriteManager) {
  23711. this._spriteManagers.push(spriteManager);
  23712. };
  23713. RenderingGroup.prototype.dispatchParticles = function (particleSystem) {
  23714. this._particleSystems.push(particleSystem);
  23715. };
  23716. RenderingGroup.prototype._renderParticles = function (activeMeshes) {
  23717. if (this._particleSystems.length === 0) {
  23718. return;
  23719. }
  23720. // Particles
  23721. var activeCamera = this._scene.activeCamera;
  23722. this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);
  23723. for (var particleIndex = 0; particleIndex < this._particleSystems.length; particleIndex++) {
  23724. var particleSystem = this._particleSystems.data[particleIndex];
  23725. if ((activeCamera && activeCamera.layerMask & particleSystem.layerMask) === 0) {
  23726. continue;
  23727. }
  23728. var emitter = particleSystem.emitter;
  23729. if (!emitter.position || !activeMeshes || activeMeshes.indexOf(emitter) !== -1) {
  23730. this._scene._activeParticles.addCount(particleSystem.render(), false);
  23731. }
  23732. }
  23733. this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene);
  23734. };
  23735. RenderingGroup.prototype._renderSprites = function () {
  23736. if (!this._scene.spritesEnabled || this._spriteManagers.length === 0) {
  23737. return;
  23738. }
  23739. // Sprites
  23740. var activeCamera = this._scene.activeCamera;
  23741. this._scene.onBeforeSpritesRenderingObservable.notifyObservers(this._scene);
  23742. for (var id = 0; id < this._spriteManagers.length; id++) {
  23743. var spriteManager = this._spriteManagers.data[id];
  23744. if (((activeCamera && activeCamera.layerMask & spriteManager.layerMask) !== 0)) {
  23745. spriteManager.render();
  23746. }
  23747. }
  23748. this._scene.onAfterSpritesRenderingObservable.notifyObservers(this._scene);
  23749. };
  23750. return RenderingGroup;
  23751. }());
  23752. BABYLON.RenderingGroup = RenderingGroup;
  23753. })(BABYLON || (BABYLON = {}));
  23754. //# sourceMappingURL=babylon.renderingGroup.js.map
  23755. var BABYLON;
  23756. (function (BABYLON) {
  23757. /** @hidden */
  23758. var ClickInfo = /** @class */ (function () {
  23759. function ClickInfo() {
  23760. this._singleClick = false;
  23761. this._doubleClick = false;
  23762. this._hasSwiped = false;
  23763. this._ignore = false;
  23764. }
  23765. Object.defineProperty(ClickInfo.prototype, "singleClick", {
  23766. get: function () {
  23767. return this._singleClick;
  23768. },
  23769. set: function (b) {
  23770. this._singleClick = b;
  23771. },
  23772. enumerable: true,
  23773. configurable: true
  23774. });
  23775. Object.defineProperty(ClickInfo.prototype, "doubleClick", {
  23776. get: function () {
  23777. return this._doubleClick;
  23778. },
  23779. set: function (b) {
  23780. this._doubleClick = b;
  23781. },
  23782. enumerable: true,
  23783. configurable: true
  23784. });
  23785. Object.defineProperty(ClickInfo.prototype, "hasSwiped", {
  23786. get: function () {
  23787. return this._hasSwiped;
  23788. },
  23789. set: function (b) {
  23790. this._hasSwiped = b;
  23791. },
  23792. enumerable: true,
  23793. configurable: true
  23794. });
  23795. Object.defineProperty(ClickInfo.prototype, "ignore", {
  23796. get: function () {
  23797. return this._ignore;
  23798. },
  23799. set: function (b) {
  23800. this._ignore = b;
  23801. },
  23802. enumerable: true,
  23803. configurable: true
  23804. });
  23805. return ClickInfo;
  23806. }());
  23807. /**
  23808. * This class is used by the onRenderingGroupObservable
  23809. */
  23810. var RenderingGroupInfo = /** @class */ (function () {
  23811. function RenderingGroupInfo() {
  23812. }
  23813. /**
  23814. * Stage corresponding to the very first hook in the renderingGroup phase: before the render buffer may be cleared
  23815. * This stage will be fired no matter what
  23816. */
  23817. RenderingGroupInfo.STAGE_PRECLEAR = 1;
  23818. /**
  23819. * Called before opaque object are rendered.
  23820. * This stage will be fired only if there's 3D Opaque content to render
  23821. */
  23822. RenderingGroupInfo.STAGE_PREOPAQUE = 2;
  23823. /**
  23824. * Called after the opaque objects are rendered and before the transparent ones
  23825. * This stage will be fired only if there's 3D transparent content to render
  23826. */
  23827. RenderingGroupInfo.STAGE_PRETRANSPARENT = 3;
  23828. /**
  23829. * Called after the transparent object are rendered, last hook of the renderingGroup phase
  23830. * This stage will be fired no matter what
  23831. */
  23832. RenderingGroupInfo.STAGE_POSTTRANSPARENT = 4;
  23833. return RenderingGroupInfo;
  23834. }());
  23835. BABYLON.RenderingGroupInfo = RenderingGroupInfo;
  23836. /**
  23837. * Represents a scene to be rendered by the engine.
  23838. * @see http://doc.babylonjs.com/features/scene
  23839. */
  23840. var Scene = /** @class */ (function () {
  23841. /**
  23842. * Creates a new Scene
  23843. * @param engine defines the engine to use to render this scene
  23844. */
  23845. function Scene(engine) {
  23846. // Members
  23847. /**
  23848. * Gets or sets a boolean that indicates if the scene must clear the render buffer before rendering a frame
  23849. */
  23850. this.autoClear = true;
  23851. /**
  23852. * Gets or sets a boolean that indicates if the scene must clear the depth and stencil buffers before rendering a frame
  23853. */
  23854. this.autoClearDepthAndStencil = true;
  23855. /**
  23856. * Defines the color used to clear the render buffer (Default is (0.2, 0.2, 0.3, 1.0))
  23857. */
  23858. this.clearColor = new BABYLON.Color4(0.2, 0.2, 0.3, 1.0);
  23859. /**
  23860. * Defines the color used to simulate the ambient color (Default is (0, 0, 0))
  23861. */
  23862. this.ambientColor = new BABYLON.Color3(0, 0, 0);
  23863. this._forceWireframe = false;
  23864. this._forcePointsCloud = false;
  23865. /**
  23866. * Gets or sets a boolean indicating if all bounding boxes must be rendered
  23867. */
  23868. this.forceShowBoundingBoxes = false;
  23869. /**
  23870. * Gets or sets a boolean indicating if animations are enabled
  23871. */
  23872. this.animationsEnabled = true;
  23873. this._animationPropertiesOverride = null;
  23874. /**
  23875. * Gets or sets a boolean indicating if a constant deltatime has to be used
  23876. * This is mostly useful for testing purposes when you do not want the animations to scale with the framerate
  23877. */
  23878. this.useConstantAnimationDeltaTime = false;
  23879. /**
  23880. * Gets or sets a boolean indicating if the scene must keep the meshUnderPointer property updated
  23881. * Please note that it requires to run a ray cast through the scene on every frame
  23882. */
  23883. this.constantlyUpdateMeshUnderPointer = false;
  23884. /**
  23885. * Defines the HTML cursor to use when hovering over interactive elements
  23886. */
  23887. this.hoverCursor = "pointer";
  23888. /**
  23889. * Defines the HTML default cursor to use (empty by default)
  23890. */
  23891. this.defaultCursor = "";
  23892. /**
  23893. * This is used to call preventDefault() on pointer down
  23894. * in order to block unwanted artifacts like system double clicks
  23895. */
  23896. this.preventDefaultOnPointerDown = true;
  23897. // Metadata
  23898. /**
  23899. * Gets or sets user defined metadata
  23900. */
  23901. this.metadata = null;
  23902. /**
  23903. * Use this array to add regular expressions used to disable offline support for specific urls
  23904. */
  23905. this.disableOfflineSupportExceptionRules = new Array();
  23906. /**
  23907. * An event triggered when the scene is disposed.
  23908. */
  23909. this.onDisposeObservable = new BABYLON.Observable();
  23910. this._onDisposeObserver = null;
  23911. /**
  23912. * An event triggered before rendering the scene (right after animations and physics)
  23913. */
  23914. this.onBeforeRenderObservable = new BABYLON.Observable();
  23915. this._onBeforeRenderObserver = null;
  23916. /**
  23917. * An event triggered after rendering the scene
  23918. */
  23919. this.onAfterRenderObservable = new BABYLON.Observable();
  23920. this._onAfterRenderObserver = null;
  23921. /**
  23922. * An event triggered before animating the scene
  23923. */
  23924. this.onBeforeAnimationsObservable = new BABYLON.Observable();
  23925. /**
  23926. * An event triggered after animations processing
  23927. */
  23928. this.onAfterAnimationsObservable = new BABYLON.Observable();
  23929. /**
  23930. * An event triggered before draw calls are ready to be sent
  23931. */
  23932. this.onBeforeDrawPhaseObservable = new BABYLON.Observable();
  23933. /**
  23934. * An event triggered after draw calls have been sent
  23935. */
  23936. this.onAfterDrawPhaseObservable = new BABYLON.Observable();
  23937. /**
  23938. * An event triggered when physic simulation is about to be run
  23939. */
  23940. this.onBeforePhysicsObservable = new BABYLON.Observable();
  23941. /**
  23942. * An event triggered when physic simulation has been done
  23943. */
  23944. this.onAfterPhysicsObservable = new BABYLON.Observable();
  23945. /**
  23946. * An event triggered when the scene is ready
  23947. */
  23948. this.onReadyObservable = new BABYLON.Observable();
  23949. /**
  23950. * An event triggered before rendering a camera
  23951. */
  23952. this.onBeforeCameraRenderObservable = new BABYLON.Observable();
  23953. this._onBeforeCameraRenderObserver = null;
  23954. /**
  23955. * An event triggered after rendering a camera
  23956. */
  23957. this.onAfterCameraRenderObservable = new BABYLON.Observable();
  23958. this._onAfterCameraRenderObserver = null;
  23959. /**
  23960. * An event triggered when active meshes evaluation is about to start
  23961. */
  23962. this.onBeforeActiveMeshesEvaluationObservable = new BABYLON.Observable();
  23963. /**
  23964. * An event triggered when active meshes evaluation is done
  23965. */
  23966. this.onAfterActiveMeshesEvaluationObservable = new BABYLON.Observable();
  23967. /**
  23968. * An event triggered when particles rendering is about to start
  23969. * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)
  23970. */
  23971. this.onBeforeParticlesRenderingObservable = new BABYLON.Observable();
  23972. /**
  23973. * An event triggered when particles rendering is done
  23974. * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)
  23975. */
  23976. this.onAfterParticlesRenderingObservable = new BABYLON.Observable();
  23977. /**
  23978. * An event triggered when sprites rendering is about to start
  23979. * Note: This event can be trigger more than once per frame (because sprites can be rendered by render target textures as well)
  23980. */
  23981. this.onBeforeSpritesRenderingObservable = new BABYLON.Observable();
  23982. /**
  23983. * An event triggered when sprites rendering is done
  23984. * Note: This event can be trigger more than once per frame (because sprites can be rendered by render target textures as well)
  23985. */
  23986. this.onAfterSpritesRenderingObservable = new BABYLON.Observable();
  23987. /**
  23988. * An event triggered when SceneLoader.Append or SceneLoader.Load or SceneLoader.ImportMesh were successfully executed
  23989. */
  23990. this.onDataLoadedObservable = new BABYLON.Observable();
  23991. /**
  23992. * An event triggered when a camera is created
  23993. */
  23994. this.onNewCameraAddedObservable = new BABYLON.Observable();
  23995. /**
  23996. * An event triggered when a camera is removed
  23997. */
  23998. this.onCameraRemovedObservable = new BABYLON.Observable();
  23999. /**
  24000. * An event triggered when a light is created
  24001. */
  24002. this.onNewLightAddedObservable = new BABYLON.Observable();
  24003. /**
  24004. * An event triggered when a light is removed
  24005. */
  24006. this.onLightRemovedObservable = new BABYLON.Observable();
  24007. /**
  24008. * An event triggered when a geometry is created
  24009. */
  24010. this.onNewGeometryAddedObservable = new BABYLON.Observable();
  24011. /**
  24012. * An event triggered when a geometry is removed
  24013. */
  24014. this.onGeometryRemovedObservable = new BABYLON.Observable();
  24015. /**
  24016. * An event triggered when a transform node is created
  24017. */
  24018. this.onNewTransformNodeAddedObservable = new BABYLON.Observable();
  24019. /**
  24020. * An event triggered when a transform node is removed
  24021. */
  24022. this.onTransformNodeRemovedObservable = new BABYLON.Observable();
  24023. /**
  24024. * An event triggered when a mesh is created
  24025. */
  24026. this.onNewMeshAddedObservable = new BABYLON.Observable();
  24027. /**
  24028. * An event triggered when a mesh is removed
  24029. */
  24030. this.onMeshRemovedObservable = new BABYLON.Observable();
  24031. /**
  24032. * An event triggered when render targets are about to be rendered
  24033. * Can happen multiple times per frame.
  24034. */
  24035. this.onBeforeRenderTargetsRenderObservable = new BABYLON.Observable();
  24036. /**
  24037. * An event triggered when render targets were rendered.
  24038. * Can happen multiple times per frame.
  24039. */
  24040. this.onAfterRenderTargetsRenderObservable = new BABYLON.Observable();
  24041. /**
  24042. * An event triggered before calculating deterministic simulation step
  24043. */
  24044. this.onBeforeStepObservable = new BABYLON.Observable();
  24045. /**
  24046. * An event triggered after calculating deterministic simulation step
  24047. */
  24048. this.onAfterStepObservable = new BABYLON.Observable();
  24049. /**
  24050. * This Observable will be triggered for each stage of each renderingGroup of each rendered camera.
  24051. * The RenderinGroupInfo class contains all the information about the context in which the observable is called
  24052. * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
  24053. */
  24054. this.onRenderingGroupObservable = new BABYLON.Observable();
  24055. // Animations
  24056. /**
  24057. * Gets a list of Animations associated with the scene
  24058. */
  24059. this.animations = [];
  24060. this._registeredForLateAnimationBindings = new BABYLON.SmartArrayNoDuplicate(256);
  24061. /**
  24062. * This observable event is triggered when any ponter event is triggered. It is registered during Scene.attachControl() and it is called BEFORE the 3D engine process anything (mesh/sprite picking for instance).
  24063. * You have the possibility to skip the process and the call to onPointerObservable by setting PointerInfoPre.skipOnPointerObservable to true
  24064. */
  24065. this.onPrePointerObservable = new BABYLON.Observable();
  24066. /**
  24067. * Observable event triggered each time an input event is received from the rendering canvas
  24068. */
  24069. this.onPointerObservable = new BABYLON.Observable();
  24070. this._meshPickProceed = false;
  24071. this._currentPickResult = null;
  24072. this._previousPickResult = null;
  24073. this._totalPointersPressed = 0;
  24074. this._doubleClickOccured = false;
  24075. /** Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position */
  24076. this.cameraToUseForPointers = null;
  24077. this._startingPointerPosition = new BABYLON.Vector2(0, 0);
  24078. this._previousStartingPointerPosition = new BABYLON.Vector2(0, 0);
  24079. this._startingPointerTime = 0;
  24080. this._previousStartingPointerTime = 0;
  24081. this._pointerCaptures = {};
  24082. // Deterministic lockstep
  24083. this._timeAccumulator = 0;
  24084. this._currentStepId = 0;
  24085. this._currentInternalStep = 0;
  24086. // Keyboard
  24087. /**
  24088. * This observable event is triggered when any keyboard event si raised and registered during Scene.attachControl()
  24089. * You have the possibility to skip the process and the call to onKeyboardObservable by setting KeyboardInfoPre.skipOnPointerObservable to true
  24090. */
  24091. this.onPreKeyboardObservable = new BABYLON.Observable();
  24092. /**
  24093. * Observable event triggered each time an keyboard event is received from the hosting window
  24094. */
  24095. this.onKeyboardObservable = new BABYLON.Observable();
  24096. // Coordinates system
  24097. this._useRightHandedSystem = false;
  24098. // Fog
  24099. this._fogEnabled = true;
  24100. this._fogMode = Scene.FOGMODE_NONE;
  24101. /**
  24102. * Gets or sets the fog color to use
  24103. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24104. */
  24105. this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  24106. /**
  24107. * Gets or sets the fog density to use
  24108. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24109. */
  24110. this.fogDensity = 0.1;
  24111. /**
  24112. * Gets or sets the fog start distance to use
  24113. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24114. */
  24115. this.fogStart = 0;
  24116. /**
  24117. * Gets or sets the fog end distance to use
  24118. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24119. */
  24120. this.fogEnd = 1000.0;
  24121. // Lights
  24122. this._shadowsEnabled = true;
  24123. this._lightsEnabled = true;
  24124. /**
  24125. * All of the lights added to this scene
  24126. * @see http://doc.babylonjs.com/babylon101/lights
  24127. */
  24128. this.lights = new Array();
  24129. // Cameras
  24130. /** All of the cameras added to this scene.
  24131. * @see http://doc.babylonjs.com/babylon101/cameras
  24132. */
  24133. this.cameras = new Array();
  24134. /** All of the active cameras added to this scene. */
  24135. this.activeCameras = new Array();
  24136. // Meshes
  24137. /**
  24138. * All of the tranform nodes added to this scene
  24139. * @see http://doc.babylonjs.com/how_to/transformnode
  24140. */
  24141. this.transformNodes = new Array();
  24142. /**
  24143. * All of the (abstract) meshes added to this scene
  24144. */
  24145. this.meshes = new Array();
  24146. /**
  24147. * All of the animation groups added to this scene
  24148. * @see http://doc.babylonjs.com/how_to/group
  24149. */
  24150. this.animationGroups = new Array();
  24151. // Geometries
  24152. this._geometries = new Array();
  24153. /**
  24154. * All of the materials added to this scene
  24155. * @see http://doc.babylonjs.com/babylon101/materials
  24156. */
  24157. this.materials = new Array();
  24158. /**
  24159. * All of the multi-materials added to this scene
  24160. * @see http://doc.babylonjs.com/how_to/multi_materials
  24161. */
  24162. this.multiMaterials = new Array();
  24163. // Textures
  24164. this._texturesEnabled = true;
  24165. /**
  24166. * All of the textures added to this scene
  24167. */
  24168. this.textures = new Array();
  24169. // Particles
  24170. /**
  24171. * Gets or sets a boolean indicating if particles are enabled on this scene
  24172. */
  24173. this.particlesEnabled = true;
  24174. /**
  24175. * All of the particle systems added to this scene
  24176. * @see http://doc.babylonjs.com/babylon101/particles
  24177. */
  24178. this.particleSystems = new Array();
  24179. // Sprites
  24180. /**
  24181. * Gets or sets a boolean indicating if sprites are enabled on this scene
  24182. */
  24183. this.spritesEnabled = true;
  24184. /**
  24185. * All of the sprite managers added to this scene
  24186. * @see http://doc.babylonjs.com/babylon101/sprites
  24187. */
  24188. this.spriteManagers = new Array();
  24189. /**
  24190. * The list of layers (background and foreground) of the scene
  24191. */
  24192. this.layers = new Array();
  24193. /**
  24194. * The list of effect layers (highlights/glow) added to the scene
  24195. * @see http://doc.babylonjs.com/how_to/highlight_layer
  24196. * @see http://doc.babylonjs.com/how_to/glow_layer
  24197. */
  24198. this.effectLayers = new Array();
  24199. // Skeletons
  24200. this._skeletonsEnabled = true;
  24201. /**
  24202. * The list of skeletons added to the scene
  24203. * @see http://doc.babylonjs.com/how_to/how_to_use_bones_and_skeletons
  24204. */
  24205. this.skeletons = new Array();
  24206. // Morph targets
  24207. /**
  24208. * The list of morph target managers added to the scene
  24209. * @see http://doc.babylonjs.com/how_to/how_to_dynamically_morph_a_mesh
  24210. */
  24211. this.morphTargetManagers = new Array();
  24212. // Lens flares
  24213. /**
  24214. * Gets or sets a boolean indicating if lens flares are enabled on this scene
  24215. */
  24216. this.lensFlaresEnabled = true;
  24217. /**
  24218. * The list of lens flare system added to the scene
  24219. * @see http://doc.babylonjs.com/how_to/how_to_use_lens_flares
  24220. */
  24221. this.lensFlareSystems = new Array();
  24222. // Collisions
  24223. /**
  24224. * Gets or sets a boolean indicating if collisions are enabled on this scene
  24225. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  24226. */
  24227. this.collisionsEnabled = true;
  24228. /**
  24229. * Defines the gravity applied to this scene (used only for collisions)
  24230. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
  24231. */
  24232. this.gravity = new BABYLON.Vector3(0, -9.807, 0);
  24233. // Postprocesses
  24234. /**
  24235. * Gets or sets a boolean indicating if postprocesses are enabled on this scene
  24236. */
  24237. this.postProcessesEnabled = true;
  24238. /**
  24239. * The list of postprocesses added to the scene
  24240. */
  24241. this.postProcesses = new Array();
  24242. // Customs render targets
  24243. /**
  24244. * Gets or sets a boolean indicating if render targets are enabled on this scene
  24245. */
  24246. this.renderTargetsEnabled = true;
  24247. /**
  24248. * Gets or sets a boolean indicating if next render targets must be dumped as image for debugging purposes
  24249. * We recommend not using it and instead rely on Spector.js: http://spector.babylonjs.com
  24250. */
  24251. this.dumpNextRenderTargets = false;
  24252. /**
  24253. * The list of user defined render targets added to the scene
  24254. */
  24255. this.customRenderTargets = new Array();
  24256. /**
  24257. * Gets the list of meshes imported to the scene through SceneLoader
  24258. */
  24259. this.importedMeshesFiles = new Array();
  24260. // Probes
  24261. /**
  24262. * Gets or sets a boolean indicating if probes are enabled on this scene
  24263. */
  24264. this.probesEnabled = true;
  24265. /**
  24266. * The list of reflection probes added to the scene
  24267. * @see http://doc.babylonjs.com/how_to/how_to_use_reflection_probes
  24268. */
  24269. this.reflectionProbes = new Array();
  24270. /** @hidden */
  24271. this._actionManagers = new Array();
  24272. this._meshesForIntersections = new BABYLON.SmartArrayNoDuplicate(256);
  24273. // Procedural textures
  24274. /**
  24275. * Gets or sets a boolean indicating if procedural textures are enabled on this scene
  24276. */
  24277. this.proceduralTexturesEnabled = true;
  24278. /**
  24279. * The list of procedural textures added to the scene
  24280. * @see http://doc.babylonjs.com/how_to/how_to_use_procedural_textures
  24281. */
  24282. this.proceduralTextures = new Array();
  24283. /**
  24284. * The list of sound tracks added to the scene
  24285. * @see http://doc.babylonjs.com/how_to/playing_sounds_and_music
  24286. */
  24287. this.soundTracks = new Array();
  24288. this._audioEnabled = true;
  24289. this._headphone = false;
  24290. // Performance counters
  24291. this._totalVertices = new BABYLON.PerfCounter();
  24292. /** @hidden */
  24293. this._activeIndices = new BABYLON.PerfCounter();
  24294. /** @hidden */
  24295. this._activeParticles = new BABYLON.PerfCounter();
  24296. /** @hidden */
  24297. this._activeBones = new BABYLON.PerfCounter();
  24298. this._animationTime = 0;
  24299. /**
  24300. * Gets or sets a general scale for animation speed
  24301. * @see https://www.babylonjs-playground.com/#IBU2W7#3
  24302. */
  24303. this.animationTimeScale = 1;
  24304. this._renderId = 0;
  24305. this._executeWhenReadyTimeoutId = -1;
  24306. this._intermediateRendering = false;
  24307. this._viewUpdateFlag = -1;
  24308. this._projectionUpdateFlag = -1;
  24309. this._alternateViewUpdateFlag = -1;
  24310. this._alternateProjectionUpdateFlag = -1;
  24311. /** @hidden */
  24312. this._toBeDisposed = new BABYLON.SmartArray(256);
  24313. this._activeRequests = new Array();
  24314. this._pendingData = new Array();
  24315. this._isDisposed = false;
  24316. /**
  24317. * Gets or sets a boolean indicating that all submeshes of active meshes must be rendered
  24318. * Use this boolean to avoid computing frustum clipping on submeshes (This could help when you are CPU bound)
  24319. */
  24320. this.dispatchAllSubMeshesOfActiveMeshes = false;
  24321. this._activeMeshes = new BABYLON.SmartArray(256);
  24322. this._processedMaterials = new BABYLON.SmartArray(256);
  24323. this._renderTargets = new BABYLON.SmartArrayNoDuplicate(256);
  24324. /** @hidden */
  24325. this._activeParticleSystems = new BABYLON.SmartArray(256);
  24326. this._activeSkeletons = new BABYLON.SmartArrayNoDuplicate(32);
  24327. this._softwareSkinnedMeshes = new BABYLON.SmartArrayNoDuplicate(32);
  24328. /** @hidden */
  24329. this._activeAnimatables = new Array();
  24330. this._transformMatrix = BABYLON.Matrix.Zero();
  24331. this._useAlternateCameraConfiguration = false;
  24332. this._alternateRendering = false;
  24333. /**
  24334. * Gets or sets a boolean indicating if lights must be sorted by priority (off by default)
  24335. * This is useful if there are more lights that the maximum simulteanous authorized
  24336. */
  24337. this.requireLightSorting = false;
  24338. this._depthRenderer = {};
  24339. this._activeMeshesFrozen = false;
  24340. this._tempPickingRay = BABYLON.Ray ? BABYLON.Ray.Zero() : null;
  24341. this._engine = engine || BABYLON.Engine.LastCreatedEngine;
  24342. this._engine.scenes.push(this);
  24343. this._uid = null;
  24344. this._renderingManager = new BABYLON.RenderingManager(this);
  24345. this.postProcessManager = new BABYLON.PostProcessManager(this);
  24346. if (BABYLON.OutlineRenderer) {
  24347. this._outlineRenderer = new BABYLON.OutlineRenderer(this);
  24348. }
  24349. if (BABYLON.Tools.IsWindowObjectExist()) {
  24350. this.attachControl();
  24351. }
  24352. //simplification queue
  24353. if (BABYLON.SimplificationQueue) {
  24354. this.simplificationQueue = new BABYLON.SimplificationQueue();
  24355. }
  24356. //collision coordinator initialization. For now legacy per default.
  24357. this.workerCollisions = false; //(!!Worker && (!!BABYLON.CollisionWorker || BABYLON.WorkerIncluded));
  24358. // Uniform Buffer
  24359. this._createUbo();
  24360. // Default Image processing definition.
  24361. this._imageProcessingConfiguration = new BABYLON.ImageProcessingConfiguration();
  24362. }
  24363. Object.defineProperty(Scene, "FOGMODE_NONE", {
  24364. /** The fog is deactivated */
  24365. get: function () {
  24366. return Scene._FOGMODE_NONE;
  24367. },
  24368. enumerable: true,
  24369. configurable: true
  24370. });
  24371. Object.defineProperty(Scene, "FOGMODE_EXP", {
  24372. /** The fog density is following an exponential function */
  24373. get: function () {
  24374. return Scene._FOGMODE_EXP;
  24375. },
  24376. enumerable: true,
  24377. configurable: true
  24378. });
  24379. Object.defineProperty(Scene, "FOGMODE_EXP2", {
  24380. /** The fog density is following an exponential function faster than FOGMODE_EXP */
  24381. get: function () {
  24382. return Scene._FOGMODE_EXP2;
  24383. },
  24384. enumerable: true,
  24385. configurable: true
  24386. });
  24387. Object.defineProperty(Scene, "FOGMODE_LINEAR", {
  24388. /** The fog density is following a linear function. */
  24389. get: function () {
  24390. return Scene._FOGMODE_LINEAR;
  24391. },
  24392. enumerable: true,
  24393. configurable: true
  24394. });
  24395. Object.defineProperty(Scene.prototype, "environmentTexture", {
  24396. /**
  24397. * Texture used in all pbr material as the reflection texture.
  24398. * As in the majority of the scene they are the same (exception for multi room and so on),
  24399. * this is easier to reference from here than from all the materials.
  24400. */
  24401. get: function () {
  24402. return this._environmentTexture;
  24403. },
  24404. /**
  24405. * Texture used in all pbr material as the reflection texture.
  24406. * As in the majority of the scene they are the same (exception for multi room and so on),
  24407. * this is easier to set here than in all the materials.
  24408. */
  24409. set: function (value) {
  24410. if (this._environmentTexture === value) {
  24411. return;
  24412. }
  24413. this._environmentTexture = value;
  24414. this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  24415. },
  24416. enumerable: true,
  24417. configurable: true
  24418. });
  24419. Object.defineProperty(Scene.prototype, "imageProcessingConfiguration", {
  24420. /**
  24421. * Default image processing configuration used either in the rendering
  24422. * Forward main pass or through the imageProcessingPostProcess if present.
  24423. * As in the majority of the scene they are the same (exception for multi camera),
  24424. * this is easier to reference from here than from all the materials and post process.
  24425. *
  24426. * No setter as we it is a shared configuration, you can set the values instead.
  24427. */
  24428. get: function () {
  24429. return this._imageProcessingConfiguration;
  24430. },
  24431. enumerable: true,
  24432. configurable: true
  24433. });
  24434. Object.defineProperty(Scene.prototype, "forceWireframe", {
  24435. get: function () {
  24436. return this._forceWireframe;
  24437. },
  24438. /**
  24439. * Gets or sets a boolean indicating if all rendering must be done in wireframe
  24440. */
  24441. set: function (value) {
  24442. if (this._forceWireframe === value) {
  24443. return;
  24444. }
  24445. this._forceWireframe = value;
  24446. this.markAllMaterialsAsDirty(BABYLON.Material.MiscDirtyFlag);
  24447. },
  24448. enumerable: true,
  24449. configurable: true
  24450. });
  24451. Object.defineProperty(Scene.prototype, "forcePointsCloud", {
  24452. get: function () {
  24453. return this._forcePointsCloud;
  24454. },
  24455. /**
  24456. * Gets or sets a boolean indicating if all rendering must be done in point cloud
  24457. */
  24458. set: function (value) {
  24459. if (this._forcePointsCloud === value) {
  24460. return;
  24461. }
  24462. this._forcePointsCloud = value;
  24463. this.markAllMaterialsAsDirty(BABYLON.Material.MiscDirtyFlag);
  24464. },
  24465. enumerable: true,
  24466. configurable: true
  24467. });
  24468. Object.defineProperty(Scene.prototype, "animationPropertiesOverride", {
  24469. /**
  24470. * Gets or sets the animation properties override
  24471. */
  24472. get: function () {
  24473. return this._animationPropertiesOverride;
  24474. },
  24475. set: function (value) {
  24476. this._animationPropertiesOverride = value;
  24477. },
  24478. enumerable: true,
  24479. configurable: true
  24480. });
  24481. Object.defineProperty(Scene.prototype, "onDispose", {
  24482. /** Sets a function to be executed when this scene is disposed. */
  24483. set: function (callback) {
  24484. if (this._onDisposeObserver) {
  24485. this.onDisposeObservable.remove(this._onDisposeObserver);
  24486. }
  24487. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  24488. },
  24489. enumerable: true,
  24490. configurable: true
  24491. });
  24492. Object.defineProperty(Scene.prototype, "beforeRender", {
  24493. /** Sets a function to be executed before rendering this scene */
  24494. set: function (callback) {
  24495. if (this._onBeforeRenderObserver) {
  24496. this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
  24497. }
  24498. if (callback) {
  24499. this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);
  24500. }
  24501. },
  24502. enumerable: true,
  24503. configurable: true
  24504. });
  24505. Object.defineProperty(Scene.prototype, "afterRender", {
  24506. /** Sets a function to be executed after rendering this scene */
  24507. set: function (callback) {
  24508. if (this._onAfterRenderObserver) {
  24509. this.onAfterRenderObservable.remove(this._onAfterRenderObserver);
  24510. }
  24511. if (callback) {
  24512. this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
  24513. }
  24514. },
  24515. enumerable: true,
  24516. configurable: true
  24517. });
  24518. Object.defineProperty(Scene.prototype, "beforeCameraRender", {
  24519. /** Sets a function to be executed before rendering a camera*/
  24520. set: function (callback) {
  24521. if (this._onBeforeCameraRenderObserver) {
  24522. this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);
  24523. }
  24524. this._onBeforeCameraRenderObserver = this.onBeforeCameraRenderObservable.add(callback);
  24525. },
  24526. enumerable: true,
  24527. configurable: true
  24528. });
  24529. Object.defineProperty(Scene.prototype, "afterCameraRender", {
  24530. /** Sets a function to be executed after rendering a camera*/
  24531. set: function (callback) {
  24532. if (this._onAfterCameraRenderObserver) {
  24533. this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver);
  24534. }
  24535. this._onAfterCameraRenderObserver = this.onAfterCameraRenderObservable.add(callback);
  24536. },
  24537. enumerable: true,
  24538. configurable: true
  24539. });
  24540. Object.defineProperty(Scene.prototype, "gamepadManager", {
  24541. /**
  24542. * Gets the gamepad manager associated with the scene
  24543. * @see http://doc.babylonjs.com/how_to/how_to_use_gamepads
  24544. */
  24545. get: function () {
  24546. if (!this._gamepadManager) {
  24547. this._gamepadManager = new BABYLON.GamepadManager(this);
  24548. }
  24549. return this._gamepadManager;
  24550. },
  24551. enumerable: true,
  24552. configurable: true
  24553. });
  24554. Object.defineProperty(Scene.prototype, "unTranslatedPointer", {
  24555. /**
  24556. * Gets the pointer coordinates without any translation (ie. straight out of the pointer event)
  24557. */
  24558. get: function () {
  24559. return new BABYLON.Vector2(this._unTranslatedPointerX, this._unTranslatedPointerY);
  24560. },
  24561. enumerable: true,
  24562. configurable: true
  24563. });
  24564. Object.defineProperty(Scene.prototype, "useRightHandedSystem", {
  24565. get: function () {
  24566. return this._useRightHandedSystem;
  24567. },
  24568. /**
  24569. * Gets or sets a boolean indicating if the scene must use right-handed coordinates system
  24570. */
  24571. set: function (value) {
  24572. if (this._useRightHandedSystem === value) {
  24573. return;
  24574. }
  24575. this._useRightHandedSystem = value;
  24576. this.markAllMaterialsAsDirty(BABYLON.Material.MiscDirtyFlag);
  24577. },
  24578. enumerable: true,
  24579. configurable: true
  24580. });
  24581. /**
  24582. * Sets the step Id used by deterministic lock step
  24583. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  24584. * @param newStepId defines the step Id
  24585. */
  24586. Scene.prototype.setStepId = function (newStepId) {
  24587. this._currentStepId = newStepId;
  24588. };
  24589. ;
  24590. /**
  24591. * Gets the step Id used by deterministic lock step
  24592. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  24593. * @returns the step Id
  24594. */
  24595. Scene.prototype.getStepId = function () {
  24596. return this._currentStepId;
  24597. };
  24598. ;
  24599. /**
  24600. * Gets the internal step used by deterministic lock step
  24601. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  24602. * @returns the internal step
  24603. */
  24604. Scene.prototype.getInternalStep = function () {
  24605. return this._currentInternalStep;
  24606. };
  24607. ;
  24608. Object.defineProperty(Scene.prototype, "fogEnabled", {
  24609. get: function () {
  24610. return this._fogEnabled;
  24611. },
  24612. /**
  24613. * Gets or sets a boolean indicating if fog is enabled on this scene
  24614. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24615. */
  24616. set: function (value) {
  24617. if (this._fogEnabled === value) {
  24618. return;
  24619. }
  24620. this._fogEnabled = value;
  24621. this.markAllMaterialsAsDirty(BABYLON.Material.MiscDirtyFlag);
  24622. },
  24623. enumerable: true,
  24624. configurable: true
  24625. });
  24626. Object.defineProperty(Scene.prototype, "fogMode", {
  24627. get: function () {
  24628. return this._fogMode;
  24629. },
  24630. /**
  24631. * Gets or sets the fog mode to use
  24632. * @see http://doc.babylonjs.com/babylon101/environment#fog
  24633. */
  24634. set: function (value) {
  24635. if (this._fogMode === value) {
  24636. return;
  24637. }
  24638. this._fogMode = value;
  24639. this.markAllMaterialsAsDirty(BABYLON.Material.MiscDirtyFlag);
  24640. },
  24641. enumerable: true,
  24642. configurable: true
  24643. });
  24644. Object.defineProperty(Scene.prototype, "shadowsEnabled", {
  24645. get: function () {
  24646. return this._shadowsEnabled;
  24647. },
  24648. /**
  24649. * Gets or sets a boolean indicating if shadows are enabled on this scene
  24650. */
  24651. set: function (value) {
  24652. if (this._shadowsEnabled === value) {
  24653. return;
  24654. }
  24655. this._shadowsEnabled = value;
  24656. this.markAllMaterialsAsDirty(BABYLON.Material.LightDirtyFlag);
  24657. },
  24658. enumerable: true,
  24659. configurable: true
  24660. });
  24661. Object.defineProperty(Scene.prototype, "lightsEnabled", {
  24662. get: function () {
  24663. return this._lightsEnabled;
  24664. },
  24665. /**
  24666. * Gets or sets a boolean indicating if lights are enabled on this scene
  24667. */
  24668. set: function (value) {
  24669. if (this._lightsEnabled === value) {
  24670. return;
  24671. }
  24672. this._lightsEnabled = value;
  24673. this.markAllMaterialsAsDirty(BABYLON.Material.LightDirtyFlag);
  24674. },
  24675. enumerable: true,
  24676. configurable: true
  24677. });
  24678. Object.defineProperty(Scene.prototype, "defaultMaterial", {
  24679. /** The default material used on meshes when no material is affected */
  24680. get: function () {
  24681. if (!this._defaultMaterial) {
  24682. this._defaultMaterial = new BABYLON.StandardMaterial("default material", this);
  24683. }
  24684. return this._defaultMaterial;
  24685. },
  24686. /** The default material used on meshes when no material is affected */
  24687. set: function (value) {
  24688. this._defaultMaterial = value;
  24689. },
  24690. enumerable: true,
  24691. configurable: true
  24692. });
  24693. Object.defineProperty(Scene.prototype, "texturesEnabled", {
  24694. get: function () {
  24695. return this._texturesEnabled;
  24696. },
  24697. /**
  24698. * Gets or sets a boolean indicating if textures are enabled on this scene
  24699. */
  24700. set: function (value) {
  24701. if (this._texturesEnabled === value) {
  24702. return;
  24703. }
  24704. this._texturesEnabled = value;
  24705. this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  24706. },
  24707. enumerable: true,
  24708. configurable: true
  24709. });
  24710. Object.defineProperty(Scene.prototype, "skeletonsEnabled", {
  24711. get: function () {
  24712. return this._skeletonsEnabled;
  24713. },
  24714. /**
  24715. * Gets or sets a boolean indicating if skeletons are enabled on this scene
  24716. */
  24717. set: function (value) {
  24718. if (this._skeletonsEnabled === value) {
  24719. return;
  24720. }
  24721. this._skeletonsEnabled = value;
  24722. this.markAllMaterialsAsDirty(BABYLON.Material.AttributesDirtyFlag);
  24723. },
  24724. enumerable: true,
  24725. configurable: true
  24726. });
  24727. Object.defineProperty(Scene.prototype, "postProcessRenderPipelineManager", {
  24728. /**
  24729. * Gets the postprocess render pipeline manager
  24730. * @see http://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
  24731. * @see http://doc.babylonjs.com/how_to/using_default_rendering_pipeline
  24732. */
  24733. get: function () {
  24734. if (!this._postProcessRenderPipelineManager) {
  24735. this._postProcessRenderPipelineManager = new BABYLON.PostProcessRenderPipelineManager();
  24736. }
  24737. return this._postProcessRenderPipelineManager;
  24738. },
  24739. enumerable: true,
  24740. configurable: true
  24741. });
  24742. Object.defineProperty(Scene.prototype, "mainSoundTrack", {
  24743. /**
  24744. * Gets the main soundtrack associated with the scene
  24745. */
  24746. get: function () {
  24747. if (!this._mainSoundTrack) {
  24748. this._mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
  24749. }
  24750. return this._mainSoundTrack;
  24751. },
  24752. enumerable: true,
  24753. configurable: true
  24754. });
  24755. Object.defineProperty(Scene.prototype, "_isAlternateRenderingEnabled", {
  24756. /** @hidden */
  24757. get: function () {
  24758. return this._alternateRendering;
  24759. },
  24760. enumerable: true,
  24761. configurable: true
  24762. });
  24763. Object.defineProperty(Scene.prototype, "frustumPlanes", {
  24764. /**
  24765. * Gets the list of frustum planes (built from the active camera)
  24766. */
  24767. get: function () {
  24768. return this._frustumPlanes;
  24769. },
  24770. enumerable: true,
  24771. configurable: true
  24772. });
  24773. Object.defineProperty(Scene.prototype, "geometryBufferRenderer", {
  24774. /**
  24775. * Gets the current geometry buffer associated to the scene.
  24776. */
  24777. get: function () {
  24778. return this._geometryBufferRenderer;
  24779. },
  24780. /**
  24781. * Sets the current geometry buffer for the scene.
  24782. */
  24783. set: function (geometryBufferRenderer) {
  24784. if (geometryBufferRenderer && geometryBufferRenderer.isSupported) {
  24785. this._geometryBufferRenderer = geometryBufferRenderer;
  24786. }
  24787. },
  24788. enumerable: true,
  24789. configurable: true
  24790. });
  24791. Object.defineProperty(Scene.prototype, "debugLayer", {
  24792. /**
  24793. * Gets the debug layer (aka Inspector) associated with the scene
  24794. * @see http://doc.babylonjs.com/features/playground_debuglayer
  24795. */
  24796. get: function () {
  24797. if (!this._debugLayer) {
  24798. this._debugLayer = new BABYLON.DebugLayer(this);
  24799. }
  24800. return this._debugLayer;
  24801. },
  24802. enumerable: true,
  24803. configurable: true
  24804. });
  24805. Object.defineProperty(Scene.prototype, "workerCollisions", {
  24806. /**
  24807. * Gets a boolean indicating if collisions are processed on a web worker
  24808. * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity#web-worker-based-collision-system-since-21
  24809. */
  24810. get: function () {
  24811. return this._workerCollisions;
  24812. },
  24813. set: function (enabled) {
  24814. if (!BABYLON.CollisionCoordinatorLegacy) {
  24815. return;
  24816. }
  24817. enabled = (enabled && !!Worker && !!BABYLON.CollisionWorker);
  24818. this._workerCollisions = enabled;
  24819. if (this.collisionCoordinator) {
  24820. this.collisionCoordinator.destroy();
  24821. }
  24822. this.collisionCoordinator = enabled ? new BABYLON.CollisionCoordinatorWorker() : new BABYLON.CollisionCoordinatorLegacy();
  24823. this.collisionCoordinator.init(this);
  24824. },
  24825. enumerable: true,
  24826. configurable: true
  24827. });
  24828. Object.defineProperty(Scene.prototype, "selectionOctree", {
  24829. /**
  24830. * Gets the octree used to boost mesh selection (picking)
  24831. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene_with_octrees
  24832. */
  24833. get: function () {
  24834. return this._selectionOctree;
  24835. },
  24836. enumerable: true,
  24837. configurable: true
  24838. });
  24839. Object.defineProperty(Scene.prototype, "meshUnderPointer", {
  24840. /**
  24841. * Gets the mesh that is currently under the pointer
  24842. */
  24843. get: function () {
  24844. return this._pointerOverMesh;
  24845. },
  24846. enumerable: true,
  24847. configurable: true
  24848. });
  24849. Object.defineProperty(Scene.prototype, "pointerX", {
  24850. /**
  24851. * Gets the current on-screen X position of the pointer
  24852. */
  24853. get: function () {
  24854. return this._pointerX;
  24855. },
  24856. enumerable: true,
  24857. configurable: true
  24858. });
  24859. Object.defineProperty(Scene.prototype, "pointerY", {
  24860. /**
  24861. * Gets the current on-screen Y position of the pointer
  24862. */
  24863. get: function () {
  24864. return this._pointerY;
  24865. },
  24866. enumerable: true,
  24867. configurable: true
  24868. });
  24869. /**
  24870. * Gets the cached material (ie. the latest rendered one)
  24871. * @returns the cached material
  24872. */
  24873. Scene.prototype.getCachedMaterial = function () {
  24874. return this._cachedMaterial;
  24875. };
  24876. /**
  24877. * Gets the cached effect (ie. the latest rendered one)
  24878. * @returns the cached effect
  24879. */
  24880. Scene.prototype.getCachedEffect = function () {
  24881. return this._cachedEffect;
  24882. };
  24883. /**
  24884. * Gets the cached visibility state (ie. the latest rendered one)
  24885. * @returns the cached visibility state
  24886. */
  24887. Scene.prototype.getCachedVisibility = function () {
  24888. return this._cachedVisibility;
  24889. };
  24890. /**
  24891. * Gets a boolean indicating if the current material / effect / visibility must be bind again
  24892. * @param material defines the current material
  24893. * @param effect defines the current effect
  24894. * @param visibility defines the current visibility state
  24895. * @returns true if one parameter is not cached
  24896. */
  24897. Scene.prototype.isCachedMaterialInvalid = function (material, effect, visibility) {
  24898. if (visibility === void 0) { visibility = 1; }
  24899. return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;
  24900. };
  24901. /**
  24902. * Gets the bounding box renderer associated with the scene
  24903. * @returns a BoundingBoxRenderer
  24904. */
  24905. Scene.prototype.getBoundingBoxRenderer = function () {
  24906. if (!this._boundingBoxRenderer) {
  24907. this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
  24908. }
  24909. return this._boundingBoxRenderer;
  24910. };
  24911. /**
  24912. * Gets the outline renderer associated with the scene
  24913. * @returns a OutlineRenderer
  24914. */
  24915. Scene.prototype.getOutlineRenderer = function () {
  24916. return this._outlineRenderer;
  24917. };
  24918. /**
  24919. * Gets the engine associated with the scene
  24920. * @returns an Engine
  24921. */
  24922. Scene.prototype.getEngine = function () {
  24923. return this._engine;
  24924. };
  24925. /**
  24926. * Gets the total number of vertices rendered per frame
  24927. * @returns the total number of vertices rendered per frame
  24928. */
  24929. Scene.prototype.getTotalVertices = function () {
  24930. return this._totalVertices.current;
  24931. };
  24932. Object.defineProperty(Scene.prototype, "totalVerticesPerfCounter", {
  24933. /**
  24934. * Gets the performance counter for total vertices
  24935. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#instrumentation
  24936. */
  24937. get: function () {
  24938. return this._totalVertices;
  24939. },
  24940. enumerable: true,
  24941. configurable: true
  24942. });
  24943. /**
  24944. * Gets the total number of active indices rendered per frame (You can deduce the number of rendered triangles by dividing this number by 3)
  24945. * @returns the total number of active indices rendered per frame
  24946. */
  24947. Scene.prototype.getActiveIndices = function () {
  24948. return this._activeIndices.current;
  24949. };
  24950. Object.defineProperty(Scene.prototype, "totalActiveIndicesPerfCounter", {
  24951. /**
  24952. * Gets the performance counter for active indices
  24953. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#instrumentation
  24954. */
  24955. get: function () {
  24956. return this._activeIndices;
  24957. },
  24958. enumerable: true,
  24959. configurable: true
  24960. });
  24961. /**
  24962. * Gets the total number of active particles rendered per frame
  24963. * @returns the total number of active particles rendered per frame
  24964. */
  24965. Scene.prototype.getActiveParticles = function () {
  24966. return this._activeParticles.current;
  24967. };
  24968. Object.defineProperty(Scene.prototype, "activeParticlesPerfCounter", {
  24969. /**
  24970. * Gets the performance counter for active particles
  24971. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#instrumentation
  24972. */
  24973. get: function () {
  24974. return this._activeParticles;
  24975. },
  24976. enumerable: true,
  24977. configurable: true
  24978. });
  24979. /**
  24980. * Gets the total number of active bones rendered per frame
  24981. * @returns the total number of active bones rendered per frame
  24982. */
  24983. Scene.prototype.getActiveBones = function () {
  24984. return this._activeBones.current;
  24985. };
  24986. Object.defineProperty(Scene.prototype, "activeBonesPerfCounter", {
  24987. /**
  24988. * Gets the performance counter for active bones
  24989. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene#instrumentation
  24990. */
  24991. get: function () {
  24992. return this._activeBones;
  24993. },
  24994. enumerable: true,
  24995. configurable: true
  24996. });
  24997. /** @hidden */
  24998. Scene.prototype.getInterFramePerfCounter = function () {
  24999. BABYLON.Tools.Warn("getInterFramePerfCounter is deprecated. Please use SceneInstrumentation class");
  25000. return 0;
  25001. };
  25002. Object.defineProperty(Scene.prototype, "interFramePerfCounter", {
  25003. /** @hidden */
  25004. get: function () {
  25005. BABYLON.Tools.Warn("interFramePerfCounter is deprecated. Please use SceneInstrumentation class");
  25006. return null;
  25007. },
  25008. enumerable: true,
  25009. configurable: true
  25010. });
  25011. /** @hidden */
  25012. Scene.prototype.getLastFrameDuration = function () {
  25013. BABYLON.Tools.Warn("getLastFrameDuration is deprecated. Please use SceneInstrumentation class");
  25014. return 0;
  25015. };
  25016. Object.defineProperty(Scene.prototype, "lastFramePerfCounter", {
  25017. /** @hidden */
  25018. get: function () {
  25019. BABYLON.Tools.Warn("lastFramePerfCounter is deprecated. Please use SceneInstrumentation class");
  25020. return null;
  25021. },
  25022. enumerable: true,
  25023. configurable: true
  25024. });
  25025. /** @hidden */
  25026. Scene.prototype.getEvaluateActiveMeshesDuration = function () {
  25027. BABYLON.Tools.Warn("getEvaluateActiveMeshesDuration is deprecated. Please use SceneInstrumentation class");
  25028. return 0;
  25029. };
  25030. Object.defineProperty(Scene.prototype, "evaluateActiveMeshesDurationPerfCounter", {
  25031. /** @hidden */
  25032. get: function () {
  25033. BABYLON.Tools.Warn("evaluateActiveMeshesDurationPerfCounter is deprecated. Please use SceneInstrumentation class");
  25034. return null;
  25035. },
  25036. enumerable: true,
  25037. configurable: true
  25038. });
  25039. /**
  25040. * Gets the array of active meshes
  25041. * @returns an array of AbstractMesh
  25042. */
  25043. Scene.prototype.getActiveMeshes = function () {
  25044. return this._activeMeshes;
  25045. };
  25046. /** @hidden */
  25047. Scene.prototype.getRenderTargetsDuration = function () {
  25048. BABYLON.Tools.Warn("getRenderTargetsDuration is deprecated. Please use SceneInstrumentation class");
  25049. return 0;
  25050. };
  25051. /** @hidden */
  25052. Scene.prototype.getRenderDuration = function () {
  25053. BABYLON.Tools.Warn("getRenderDuration is deprecated. Please use SceneInstrumentation class");
  25054. return 0;
  25055. };
  25056. Object.defineProperty(Scene.prototype, "renderDurationPerfCounter", {
  25057. /** @hidden */
  25058. get: function () {
  25059. BABYLON.Tools.Warn("renderDurationPerfCounter is deprecated. Please use SceneInstrumentation class");
  25060. return null;
  25061. },
  25062. enumerable: true,
  25063. configurable: true
  25064. });
  25065. /** @hidden */
  25066. Scene.prototype.getParticlesDuration = function () {
  25067. BABYLON.Tools.Warn("getParticlesDuration is deprecated. Please use SceneInstrumentation class");
  25068. return 0;
  25069. };
  25070. Object.defineProperty(Scene.prototype, "particlesDurationPerfCounter", {
  25071. /** @hidden */
  25072. get: function () {
  25073. BABYLON.Tools.Warn("particlesDurationPerfCounter is deprecated. Please use SceneInstrumentation class");
  25074. return null;
  25075. },
  25076. enumerable: true,
  25077. configurable: true
  25078. });
  25079. /** @hidden */
  25080. Scene.prototype.getSpritesDuration = function () {
  25081. BABYLON.Tools.Warn("getSpritesDuration is deprecated. Please use SceneInstrumentation class");
  25082. return 0;
  25083. };
  25084. Object.defineProperty(Scene.prototype, "spriteDuractionPerfCounter", {
  25085. /** @hidden */
  25086. get: function () {
  25087. BABYLON.Tools.Warn("spriteDuractionPerfCounter is deprecated. Please use SceneInstrumentation class");
  25088. return null;
  25089. },
  25090. enumerable: true,
  25091. configurable: true
  25092. });
  25093. /**
  25094. * Gets the animation ratio (which is 1.0 is the scene renders at 60fps and 2 if the scene renders at 30fps, etc.)
  25095. * @returns a number
  25096. */
  25097. Scene.prototype.getAnimationRatio = function () {
  25098. return this._animationRatio;
  25099. };
  25100. /**
  25101. * Gets an unique Id for the current frame
  25102. * @returns a number
  25103. */
  25104. Scene.prototype.getRenderId = function () {
  25105. return this._renderId;
  25106. };
  25107. /** Call this function if you want to manually increment the render Id*/
  25108. Scene.prototype.incrementRenderId = function () {
  25109. this._renderId++;
  25110. };
  25111. Scene.prototype._updatePointerPosition = function (evt) {
  25112. var canvasRect = this._engine.getRenderingCanvasClientRect();
  25113. if (!canvasRect) {
  25114. return;
  25115. }
  25116. this._pointerX = evt.clientX - canvasRect.left;
  25117. this._pointerY = evt.clientY - canvasRect.top;
  25118. this._unTranslatedPointerX = this._pointerX;
  25119. this._unTranslatedPointerY = this._pointerY;
  25120. };
  25121. Scene.prototype._createUbo = function () {
  25122. this._sceneUbo = new BABYLON.UniformBuffer(this._engine, undefined, true);
  25123. this._sceneUbo.addUniform("viewProjection", 16);
  25124. this._sceneUbo.addUniform("view", 16);
  25125. };
  25126. Scene.prototype._createAlternateUbo = function () {
  25127. this._alternateSceneUbo = new BABYLON.UniformBuffer(this._engine, undefined, true);
  25128. this._alternateSceneUbo.addUniform("viewProjection", 16);
  25129. this._alternateSceneUbo.addUniform("view", 16);
  25130. };
  25131. // Pointers handling
  25132. Scene.prototype._pickSpriteButKeepRay = function (originalPointerInfo, x, y, predicate, fastCheck, camera) {
  25133. var result = this.pickSprite(x, y, predicate, fastCheck, camera);
  25134. if (result) {
  25135. result.ray = originalPointerInfo ? originalPointerInfo.ray : null;
  25136. }
  25137. return result;
  25138. };
  25139. Scene.prototype._setRayOnPointerInfo = function (pointerInfo) {
  25140. if (pointerInfo.pickInfo) {
  25141. if (!pointerInfo.pickInfo.ray) {
  25142. pointerInfo.pickInfo.ray = this.createPickingRay(pointerInfo.event.offsetX, pointerInfo.event.offsetY, BABYLON.Matrix.Identity(), this.activeCamera);
  25143. }
  25144. }
  25145. };
  25146. /**
  25147. * Use this method to simulate a pointer move on a mesh
  25148. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  25149. * @param pickResult pickingInfo of the object wished to simulate pointer event on
  25150. * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  25151. * @returns the current scene
  25152. */
  25153. Scene.prototype.simulatePointerMove = function (pickResult, pointerEventInit) {
  25154. var evt = new PointerEvent("pointermove", pointerEventInit);
  25155. if (this._checkPrePointerObservable(pickResult, evt, BABYLON.PointerEventTypes.POINTERMOVE)) {
  25156. return this;
  25157. }
  25158. return this._processPointerMove(pickResult, evt);
  25159. };
  25160. Scene.prototype._processPointerMove = function (pickResult, evt) {
  25161. var canvas = this._engine.getRenderingCanvas();
  25162. if (!canvas) {
  25163. return this;
  25164. }
  25165. if (pickResult && pickResult.hit && pickResult.pickedMesh) {
  25166. this.setPointerOverSprite(null);
  25167. this.setPointerOverMesh(pickResult.pickedMesh);
  25168. if (this._pointerOverMesh && this._pointerOverMesh.actionManager && this._pointerOverMesh.actionManager.hasPointerTriggers) {
  25169. if (this._pointerOverMesh.actionManager.hoverCursor) {
  25170. canvas.style.cursor = this._pointerOverMesh.actionManager.hoverCursor;
  25171. }
  25172. else {
  25173. canvas.style.cursor = this.hoverCursor;
  25174. }
  25175. }
  25176. else {
  25177. canvas.style.cursor = this.defaultCursor;
  25178. }
  25179. }
  25180. else {
  25181. this.setPointerOverMesh(null);
  25182. // Sprites
  25183. pickResult = this._pickSpriteButKeepRay(pickResult, this._unTranslatedPointerX, this._unTranslatedPointerY, this._spritePredicate, false, this.cameraToUseForPointers || undefined);
  25184. if (pickResult && pickResult.hit && pickResult.pickedSprite) {
  25185. this.setPointerOverSprite(pickResult.pickedSprite);
  25186. if (this._pointerOverSprite && this._pointerOverSprite.actionManager && this._pointerOverSprite.actionManager.hoverCursor) {
  25187. canvas.style.cursor = this._pointerOverSprite.actionManager.hoverCursor;
  25188. }
  25189. else {
  25190. canvas.style.cursor = this.hoverCursor;
  25191. }
  25192. }
  25193. else {
  25194. this.setPointerOverSprite(null);
  25195. // Restore pointer
  25196. canvas.style.cursor = this.defaultCursor;
  25197. }
  25198. }
  25199. if (pickResult) {
  25200. var type = evt.type === "mousewheel" || evt.type === "DOMMouseScroll" ? BABYLON.PointerEventTypes.POINTERWHEEL : BABYLON.PointerEventTypes.POINTERMOVE;
  25201. if (this.onPointerMove) {
  25202. this.onPointerMove(evt, pickResult, type);
  25203. }
  25204. if (this.onPointerObservable.hasObservers()) {
  25205. var pi = new BABYLON.PointerInfo(type, evt, pickResult);
  25206. this._setRayOnPointerInfo(pi);
  25207. this.onPointerObservable.notifyObservers(pi, type);
  25208. }
  25209. }
  25210. return this;
  25211. };
  25212. Scene.prototype._checkPrePointerObservable = function (pickResult, evt, type) {
  25213. var pi = new BABYLON.PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);
  25214. if (pickResult) {
  25215. pi.ray = pickResult.ray;
  25216. }
  25217. this.onPrePointerObservable.notifyObservers(pi, type);
  25218. if (pi.skipOnPointerObservable) {
  25219. return true;
  25220. }
  25221. else {
  25222. return false;
  25223. }
  25224. };
  25225. /**
  25226. * Use this method to simulate a pointer down on a mesh
  25227. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  25228. * @param pickResult pickingInfo of the object wished to simulate pointer event on
  25229. * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  25230. * @returns the current scene
  25231. */
  25232. Scene.prototype.simulatePointerDown = function (pickResult, pointerEventInit) {
  25233. var evt = new PointerEvent("pointerdown", pointerEventInit);
  25234. if (this._checkPrePointerObservable(pickResult, evt, BABYLON.PointerEventTypes.POINTERDOWN)) {
  25235. return this;
  25236. }
  25237. return this._processPointerDown(pickResult, evt);
  25238. };
  25239. Scene.prototype._processPointerDown = function (pickResult, evt) {
  25240. var _this = this;
  25241. if (pickResult && pickResult.hit && pickResult.pickedMesh) {
  25242. this._pickedDownMesh = pickResult.pickedMesh;
  25243. var actionManager = pickResult.pickedMesh.actionManager;
  25244. if (actionManager) {
  25245. if (actionManager.hasPickTriggers) {
  25246. actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25247. switch (evt.button) {
  25248. case 0:
  25249. actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25250. break;
  25251. case 1:
  25252. actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25253. break;
  25254. case 2:
  25255. actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25256. break;
  25257. }
  25258. }
  25259. if (actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  25260. window.setTimeout(function () {
  25261. var pickResult = _this.pick(_this._unTranslatedPointerX, _this._unTranslatedPointerY, function (mesh) { return (mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger) && mesh == _this._pickedDownMesh); }, false, _this.cameraToUseForPointers);
  25262. if (pickResult && pickResult.hit && pickResult.pickedMesh && actionManager) {
  25263. if (_this._totalPointersPressed !== 0 &&
  25264. ((Date.now() - _this._startingPointerTime) > Scene.LongPressDelay) &&
  25265. (Math.abs(_this._startingPointerPosition.x - _this._pointerX) < Scene.DragMovementThreshold &&
  25266. Math.abs(_this._startingPointerPosition.y - _this._pointerY) < Scene.DragMovementThreshold)) {
  25267. _this._startingPointerTime = 0;
  25268. actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25269. }
  25270. }
  25271. }, Scene.LongPressDelay);
  25272. }
  25273. }
  25274. }
  25275. if (pickResult) {
  25276. var type = BABYLON.PointerEventTypes.POINTERDOWN;
  25277. if (this.onPointerDown) {
  25278. this.onPointerDown(evt, pickResult, type);
  25279. }
  25280. if (this.onPointerObservable.hasObservers()) {
  25281. var pi = new BABYLON.PointerInfo(type, evt, pickResult);
  25282. this._setRayOnPointerInfo(pi);
  25283. this.onPointerObservable.notifyObservers(pi, type);
  25284. }
  25285. }
  25286. return this;
  25287. };
  25288. /**
  25289. * Use this method to simulate a pointer up on a mesh
  25290. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  25291. * @param pickResult pickingInfo of the object wished to simulate pointer event on
  25292. * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  25293. * @returns the current scene
  25294. */
  25295. Scene.prototype.simulatePointerUp = function (pickResult, pointerEventInit) {
  25296. var evt = new PointerEvent("pointerup", pointerEventInit);
  25297. var clickInfo = new ClickInfo();
  25298. clickInfo.singleClick = true;
  25299. clickInfo.ignore = true;
  25300. if (this._checkPrePointerObservable(pickResult, evt, BABYLON.PointerEventTypes.POINTERUP)) {
  25301. return this;
  25302. }
  25303. return this._processPointerUp(pickResult, evt, clickInfo);
  25304. };
  25305. Scene.prototype._processPointerUp = function (pickResult, evt, clickInfo) {
  25306. if (pickResult && pickResult && pickResult.pickedMesh) {
  25307. this._pickedUpMesh = pickResult.pickedMesh;
  25308. if (this._pickedDownMesh === this._pickedUpMesh) {
  25309. if (this.onPointerPick) {
  25310. this.onPointerPick(evt, pickResult);
  25311. }
  25312. if (clickInfo.singleClick && !clickInfo.ignore && this.onPointerObservable.hasObservers()) {
  25313. var type_1 = BABYLON.PointerEventTypes.POINTERPICK;
  25314. var pi = new BABYLON.PointerInfo(type_1, evt, pickResult);
  25315. this._setRayOnPointerInfo(pi);
  25316. this.onPointerObservable.notifyObservers(pi, type_1);
  25317. }
  25318. }
  25319. if (pickResult.pickedMesh.actionManager) {
  25320. if (clickInfo.ignore) {
  25321. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25322. }
  25323. if (!clickInfo.hasSwiped && !clickInfo.ignore && clickInfo.singleClick) {
  25324. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25325. }
  25326. if (clickInfo.doubleClick && !clickInfo.ignore && pickResult.pickedMesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnDoublePickTrigger)) {
  25327. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnDoublePickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  25328. }
  25329. }
  25330. }
  25331. if (this._pickedDownMesh &&
  25332. this._pickedDownMesh.actionManager &&
  25333. this._pickedDownMesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnPickOutTrigger) &&
  25334. this._pickedDownMesh !== this._pickedUpMesh) {
  25335. this._pickedDownMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, BABYLON.ActionEvent.CreateNew(this._pickedDownMesh, evt));
  25336. }
  25337. var type = BABYLON.PointerEventTypes.POINTERUP;
  25338. if (this.onPointerObservable.hasObservers()) {
  25339. if (!clickInfo.ignore) {
  25340. if (!clickInfo.hasSwiped) {
  25341. if (clickInfo.singleClick && this.onPointerObservable.hasSpecificMask(BABYLON.PointerEventTypes.POINTERTAP)) {
  25342. var type_2 = BABYLON.PointerEventTypes.POINTERTAP;
  25343. var pi = new BABYLON.PointerInfo(type_2, evt, pickResult);
  25344. this._setRayOnPointerInfo(pi);
  25345. this.onPointerObservable.notifyObservers(pi, type_2);
  25346. }
  25347. if (clickInfo.doubleClick && this.onPointerObservable.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP)) {
  25348. var type_3 = BABYLON.PointerEventTypes.POINTERDOUBLETAP;
  25349. var pi = new BABYLON.PointerInfo(type_3, evt, pickResult);
  25350. this._setRayOnPointerInfo(pi);
  25351. this.onPointerObservable.notifyObservers(pi, type_3);
  25352. }
  25353. }
  25354. }
  25355. else {
  25356. var pi = new BABYLON.PointerInfo(type, evt, pickResult);
  25357. this._setRayOnPointerInfo(pi);
  25358. this.onPointerObservable.notifyObservers(pi, type);
  25359. }
  25360. }
  25361. if (this.onPointerUp) {
  25362. this.onPointerUp(evt, pickResult, type);
  25363. }
  25364. return this;
  25365. };
  25366. /**
  25367. * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)
  25368. * @param pointerId defines the pointer id to use in a multi-touch scenario (0 by default)
  25369. * @returns true if the pointer was captured
  25370. */
  25371. Scene.prototype.isPointerCaptured = function (pointerId) {
  25372. if (pointerId === void 0) { pointerId = 0; }
  25373. return this._pointerCaptures[pointerId];
  25374. };
  25375. /**
  25376. * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp
  25377. * @param attachUp defines if you want to attach events to pointerup
  25378. * @param attachDown defines if you want to attach events to pointerdown
  25379. * @param attachMove defines if you want to attach events to pointermove
  25380. */
  25381. Scene.prototype.attachControl = function (attachUp, attachDown, attachMove) {
  25382. var _this = this;
  25383. if (attachUp === void 0) { attachUp = true; }
  25384. if (attachDown === void 0) { attachDown = true; }
  25385. if (attachMove === void 0) { attachMove = true; }
  25386. this._initActionManager = function (act, clickInfo) {
  25387. if (!_this._meshPickProceed) {
  25388. var pickResult = _this.pick(_this._unTranslatedPointerX, _this._unTranslatedPointerY, _this.pointerDownPredicate, false, _this.cameraToUseForPointers);
  25389. _this._currentPickResult = pickResult;
  25390. if (pickResult) {
  25391. act = (pickResult.hit && pickResult.pickedMesh) ? pickResult.pickedMesh.actionManager : null;
  25392. }
  25393. _this._meshPickProceed = true;
  25394. }
  25395. return act;
  25396. };
  25397. this._delayedSimpleClick = function (btn, clickInfo, cb) {
  25398. // double click delay is over and that no double click has been raised since, or the 2 consecutive keys pressed are different
  25399. if ((Date.now() - _this._previousStartingPointerTime > Scene.DoubleClickDelay && !_this._doubleClickOccured) ||
  25400. btn !== _this._previousButtonPressed) {
  25401. _this._doubleClickOccured = false;
  25402. clickInfo.singleClick = true;
  25403. clickInfo.ignore = false;
  25404. cb(clickInfo, _this._currentPickResult);
  25405. }
  25406. };
  25407. this._initClickEvent = function (obs1, obs2, evt, cb) {
  25408. var clickInfo = new ClickInfo();
  25409. _this._currentPickResult = null;
  25410. var act = null;
  25411. var checkPicking = obs1.hasSpecificMask(BABYLON.PointerEventTypes.POINTERPICK) || obs2.hasSpecificMask(BABYLON.PointerEventTypes.POINTERPICK)
  25412. || obs1.hasSpecificMask(BABYLON.PointerEventTypes.POINTERTAP) || obs2.hasSpecificMask(BABYLON.PointerEventTypes.POINTERTAP)
  25413. || obs1.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP) || obs2.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP);
  25414. if (!checkPicking && BABYLON.ActionManager && BABYLON.ActionManager.HasPickTriggers) {
  25415. act = _this._initActionManager(act, clickInfo);
  25416. if (act)
  25417. checkPicking = act.hasPickTriggers;
  25418. }
  25419. if (checkPicking) {
  25420. var btn = evt.button;
  25421. clickInfo.hasSwiped = Math.abs(_this._startingPointerPosition.x - _this._pointerX) > Scene.DragMovementThreshold ||
  25422. Math.abs(_this._startingPointerPosition.y - _this._pointerY) > Scene.DragMovementThreshold;
  25423. if (!clickInfo.hasSwiped) {
  25424. var checkSingleClickImmediately = !Scene.ExclusiveDoubleClickMode;
  25425. if (!checkSingleClickImmediately) {
  25426. checkSingleClickImmediately = !obs1.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP) &&
  25427. !obs2.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP);
  25428. if (checkSingleClickImmediately && !BABYLON.ActionManager.HasSpecificTrigger(BABYLON.ActionManager.OnDoublePickTrigger)) {
  25429. act = _this._initActionManager(act, clickInfo);
  25430. if (act)
  25431. checkSingleClickImmediately = !act.hasSpecificTrigger(BABYLON.ActionManager.OnDoublePickTrigger);
  25432. }
  25433. }
  25434. if (checkSingleClickImmediately) {
  25435. // single click detected if double click delay is over or two different successive keys pressed without exclusive double click or no double click required
  25436. if (Date.now() - _this._previousStartingPointerTime > Scene.DoubleClickDelay ||
  25437. btn !== _this._previousButtonPressed) {
  25438. clickInfo.singleClick = true;
  25439. cb(clickInfo, _this._currentPickResult);
  25440. }
  25441. }
  25442. // at least one double click is required to be check and exclusive double click is enabled
  25443. else {
  25444. // wait that no double click has been raised during the double click delay
  25445. _this._previousDelayedSimpleClickTimeout = _this._delayedSimpleClickTimeout;
  25446. _this._delayedSimpleClickTimeout = window.setTimeout(_this._delayedSimpleClick.bind(_this, btn, clickInfo, cb), Scene.DoubleClickDelay);
  25447. }
  25448. var checkDoubleClick = obs1.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP) ||
  25449. obs2.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP);
  25450. if (!checkDoubleClick && BABYLON.ActionManager.HasSpecificTrigger(BABYLON.ActionManager.OnDoublePickTrigger)) {
  25451. act = _this._initActionManager(act, clickInfo);
  25452. if (act)
  25453. checkDoubleClick = act.hasSpecificTrigger(BABYLON.ActionManager.OnDoublePickTrigger);
  25454. }
  25455. if (checkDoubleClick) {
  25456. // two successive keys pressed are equal, double click delay is not over and double click has not just occurred
  25457. if (btn === _this._previousButtonPressed &&
  25458. Date.now() - _this._previousStartingPointerTime < Scene.DoubleClickDelay &&
  25459. !_this._doubleClickOccured) {
  25460. // pointer has not moved for 2 clicks, it's a double click
  25461. if (!clickInfo.hasSwiped &&
  25462. Math.abs(_this._previousStartingPointerPosition.x - _this._startingPointerPosition.x) < Scene.DragMovementThreshold &&
  25463. Math.abs(_this._previousStartingPointerPosition.y - _this._startingPointerPosition.y) < Scene.DragMovementThreshold) {
  25464. _this._previousStartingPointerTime = 0;
  25465. _this._doubleClickOccured = true;
  25466. clickInfo.doubleClick = true;
  25467. clickInfo.ignore = false;
  25468. if (Scene.ExclusiveDoubleClickMode && _this._previousDelayedSimpleClickTimeout) {
  25469. clearTimeout(_this._previousDelayedSimpleClickTimeout);
  25470. }
  25471. _this._previousDelayedSimpleClickTimeout = _this._delayedSimpleClickTimeout;
  25472. cb(clickInfo, _this._currentPickResult);
  25473. }
  25474. // if the two successive clicks are too far, it's just two simple clicks
  25475. else {
  25476. _this._doubleClickOccured = false;
  25477. _this._previousStartingPointerTime = _this._startingPointerTime;
  25478. _this._previousStartingPointerPosition.x = _this._startingPointerPosition.x;
  25479. _this._previousStartingPointerPosition.y = _this._startingPointerPosition.y;
  25480. _this._previousButtonPressed = btn;
  25481. if (Scene.ExclusiveDoubleClickMode) {
  25482. if (_this._previousDelayedSimpleClickTimeout) {
  25483. clearTimeout(_this._previousDelayedSimpleClickTimeout);
  25484. }
  25485. _this._previousDelayedSimpleClickTimeout = _this._delayedSimpleClickTimeout;
  25486. cb(clickInfo, _this._previousPickResult);
  25487. }
  25488. else {
  25489. cb(clickInfo, _this._currentPickResult);
  25490. }
  25491. }
  25492. }
  25493. // just the first click of the double has been raised
  25494. else {
  25495. _this._doubleClickOccured = false;
  25496. _this._previousStartingPointerTime = _this._startingPointerTime;
  25497. _this._previousStartingPointerPosition.x = _this._startingPointerPosition.x;
  25498. _this._previousStartingPointerPosition.y = _this._startingPointerPosition.y;
  25499. _this._previousButtonPressed = btn;
  25500. }
  25501. }
  25502. }
  25503. }
  25504. clickInfo.ignore = true;
  25505. cb(clickInfo, _this._currentPickResult);
  25506. };
  25507. this._spritePredicate = function (sprite) {
  25508. return sprite.isPickable && sprite.actionManager && sprite.actionManager.hasPointerTriggers;
  25509. };
  25510. this._onPointerMove = function (evt) {
  25511. _this._updatePointerPosition(evt);
  25512. // PreObservable support
  25513. if (_this._checkPrePointerObservable(null, evt, evt.type === "mousewheel" || evt.type === "DOMMouseScroll" ? BABYLON.PointerEventTypes.POINTERWHEEL : BABYLON.PointerEventTypes.POINTERMOVE)) {
  25514. return;
  25515. }
  25516. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  25517. return;
  25518. }
  25519. if (!_this.pointerMovePredicate) {
  25520. _this.pointerMovePredicate = function (mesh) { return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled() && (mesh.enablePointerMoveEvents || _this.constantlyUpdateMeshUnderPointer || (mesh.actionManager !== null && mesh.actionManager !== undefined)); };
  25521. }
  25522. // Meshes
  25523. var pickResult = _this.pick(_this._unTranslatedPointerX, _this._unTranslatedPointerY, _this.pointerMovePredicate, false, _this.cameraToUseForPointers);
  25524. _this._processPointerMove(pickResult, evt);
  25525. };
  25526. this._onPointerDown = function (evt) {
  25527. _this._totalPointersPressed++;
  25528. _this._pickedDownMesh = null;
  25529. _this._meshPickProceed = false;
  25530. _this._updatePointerPosition(evt);
  25531. if (_this.preventDefaultOnPointerDown && canvas) {
  25532. evt.preventDefault();
  25533. canvas.focus();
  25534. }
  25535. // PreObservable support
  25536. if (_this._checkPrePointerObservable(null, evt, BABYLON.PointerEventTypes.POINTERDOWN)) {
  25537. return;
  25538. }
  25539. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  25540. return;
  25541. }
  25542. _this._pointerCaptures[evt.pointerId] = true;
  25543. _this._startingPointerPosition.x = _this._pointerX;
  25544. _this._startingPointerPosition.y = _this._pointerY;
  25545. _this._startingPointerTime = Date.now();
  25546. if (!_this.pointerDownPredicate) {
  25547. _this.pointerDownPredicate = function (mesh) {
  25548. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled();
  25549. };
  25550. }
  25551. // Meshes
  25552. _this._pickedDownMesh = null;
  25553. var pickResult = _this.pick(_this._unTranslatedPointerX, _this._unTranslatedPointerY, _this.pointerDownPredicate, false, _this.cameraToUseForPointers);
  25554. _this._processPointerDown(pickResult, evt);
  25555. // Sprites
  25556. _this._pickedDownSprite = null;
  25557. if (_this.spriteManagers.length > 0) {
  25558. pickResult = _this.pickSprite(_this._unTranslatedPointerX, _this._unTranslatedPointerY, _this._spritePredicate, false, _this.cameraToUseForPointers || undefined);
  25559. if (pickResult && pickResult.hit && pickResult.pickedSprite) {
  25560. if (pickResult.pickedSprite.actionManager) {
  25561. _this._pickedDownSprite = pickResult.pickedSprite;
  25562. switch (evt.button) {
  25563. case 0:
  25564. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  25565. break;
  25566. case 1:
  25567. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  25568. break;
  25569. case 2:
  25570. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  25571. break;
  25572. }
  25573. if (pickResult.pickedSprite.actionManager) {
  25574. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  25575. }
  25576. }
  25577. }
  25578. }
  25579. };
  25580. this._onPointerUp = function (evt) {
  25581. if (_this._totalPointersPressed === 0) { // We are attaching the pointer up to windows because of a bug in FF
  25582. return; // So we need to test it the pointer down was pressed before.
  25583. }
  25584. _this._totalPointersPressed--;
  25585. _this._pickedUpMesh = null;
  25586. _this._meshPickProceed = false;
  25587. _this._updatePointerPosition(evt);
  25588. _this._initClickEvent(_this.onPrePointerObservable, _this.onPointerObservable, evt, function (clickInfo, pickResult) {
  25589. // PreObservable support
  25590. if (_this.onPrePointerObservable.hasObservers()) {
  25591. if (!clickInfo.ignore) {
  25592. if (!clickInfo.hasSwiped) {
  25593. if (clickInfo.singleClick && _this.onPrePointerObservable.hasSpecificMask(BABYLON.PointerEventTypes.POINTERTAP)) {
  25594. if (_this._checkPrePointerObservable(null, evt, BABYLON.PointerEventTypes.POINTERTAP)) {
  25595. return;
  25596. }
  25597. }
  25598. if (clickInfo.doubleClick && _this.onPrePointerObservable.hasSpecificMask(BABYLON.PointerEventTypes.POINTERDOUBLETAP)) {
  25599. if (_this._checkPrePointerObservable(null, evt, BABYLON.PointerEventTypes.POINTERDOUBLETAP)) {
  25600. return;
  25601. }
  25602. }
  25603. }
  25604. }
  25605. else {
  25606. if (_this._checkPrePointerObservable(null, evt, BABYLON.PointerEventTypes.POINTERUP)) {
  25607. return;
  25608. }
  25609. }
  25610. }
  25611. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  25612. return;
  25613. }
  25614. _this._pointerCaptures[evt.pointerId] = false;
  25615. if (!_this.pointerUpPredicate) {
  25616. _this.pointerUpPredicate = function (mesh) {
  25617. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled();
  25618. };
  25619. }
  25620. // Meshes
  25621. if (!_this._meshPickProceed && (BABYLON.ActionManager && BABYLON.ActionManager.HasTriggers || _this.onPointerObservable.hasObservers())) {
  25622. _this._initActionManager(null, clickInfo);
  25623. }
  25624. if (!pickResult) {
  25625. pickResult = _this._currentPickResult;
  25626. }
  25627. _this._processPointerUp(pickResult, evt, clickInfo);
  25628. // Sprites
  25629. if (!clickInfo.ignore) {
  25630. if (_this.spriteManagers.length > 0) {
  25631. var spritePickResult = _this.pickSprite(_this._unTranslatedPointerX, _this._unTranslatedPointerY, _this._spritePredicate, false, _this.cameraToUseForPointers || undefined);
  25632. if (spritePickResult) {
  25633. if (spritePickResult.hit && spritePickResult.pickedSprite) {
  25634. if (spritePickResult.pickedSprite.actionManager) {
  25635. spritePickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, BABYLON.ActionEvent.CreateNewFromSprite(spritePickResult.pickedSprite, _this, evt));
  25636. if (spritePickResult.pickedSprite.actionManager) {
  25637. if (Math.abs(_this._startingPointerPosition.x - _this._pointerX) < Scene.DragMovementThreshold && Math.abs(_this._startingPointerPosition.y - _this._pointerY) < Scene.DragMovementThreshold) {
  25638. spritePickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(spritePickResult.pickedSprite, _this, evt));
  25639. }
  25640. }
  25641. }
  25642. }
  25643. if (_this._pickedDownSprite && _this._pickedDownSprite.actionManager && _this._pickedDownSprite !== spritePickResult.pickedSprite) {
  25644. _this._pickedDownSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, BABYLON.ActionEvent.CreateNewFromSprite(_this._pickedDownSprite, _this, evt));
  25645. }
  25646. }
  25647. }
  25648. }
  25649. _this._previousPickResult = _this._currentPickResult;
  25650. });
  25651. };
  25652. this._onKeyDown = function (evt) {
  25653. var type = BABYLON.KeyboardEventTypes.KEYDOWN;
  25654. if (_this.onPreKeyboardObservable.hasObservers()) {
  25655. var pi = new BABYLON.KeyboardInfoPre(type, evt);
  25656. _this.onPreKeyboardObservable.notifyObservers(pi, type);
  25657. if (pi.skipOnPointerObservable) {
  25658. return;
  25659. }
  25660. }
  25661. if (_this.onKeyboardObservable.hasObservers()) {
  25662. var pi = new BABYLON.KeyboardInfo(type, evt);
  25663. _this.onKeyboardObservable.notifyObservers(pi, type);
  25664. }
  25665. if (_this.actionManager) {
  25666. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  25667. }
  25668. };
  25669. this._onKeyUp = function (evt) {
  25670. var type = BABYLON.KeyboardEventTypes.KEYUP;
  25671. if (_this.onPreKeyboardObservable.hasObservers()) {
  25672. var pi = new BABYLON.KeyboardInfoPre(type, evt);
  25673. _this.onPreKeyboardObservable.notifyObservers(pi, type);
  25674. if (pi.skipOnPointerObservable) {
  25675. return;
  25676. }
  25677. }
  25678. if (_this.onKeyboardObservable.hasObservers()) {
  25679. var pi = new BABYLON.KeyboardInfo(type, evt);
  25680. _this.onKeyboardObservable.notifyObservers(pi, type);
  25681. }
  25682. if (_this.actionManager) {
  25683. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  25684. }
  25685. };
  25686. var engine = this.getEngine();
  25687. this._onCanvasFocusObserver = engine.onCanvasFocusObservable.add(function () {
  25688. if (!canvas) {
  25689. return;
  25690. }
  25691. canvas.addEventListener("keydown", _this._onKeyDown, false);
  25692. canvas.addEventListener("keyup", _this._onKeyUp, false);
  25693. });
  25694. this._onCanvasBlurObserver = engine.onCanvasBlurObservable.add(function () {
  25695. if (!canvas) {
  25696. return;
  25697. }
  25698. canvas.removeEventListener("keydown", _this._onKeyDown);
  25699. canvas.removeEventListener("keyup", _this._onKeyUp);
  25700. });
  25701. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  25702. var canvas = this._engine.getRenderingCanvas();
  25703. if (!canvas) {
  25704. return;
  25705. }
  25706. if (attachMove) {
  25707. canvas.addEventListener(eventPrefix + "move", this._onPointerMove, false);
  25708. // Wheel
  25709. canvas.addEventListener('mousewheel', this._onPointerMove, false);
  25710. canvas.addEventListener('DOMMouseScroll', this._onPointerMove, false);
  25711. }
  25712. if (attachDown) {
  25713. canvas.addEventListener(eventPrefix + "down", this._onPointerDown, false);
  25714. }
  25715. if (attachUp) {
  25716. window.addEventListener(eventPrefix + "up", this._onPointerUp, false);
  25717. }
  25718. canvas.tabIndex = 1;
  25719. };
  25720. /** Detaches all event handlers*/
  25721. Scene.prototype.detachControl = function () {
  25722. var engine = this.getEngine();
  25723. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  25724. var canvas = engine.getRenderingCanvas();
  25725. if (!canvas) {
  25726. return;
  25727. }
  25728. canvas.removeEventListener(eventPrefix + "move", this._onPointerMove);
  25729. canvas.removeEventListener(eventPrefix + "down", this._onPointerDown);
  25730. window.removeEventListener(eventPrefix + "up", this._onPointerUp);
  25731. if (this._onCanvasBlurObserver) {
  25732. engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);
  25733. }
  25734. if (this._onCanvasFocusObserver) {
  25735. engine.onCanvasFocusObservable.remove(this._onCanvasFocusObserver);
  25736. }
  25737. // Wheel
  25738. canvas.removeEventListener('mousewheel', this._onPointerMove);
  25739. canvas.removeEventListener('DOMMouseScroll', this._onPointerMove);
  25740. // Keyboard
  25741. canvas.removeEventListener("keydown", this._onKeyDown);
  25742. canvas.removeEventListener("keyup", this._onKeyUp);
  25743. // Observables
  25744. this.onKeyboardObservable.clear();
  25745. this.onPreKeyboardObservable.clear();
  25746. this.onPointerObservable.clear();
  25747. this.onPrePointerObservable.clear();
  25748. };
  25749. /**
  25750. * This function will check if the scene can be rendered (textures are loaded, shaders are compiled)
  25751. * Delay loaded resources are not taking in account
  25752. * @return true if all required resources are ready
  25753. */
  25754. Scene.prototype.isReady = function () {
  25755. if (this._isDisposed) {
  25756. return false;
  25757. }
  25758. if (this._pendingData.length > 0) {
  25759. return false;
  25760. }
  25761. var index;
  25762. var engine = this.getEngine();
  25763. // Geometries
  25764. for (index = 0; index < this._geometries.length; index++) {
  25765. var geometry = this._geometries[index];
  25766. if (geometry.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  25767. return false;
  25768. }
  25769. }
  25770. // Meshes
  25771. for (index = 0; index < this.meshes.length; index++) {
  25772. var mesh = this.meshes[index];
  25773. if (!mesh.isEnabled()) {
  25774. continue;
  25775. }
  25776. if (!mesh.subMeshes || mesh.subMeshes.length === 0) {
  25777. continue;
  25778. }
  25779. if (!mesh.isReady(true)) {
  25780. return false;
  25781. }
  25782. // Effect layers
  25783. var hardwareInstancedRendering = mesh.getClassName() === "InstancedMesh" || engine.getCaps().instancedArrays && mesh.instances.length > 0;
  25784. for (var _i = 0, _a = this.effectLayers; _i < _a.length; _i++) {
  25785. var layer = _a[_i];
  25786. if (!layer.hasMesh(mesh)) {
  25787. continue;
  25788. }
  25789. for (var _b = 0, _c = mesh.subMeshes; _b < _c.length; _b++) {
  25790. var subMesh = _c[_b];
  25791. if (!layer.isReady(subMesh, hardwareInstancedRendering)) {
  25792. return false;
  25793. }
  25794. }
  25795. }
  25796. }
  25797. // Post-processes
  25798. if (this.activeCameras && this.activeCameras.length > 0) {
  25799. for (var _d = 0, _e = this.activeCameras; _d < _e.length; _d++) {
  25800. var camera = _e[_d];
  25801. if (!camera.isReady(true)) {
  25802. return false;
  25803. }
  25804. }
  25805. }
  25806. else if (this.activeCamera) {
  25807. if (!this.activeCamera.isReady(true)) {
  25808. return false;
  25809. }
  25810. }
  25811. // Particles
  25812. for (var _f = 0, _g = this.particleSystems; _f < _g.length; _f++) {
  25813. var particleSystem = _g[_f];
  25814. if (!particleSystem.isReady()) {
  25815. return false;
  25816. }
  25817. }
  25818. return true;
  25819. };
  25820. /** Resets all cached information relative to material (including effect and visibility) */
  25821. Scene.prototype.resetCachedMaterial = function () {
  25822. this._cachedMaterial = null;
  25823. this._cachedEffect = null;
  25824. this._cachedVisibility = null;
  25825. };
  25826. /**
  25827. * Registers a function to be called before every frame render
  25828. * @param func defines the function to register
  25829. */
  25830. Scene.prototype.registerBeforeRender = function (func) {
  25831. this.onBeforeRenderObservable.add(func);
  25832. };
  25833. /**
  25834. * Unregisters a function called before every frame render
  25835. * @param func defines the function to unregister
  25836. */
  25837. Scene.prototype.unregisterBeforeRender = function (func) {
  25838. this.onBeforeRenderObservable.removeCallback(func);
  25839. };
  25840. /**
  25841. * Registers a function to be called after every frame render
  25842. * @param func defines the function to register
  25843. */
  25844. Scene.prototype.registerAfterRender = function (func) {
  25845. this.onAfterRenderObservable.add(func);
  25846. };
  25847. /**
  25848. * Unregisters a function called after every frame render
  25849. * @param func defines the function to unregister
  25850. */
  25851. Scene.prototype.unregisterAfterRender = function (func) {
  25852. this.onAfterRenderObservable.removeCallback(func);
  25853. };
  25854. Scene.prototype._executeOnceBeforeRender = function (func) {
  25855. var _this = this;
  25856. var execFunc = function () {
  25857. func();
  25858. setTimeout(function () {
  25859. _this.unregisterBeforeRender(execFunc);
  25860. });
  25861. };
  25862. this.registerBeforeRender(execFunc);
  25863. };
  25864. /**
  25865. * The provided function will run before render once and will be disposed afterwards.
  25866. * A timeout delay can be provided so that the function will be executed in N ms.
  25867. * The timeout is using the browser's native setTimeout so time percision cannot be guaranteed.
  25868. * @param func The function to be executed.
  25869. * @param timeout optional delay in ms
  25870. */
  25871. Scene.prototype.executeOnceBeforeRender = function (func, timeout) {
  25872. var _this = this;
  25873. if (timeout !== undefined) {
  25874. setTimeout(function () {
  25875. _this._executeOnceBeforeRender(func);
  25876. }, timeout);
  25877. }
  25878. else {
  25879. this._executeOnceBeforeRender(func);
  25880. }
  25881. };
  25882. /** @hidden */
  25883. Scene.prototype._addPendingData = function (data) {
  25884. this._pendingData.push(data);
  25885. };
  25886. /** @hidden */
  25887. Scene.prototype._removePendingData = function (data) {
  25888. var wasLoading = this.isLoading;
  25889. var index = this._pendingData.indexOf(data);
  25890. if (index !== -1) {
  25891. this._pendingData.splice(index, 1);
  25892. }
  25893. if (wasLoading && !this.isLoading) {
  25894. this.onDataLoadedObservable.notifyObservers(this);
  25895. }
  25896. };
  25897. /**
  25898. * Returns the number of items waiting to be loaded
  25899. * @returns the number of items waiting to be loaded
  25900. */
  25901. Scene.prototype.getWaitingItemsCount = function () {
  25902. return this._pendingData.length;
  25903. };
  25904. Object.defineProperty(Scene.prototype, "isLoading", {
  25905. /**
  25906. * Returns a boolean indicating if the scene is still loading data
  25907. */
  25908. get: function () {
  25909. return this._pendingData.length > 0;
  25910. },
  25911. enumerable: true,
  25912. configurable: true
  25913. });
  25914. /**
  25915. * Registers a function to be executed when the scene is ready
  25916. * @param {Function} func - the function to be executed
  25917. */
  25918. Scene.prototype.executeWhenReady = function (func) {
  25919. var _this = this;
  25920. this.onReadyObservable.add(func);
  25921. if (this._executeWhenReadyTimeoutId !== -1) {
  25922. return;
  25923. }
  25924. this._executeWhenReadyTimeoutId = setTimeout(function () {
  25925. _this._checkIsReady();
  25926. }, 150);
  25927. };
  25928. /**
  25929. * Returns a promise that resolves when the scene is ready
  25930. * @returns A promise that resolves when the scene is ready
  25931. */
  25932. Scene.prototype.whenReadyAsync = function () {
  25933. var _this = this;
  25934. return new Promise(function (resolve) {
  25935. _this.executeWhenReady(function () {
  25936. resolve();
  25937. });
  25938. });
  25939. };
  25940. /** @hidden */
  25941. Scene.prototype._checkIsReady = function () {
  25942. var _this = this;
  25943. if (this.isReady()) {
  25944. this.onReadyObservable.notifyObservers(this);
  25945. this.onReadyObservable.clear();
  25946. this._executeWhenReadyTimeoutId = -1;
  25947. return;
  25948. }
  25949. this._executeWhenReadyTimeoutId = setTimeout(function () {
  25950. _this._checkIsReady();
  25951. }, 150);
  25952. };
  25953. // Animations
  25954. /**
  25955. * Will start the animation sequence of a given target
  25956. * @param target defines the target
  25957. * @param from defines from which frame should animation start
  25958. * @param to defines until which frame should animation run.
  25959. * @param weight defines the weight to apply to the animation (1.0 by default)
  25960. * @param loop defines if the animation loops
  25961. * @param speedRatio defines the speed in which to run the animation (1.0 by default)
  25962. * @param onAnimationEnd defines the function to be executed when the animation ends
  25963. * @param animatable defines an animatable object. If not provided a new one will be created from the given params
  25964. * @returns the animatable object created for this animation
  25965. */
  25966. Scene.prototype.beginWeightedAnimation = function (target, from, to, weight, loop, speedRatio, onAnimationEnd, animatable) {
  25967. if (weight === void 0) { weight = 1.0; }
  25968. if (speedRatio === void 0) { speedRatio = 1.0; }
  25969. var returnedAnimatable = this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, false);
  25970. returnedAnimatable.weight = weight;
  25971. return returnedAnimatable;
  25972. };
  25973. /**
  25974. * Will start the animation sequence of a given target
  25975. * @param target defines the target
  25976. * @param from defines from which frame should animation start
  25977. * @param to defines until which frame should animation run.
  25978. * @param loop defines if the animation loops
  25979. * @param speedRatio defines the speed in which to run the animation (1.0 by default)
  25980. * @param onAnimationEnd defines the function to be executed when the animation ends
  25981. * @param animatable defines an animatable object. If not provided a new one will be created from the given params
  25982. * @param stopCurrent defines if the current animations must be stopped first (true by default)
  25983. * @returns the animatable object created for this animation
  25984. */
  25985. Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent) {
  25986. if (speedRatio === void 0) { speedRatio = 1.0; }
  25987. if (stopCurrent === void 0) { stopCurrent = true; }
  25988. if (from > to && speedRatio > 0) {
  25989. speedRatio *= -1;
  25990. }
  25991. if (stopCurrent) {
  25992. this.stopAnimation(target);
  25993. }
  25994. if (!animatable) {
  25995. animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
  25996. }
  25997. // Local animations
  25998. if (target.animations) {
  25999. animatable.appendAnimations(target, target.animations);
  26000. }
  26001. // Children animations
  26002. if (target.getAnimatables) {
  26003. var animatables = target.getAnimatables();
  26004. for (var index = 0; index < animatables.length; index++) {
  26005. this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent);
  26006. }
  26007. }
  26008. animatable.reset();
  26009. return animatable;
  26010. };
  26011. /**
  26012. * Begin a new animation on a given node
  26013. * @param target defines the target where the animation will take place
  26014. * @param animations defines the list of animations to start
  26015. * @param from defines the initial value
  26016. * @param to defines the final value
  26017. * @param loop defines if you want animation to loop (off by default)
  26018. * @param speedRatio defines the speed ratio to apply to all animations
  26019. * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)
  26020. * @returns the list of created animatables
  26021. */
  26022. Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd) {
  26023. if (speedRatio === undefined) {
  26024. speedRatio = 1.0;
  26025. }
  26026. var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
  26027. return animatable;
  26028. };
  26029. /**
  26030. * Begin a new animation on a given node and its hierarchy
  26031. * @param target defines the root node where the animation will take place
  26032. * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used.
  26033. * @param animations defines the list of animations to start
  26034. * @param from defines the initial value
  26035. * @param to defines the final value
  26036. * @param loop defines if you want animation to loop (off by default)
  26037. * @param speedRatio defines the speed ratio to apply to all animations
  26038. * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)
  26039. * @returns the list of animatables created for all nodes
  26040. */
  26041. Scene.prototype.beginDirectHierarchyAnimation = function (target, directDescendantsOnly, animations, from, to, loop, speedRatio, onAnimationEnd) {
  26042. var children = target.getDescendants(directDescendantsOnly);
  26043. var result = [];
  26044. result.push(this.beginDirectAnimation(target, animations, from, to, loop, speedRatio, onAnimationEnd));
  26045. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  26046. var child = children_1[_i];
  26047. result.push(this.beginDirectAnimation(child, animations, from, to, loop, speedRatio, onAnimationEnd));
  26048. }
  26049. return result;
  26050. };
  26051. /**
  26052. * Gets the animatable associated with a specific target
  26053. * @param target defines the target of the animatable
  26054. * @returns the required animatable if found
  26055. */
  26056. Scene.prototype.getAnimatableByTarget = function (target) {
  26057. for (var index = 0; index < this._activeAnimatables.length; index++) {
  26058. if (this._activeAnimatables[index].target === target) {
  26059. return this._activeAnimatables[index];
  26060. }
  26061. }
  26062. return null;
  26063. };
  26064. /**
  26065. * Gets all animatables associated with a given target
  26066. * @param target defines the target to look animatables for
  26067. * @returns an array of Animatables
  26068. */
  26069. Scene.prototype.getAllAnimatablesByTarget = function (target) {
  26070. var result = [];
  26071. for (var index = 0; index < this._activeAnimatables.length; index++) {
  26072. if (this._activeAnimatables[index].target === target) {
  26073. result.push(this._activeAnimatables[index]);
  26074. }
  26075. }
  26076. return result;
  26077. };
  26078. Object.defineProperty(Scene.prototype, "animatables", {
  26079. /**
  26080. * Gets all animatable attached to the scene
  26081. */
  26082. get: function () {
  26083. return this._activeAnimatables;
  26084. },
  26085. enumerable: true,
  26086. configurable: true
  26087. });
  26088. /**
  26089. * Will stop the animation of the given target
  26090. * @param target - the target
  26091. * @param animationName - the name of the animation to stop (all animations will be stopped if empty)
  26092. */
  26093. Scene.prototype.stopAnimation = function (target, animationName) {
  26094. var animatables = this.getAllAnimatablesByTarget(target);
  26095. for (var _i = 0, animatables_1 = animatables; _i < animatables_1.length; _i++) {
  26096. var animatable = animatables_1[_i];
  26097. animatable.stop(animationName);
  26098. }
  26099. };
  26100. /**
  26101. * Stops and removes all animations that have been applied to the scene
  26102. */
  26103. Scene.prototype.stopAllAnimations = function () {
  26104. if (this._activeAnimatables) {
  26105. for (var i = 0; i < this._activeAnimatables.length; i++) {
  26106. this._activeAnimatables[i].stop();
  26107. }
  26108. this._activeAnimatables = [];
  26109. }
  26110. for (var _i = 0, _a = this.animationGroups; _i < _a.length; _i++) {
  26111. var group = _a[_i];
  26112. group.stop();
  26113. }
  26114. };
  26115. Scene.prototype._animate = function () {
  26116. if (!this.animationsEnabled || this._activeAnimatables.length === 0) {
  26117. return;
  26118. }
  26119. // Getting time
  26120. var now = BABYLON.Tools.Now;
  26121. if (!this._animationTimeLast) {
  26122. if (this._pendingData.length > 0) {
  26123. return;
  26124. }
  26125. this._animationTimeLast = now;
  26126. }
  26127. var deltaTime = this.useConstantAnimationDeltaTime ? 16.0 : (now - this._animationTimeLast) * this.animationTimeScale;
  26128. this._animationTime += deltaTime;
  26129. this._animationTimeLast = now;
  26130. for (var index = 0; index < this._activeAnimatables.length; index++) {
  26131. this._activeAnimatables[index]._animate(this._animationTime);
  26132. }
  26133. // Late animation bindings
  26134. this._processLateAnimationBindings();
  26135. };
  26136. /** @hidden */
  26137. Scene.prototype._registerTargetForLateAnimationBinding = function (runtimeAnimation, originalValue) {
  26138. var target = runtimeAnimation.target;
  26139. this._registeredForLateAnimationBindings.pushNoDuplicate(target);
  26140. if (!target._lateAnimationHolders) {
  26141. target._lateAnimationHolders = {};
  26142. }
  26143. if (!target._lateAnimationHolders[runtimeAnimation.targetPath]) {
  26144. target._lateAnimationHolders[runtimeAnimation.targetPath] = {
  26145. totalWeight: 0,
  26146. animations: [],
  26147. originalValue: originalValue
  26148. };
  26149. }
  26150. target._lateAnimationHolders[runtimeAnimation.targetPath].animations.push(runtimeAnimation);
  26151. target._lateAnimationHolders[runtimeAnimation.targetPath].totalWeight += runtimeAnimation.weight;
  26152. };
  26153. Scene.prototype._processLateAnimationBindingsForMatrices = function (holder) {
  26154. var normalizer = 1.0;
  26155. var finalPosition = BABYLON.Tmp.Vector3[0];
  26156. var finalScaling = BABYLON.Tmp.Vector3[1];
  26157. var finalQuaternion = BABYLON.Tmp.Quaternion[0];
  26158. var startIndex = 0;
  26159. var originalAnimation = holder.animations[0];
  26160. var originalValue = holder.originalValue;
  26161. var scale = 1;
  26162. if (holder.totalWeight < 1.0) {
  26163. // We need to mix the original value in
  26164. originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
  26165. scale = 1.0 - holder.totalWeight;
  26166. }
  26167. else {
  26168. startIndex = 1;
  26169. // We need to normalize the weights
  26170. normalizer = holder.totalWeight;
  26171. originalAnimation.currentValue.decompose(finalScaling, finalQuaternion, finalPosition);
  26172. scale = originalAnimation.weight / normalizer;
  26173. if (scale == 1) {
  26174. return originalAnimation.currentValue;
  26175. }
  26176. }
  26177. finalScaling.scaleInPlace(scale);
  26178. finalPosition.scaleInPlace(scale);
  26179. finalQuaternion.scaleInPlace(scale);
  26180. for (var animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {
  26181. var runtimeAnimation = holder.animations[animIndex];
  26182. var scale = runtimeAnimation.weight / normalizer;
  26183. var currentPosition = BABYLON.Tmp.Vector3[2];
  26184. var currentScaling = BABYLON.Tmp.Vector3[3];
  26185. var currentQuaternion = BABYLON.Tmp.Quaternion[1];
  26186. runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);
  26187. currentScaling.scaleAndAddToRef(scale, finalScaling);
  26188. currentQuaternion.scaleAndAddToRef(scale, finalQuaternion);
  26189. currentPosition.scaleAndAddToRef(scale, finalPosition);
  26190. }
  26191. BABYLON.Matrix.ComposeToRef(finalScaling, finalQuaternion, finalPosition, originalAnimation._workValue);
  26192. return originalAnimation._workValue;
  26193. };
  26194. Scene.prototype._processLateAnimationBindingsForQuaternions = function (holder) {
  26195. var originalAnimation = holder.animations[0];
  26196. var originalValue = holder.originalValue;
  26197. if (holder.animations.length === 1) {
  26198. return BABYLON.Quaternion.Slerp(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight));
  26199. }
  26200. var normalizer = 1.0;
  26201. var quaternions;
  26202. var weights;
  26203. if (holder.totalWeight < 1.0) {
  26204. var scale = 1.0 - holder.totalWeight;
  26205. quaternions = [];
  26206. weights = [];
  26207. quaternions.push(originalValue);
  26208. weights.push(scale);
  26209. }
  26210. else {
  26211. if (holder.animations.length === 2) { // Slerp as soon as we can
  26212. return BABYLON.Quaternion.Slerp(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
  26213. }
  26214. quaternions = [];
  26215. weights = [];
  26216. normalizer = holder.totalWeight;
  26217. }
  26218. for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
  26219. var runtimeAnimation = holder.animations[animIndex];
  26220. quaternions.push(runtimeAnimation.currentValue);
  26221. weights.push(runtimeAnimation.weight / normalizer);
  26222. }
  26223. // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
  26224. var cumulativeAmount = 0;
  26225. var cumulativeQuaternion = null;
  26226. for (var index = 0; index < quaternions.length;) {
  26227. if (!cumulativeQuaternion) {
  26228. cumulativeQuaternion = BABYLON.Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
  26229. cumulativeAmount = weights[index] + weights[index + 1];
  26230. index += 2;
  26231. continue;
  26232. }
  26233. cumulativeAmount += weights[index];
  26234. BABYLON.Quaternion.SlerpToRef(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount, cumulativeQuaternion);
  26235. index++;
  26236. }
  26237. return cumulativeQuaternion;
  26238. };
  26239. Scene.prototype._processLateAnimationBindings = function () {
  26240. if (!this._registeredForLateAnimationBindings.length) {
  26241. return;
  26242. }
  26243. for (var index = 0; index < this._registeredForLateAnimationBindings.length; index++) {
  26244. var target = this._registeredForLateAnimationBindings.data[index];
  26245. for (var path in target._lateAnimationHolders) {
  26246. var holder = target._lateAnimationHolders[path];
  26247. var originalAnimation = holder.animations[0];
  26248. var originalValue = holder.originalValue;
  26249. var matrixDecomposeMode = BABYLON.Animation.AllowMatrixDecomposeForInterpolation && originalValue.m; // ie. data is matrix
  26250. var finalValue = void 0;
  26251. if (matrixDecomposeMode) {
  26252. finalValue = this._processLateAnimationBindingsForMatrices(holder);
  26253. }
  26254. else {
  26255. var quaternionMode = originalValue.w !== undefined;
  26256. if (quaternionMode) {
  26257. finalValue = this._processLateAnimationBindingsForQuaternions(holder);
  26258. }
  26259. else {
  26260. var startIndex = 0;
  26261. var normalizer = 1.0;
  26262. if (holder.totalWeight < 1.0) {
  26263. // We need to mix the original value in
  26264. if (originalValue.scale) {
  26265. finalValue = originalValue.scale(1.0 - holder.totalWeight);
  26266. }
  26267. else {
  26268. finalValue = originalValue * (1.0 - holder.totalWeight);
  26269. }
  26270. }
  26271. else {
  26272. // We need to normalize the weights
  26273. normalizer = holder.totalWeight;
  26274. var scale_1 = originalAnimation.weight / normalizer;
  26275. if (scale_1 !== 1) {
  26276. if (originalAnimation.currentValue.scale) {
  26277. finalValue = originalAnimation.currentValue.scale(scale_1);
  26278. }
  26279. else {
  26280. finalValue = originalAnimation.currentValue * scale_1;
  26281. }
  26282. }
  26283. else {
  26284. finalValue = originalAnimation.currentValue;
  26285. }
  26286. startIndex = 1;
  26287. }
  26288. for (var animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {
  26289. var runtimeAnimation = holder.animations[animIndex];
  26290. var scale = runtimeAnimation.weight / normalizer;
  26291. if (runtimeAnimation.currentValue.scaleAndAddToRef) {
  26292. runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);
  26293. }
  26294. else {
  26295. finalValue += runtimeAnimation.currentValue * scale;
  26296. }
  26297. }
  26298. }
  26299. }
  26300. target[path] = finalValue;
  26301. }
  26302. target._lateAnimationHolders = {};
  26303. }
  26304. this._registeredForLateAnimationBindings.reset();
  26305. };
  26306. // Matrix
  26307. /** @hidden */
  26308. Scene.prototype._switchToAlternateCameraConfiguration = function (active) {
  26309. this._useAlternateCameraConfiguration = active;
  26310. };
  26311. /**
  26312. * Gets the current view matrix
  26313. * @returns a Matrix
  26314. */
  26315. Scene.prototype.getViewMatrix = function () {
  26316. return this._useAlternateCameraConfiguration ? this._alternateViewMatrix : this._viewMatrix;
  26317. };
  26318. /**
  26319. * Gets the current projection matrix
  26320. * @returns a Matrix
  26321. */
  26322. Scene.prototype.getProjectionMatrix = function () {
  26323. return this._useAlternateCameraConfiguration ? this._alternateProjectionMatrix : this._projectionMatrix;
  26324. };
  26325. /**
  26326. * Gets the current transform matrix
  26327. * @returns a Matrix made of View * Projection
  26328. */
  26329. Scene.prototype.getTransformMatrix = function () {
  26330. return this._useAlternateCameraConfiguration ? this._alternateTransformMatrix : this._transformMatrix;
  26331. };
  26332. /**
  26333. * Sets the current transform matrix
  26334. * @param view defines the View matrix to use
  26335. * @param projection defines the Projection matrix to use
  26336. */
  26337. Scene.prototype.setTransformMatrix = function (view, projection) {
  26338. if (this._viewUpdateFlag === view.updateFlag && this._projectionUpdateFlag === projection.updateFlag) {
  26339. return;
  26340. }
  26341. this._viewUpdateFlag = view.updateFlag;
  26342. this._projectionUpdateFlag = projection.updateFlag;
  26343. this._viewMatrix = view;
  26344. this._projectionMatrix = projection;
  26345. this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  26346. // Update frustum
  26347. if (!this._frustumPlanes) {
  26348. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  26349. }
  26350. else {
  26351. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  26352. }
  26353. if (this.activeCamera && this.activeCamera._alternateCamera) {
  26354. var otherCamera = this.activeCamera._alternateCamera;
  26355. otherCamera.getViewMatrix().multiplyToRef(otherCamera.getProjectionMatrix(), BABYLON.Tmp.Matrix[0]);
  26356. BABYLON.Frustum.GetRightPlaneToRef(BABYLON.Tmp.Matrix[0], this._frustumPlanes[3]); // Replace right plane by second camera right plane
  26357. }
  26358. if (this._sceneUbo.useUbo) {
  26359. this._sceneUbo.updateMatrix("viewProjection", this._transformMatrix);
  26360. this._sceneUbo.updateMatrix("view", this._viewMatrix);
  26361. this._sceneUbo.update();
  26362. }
  26363. };
  26364. /** @hidden */
  26365. Scene.prototype._setAlternateTransformMatrix = function (view, projection) {
  26366. if (this._alternateViewUpdateFlag === view.updateFlag && this._alternateProjectionUpdateFlag === projection.updateFlag) {
  26367. return;
  26368. }
  26369. this._alternateViewUpdateFlag = view.updateFlag;
  26370. this._alternateProjectionUpdateFlag = projection.updateFlag;
  26371. this._alternateViewMatrix = view;
  26372. this._alternateProjectionMatrix = projection;
  26373. if (!this._alternateTransformMatrix) {
  26374. this._alternateTransformMatrix = BABYLON.Matrix.Zero();
  26375. }
  26376. this._alternateViewMatrix.multiplyToRef(this._alternateProjectionMatrix, this._alternateTransformMatrix);
  26377. if (!this._alternateSceneUbo) {
  26378. this._createAlternateUbo();
  26379. }
  26380. if (this._alternateSceneUbo.useUbo) {
  26381. this._alternateSceneUbo.updateMatrix("viewProjection", this._alternateTransformMatrix);
  26382. this._alternateSceneUbo.updateMatrix("view", this._alternateViewMatrix);
  26383. this._alternateSceneUbo.update();
  26384. }
  26385. };
  26386. /**
  26387. * Gets the uniform buffer used to store scene data
  26388. * @returns a UniformBuffer
  26389. */
  26390. Scene.prototype.getSceneUniformBuffer = function () {
  26391. return this._useAlternateCameraConfiguration ? this._alternateSceneUbo : this._sceneUbo;
  26392. };
  26393. /**
  26394. * Gets an unique (relatively to the current scene) Id
  26395. * @returns an unique number for the scene
  26396. */
  26397. Scene.prototype.getUniqueId = function () {
  26398. var result = Scene._uniqueIdCounter;
  26399. Scene._uniqueIdCounter++;
  26400. return result;
  26401. };
  26402. /**
  26403. * Add a mesh to the list of scene's meshes
  26404. * @param newMesh defines the mesh to add
  26405. * @param recursive if all child meshes should also be added to the scene
  26406. */
  26407. Scene.prototype.addMesh = function (newMesh, recursive) {
  26408. var _this = this;
  26409. if (recursive === void 0) { recursive = false; }
  26410. this.meshes.push(newMesh);
  26411. //notify the collision coordinator
  26412. if (this.collisionCoordinator) {
  26413. this.collisionCoordinator.onMeshAdded(newMesh);
  26414. }
  26415. newMesh._resyncLightSources();
  26416. this.onNewMeshAddedObservable.notifyObservers(newMesh);
  26417. if (recursive) {
  26418. newMesh.getChildMeshes().forEach(function (m) {
  26419. _this.addMesh(m);
  26420. });
  26421. }
  26422. };
  26423. /**
  26424. * Remove a mesh for the list of scene's meshes
  26425. * @param toRemove defines the mesh to remove
  26426. * @param recursive if all child meshes should also be removed from the scene
  26427. * @returns the index where the mesh was in the mesh list
  26428. */
  26429. Scene.prototype.removeMesh = function (toRemove, recursive) {
  26430. var _this = this;
  26431. if (recursive === void 0) { recursive = false; }
  26432. var index = this.meshes.indexOf(toRemove);
  26433. if (index !== -1) {
  26434. // Remove from the scene if mesh found
  26435. this.meshes.splice(index, 1);
  26436. }
  26437. this.onMeshRemovedObservable.notifyObservers(toRemove);
  26438. if (recursive) {
  26439. toRemove.getChildMeshes().forEach(function (m) {
  26440. _this.removeMesh(m);
  26441. });
  26442. }
  26443. return index;
  26444. };
  26445. /**
  26446. * Add a transform node to the list of scene's transform nodes
  26447. * @param newTransformNode defines the transform node to add
  26448. */
  26449. Scene.prototype.addTransformNode = function (newTransformNode) {
  26450. this.transformNodes.push(newTransformNode);
  26451. this.onNewTransformNodeAddedObservable.notifyObservers(newTransformNode);
  26452. };
  26453. /**
  26454. * Remove a transform node for the list of scene's transform nodes
  26455. * @param toRemove defines the transform node to remove
  26456. * @returns the index where the transform node was in the transform node list
  26457. */
  26458. Scene.prototype.removeTransformNode = function (toRemove) {
  26459. var index = this.transformNodes.indexOf(toRemove);
  26460. if (index !== -1) {
  26461. // Remove from the scene if found
  26462. this.transformNodes.splice(index, 1);
  26463. }
  26464. this.onTransformNodeRemovedObservable.notifyObservers(toRemove);
  26465. return index;
  26466. };
  26467. /**
  26468. * Remove a skeleton for the list of scene's skeletons
  26469. * @param toRemove defines the skeleton to remove
  26470. * @returns the index where the skeleton was in the skeleton list
  26471. */
  26472. Scene.prototype.removeSkeleton = function (toRemove) {
  26473. var index = this.skeletons.indexOf(toRemove);
  26474. if (index !== -1) {
  26475. // Remove from the scene if found
  26476. this.skeletons.splice(index, 1);
  26477. }
  26478. return index;
  26479. };
  26480. /**
  26481. * Remove a morph target for the list of scene's morph targets
  26482. * @param toRemove defines the morph target to remove
  26483. * @returns the index where the morph target was in the morph target list
  26484. */
  26485. Scene.prototype.removeMorphTargetManager = function (toRemove) {
  26486. var index = this.morphTargetManagers.indexOf(toRemove);
  26487. if (index !== -1) {
  26488. // Remove from the scene if found
  26489. this.morphTargetManagers.splice(index, 1);
  26490. }
  26491. return index;
  26492. };
  26493. /**
  26494. * Remove a light for the list of scene's lights
  26495. * @param toRemove defines the light to remove
  26496. * @returns the index where the light was in the light list
  26497. */
  26498. Scene.prototype.removeLight = function (toRemove) {
  26499. var index = this.lights.indexOf(toRemove);
  26500. if (index !== -1) {
  26501. // Remove from meshes
  26502. for (var _i = 0, _a = this.meshes; _i < _a.length; _i++) {
  26503. var mesh = _a[_i];
  26504. mesh._removeLightSource(toRemove);
  26505. }
  26506. // Remove from the scene if mesh found
  26507. this.lights.splice(index, 1);
  26508. this.sortLightsByPriority();
  26509. }
  26510. this.onLightRemovedObservable.notifyObservers(toRemove);
  26511. return index;
  26512. };
  26513. /**
  26514. * Remove a camera for the list of scene's cameras
  26515. * @param toRemove defines the camera to remove
  26516. * @returns the index where the camera was in the camera list
  26517. */
  26518. Scene.prototype.removeCamera = function (toRemove) {
  26519. var index = this.cameras.indexOf(toRemove);
  26520. if (index !== -1) {
  26521. // Remove from the scene if mesh found
  26522. this.cameras.splice(index, 1);
  26523. }
  26524. // Remove from activeCameras
  26525. var index2 = this.activeCameras.indexOf(toRemove);
  26526. if (index2 !== -1) {
  26527. // Remove from the scene if mesh found
  26528. this.activeCameras.splice(index2, 1);
  26529. }
  26530. // Reset the activeCamera
  26531. if (this.activeCamera === toRemove) {
  26532. if (this.cameras.length > 0) {
  26533. this.activeCamera = this.cameras[0];
  26534. }
  26535. else {
  26536. this.activeCamera = null;
  26537. }
  26538. }
  26539. this.onCameraRemovedObservable.notifyObservers(toRemove);
  26540. return index;
  26541. };
  26542. /**
  26543. * Remove a particle system for the list of scene's particle systems
  26544. * @param toRemove defines the particle system to remove
  26545. * @returns the index where the particle system was in the particle system list
  26546. */
  26547. Scene.prototype.removeParticleSystem = function (toRemove) {
  26548. var index = this.particleSystems.indexOf(toRemove);
  26549. if (index !== -1) {
  26550. this.particleSystems.splice(index, 1);
  26551. }
  26552. return index;
  26553. };
  26554. /**
  26555. * Remove a animation for the list of scene's animations
  26556. * @param toRemove defines the animation to remove
  26557. * @returns the index where the animation was in the animation list
  26558. */
  26559. Scene.prototype.removeAnimation = function (toRemove) {
  26560. var index = this.animations.indexOf(toRemove);
  26561. if (index !== -1) {
  26562. this.animations.splice(index, 1);
  26563. }
  26564. return index;
  26565. };
  26566. /**
  26567. * Removes the given animation group from this scene.
  26568. * @param toRemove The animation group to remove
  26569. * @returns The index of the removed animation group
  26570. */
  26571. Scene.prototype.removeAnimationGroup = function (toRemove) {
  26572. var index = this.animationGroups.indexOf(toRemove);
  26573. if (index !== -1) {
  26574. this.animationGroups.splice(index, 1);
  26575. }
  26576. return index;
  26577. };
  26578. /**
  26579. * Removes the given multi-material from this scene.
  26580. * @param toRemove The multi-material to remove
  26581. * @returns The index of the removed multi-material
  26582. */
  26583. Scene.prototype.removeMultiMaterial = function (toRemove) {
  26584. var index = this.multiMaterials.indexOf(toRemove);
  26585. if (index !== -1) {
  26586. this.multiMaterials.splice(index, 1);
  26587. }
  26588. return index;
  26589. };
  26590. /**
  26591. * Removes the given material from this scene.
  26592. * @param toRemove The material to remove
  26593. * @returns The index of the removed material
  26594. */
  26595. Scene.prototype.removeMaterial = function (toRemove) {
  26596. var index = this.materials.indexOf(toRemove);
  26597. if (index !== -1) {
  26598. this.materials.splice(index, 1);
  26599. }
  26600. return index;
  26601. };
  26602. /**
  26603. * Removes the given lens flare system from this scene.
  26604. * @param toRemove The lens flare system to remove
  26605. * @returns The index of the removed lens flare system
  26606. */
  26607. Scene.prototype.removeLensFlareSystem = function (toRemove) {
  26608. var index = this.lensFlareSystems.indexOf(toRemove);
  26609. if (index !== -1) {
  26610. this.lensFlareSystems.splice(index, 1);
  26611. }
  26612. return index;
  26613. };
  26614. /**
  26615. * Removes the given action manager from this scene.
  26616. * @param toRemove The action manager to remove
  26617. * @returns The index of the removed action manager
  26618. */
  26619. Scene.prototype.removeActionManager = function (toRemove) {
  26620. var index = this._actionManagers.indexOf(toRemove);
  26621. if (index !== -1) {
  26622. this._actionManagers.splice(index, 1);
  26623. }
  26624. return index;
  26625. };
  26626. /**
  26627. * Removes the given effect layer from this scene.
  26628. * @param toRemove defines the effect layer to remove
  26629. * @returns the index of the removed effect layer
  26630. */
  26631. Scene.prototype.removeEffectLayer = function (toRemove) {
  26632. var index = this.effectLayers.indexOf(toRemove);
  26633. if (index !== -1) {
  26634. this.effectLayers.splice(index, 1);
  26635. }
  26636. return index;
  26637. };
  26638. /**
  26639. * Removes the given texture from this scene.
  26640. * @param toRemove The texture to remove
  26641. * @returns The index of the removed texture
  26642. */
  26643. Scene.prototype.removeTexture = function (toRemove) {
  26644. var index = this.textures.indexOf(toRemove);
  26645. if (index !== -1) {
  26646. this.textures.splice(index, 1);
  26647. }
  26648. return index;
  26649. };
  26650. /**
  26651. * Adds the given light to this scene
  26652. * @param newLight The light to add
  26653. */
  26654. Scene.prototype.addLight = function (newLight) {
  26655. this.lights.push(newLight);
  26656. this.sortLightsByPriority();
  26657. // Add light to all meshes (To support if the light is removed and then readded)
  26658. for (var _i = 0, _a = this.meshes; _i < _a.length; _i++) {
  26659. var mesh = _a[_i];
  26660. if (mesh._lightSources.indexOf(newLight) === -1) {
  26661. mesh._lightSources.push(newLight);
  26662. mesh._resyncLightSources();
  26663. }
  26664. }
  26665. this.onNewLightAddedObservable.notifyObservers(newLight);
  26666. };
  26667. /**
  26668. * Sorts the list list based on light priorities
  26669. */
  26670. Scene.prototype.sortLightsByPriority = function () {
  26671. if (this.requireLightSorting) {
  26672. this.lights.sort(BABYLON.Light.CompareLightsPriority);
  26673. }
  26674. };
  26675. /**
  26676. * Adds the given camera to this scene
  26677. * @param newCamera The camera to add
  26678. */
  26679. Scene.prototype.addCamera = function (newCamera) {
  26680. this.cameras.push(newCamera);
  26681. this.onNewCameraAddedObservable.notifyObservers(newCamera);
  26682. };
  26683. /**
  26684. * Adds the given skeleton to this scene
  26685. * @param newSkeleton The skeleton to add
  26686. */
  26687. Scene.prototype.addSkeleton = function (newSkeleton) {
  26688. this.skeletons.push(newSkeleton);
  26689. };
  26690. /**
  26691. * Adds the given particle system to this scene
  26692. * @param newParticleSystem The particle system to add
  26693. */
  26694. Scene.prototype.addParticleSystem = function (newParticleSystem) {
  26695. this.particleSystems.push(newParticleSystem);
  26696. };
  26697. /**
  26698. * Adds the given animation to this scene
  26699. * @param newAnimation The animation to add
  26700. */
  26701. Scene.prototype.addAnimation = function (newAnimation) {
  26702. this.animations.push(newAnimation);
  26703. };
  26704. /**
  26705. * Adds the given animation group to this scene.
  26706. * @param newAnimationGroup The animation group to add
  26707. */
  26708. Scene.prototype.addAnimationGroup = function (newAnimationGroup) {
  26709. this.animationGroups.push(newAnimationGroup);
  26710. };
  26711. /**
  26712. * Adds the given multi-material to this scene
  26713. * @param newMultiMaterial The multi-material to add
  26714. */
  26715. Scene.prototype.addMultiMaterial = function (newMultiMaterial) {
  26716. this.multiMaterials.push(newMultiMaterial);
  26717. };
  26718. /**
  26719. * Adds the given material to this scene
  26720. * @param newMaterial The material to add
  26721. */
  26722. Scene.prototype.addMaterial = function (newMaterial) {
  26723. this.materials.push(newMaterial);
  26724. };
  26725. /**
  26726. * Adds the given morph target to this scene
  26727. * @param newMorphTargetManager The morph target to add
  26728. */
  26729. Scene.prototype.addMorphTargetManager = function (newMorphTargetManager) {
  26730. this.morphTargetManagers.push(newMorphTargetManager);
  26731. };
  26732. /**
  26733. * Adds the given geometry to this scene
  26734. * @param newGeometry The geometry to add
  26735. */
  26736. Scene.prototype.addGeometry = function (newGeometry) {
  26737. this._geometries.push(newGeometry);
  26738. };
  26739. /**
  26740. * Adds the given lens flare system to this scene
  26741. * @param newLensFlareSystem The lens flare system to add
  26742. */
  26743. Scene.prototype.addLensFlareSystem = function (newLensFlareSystem) {
  26744. this.lensFlareSystems.push(newLensFlareSystem);
  26745. };
  26746. /**
  26747. * Adds the given effect layer to this scene
  26748. * @param newEffectLayer defines the effect layer to add
  26749. */
  26750. Scene.prototype.addEffectLayer = function (newEffectLayer) {
  26751. this.effectLayers.push(newEffectLayer);
  26752. };
  26753. /**
  26754. * Adds the given action manager to this scene
  26755. * @param newActionManager The action manager to add
  26756. */
  26757. Scene.prototype.addActionManager = function (newActionManager) {
  26758. this._actionManagers.push(newActionManager);
  26759. };
  26760. /**
  26761. * Adds the given texture to this scene.
  26762. * @param newTexture The texture to add
  26763. */
  26764. Scene.prototype.addTexture = function (newTexture) {
  26765. this.textures.push(newTexture);
  26766. };
  26767. /**
  26768. * Switch active camera
  26769. * @param newCamera defines the new active camera
  26770. * @param attachControl defines if attachControl must be called for the new active camera (default: true)
  26771. */
  26772. Scene.prototype.switchActiveCamera = function (newCamera, attachControl) {
  26773. if (attachControl === void 0) { attachControl = true; }
  26774. var canvas = this._engine.getRenderingCanvas();
  26775. if (!canvas) {
  26776. return;
  26777. }
  26778. if (this.activeCamera) {
  26779. this.activeCamera.detachControl(canvas);
  26780. }
  26781. this.activeCamera = newCamera;
  26782. if (attachControl) {
  26783. newCamera.attachControl(canvas);
  26784. }
  26785. };
  26786. /**
  26787. * sets the active camera of the scene using its ID
  26788. * @param id defines the camera's ID
  26789. * @return the new active camera or null if none found.
  26790. */
  26791. Scene.prototype.setActiveCameraByID = function (id) {
  26792. var camera = this.getCameraByID(id);
  26793. if (camera) {
  26794. this.activeCamera = camera;
  26795. return camera;
  26796. }
  26797. return null;
  26798. };
  26799. /**
  26800. * sets the active camera of the scene using its name
  26801. * @param name defines the camera's name
  26802. * @returns the new active camera or null if none found.
  26803. */
  26804. Scene.prototype.setActiveCameraByName = function (name) {
  26805. var camera = this.getCameraByName(name);
  26806. if (camera) {
  26807. this.activeCamera = camera;
  26808. return camera;
  26809. }
  26810. return null;
  26811. };
  26812. /**
  26813. * get an animation group using its name
  26814. * @param name defines the material's name
  26815. * @return the animation group or null if none found.
  26816. */
  26817. Scene.prototype.getAnimationGroupByName = function (name) {
  26818. for (var index = 0; index < this.animationGroups.length; index++) {
  26819. if (this.animationGroups[index].name === name) {
  26820. return this.animationGroups[index];
  26821. }
  26822. }
  26823. return null;
  26824. };
  26825. /**
  26826. * get a material using its id
  26827. * @param id defines the material's ID
  26828. * @return the material or null if none found.
  26829. */
  26830. Scene.prototype.getMaterialByID = function (id) {
  26831. for (var index = 0; index < this.materials.length; index++) {
  26832. if (this.materials[index].id === id) {
  26833. return this.materials[index];
  26834. }
  26835. }
  26836. return null;
  26837. };
  26838. /**
  26839. * Gets a material using its name
  26840. * @param name defines the material's name
  26841. * @return the material or null if none found.
  26842. */
  26843. Scene.prototype.getMaterialByName = function (name) {
  26844. for (var index = 0; index < this.materials.length; index++) {
  26845. if (this.materials[index].name === name) {
  26846. return this.materials[index];
  26847. }
  26848. }
  26849. return null;
  26850. };
  26851. /**
  26852. * Gets a lens flare system using its name
  26853. * @param name defines the name to look for
  26854. * @returns the lens flare system or null if not found
  26855. */
  26856. Scene.prototype.getLensFlareSystemByName = function (name) {
  26857. for (var index = 0; index < this.lensFlareSystems.length; index++) {
  26858. if (this.lensFlareSystems[index].name === name) {
  26859. return this.lensFlareSystems[index];
  26860. }
  26861. }
  26862. return null;
  26863. };
  26864. /**
  26865. * Gets a lens flare system using its id
  26866. * @param id defines the id to look for
  26867. * @returns the lens flare system or null if not found
  26868. */
  26869. Scene.prototype.getLensFlareSystemByID = function (id) {
  26870. for (var index = 0; index < this.lensFlareSystems.length; index++) {
  26871. if (this.lensFlareSystems[index].id === id) {
  26872. return this.lensFlareSystems[index];
  26873. }
  26874. }
  26875. return null;
  26876. };
  26877. /**
  26878. * Gets a camera using its id
  26879. * @param id defines the id to look for
  26880. * @returns the camera or null if not found
  26881. */
  26882. Scene.prototype.getCameraByID = function (id) {
  26883. for (var index = 0; index < this.cameras.length; index++) {
  26884. if (this.cameras[index].id === id) {
  26885. return this.cameras[index];
  26886. }
  26887. }
  26888. return null;
  26889. };
  26890. /**
  26891. * Gets a camera using its unique id
  26892. * @param uniqueId defines the unique id to look for
  26893. * @returns the camera or null if not found
  26894. */
  26895. Scene.prototype.getCameraByUniqueID = function (uniqueId) {
  26896. for (var index = 0; index < this.cameras.length; index++) {
  26897. if (this.cameras[index].uniqueId === uniqueId) {
  26898. return this.cameras[index];
  26899. }
  26900. }
  26901. return null;
  26902. };
  26903. /**
  26904. * Gets a camera using its name
  26905. * @param name defines the camera's name
  26906. * @return the camera or null if none found.
  26907. */
  26908. Scene.prototype.getCameraByName = function (name) {
  26909. for (var index = 0; index < this.cameras.length; index++) {
  26910. if (this.cameras[index].name === name) {
  26911. return this.cameras[index];
  26912. }
  26913. }
  26914. return null;
  26915. };
  26916. /**
  26917. * Gets a bone using its id
  26918. * @param id defines the bone's id
  26919. * @return the bone or null if not found
  26920. */
  26921. Scene.prototype.getBoneByID = function (id) {
  26922. for (var skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {
  26923. var skeleton = this.skeletons[skeletonIndex];
  26924. for (var boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {
  26925. if (skeleton.bones[boneIndex].id === id) {
  26926. return skeleton.bones[boneIndex];
  26927. }
  26928. }
  26929. }
  26930. return null;
  26931. };
  26932. /**
  26933. * Gets a bone using its id
  26934. * @param name defines the bone's name
  26935. * @return the bone or null if not found
  26936. */
  26937. Scene.prototype.getBoneByName = function (name) {
  26938. for (var skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {
  26939. var skeleton = this.skeletons[skeletonIndex];
  26940. for (var boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {
  26941. if (skeleton.bones[boneIndex].name === name) {
  26942. return skeleton.bones[boneIndex];
  26943. }
  26944. }
  26945. }
  26946. return null;
  26947. };
  26948. /**
  26949. * Gets a light node using its name
  26950. * @param name defines the the light's name
  26951. * @return the light or null if none found.
  26952. */
  26953. Scene.prototype.getLightByName = function (name) {
  26954. for (var index = 0; index < this.lights.length; index++) {
  26955. if (this.lights[index].name === name) {
  26956. return this.lights[index];
  26957. }
  26958. }
  26959. return null;
  26960. };
  26961. /**
  26962. * Gets a light node using its id
  26963. * @param id defines the light's id
  26964. * @return the light or null if none found.
  26965. */
  26966. Scene.prototype.getLightByID = function (id) {
  26967. for (var index = 0; index < this.lights.length; index++) {
  26968. if (this.lights[index].id === id) {
  26969. return this.lights[index];
  26970. }
  26971. }
  26972. return null;
  26973. };
  26974. /**
  26975. * Gets a light node using its scene-generated unique ID
  26976. * @param uniqueId defines the light's unique id
  26977. * @return the light or null if none found.
  26978. */
  26979. Scene.prototype.getLightByUniqueID = function (uniqueId) {
  26980. for (var index = 0; index < this.lights.length; index++) {
  26981. if (this.lights[index].uniqueId === uniqueId) {
  26982. return this.lights[index];
  26983. }
  26984. }
  26985. return null;
  26986. };
  26987. /**
  26988. * Gets a particle system by id
  26989. * @param id defines the particle system id
  26990. * @return the corresponding system or null if none found
  26991. */
  26992. Scene.prototype.getParticleSystemByID = function (id) {
  26993. for (var index = 0; index < this.particleSystems.length; index++) {
  26994. if (this.particleSystems[index].id === id) {
  26995. return this.particleSystems[index];
  26996. }
  26997. }
  26998. return null;
  26999. };
  27000. /**
  27001. * Gets a geometry using its ID
  27002. * @param id defines the geometry's id
  27003. * @return the geometry or null if none found.
  27004. */
  27005. Scene.prototype.getGeometryByID = function (id) {
  27006. for (var index = 0; index < this._geometries.length; index++) {
  27007. if (this._geometries[index].id === id) {
  27008. return this._geometries[index];
  27009. }
  27010. }
  27011. return null;
  27012. };
  27013. /**
  27014. * Add a new geometry to this scene
  27015. * @param geometry defines the geometry to be added to the scene.
  27016. * @param force defines if the geometry must be pushed even if a geometry with this id already exists
  27017. * @return a boolean defining if the geometry was added or not
  27018. */
  27019. Scene.prototype.pushGeometry = function (geometry, force) {
  27020. if (!force && this.getGeometryByID(geometry.id)) {
  27021. return false;
  27022. }
  27023. this._geometries.push(geometry);
  27024. //notify the collision coordinator
  27025. if (this.collisionCoordinator) {
  27026. this.collisionCoordinator.onGeometryAdded(geometry);
  27027. }
  27028. this.onNewGeometryAddedObservable.notifyObservers(geometry);
  27029. return true;
  27030. };
  27031. /**
  27032. * Removes an existing geometry
  27033. * @param geometry defines the geometry to be removed from the scene
  27034. * @return a boolean defining if the geometry was removed or not
  27035. */
  27036. Scene.prototype.removeGeometry = function (geometry) {
  27037. var index = this._geometries.indexOf(geometry);
  27038. if (index > -1) {
  27039. this._geometries.splice(index, 1);
  27040. //notify the collision coordinator
  27041. if (this.collisionCoordinator) {
  27042. this.collisionCoordinator.onGeometryDeleted(geometry);
  27043. }
  27044. this.onGeometryRemovedObservable.notifyObservers(geometry);
  27045. return true;
  27046. }
  27047. return false;
  27048. };
  27049. /**
  27050. * Gets the list of geometries attached to the scene
  27051. * @returns an array of Geometry
  27052. */
  27053. Scene.prototype.getGeometries = function () {
  27054. return this._geometries;
  27055. };
  27056. /**
  27057. * Gets the first added mesh found of a given ID
  27058. * @param id defines the id to search for
  27059. * @return the mesh found or null if not found at all
  27060. */
  27061. Scene.prototype.getMeshByID = function (id) {
  27062. for (var index = 0; index < this.meshes.length; index++) {
  27063. if (this.meshes[index].id === id) {
  27064. return this.meshes[index];
  27065. }
  27066. }
  27067. return null;
  27068. };
  27069. /**
  27070. * Gets a list of meshes using their id
  27071. * @param id defines the id to search for
  27072. * @returns a list of meshes
  27073. */
  27074. Scene.prototype.getMeshesByID = function (id) {
  27075. return this.meshes.filter(function (m) {
  27076. return m.id === id;
  27077. });
  27078. };
  27079. /**
  27080. * Gets the first added transform node found of a given ID
  27081. * @param id defines the id to search for
  27082. * @return the found transform node or null if not found at all.
  27083. */
  27084. Scene.prototype.getTransformNodeByID = function (id) {
  27085. for (var index = 0; index < this.transformNodes.length; index++) {
  27086. if (this.transformNodes[index].id === id) {
  27087. return this.transformNodes[index];
  27088. }
  27089. }
  27090. return null;
  27091. };
  27092. /**
  27093. * Gets a list of transform nodes using their id
  27094. * @param id defines the id to search for
  27095. * @returns a list of transform nodes
  27096. */
  27097. Scene.prototype.getTransformNodesByID = function (id) {
  27098. return this.transformNodes.filter(function (m) {
  27099. return m.id === id;
  27100. });
  27101. };
  27102. /**
  27103. * Gets a mesh with its auto-generated unique id
  27104. * @param uniqueId defines the unique id to search for
  27105. * @return the found mesh or null if not found at all.
  27106. */
  27107. Scene.prototype.getMeshByUniqueID = function (uniqueId) {
  27108. for (var index = 0; index < this.meshes.length; index++) {
  27109. if (this.meshes[index].uniqueId === uniqueId) {
  27110. return this.meshes[index];
  27111. }
  27112. }
  27113. return null;
  27114. };
  27115. /**
  27116. * Gets a the last added mesh using a given id
  27117. * @param id defines the id to search for
  27118. * @return the found mesh or null if not found at all.
  27119. */
  27120. Scene.prototype.getLastMeshByID = function (id) {
  27121. for (var index = this.meshes.length - 1; index >= 0; index--) {
  27122. if (this.meshes[index].id === id) {
  27123. return this.meshes[index];
  27124. }
  27125. }
  27126. return null;
  27127. };
  27128. /**
  27129. * Gets a the last added node (Mesh, Camera, Light) using a given id
  27130. * @param id defines the id to search for
  27131. * @return the found node or null if not found at all
  27132. */
  27133. Scene.prototype.getLastEntryByID = function (id) {
  27134. var index;
  27135. for (index = this.meshes.length - 1; index >= 0; index--) {
  27136. if (this.meshes[index].id === id) {
  27137. return this.meshes[index];
  27138. }
  27139. }
  27140. for (index = this.transformNodes.length - 1; index >= 0; index--) {
  27141. if (this.transformNodes[index].id === id) {
  27142. return this.transformNodes[index];
  27143. }
  27144. }
  27145. for (index = this.cameras.length - 1; index >= 0; index--) {
  27146. if (this.cameras[index].id === id) {
  27147. return this.cameras[index];
  27148. }
  27149. }
  27150. for (index = this.lights.length - 1; index >= 0; index--) {
  27151. if (this.lights[index].id === id) {
  27152. return this.lights[index];
  27153. }
  27154. }
  27155. return null;
  27156. };
  27157. /**
  27158. * Gets a node (Mesh, Camera, Light) using a given id
  27159. * @param id defines the id to search for
  27160. * @return the found node or null if not found at all
  27161. */
  27162. Scene.prototype.getNodeByID = function (id) {
  27163. var mesh = this.getMeshByID(id);
  27164. if (mesh) {
  27165. return mesh;
  27166. }
  27167. var light = this.getLightByID(id);
  27168. if (light) {
  27169. return light;
  27170. }
  27171. var camera = this.getCameraByID(id);
  27172. if (camera) {
  27173. return camera;
  27174. }
  27175. var bone = this.getBoneByID(id);
  27176. return bone;
  27177. };
  27178. /**
  27179. * Gets a node (Mesh, Camera, Light) using a given name
  27180. * @param name defines the name to search for
  27181. * @return the found node or null if not found at all.
  27182. */
  27183. Scene.prototype.getNodeByName = function (name) {
  27184. var mesh = this.getMeshByName(name);
  27185. if (mesh) {
  27186. return mesh;
  27187. }
  27188. var light = this.getLightByName(name);
  27189. if (light) {
  27190. return light;
  27191. }
  27192. var camera = this.getCameraByName(name);
  27193. if (camera) {
  27194. return camera;
  27195. }
  27196. var bone = this.getBoneByName(name);
  27197. return bone;
  27198. };
  27199. /**
  27200. * Gets a mesh using a given name
  27201. * @param name defines the name to search for
  27202. * @return the found mesh or null if not found at all.
  27203. */
  27204. Scene.prototype.getMeshByName = function (name) {
  27205. for (var index = 0; index < this.meshes.length; index++) {
  27206. if (this.meshes[index].name === name) {
  27207. return this.meshes[index];
  27208. }
  27209. }
  27210. return null;
  27211. };
  27212. /**
  27213. * Gets a transform node using a given name
  27214. * @param name defines the name to search for
  27215. * @return the found transform node or null if not found at all.
  27216. */
  27217. Scene.prototype.getTransformNodeByName = function (name) {
  27218. for (var index = 0; index < this.transformNodes.length; index++) {
  27219. if (this.transformNodes[index].name === name) {
  27220. return this.transformNodes[index];
  27221. }
  27222. }
  27223. return null;
  27224. };
  27225. /**
  27226. * Gets a sound using a given name
  27227. * @param name defines the name to search for
  27228. * @return the found sound or null if not found at all.
  27229. */
  27230. Scene.prototype.getSoundByName = function (name) {
  27231. var index;
  27232. if (BABYLON.AudioEngine) {
  27233. for (index = 0; index < this.mainSoundTrack.soundCollection.length; index++) {
  27234. if (this.mainSoundTrack.soundCollection[index].name === name) {
  27235. return this.mainSoundTrack.soundCollection[index];
  27236. }
  27237. }
  27238. for (var sdIndex = 0; sdIndex < this.soundTracks.length; sdIndex++) {
  27239. for (index = 0; index < this.soundTracks[sdIndex].soundCollection.length; index++) {
  27240. if (this.soundTracks[sdIndex].soundCollection[index].name === name) {
  27241. return this.soundTracks[sdIndex].soundCollection[index];
  27242. }
  27243. }
  27244. }
  27245. }
  27246. return null;
  27247. };
  27248. /**
  27249. * Gets a skeleton using a given id (if many are found, this function will pick the last one)
  27250. * @param id defines the id to search for
  27251. * @return the found skeleton or null if not found at all.
  27252. */
  27253. Scene.prototype.getLastSkeletonByID = function (id) {
  27254. for (var index = this.skeletons.length - 1; index >= 0; index--) {
  27255. if (this.skeletons[index].id === id) {
  27256. return this.skeletons[index];
  27257. }
  27258. }
  27259. return null;
  27260. };
  27261. /**
  27262. * Gets a skeleton using a given id (if many are found, this function will pick the first one)
  27263. * @param id defines the id to search for
  27264. * @return the found skeleton or null if not found at all.
  27265. */
  27266. Scene.prototype.getSkeletonById = function (id) {
  27267. for (var index = 0; index < this.skeletons.length; index++) {
  27268. if (this.skeletons[index].id === id) {
  27269. return this.skeletons[index];
  27270. }
  27271. }
  27272. return null;
  27273. };
  27274. /**
  27275. * Gets a skeleton using a given name
  27276. * @param name defines the name to search for
  27277. * @return the found skeleton or null if not found at all.
  27278. */
  27279. Scene.prototype.getSkeletonByName = function (name) {
  27280. for (var index = 0; index < this.skeletons.length; index++) {
  27281. if (this.skeletons[index].name === name) {
  27282. return this.skeletons[index];
  27283. }
  27284. }
  27285. return null;
  27286. };
  27287. /**
  27288. * Gets a morph target manager using a given id (if many are found, this function will pick the last one)
  27289. * @param id defines the id to search for
  27290. * @return the found morph target manager or null if not found at all.
  27291. */
  27292. Scene.prototype.getMorphTargetManagerById = function (id) {
  27293. for (var index = 0; index < this.morphTargetManagers.length; index++) {
  27294. if (this.morphTargetManagers[index].uniqueId === id) {
  27295. return this.morphTargetManagers[index];
  27296. }
  27297. }
  27298. return null;
  27299. };
  27300. /**
  27301. * Gets a boolean indicating if the given mesh is active
  27302. * @param mesh defines the mesh to look for
  27303. * @returns true if the mesh is in the active list
  27304. */
  27305. Scene.prototype.isActiveMesh = function (mesh) {
  27306. return (this._activeMeshes.indexOf(mesh) !== -1);
  27307. };
  27308. /**
  27309. * Return a the first highlight layer of the scene with a given name.
  27310. * @param name The name of the highlight layer to look for.
  27311. * @return The highlight layer if found otherwise null.
  27312. */
  27313. Scene.prototype.getHighlightLayerByName = function (name) {
  27314. for (var index = 0; index < this.effectLayers.length; index++) {
  27315. if (this.effectLayers[index].name === name && this.effectLayers[index].getEffectName() === BABYLON.HighlightLayer.EffectName) {
  27316. return this.effectLayers[index];
  27317. }
  27318. }
  27319. return null;
  27320. };
  27321. /**
  27322. * Return a the first highlight layer of the scene with a given name.
  27323. * @param name The name of the highlight layer to look for.
  27324. * @return The highlight layer if found otherwise null.
  27325. */
  27326. Scene.prototype.getGlowLayerByName = function (name) {
  27327. for (var index = 0; index < this.effectLayers.length; index++) {
  27328. if (this.effectLayers[index].name === name && this.effectLayers[index].getEffectName() === BABYLON.GlowLayer.EffectName) {
  27329. return this.effectLayers[index];
  27330. }
  27331. }
  27332. return null;
  27333. };
  27334. Object.defineProperty(Scene.prototype, "uid", {
  27335. /**
  27336. * Return a unique id as a string which can serve as an identifier for the scene
  27337. */
  27338. get: function () {
  27339. if (!this._uid) {
  27340. this._uid = BABYLON.Tools.RandomId();
  27341. }
  27342. return this._uid;
  27343. },
  27344. enumerable: true,
  27345. configurable: true
  27346. });
  27347. /**
  27348. * Add an externaly attached data from its key.
  27349. * This method call will fail and return false, if such key already exists.
  27350. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  27351. * @param key the unique key that identifies the data
  27352. * @param data the data object to associate to the key for this Engine instance
  27353. * @return true if no such key were already present and the data was added successfully, false otherwise
  27354. */
  27355. Scene.prototype.addExternalData = function (key, data) {
  27356. if (!this._externalData) {
  27357. this._externalData = new BABYLON.StringDictionary();
  27358. }
  27359. return this._externalData.add(key, data);
  27360. };
  27361. /**
  27362. * Get an externaly attached data from its key
  27363. * @param key the unique key that identifies the data
  27364. * @return the associated data, if present (can be null), or undefined if not present
  27365. */
  27366. Scene.prototype.getExternalData = function (key) {
  27367. if (!this._externalData) {
  27368. return null;
  27369. }
  27370. return this._externalData.get(key);
  27371. };
  27372. /**
  27373. * Get an externaly attached data from its key, create it using a factory if it's not already present
  27374. * @param key the unique key that identifies the data
  27375. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  27376. * @return the associated data, can be null if the factory returned null.
  27377. */
  27378. Scene.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  27379. if (!this._externalData) {
  27380. this._externalData = new BABYLON.StringDictionary();
  27381. }
  27382. return this._externalData.getOrAddWithFactory(key, factory);
  27383. };
  27384. /**
  27385. * Remove an externaly attached data from the Engine instance
  27386. * @param key the unique key that identifies the data
  27387. * @return true if the data was successfully removed, false if it doesn't exist
  27388. */
  27389. Scene.prototype.removeExternalData = function (key) {
  27390. return this._externalData.remove(key);
  27391. };
  27392. Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
  27393. if (this.dispatchAllSubMeshesOfActiveMeshes || mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
  27394. if (mesh.showSubMeshesBoundingBox) {
  27395. var boundingInfo = subMesh.getBoundingInfo();
  27396. if (boundingInfo !== null && boundingInfo !== undefined) {
  27397. this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
  27398. }
  27399. }
  27400. var material = subMesh.getMaterial();
  27401. if (material !== null && material !== undefined) {
  27402. // Render targets
  27403. if (material.getRenderTargetTextures !== undefined) {
  27404. if (this._processedMaterials.indexOf(material) === -1) {
  27405. this._processedMaterials.push(material);
  27406. this._renderTargets.concatWithNoDuplicate(material.getRenderTargetTextures());
  27407. }
  27408. }
  27409. // Dispatch
  27410. this._activeIndices.addCount(subMesh.indexCount, false);
  27411. this._renderingManager.dispatch(subMesh, mesh, material);
  27412. }
  27413. }
  27414. };
  27415. /**
  27416. * Clear the processed materials smart array preventing retention point in material dispose.
  27417. */
  27418. Scene.prototype.freeProcessedMaterials = function () {
  27419. this._processedMaterials.dispose();
  27420. };
  27421. /**
  27422. * Clear the active meshes smart array preventing retention point in mesh dispose.
  27423. */
  27424. Scene.prototype.freeActiveMeshes = function () {
  27425. this._activeMeshes.dispose();
  27426. if (this.activeCamera && this.activeCamera._activeMeshes) {
  27427. this.activeCamera._activeMeshes.dispose();
  27428. }
  27429. if (this.activeCameras) {
  27430. for (var i = 0; i < this.activeCameras.length; i++) {
  27431. var activeCamera = this.activeCameras[i];
  27432. if (activeCamera && activeCamera._activeMeshes) {
  27433. activeCamera._activeMeshes.dispose();
  27434. }
  27435. }
  27436. }
  27437. };
  27438. /**
  27439. * Clear the info related to rendering groups preventing retention points during dispose.
  27440. */
  27441. Scene.prototype.freeRenderingGroups = function () {
  27442. if (this._renderingManager) {
  27443. this._renderingManager.freeRenderingGroups();
  27444. }
  27445. if (this.textures) {
  27446. for (var i = 0; i < this.textures.length; i++) {
  27447. var texture = this.textures[i];
  27448. if (texture && texture.renderList) {
  27449. texture.freeRenderingGroups();
  27450. }
  27451. }
  27452. }
  27453. };
  27454. /** @hidden */
  27455. Scene.prototype._isInIntermediateRendering = function () {
  27456. return this._intermediateRendering;
  27457. };
  27458. /**
  27459. * Defines the current active mesh candidate provider
  27460. * @param provider defines the provider to use
  27461. */
  27462. Scene.prototype.setActiveMeshCandidateProvider = function (provider) {
  27463. this._activeMeshCandidateProvider = provider;
  27464. };
  27465. /**
  27466. * Gets the current active mesh candidate provider
  27467. * @returns the current active mesh candidate provider
  27468. */
  27469. Scene.prototype.getActiveMeshCandidateProvider = function () {
  27470. return this._activeMeshCandidateProvider;
  27471. };
  27472. /**
  27473. * Use this function to stop evaluating active meshes. The current list will be keep alive between frames
  27474. * @returns the current scene
  27475. */
  27476. Scene.prototype.freezeActiveMeshes = function () {
  27477. if (!this.activeCamera) {
  27478. return this;
  27479. }
  27480. if (!this._frustumPlanes) {
  27481. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  27482. }
  27483. this._evaluateActiveMeshes();
  27484. this._activeMeshesFrozen = true;
  27485. return this;
  27486. };
  27487. /**
  27488. * Use this function to restart evaluating active meshes on every frame
  27489. * @returns the current scene
  27490. */
  27491. Scene.prototype.unfreezeActiveMeshes = function () {
  27492. this._activeMeshesFrozen = false;
  27493. return this;
  27494. };
  27495. Scene.prototype._evaluateActiveMeshes = function () {
  27496. if (this._activeMeshesFrozen && this._activeMeshes.length) {
  27497. return;
  27498. }
  27499. if (!this.activeCamera) {
  27500. return;
  27501. }
  27502. this.onBeforeActiveMeshesEvaluationObservable.notifyObservers(this);
  27503. this.activeCamera._activeMeshes.reset();
  27504. this._activeMeshes.reset();
  27505. this._renderingManager.reset();
  27506. this._processedMaterials.reset();
  27507. this._activeParticleSystems.reset();
  27508. this._activeSkeletons.reset();
  27509. this._softwareSkinnedMeshes.reset();
  27510. if (this._boundingBoxRenderer) {
  27511. this._boundingBoxRenderer.reset();
  27512. }
  27513. // Meshes
  27514. var meshes;
  27515. var len;
  27516. var checkIsEnabled = true;
  27517. // Determine mesh candidates
  27518. if (this._activeMeshCandidateProvider !== undefined) {
  27519. // Use _activeMeshCandidateProvider
  27520. meshes = this._activeMeshCandidateProvider.getMeshes(this);
  27521. checkIsEnabled = this._activeMeshCandidateProvider.checksIsEnabled === false;
  27522. if (meshes !== undefined) {
  27523. len = meshes.length;
  27524. }
  27525. else {
  27526. len = 0;
  27527. }
  27528. }
  27529. else if (this._selectionOctree !== undefined) {
  27530. // Octree
  27531. var selection = this._selectionOctree.select(this._frustumPlanes);
  27532. meshes = selection.data;
  27533. len = selection.length;
  27534. }
  27535. else {
  27536. // Full scene traversal
  27537. len = this.meshes.length;
  27538. meshes = this.meshes;
  27539. }
  27540. // Check each mesh
  27541. for (var meshIndex = 0, mesh, meshLOD; meshIndex < len; meshIndex++) {
  27542. mesh = meshes[meshIndex];
  27543. if (mesh.isBlocked) {
  27544. continue;
  27545. }
  27546. this._totalVertices.addCount(mesh.getTotalVertices(), false);
  27547. if (!mesh.isReady() || (checkIsEnabled && !mesh.isEnabled())) {
  27548. continue;
  27549. }
  27550. mesh.computeWorldMatrix();
  27551. // Intersections
  27552. if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
  27553. this._meshesForIntersections.pushNoDuplicate(mesh);
  27554. }
  27555. // Switch to current LOD
  27556. meshLOD = mesh.getLOD(this.activeCamera);
  27557. if (meshLOD === undefined || meshLOD === null) {
  27558. continue;
  27559. }
  27560. mesh._preActivate();
  27561. if (mesh.alwaysSelectAsActiveMesh || mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
  27562. this._activeMeshes.push(mesh);
  27563. this.activeCamera._activeMeshes.push(mesh);
  27564. mesh._activate(this._renderId);
  27565. if (meshLOD !== mesh) {
  27566. meshLOD._activate(this._renderId);
  27567. }
  27568. this._activeMesh(mesh, meshLOD);
  27569. }
  27570. }
  27571. this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this);
  27572. // Particle systems
  27573. if (this.particlesEnabled) {
  27574. this.onBeforeParticlesRenderingObservable.notifyObservers(this);
  27575. for (var particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {
  27576. var particleSystem = this.particleSystems[particleIndex];
  27577. if (!particleSystem.isStarted() || !particleSystem.emitter) {
  27578. continue;
  27579. }
  27580. var emitter = particleSystem.emitter;
  27581. if (!emitter.position || emitter.isEnabled()) {
  27582. this._activeParticleSystems.push(particleSystem);
  27583. particleSystem.animate();
  27584. this._renderingManager.dispatchParticles(particleSystem);
  27585. }
  27586. }
  27587. this.onAfterParticlesRenderingObservable.notifyObservers(this);
  27588. }
  27589. };
  27590. Scene.prototype._activeMesh = function (sourceMesh, mesh) {
  27591. if (this.skeletonsEnabled && mesh.skeleton !== null && mesh.skeleton !== undefined) {
  27592. if (this._activeSkeletons.pushNoDuplicate(mesh.skeleton)) {
  27593. mesh.skeleton.prepare();
  27594. }
  27595. if (!mesh.computeBonesUsingShaders) {
  27596. this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
  27597. }
  27598. }
  27599. if (sourceMesh.showBoundingBox || this.forceShowBoundingBoxes) {
  27600. var boundingInfo = sourceMesh.getBoundingInfo();
  27601. this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
  27602. }
  27603. if (mesh !== undefined && mesh !== null
  27604. && mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0) {
  27605. // Submeshes Octrees
  27606. var len;
  27607. var subMeshes;
  27608. if (mesh.useOctreeForRenderingSelection && mesh._submeshesOctree !== undefined && mesh._submeshesOctree !== null) {
  27609. var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
  27610. len = intersections.length;
  27611. subMeshes = intersections.data;
  27612. }
  27613. else {
  27614. subMeshes = mesh.subMeshes;
  27615. len = subMeshes.length;
  27616. }
  27617. for (var subIndex = 0, subMesh; subIndex < len; subIndex++) {
  27618. subMesh = subMeshes[subIndex];
  27619. this._evaluateSubMesh(subMesh, mesh);
  27620. }
  27621. }
  27622. };
  27623. /**
  27624. * Update the transform matrix to update from the current active camera
  27625. * @param force defines a boolean used to force the update even if cache is up to date
  27626. */
  27627. Scene.prototype.updateTransformMatrix = function (force) {
  27628. if (!this.activeCamera) {
  27629. return;
  27630. }
  27631. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
  27632. };
  27633. /**
  27634. * Defines an alternate camera (used mostly in VR-like scenario where two cameras can render the same scene from a slightly different point of view)
  27635. * @param alternateCamera defines the camera to use
  27636. */
  27637. Scene.prototype.updateAlternateTransformMatrix = function (alternateCamera) {
  27638. this._setAlternateTransformMatrix(alternateCamera.getViewMatrix(), alternateCamera.getProjectionMatrix());
  27639. };
  27640. Scene.prototype._renderForCamera = function (camera, rigParent) {
  27641. if (camera && camera._skipRendering) {
  27642. return;
  27643. }
  27644. var engine = this._engine;
  27645. this.activeCamera = camera;
  27646. if (!this.activeCamera)
  27647. throw new Error("Active camera not set");
  27648. BABYLON.Tools.StartPerformanceCounter("Rendering camera " + this.activeCamera.name);
  27649. // Viewport
  27650. engine.setViewport(this.activeCamera.viewport);
  27651. // Camera
  27652. this.resetCachedMaterial();
  27653. this._renderId++;
  27654. this.updateTransformMatrix();
  27655. if (camera._alternateCamera) {
  27656. this.updateAlternateTransformMatrix(camera._alternateCamera);
  27657. this._alternateRendering = true;
  27658. }
  27659. this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);
  27660. // Meshes
  27661. this._evaluateActiveMeshes();
  27662. // Software skinning
  27663. for (var softwareSkinnedMeshIndex = 0; softwareSkinnedMeshIndex < this._softwareSkinnedMeshes.length; softwareSkinnedMeshIndex++) {
  27664. var mesh = this._softwareSkinnedMeshes.data[softwareSkinnedMeshIndex];
  27665. mesh.applySkeleton(mesh.skeleton);
  27666. }
  27667. // Render targets
  27668. this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);
  27669. var needsRestoreFrameBuffer = false;
  27670. if (camera.customRenderTargets && camera.customRenderTargets.length > 0) {
  27671. this._renderTargets.concatWithNoDuplicate(camera.customRenderTargets);
  27672. }
  27673. if (rigParent && rigParent.customRenderTargets && rigParent.customRenderTargets.length > 0) {
  27674. this._renderTargets.concatWithNoDuplicate(rigParent.customRenderTargets);
  27675. }
  27676. if (this.renderTargetsEnabled && this._renderTargets.length > 0) {
  27677. this._intermediateRendering = true;
  27678. BABYLON.Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
  27679. for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
  27680. var renderTarget = this._renderTargets.data[renderIndex];
  27681. if (renderTarget._shouldRender()) {
  27682. this._renderId++;
  27683. var hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;
  27684. renderTarget.render(hasSpecialRenderTargetCamera, this.dumpNextRenderTargets);
  27685. }
  27686. }
  27687. BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
  27688. this._intermediateRendering = false;
  27689. this._renderId++;
  27690. needsRestoreFrameBuffer = true; // Restore back buffer
  27691. }
  27692. // Render EffecttLayer Texture
  27693. var stencilState = this._engine.getStencilBuffer();
  27694. var renderEffects = false;
  27695. var needStencil = false;
  27696. if (this.renderTargetsEnabled && this.effectLayers && this.effectLayers.length > 0) {
  27697. this._intermediateRendering = true;
  27698. for (var i = 0; i < this.effectLayers.length; i++) {
  27699. var effectLayer = this.effectLayers[i];
  27700. if (effectLayer.shouldRender() &&
  27701. (!effectLayer.camera ||
  27702. (effectLayer.camera.cameraRigMode === BABYLON.Camera.RIG_MODE_NONE && camera === effectLayer.camera) ||
  27703. (effectLayer.camera.cameraRigMode !== BABYLON.Camera.RIG_MODE_NONE && effectLayer.camera._rigCameras.indexOf(camera) > -1))) {
  27704. renderEffects = true;
  27705. needStencil = needStencil || effectLayer.needStencil();
  27706. var renderTarget = effectLayer._mainTexture;
  27707. if (renderTarget._shouldRender()) {
  27708. this._renderId++;
  27709. renderTarget.render(false, false);
  27710. needsRestoreFrameBuffer = true;
  27711. }
  27712. }
  27713. }
  27714. this._intermediateRendering = false;
  27715. this._renderId++;
  27716. }
  27717. if (needsRestoreFrameBuffer) {
  27718. engine.restoreDefaultFramebuffer(); // Restore back buffer
  27719. }
  27720. this.onAfterRenderTargetsRenderObservable.notifyObservers(this);
  27721. // Prepare Frame
  27722. this.postProcessManager._prepareFrame();
  27723. // Backgrounds
  27724. var layerIndex;
  27725. var layer;
  27726. if (this.layers.length) {
  27727. engine.setDepthBuffer(false);
  27728. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  27729. layer = this.layers[layerIndex];
  27730. if (layer.isBackground && ((layer.layerMask & this.activeCamera.layerMask) !== 0)) {
  27731. layer.render();
  27732. }
  27733. }
  27734. engine.setDepthBuffer(true);
  27735. }
  27736. // Activate effect Layer stencil
  27737. if (needStencil) {
  27738. this._engine.setStencilBuffer(true);
  27739. }
  27740. // Render
  27741. this.onBeforeDrawPhaseObservable.notifyObservers(this);
  27742. this._renderingManager.render(null, null, true, true);
  27743. this.onAfterDrawPhaseObservable.notifyObservers(this);
  27744. // Restore effect Layer stencil
  27745. if (needStencil) {
  27746. this._engine.setStencilBuffer(stencilState);
  27747. }
  27748. // Bounding boxes
  27749. if (this._boundingBoxRenderer) {
  27750. this._boundingBoxRenderer.render();
  27751. }
  27752. // Lens flares
  27753. if (this.lensFlaresEnabled) {
  27754. BABYLON.Tools.StartPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  27755. for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
  27756. var lensFlareSystem = this.lensFlareSystems[lensFlareSystemIndex];
  27757. if ((camera.layerMask & lensFlareSystem.layerMask) !== 0) {
  27758. lensFlareSystem.render();
  27759. }
  27760. }
  27761. BABYLON.Tools.EndPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  27762. }
  27763. // Effect Layer
  27764. if (renderEffects) {
  27765. engine.setDepthBuffer(false);
  27766. for (var i = 0; i < this.effectLayers.length; i++) {
  27767. if (this.effectLayers[i].shouldRender()) {
  27768. this.effectLayers[i].render();
  27769. }
  27770. }
  27771. engine.setDepthBuffer(true);
  27772. }
  27773. // Foregrounds
  27774. if (this.layers.length) {
  27775. engine.setDepthBuffer(false);
  27776. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  27777. layer = this.layers[layerIndex];
  27778. if (!layer.isBackground && ((layer.layerMask & this.activeCamera.layerMask) !== 0)) {
  27779. layer.render();
  27780. }
  27781. }
  27782. engine.setDepthBuffer(true);
  27783. }
  27784. // Finalize frame
  27785. this.postProcessManager._finalizeFrame(camera.isIntermediate);
  27786. // Reset some special arrays
  27787. this._renderTargets.reset();
  27788. this._alternateRendering = false;
  27789. this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera);
  27790. BABYLON.Tools.EndPerformanceCounter("Rendering camera " + this.activeCamera.name);
  27791. };
  27792. Scene.prototype._processSubCameras = function (camera) {
  27793. if (camera.cameraRigMode === BABYLON.Camera.RIG_MODE_NONE) {
  27794. this._renderForCamera(camera);
  27795. return;
  27796. }
  27797. // rig cameras
  27798. for (var index = 0; index < camera._rigCameras.length; index++) {
  27799. this._renderForCamera(camera._rigCameras[index], camera);
  27800. }
  27801. this.activeCamera = camera;
  27802. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  27803. };
  27804. Scene.prototype._checkIntersections = function () {
  27805. for (var index = 0; index < this._meshesForIntersections.length; index++) {
  27806. var sourceMesh = this._meshesForIntersections.data[index];
  27807. if (!sourceMesh.actionManager) {
  27808. continue;
  27809. }
  27810. for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
  27811. var action = sourceMesh.actionManager.actions[actionIndex];
  27812. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  27813. var parameters = action.getTriggerParameter();
  27814. var otherMesh = parameters instanceof BABYLON.AbstractMesh ? parameters : parameters.mesh;
  27815. var areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);
  27816. var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  27817. if (areIntersecting && currentIntersectionInProgress === -1) {
  27818. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger) {
  27819. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));
  27820. sourceMesh._intersectionsInProgress.push(otherMesh);
  27821. }
  27822. else if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  27823. sourceMesh._intersectionsInProgress.push(otherMesh);
  27824. }
  27825. }
  27826. else if (!areIntersecting && currentIntersectionInProgress > -1) {
  27827. //They intersected, and now they don't.
  27828. //is this trigger an exit trigger? execute an event.
  27829. if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  27830. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));
  27831. }
  27832. //if this is an exit trigger, or no exit trigger exists, remove the id from the intersection in progress array.
  27833. if (!sourceMesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnIntersectionExitTrigger, function (parameter) {
  27834. var parameterMesh = parameter instanceof BABYLON.AbstractMesh ? parameter : parameter.mesh;
  27835. return otherMesh === parameterMesh;
  27836. }) || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  27837. sourceMesh._intersectionsInProgress.splice(currentIntersectionInProgress, 1);
  27838. }
  27839. }
  27840. }
  27841. }
  27842. }
  27843. };
  27844. /**
  27845. * Render the scene
  27846. * @param updateCameras defines a boolean indicating if cameras must update according to their inputs (true by default)
  27847. */
  27848. Scene.prototype.render = function (updateCameras) {
  27849. if (updateCameras === void 0) { updateCameras = true; }
  27850. if (this.isDisposed) {
  27851. return;
  27852. }
  27853. this._activeParticles.fetchNewFrame();
  27854. this._totalVertices.fetchNewFrame();
  27855. this._activeIndices.fetchNewFrame();
  27856. this._activeBones.fetchNewFrame();
  27857. this._meshesForIntersections.reset();
  27858. this.resetCachedMaterial();
  27859. this.onBeforeAnimationsObservable.notifyObservers(this);
  27860. // Actions
  27861. if (this.actionManager) {
  27862. this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger);
  27863. }
  27864. //Simplification Queue
  27865. if (this.simplificationQueue && !this.simplificationQueue.running) {
  27866. this.simplificationQueue.executeNext();
  27867. }
  27868. if (this._engine.isDeterministicLockStep()) {
  27869. var deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime)) + this._timeAccumulator;
  27870. var defaultFPS = (60.0 / 1000.0);
  27871. var defaultFrameTime = 1000 / 60; // frame time in MS
  27872. if (this._physicsEngine) {
  27873. defaultFrameTime = this._physicsEngine.getTimeStep() * 1000;
  27874. }
  27875. var stepsTaken = 0;
  27876. var maxSubSteps = this._engine.getLockstepMaxSteps();
  27877. var internalSteps = Math.floor(deltaTime / (1000 * defaultFPS));
  27878. internalSteps = Math.min(internalSteps, maxSubSteps);
  27879. do {
  27880. this.onBeforeStepObservable.notifyObservers(this);
  27881. // Animations
  27882. this._animationRatio = defaultFrameTime * defaultFPS;
  27883. this._animate();
  27884. this.onAfterAnimationsObservable.notifyObservers(this);
  27885. // Physics
  27886. if (this._physicsEngine) {
  27887. this.onBeforePhysicsObservable.notifyObservers(this);
  27888. this._physicsEngine._step(defaultFrameTime / 1000);
  27889. this.onAfterPhysicsObservable.notifyObservers(this);
  27890. }
  27891. this.onAfterStepObservable.notifyObservers(this);
  27892. this._currentStepId++;
  27893. stepsTaken++;
  27894. deltaTime -= defaultFrameTime;
  27895. } while (deltaTime > 0 && stepsTaken < internalSteps);
  27896. this._timeAccumulator = deltaTime < 0 ? 0 : deltaTime;
  27897. }
  27898. else {
  27899. // Animations
  27900. var deltaTime = this.useConstantAnimationDeltaTime ? 16 : Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));
  27901. this._animationRatio = deltaTime * (60.0 / 1000.0);
  27902. this._animate();
  27903. this.onAfterAnimationsObservable.notifyObservers(this);
  27904. // Physics
  27905. if (this._physicsEngine) {
  27906. this.onBeforePhysicsObservable.notifyObservers(this);
  27907. this._physicsEngine._step(deltaTime / 1000.0);
  27908. this.onAfterPhysicsObservable.notifyObservers(this);
  27909. }
  27910. }
  27911. // update gamepad manager
  27912. if (this._gamepadManager && this._gamepadManager._isMonitoring) {
  27913. this._gamepadManager._checkGamepadsStatus();
  27914. }
  27915. // Update Cameras
  27916. if (updateCameras) {
  27917. if (this.activeCameras.length > 0) {
  27918. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  27919. var camera = this.activeCameras[cameraIndex];
  27920. camera.update();
  27921. if (camera.cameraRigMode !== BABYLON.Camera.RIG_MODE_NONE) {
  27922. // rig cameras
  27923. for (var index = 0; index < camera._rigCameras.length; index++) {
  27924. camera._rigCameras[index].update();
  27925. }
  27926. }
  27927. }
  27928. }
  27929. else if (this.activeCamera) {
  27930. this.activeCamera.update();
  27931. if (this.activeCamera.cameraRigMode !== BABYLON.Camera.RIG_MODE_NONE) {
  27932. // rig cameras
  27933. for (var index = 0; index < this.activeCamera._rigCameras.length; index++) {
  27934. this.activeCamera._rigCameras[index].update();
  27935. }
  27936. }
  27937. }
  27938. }
  27939. // Before render
  27940. this.onBeforeRenderObservable.notifyObservers(this);
  27941. // Customs render targets
  27942. this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);
  27943. var engine = this.getEngine();
  27944. var currentActiveCamera = this.activeCamera;
  27945. if (this.renderTargetsEnabled) {
  27946. BABYLON.Tools.StartPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  27947. this._intermediateRendering = true;
  27948. for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
  27949. var renderTarget = this.customRenderTargets[customIndex];
  27950. if (renderTarget._shouldRender()) {
  27951. this._renderId++;
  27952. this.activeCamera = renderTarget.activeCamera || this.activeCamera;
  27953. if (!this.activeCamera)
  27954. throw new Error("Active camera not set");
  27955. // Viewport
  27956. engine.setViewport(this.activeCamera.viewport);
  27957. // Camera
  27958. this.updateTransformMatrix();
  27959. renderTarget.render(currentActiveCamera !== this.activeCamera, this.dumpNextRenderTargets);
  27960. }
  27961. }
  27962. BABYLON.Tools.EndPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  27963. this._intermediateRendering = false;
  27964. this._renderId++;
  27965. }
  27966. // Restore back buffer
  27967. if (this.customRenderTargets.length > 0) {
  27968. engine.restoreDefaultFramebuffer();
  27969. }
  27970. this.onAfterRenderTargetsRenderObservable.notifyObservers(this);
  27971. this.activeCamera = currentActiveCamera;
  27972. // Procedural textures
  27973. if (this.proceduralTexturesEnabled) {
  27974. BABYLON.Tools.StartPerformanceCounter("Procedural textures", this.proceduralTextures.length > 0);
  27975. for (var proceduralIndex = 0; proceduralIndex < this.proceduralTextures.length; proceduralIndex++) {
  27976. var proceduralTexture = this.proceduralTextures[proceduralIndex];
  27977. if (proceduralTexture._shouldRender()) {
  27978. proceduralTexture.render();
  27979. }
  27980. }
  27981. BABYLON.Tools.EndPerformanceCounter("Procedural textures", this.proceduralTextures.length > 0);
  27982. }
  27983. // Clear
  27984. if (this.autoClearDepthAndStencil || this.autoClear) {
  27985. this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, this.autoClearDepthAndStencil, this.autoClearDepthAndStencil);
  27986. }
  27987. // Shadows
  27988. if (this.shadowsEnabled) {
  27989. for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
  27990. var light = this.lights[lightIndex];
  27991. var shadowGenerator = light.getShadowGenerator();
  27992. if (light.isEnabled() && light.shadowEnabled && shadowGenerator) {
  27993. var shadowMap = (shadowGenerator.getShadowMap());
  27994. if (this.textures.indexOf(shadowMap) !== -1) {
  27995. this._renderTargets.push(shadowMap);
  27996. }
  27997. }
  27998. }
  27999. }
  28000. // Depth renderer
  28001. for (var key in this._depthRenderer) {
  28002. this._renderTargets.push(this._depthRenderer[key].getDepthMap());
  28003. }
  28004. // Geometry renderer
  28005. if (this._geometryBufferRenderer) {
  28006. this._renderTargets.push(this._geometryBufferRenderer.getGBuffer());
  28007. }
  28008. // RenderPipeline
  28009. if (this._postProcessRenderPipelineManager) {
  28010. this._postProcessRenderPipelineManager.update();
  28011. }
  28012. // Multi-cameras?
  28013. if (this.activeCameras.length > 0) {
  28014. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  28015. if (cameraIndex > 0) {
  28016. this._engine.clear(null, false, true, true);
  28017. }
  28018. this._processSubCameras(this.activeCameras[cameraIndex]);
  28019. }
  28020. }
  28021. else {
  28022. if (!this.activeCamera) {
  28023. throw new Error("No camera defined");
  28024. }
  28025. this._processSubCameras(this.activeCamera);
  28026. }
  28027. // Intersection checks
  28028. this._checkIntersections();
  28029. // Update the audio listener attached to the camera
  28030. if (BABYLON.AudioEngine) {
  28031. this._updateAudioParameters();
  28032. }
  28033. // After render
  28034. if (this.afterRender) {
  28035. this.afterRender();
  28036. }
  28037. this.onAfterRenderObservable.notifyObservers(this);
  28038. // Cleaning
  28039. for (var index = 0; index < this._toBeDisposed.length; index++) {
  28040. var data = this._toBeDisposed.data[index];
  28041. if (data) {
  28042. data.dispose();
  28043. }
  28044. this._toBeDisposed[index] = null;
  28045. }
  28046. this._toBeDisposed.reset();
  28047. if (this.dumpNextRenderTargets) {
  28048. this.dumpNextRenderTargets = false;
  28049. }
  28050. this._activeBones.addCount(0, true);
  28051. this._activeIndices.addCount(0, true);
  28052. this._activeParticles.addCount(0, true);
  28053. };
  28054. Scene.prototype._updateAudioParameters = function () {
  28055. if (!this.audioEnabled || !this._mainSoundTrack || (this._mainSoundTrack.soundCollection.length === 0 && this.soundTracks.length === 1)) {
  28056. return;
  28057. }
  28058. var listeningCamera;
  28059. var audioEngine = BABYLON.Engine.audioEngine;
  28060. if (this.activeCameras.length > 0) {
  28061. listeningCamera = this.activeCameras[0];
  28062. }
  28063. else {
  28064. listeningCamera = this.activeCamera;
  28065. }
  28066. if (listeningCamera && audioEngine.canUseWebAudio && audioEngine.audioContext) {
  28067. audioEngine.audioContext.listener.setPosition(listeningCamera.position.x, listeningCamera.position.y, listeningCamera.position.z);
  28068. // for VR cameras
  28069. if (listeningCamera.rigCameras && listeningCamera.rigCameras.length > 0) {
  28070. listeningCamera = listeningCamera.rigCameras[0];
  28071. }
  28072. var mat = BABYLON.Matrix.Invert(listeningCamera.getViewMatrix());
  28073. var cameraDirection = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -1), mat);
  28074. cameraDirection.normalize();
  28075. // To avoid some errors on GearVR
  28076. if (!isNaN(cameraDirection.x) && !isNaN(cameraDirection.y) && !isNaN(cameraDirection.z)) {
  28077. audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
  28078. }
  28079. var i;
  28080. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  28081. var sound = this.mainSoundTrack.soundCollection[i];
  28082. if (sound.useCustomAttenuation) {
  28083. sound.updateDistanceFromListener();
  28084. }
  28085. }
  28086. for (i = 0; i < this.soundTracks.length; i++) {
  28087. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  28088. sound = this.soundTracks[i].soundCollection[j];
  28089. if (sound.useCustomAttenuation) {
  28090. sound.updateDistanceFromListener();
  28091. }
  28092. }
  28093. }
  28094. }
  28095. };
  28096. Object.defineProperty(Scene.prototype, "audioEnabled", {
  28097. // Audio
  28098. /**
  28099. * Gets or sets if audio support is enabled
  28100. * @see http://doc.babylonjs.com/how_to/playing_sounds_and_music
  28101. */
  28102. get: function () {
  28103. return this._audioEnabled;
  28104. },
  28105. set: function (value) {
  28106. this._audioEnabled = value;
  28107. if (BABYLON.AudioEngine) {
  28108. if (this._audioEnabled) {
  28109. this._enableAudio();
  28110. }
  28111. else {
  28112. this._disableAudio();
  28113. }
  28114. }
  28115. },
  28116. enumerable: true,
  28117. configurable: true
  28118. });
  28119. Scene.prototype._disableAudio = function () {
  28120. var i;
  28121. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  28122. this.mainSoundTrack.soundCollection[i].pause();
  28123. }
  28124. for (i = 0; i < this.soundTracks.length; i++) {
  28125. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  28126. this.soundTracks[i].soundCollection[j].pause();
  28127. }
  28128. }
  28129. };
  28130. Scene.prototype._enableAudio = function () {
  28131. var i;
  28132. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  28133. if (this.mainSoundTrack.soundCollection[i].isPaused) {
  28134. this.mainSoundTrack.soundCollection[i].play();
  28135. }
  28136. }
  28137. for (i = 0; i < this.soundTracks.length; i++) {
  28138. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  28139. if (this.soundTracks[i].soundCollection[j].isPaused) {
  28140. this.soundTracks[i].soundCollection[j].play();
  28141. }
  28142. }
  28143. }
  28144. };
  28145. Object.defineProperty(Scene.prototype, "headphone", {
  28146. /**
  28147. * Gets or sets if audio will be output to headphones
  28148. * @see http://doc.babylonjs.com/how_to/playing_sounds_and_music
  28149. */
  28150. get: function () {
  28151. return this._headphone;
  28152. },
  28153. set: function (value) {
  28154. this._headphone = value;
  28155. if (BABYLON.AudioEngine) {
  28156. if (this._headphone) {
  28157. this._switchAudioModeForHeadphones();
  28158. }
  28159. else {
  28160. this._switchAudioModeForNormalSpeakers();
  28161. }
  28162. }
  28163. },
  28164. enumerable: true,
  28165. configurable: true
  28166. });
  28167. Scene.prototype._switchAudioModeForHeadphones = function () {
  28168. this.mainSoundTrack.switchPanningModelToHRTF();
  28169. for (var i = 0; i < this.soundTracks.length; i++) {
  28170. this.soundTracks[i].switchPanningModelToHRTF();
  28171. }
  28172. };
  28173. Scene.prototype._switchAudioModeForNormalSpeakers = function () {
  28174. this.mainSoundTrack.switchPanningModelToEqualPower();
  28175. for (var i = 0; i < this.soundTracks.length; i++) {
  28176. this.soundTracks[i].switchPanningModelToEqualPower();
  28177. }
  28178. };
  28179. /**
  28180. * Creates a depth renderer a given camera which contains a depth map which can be used for post processing.
  28181. * @param camera The camera to create the depth renderer on (default: scene's active camera)
  28182. * @returns the created depth renderer
  28183. */
  28184. Scene.prototype.enableDepthRenderer = function (camera) {
  28185. camera = camera || this.activeCamera;
  28186. if (!camera) {
  28187. throw "No camera available to enable depth renderer";
  28188. }
  28189. if (!this._depthRenderer[camera.id]) {
  28190. var textureType = 0;
  28191. if (this._engine.getCaps().textureHalfFloatRender) {
  28192. textureType = BABYLON.Engine.TEXTURETYPE_HALF_FLOAT;
  28193. }
  28194. else if (this._engine.getCaps().textureFloatRender) {
  28195. textureType = BABYLON.Engine.TEXTURETYPE_FLOAT;
  28196. }
  28197. else {
  28198. throw "Depth renderer does not support int texture type";
  28199. }
  28200. this._depthRenderer[camera.id] = new BABYLON.DepthRenderer(this, textureType, camera);
  28201. }
  28202. return this._depthRenderer[camera.id];
  28203. };
  28204. /**
  28205. * Disables a depth renderer for a given camera
  28206. * @param camera The camera to disable the depth renderer on (default: scene's active camera)
  28207. */
  28208. Scene.prototype.disableDepthRenderer = function (camera) {
  28209. camera = camera || this.activeCamera;
  28210. if (!camera || !this._depthRenderer[camera.id]) {
  28211. return;
  28212. }
  28213. this._depthRenderer[camera.id].dispose();
  28214. delete this._depthRenderer[camera.id];
  28215. };
  28216. /**
  28217. * Enables a GeometryBufferRender and associates it with the scene
  28218. * @param ratio defines the scaling ratio to apply to the renderer (1 by default which means same resolution)
  28219. * @returns the GeometryBufferRenderer
  28220. */
  28221. Scene.prototype.enableGeometryBufferRenderer = function (ratio) {
  28222. if (ratio === void 0) { ratio = 1; }
  28223. if (this._geometryBufferRenderer) {
  28224. return this._geometryBufferRenderer;
  28225. }
  28226. this._geometryBufferRenderer = new BABYLON.GeometryBufferRenderer(this, ratio);
  28227. if (!this._geometryBufferRenderer.isSupported) {
  28228. this._geometryBufferRenderer = null;
  28229. }
  28230. return this._geometryBufferRenderer;
  28231. };
  28232. /**
  28233. * Disables the GeometryBufferRender associated with the scene
  28234. */
  28235. Scene.prototype.disableGeometryBufferRenderer = function () {
  28236. if (!this._geometryBufferRenderer) {
  28237. return;
  28238. }
  28239. this._geometryBufferRenderer.dispose();
  28240. this._geometryBufferRenderer = null;
  28241. };
  28242. /**
  28243. * Freeze all materials
  28244. * A frozen material will not be updatable but should be faster to render
  28245. */
  28246. Scene.prototype.freezeMaterials = function () {
  28247. for (var i = 0; i < this.materials.length; i++) {
  28248. this.materials[i].freeze();
  28249. }
  28250. };
  28251. /**
  28252. * Unfreeze all materials
  28253. * A frozen material will not be updatable but should be faster to render
  28254. */
  28255. Scene.prototype.unfreezeMaterials = function () {
  28256. for (var i = 0; i < this.materials.length; i++) {
  28257. this.materials[i].unfreeze();
  28258. }
  28259. };
  28260. /**
  28261. * Releases all held ressources
  28262. */
  28263. Scene.prototype.dispose = function () {
  28264. this.beforeRender = null;
  28265. this.afterRender = null;
  28266. this.skeletons = [];
  28267. this.morphTargetManagers = [];
  28268. this.importedMeshesFiles = new Array();
  28269. this.stopAllAnimations();
  28270. this.resetCachedMaterial();
  28271. for (var key in this._depthRenderer) {
  28272. this._depthRenderer[key].dispose();
  28273. }
  28274. if (this._gamepadManager) {
  28275. this._gamepadManager.dispose();
  28276. this._gamepadManager = null;
  28277. }
  28278. // Smart arrays
  28279. if (this.activeCamera) {
  28280. this.activeCamera._activeMeshes.dispose();
  28281. this.activeCamera = null;
  28282. }
  28283. this._activeMeshes.dispose();
  28284. this._renderingManager.dispose();
  28285. this._processedMaterials.dispose();
  28286. this._activeParticleSystems.dispose();
  28287. this._activeSkeletons.dispose();
  28288. this._softwareSkinnedMeshes.dispose();
  28289. this._renderTargets.dispose();
  28290. this._registeredForLateAnimationBindings.dispose();
  28291. if (this._boundingBoxRenderer) {
  28292. this._boundingBoxRenderer.dispose();
  28293. }
  28294. this._meshesForIntersections.dispose();
  28295. this._toBeDisposed.dispose();
  28296. // Abort active requests
  28297. for (var _i = 0, _a = this._activeRequests; _i < _a.length; _i++) {
  28298. var request = _a[_i];
  28299. request.abort();
  28300. }
  28301. // Debug layer
  28302. if (this._debugLayer) {
  28303. this._debugLayer.hide();
  28304. }
  28305. // Events
  28306. this.onDisposeObservable.notifyObservers(this);
  28307. this.onDisposeObservable.clear();
  28308. this.onBeforeRenderObservable.clear();
  28309. this.onAfterRenderObservable.clear();
  28310. this.onBeforeRenderTargetsRenderObservable.clear();
  28311. this.onAfterRenderTargetsRenderObservable.clear();
  28312. this.onAfterStepObservable.clear();
  28313. this.onBeforeStepObservable.clear();
  28314. this.onBeforeActiveMeshesEvaluationObservable.clear();
  28315. this.onAfterActiveMeshesEvaluationObservable.clear();
  28316. this.onBeforeParticlesRenderingObservable.clear();
  28317. this.onAfterParticlesRenderingObservable.clear();
  28318. this.onBeforeSpritesRenderingObservable.clear();
  28319. this.onAfterSpritesRenderingObservable.clear();
  28320. this.onBeforeDrawPhaseObservable.clear();
  28321. this.onAfterDrawPhaseObservable.clear();
  28322. this.onBeforePhysicsObservable.clear();
  28323. this.onAfterPhysicsObservable.clear();
  28324. this.onBeforeAnimationsObservable.clear();
  28325. this.onAfterAnimationsObservable.clear();
  28326. this.onDataLoadedObservable.clear();
  28327. this.detachControl();
  28328. // Release sounds & sounds tracks
  28329. if (BABYLON.AudioEngine) {
  28330. this.disposeSounds();
  28331. }
  28332. // VR Helper
  28333. if (this.VRHelper) {
  28334. this.VRHelper.dispose();
  28335. }
  28336. // Detach cameras
  28337. var canvas = this._engine.getRenderingCanvas();
  28338. if (canvas) {
  28339. var index;
  28340. for (index = 0; index < this.cameras.length; index++) {
  28341. this.cameras[index].detachControl(canvas);
  28342. }
  28343. }
  28344. // Release animation groups
  28345. while (this.animationGroups.length) {
  28346. this.animationGroups[0].dispose();
  28347. }
  28348. // Release lights
  28349. while (this.lights.length) {
  28350. this.lights[0].dispose();
  28351. }
  28352. // Release meshes
  28353. while (this.meshes.length) {
  28354. this.meshes[0].dispose(true);
  28355. }
  28356. while (this.transformNodes.length) {
  28357. this.removeTransformNode(this.transformNodes[0]);
  28358. }
  28359. // Release cameras
  28360. while (this.cameras.length) {
  28361. this.cameras[0].dispose();
  28362. }
  28363. // Release materials
  28364. if (this.defaultMaterial) {
  28365. this.defaultMaterial.dispose();
  28366. }
  28367. while (this.multiMaterials.length) {
  28368. this.multiMaterials[0].dispose();
  28369. }
  28370. while (this.materials.length) {
  28371. this.materials[0].dispose();
  28372. }
  28373. // Release particles
  28374. while (this.particleSystems.length) {
  28375. this.particleSystems[0].dispose();
  28376. }
  28377. // Release sprites
  28378. while (this.spriteManagers.length) {
  28379. this.spriteManagers[0].dispose();
  28380. }
  28381. // Release postProcesses
  28382. while (this.postProcesses.length) {
  28383. this.postProcesses[0].dispose();
  28384. }
  28385. // Release layers
  28386. while (this.layers.length) {
  28387. this.layers[0].dispose();
  28388. }
  28389. while (this.effectLayers.length) {
  28390. this.effectLayers[0].dispose();
  28391. }
  28392. // Release textures
  28393. while (this.textures.length) {
  28394. this.textures[0].dispose();
  28395. }
  28396. // Release UBO
  28397. this._sceneUbo.dispose();
  28398. if (this._alternateSceneUbo) {
  28399. this._alternateSceneUbo.dispose();
  28400. }
  28401. // Post-processes
  28402. this.postProcessManager.dispose();
  28403. if (this._postProcessRenderPipelineManager) {
  28404. this._postProcessRenderPipelineManager.dispose();
  28405. }
  28406. // Physics
  28407. if (this._physicsEngine) {
  28408. this.disablePhysicsEngine();
  28409. }
  28410. // Remove from engine
  28411. index = this._engine.scenes.indexOf(this);
  28412. if (index > -1) {
  28413. this._engine.scenes.splice(index, 1);
  28414. }
  28415. this._engine.wipeCaches(true);
  28416. this._isDisposed = true;
  28417. };
  28418. Object.defineProperty(Scene.prototype, "isDisposed", {
  28419. /**
  28420. * Gets if the scene is already disposed
  28421. */
  28422. get: function () {
  28423. return this._isDisposed;
  28424. },
  28425. enumerable: true,
  28426. configurable: true
  28427. });
  28428. /**
  28429. * Releases sounds & soundtracks
  28430. */
  28431. Scene.prototype.disposeSounds = function () {
  28432. if (!this._mainSoundTrack) {
  28433. return;
  28434. }
  28435. this.mainSoundTrack.dispose();
  28436. for (var scIndex = 0; scIndex < this.soundTracks.length; scIndex++) {
  28437. this.soundTracks[scIndex].dispose();
  28438. }
  28439. };
  28440. /**
  28441. * Call this function to reduce memory footprint of the scene.
  28442. * Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)
  28443. */
  28444. Scene.prototype.clearCachedVertexData = function () {
  28445. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  28446. var mesh = this.meshes[meshIndex];
  28447. var geometry = mesh.geometry;
  28448. if (geometry) {
  28449. geometry._indices = [];
  28450. for (var vbName in geometry._vertexBuffers) {
  28451. if (!geometry._vertexBuffers.hasOwnProperty(vbName)) {
  28452. continue;
  28453. }
  28454. geometry._vertexBuffers[vbName]._buffer._data = null;
  28455. }
  28456. }
  28457. }
  28458. };
  28459. /**
  28460. * This function will remove the local cached buffer data from texture.
  28461. * It will save memory but will prevent the texture from being rebuilt
  28462. */
  28463. Scene.prototype.cleanCachedTextureBuffer = function () {
  28464. for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
  28465. var baseTexture = _a[_i];
  28466. var buffer = baseTexture._buffer;
  28467. if (buffer) {
  28468. baseTexture._buffer = null;
  28469. }
  28470. }
  28471. };
  28472. // Octrees
  28473. /**
  28474. * Get the world extend vectors with an optional filter
  28475. *
  28476. * @param filterPredicate the predicate - which meshes should be included when calculating the world size
  28477. * @returns {{ min: Vector3; max: Vector3 }} min and max vectors
  28478. */
  28479. Scene.prototype.getWorldExtends = function (filterPredicate) {
  28480. var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  28481. var max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  28482. filterPredicate = filterPredicate || (function () { return true; });
  28483. this.meshes.filter(filterPredicate).forEach(function (mesh) {
  28484. mesh.computeWorldMatrix(true);
  28485. if (!mesh.subMeshes || mesh.subMeshes.length === 0 || mesh.infiniteDistance) {
  28486. return;
  28487. }
  28488. var boundingInfo = mesh.getBoundingInfo();
  28489. var minBox = boundingInfo.boundingBox.minimumWorld;
  28490. var maxBox = boundingInfo.boundingBox.maximumWorld;
  28491. BABYLON.Tools.CheckExtends(minBox, min, max);
  28492. BABYLON.Tools.CheckExtends(maxBox, min, max);
  28493. });
  28494. return {
  28495. min: min,
  28496. max: max
  28497. };
  28498. };
  28499. /**
  28500. * Creates or updates the octree used to boost selection (picking)
  28501. * @see http://doc.babylonjs.com/how_to/optimizing_your_scene_with_octrees
  28502. * @param maxCapacity defines the maximum capacity per leaf
  28503. * @param maxDepth defines the maximum depth of the octree
  28504. * @returns an octree of AbstractMesh
  28505. */
  28506. Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
  28507. if (maxCapacity === void 0) { maxCapacity = 64; }
  28508. if (maxDepth === void 0) { maxDepth = 2; }
  28509. if (!this._selectionOctree) {
  28510. this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
  28511. }
  28512. var worldExtends = this.getWorldExtends();
  28513. // Update octree
  28514. this._selectionOctree.update(worldExtends.min, worldExtends.max, this.meshes);
  28515. return this._selectionOctree;
  28516. };
  28517. // Picking
  28518. /**
  28519. * Creates a ray that can be used to pick in the scene
  28520. * @param x defines the x coordinate of the origin (on-screen)
  28521. * @param y defines the y coordinate of the origin (on-screen)
  28522. * @param world defines the world matrix to use if you want to pick in object space (instead of world space)
  28523. * @param camera defines the camera to use for the picking
  28524. * @param cameraViewSpace defines if picking will be done in view space (false by default)
  28525. * @returns a Ray
  28526. */
  28527. Scene.prototype.createPickingRay = function (x, y, world, camera, cameraViewSpace) {
  28528. if (cameraViewSpace === void 0) { cameraViewSpace = false; }
  28529. var result = BABYLON.Ray.Zero();
  28530. this.createPickingRayToRef(x, y, world, result, camera, cameraViewSpace);
  28531. return result;
  28532. };
  28533. /**
  28534. * Creates a ray that can be used to pick in the scene
  28535. * @param x defines the x coordinate of the origin (on-screen)
  28536. * @param y defines the y coordinate of the origin (on-screen)
  28537. * @param world defines the world matrix to use if you want to pick in object space (instead of world space)
  28538. * @param result defines the ray where to store the picking ray
  28539. * @param camera defines the camera to use for the picking
  28540. * @param cameraViewSpace defines if picking will be done in view space (false by default)
  28541. * @returns the current scene
  28542. */
  28543. Scene.prototype.createPickingRayToRef = function (x, y, world, result, camera, cameraViewSpace) {
  28544. if (cameraViewSpace === void 0) { cameraViewSpace = false; }
  28545. var engine = this._engine;
  28546. if (!camera) {
  28547. if (!this.activeCamera)
  28548. throw new Error("Active camera not set");
  28549. camera = this.activeCamera;
  28550. }
  28551. var cameraViewport = camera.viewport;
  28552. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  28553. // Moving coordinates to local viewport world
  28554. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  28555. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  28556. result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), cameraViewSpace ? BABYLON.Matrix.Identity() : camera.getViewMatrix(), camera.getProjectionMatrix());
  28557. return this;
  28558. };
  28559. /**
  28560. * Creates a ray that can be used to pick in the scene
  28561. * @param x defines the x coordinate of the origin (on-screen)
  28562. * @param y defines the y coordinate of the origin (on-screen)
  28563. * @param camera defines the camera to use for the picking
  28564. * @returns a Ray
  28565. */
  28566. Scene.prototype.createPickingRayInCameraSpace = function (x, y, camera) {
  28567. var result = BABYLON.Ray.Zero();
  28568. this.createPickingRayInCameraSpaceToRef(x, y, result, camera);
  28569. return result;
  28570. };
  28571. /**
  28572. * Creates a ray that can be used to pick in the scene
  28573. * @param x defines the x coordinate of the origin (on-screen)
  28574. * @param y defines the y coordinate of the origin (on-screen)
  28575. * @param result defines the ray where to store the picking ray
  28576. * @param camera defines the camera to use for the picking
  28577. * @returns the current scene
  28578. */
  28579. Scene.prototype.createPickingRayInCameraSpaceToRef = function (x, y, result, camera) {
  28580. if (!BABYLON.PickingInfo) {
  28581. return this;
  28582. }
  28583. var engine = this._engine;
  28584. if (!camera) {
  28585. if (!this.activeCamera)
  28586. throw new Error("Active camera not set");
  28587. camera = this.activeCamera;
  28588. }
  28589. var cameraViewport = camera.viewport;
  28590. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  28591. var identity = BABYLON.Matrix.Identity();
  28592. // Moving coordinates to local viewport world
  28593. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  28594. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  28595. result.update(x, y, viewport.width, viewport.height, identity, identity, camera.getProjectionMatrix());
  28596. return this;
  28597. };
  28598. Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
  28599. if (!BABYLON.PickingInfo) {
  28600. return null;
  28601. }
  28602. var pickingInfo = null;
  28603. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  28604. var mesh = this.meshes[meshIndex];
  28605. if (predicate) {
  28606. if (!predicate(mesh)) {
  28607. continue;
  28608. }
  28609. }
  28610. else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  28611. continue;
  28612. }
  28613. var world = mesh.getWorldMatrix();
  28614. var ray = rayFunction(world);
  28615. var result = mesh.intersects(ray, fastCheck);
  28616. if (!result || !result.hit)
  28617. continue;
  28618. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  28619. continue;
  28620. pickingInfo = result;
  28621. if (fastCheck) {
  28622. break;
  28623. }
  28624. }
  28625. return pickingInfo || new BABYLON.PickingInfo();
  28626. };
  28627. Scene.prototype._internalMultiPick = function (rayFunction, predicate) {
  28628. if (!BABYLON.PickingInfo) {
  28629. return null;
  28630. }
  28631. var pickingInfos = new Array();
  28632. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  28633. var mesh = this.meshes[meshIndex];
  28634. if (predicate) {
  28635. if (!predicate(mesh)) {
  28636. continue;
  28637. }
  28638. }
  28639. else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  28640. continue;
  28641. }
  28642. var world = mesh.getWorldMatrix();
  28643. var ray = rayFunction(world);
  28644. var result = mesh.intersects(ray, false);
  28645. if (!result || !result.hit)
  28646. continue;
  28647. pickingInfos.push(result);
  28648. }
  28649. return pickingInfos;
  28650. };
  28651. Scene.prototype._internalPickSprites = function (ray, predicate, fastCheck, camera) {
  28652. if (!BABYLON.PickingInfo) {
  28653. return null;
  28654. }
  28655. var pickingInfo = null;
  28656. if (!camera) {
  28657. if (!this.activeCamera) {
  28658. return null;
  28659. }
  28660. camera = this.activeCamera;
  28661. }
  28662. if (this.spriteManagers.length > 0) {
  28663. for (var spriteIndex = 0; spriteIndex < this.spriteManagers.length; spriteIndex++) {
  28664. var spriteManager = this.spriteManagers[spriteIndex];
  28665. if (!spriteManager.isPickable) {
  28666. continue;
  28667. }
  28668. var result = spriteManager.intersects(ray, camera, predicate, fastCheck);
  28669. if (!result || !result.hit)
  28670. continue;
  28671. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  28672. continue;
  28673. pickingInfo = result;
  28674. if (fastCheck) {
  28675. break;
  28676. }
  28677. }
  28678. }
  28679. return pickingInfo || new BABYLON.PickingInfo();
  28680. };
  28681. /** Launch a ray to try to pick a mesh in the scene
  28682. * @param x position on screen
  28683. * @param y position on screen
  28684. * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true
  28685. * @param fastCheck Launch a fast check only using the bounding boxes. Can be set to null.
  28686. * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
  28687. * @returns a PickingInfo
  28688. */
  28689. Scene.prototype.pick = function (x, y, predicate, fastCheck, camera) {
  28690. var _this = this;
  28691. if (!BABYLON.PickingInfo) {
  28692. return null;
  28693. }
  28694. var result = this._internalPick(function (world) {
  28695. _this.createPickingRayToRef(x, y, world, _this._tempPickingRay, camera || null);
  28696. return _this._tempPickingRay;
  28697. }, predicate, fastCheck);
  28698. if (result) {
  28699. result.ray = this.createPickingRay(x, y, BABYLON.Matrix.Identity(), camera || null);
  28700. }
  28701. return result;
  28702. };
  28703. /** Launch a ray to try to pick a sprite in the scene
  28704. * @param x position on screen
  28705. * @param y position on screen
  28706. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  28707. * @param fastCheck Launch a fast check only using the bounding boxes. Can be set to null.
  28708. * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
  28709. * @returns a PickingInfo
  28710. */
  28711. Scene.prototype.pickSprite = function (x, y, predicate, fastCheck, camera) {
  28712. this.createPickingRayInCameraSpaceToRef(x, y, this._tempPickingRay, camera);
  28713. return this._internalPickSprites(this._tempPickingRay, predicate, fastCheck, camera);
  28714. };
  28715. /** Use the given ray to pick a mesh in the scene
  28716. * @param ray The ray to use to pick meshes
  28717. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  28718. * @param fastCheck Launch a fast check only using the bounding boxes. Can be set to null
  28719. * @returns a PickingInfo
  28720. */
  28721. Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
  28722. var _this = this;
  28723. var result = this._internalPick(function (world) {
  28724. if (!_this._pickWithRayInverseMatrix) {
  28725. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  28726. }
  28727. world.invertToRef(_this._pickWithRayInverseMatrix);
  28728. if (!_this._cachedRayForTransform) {
  28729. _this._cachedRayForTransform = BABYLON.Ray.Zero();
  28730. }
  28731. BABYLON.Ray.TransformToRef(ray, _this._pickWithRayInverseMatrix, _this._cachedRayForTransform);
  28732. return _this._cachedRayForTransform;
  28733. }, predicate, fastCheck);
  28734. if (result) {
  28735. result.ray = ray;
  28736. }
  28737. return result;
  28738. };
  28739. /**
  28740. * Launch a ray to try to pick a mesh in the scene
  28741. * @param x X position on screen
  28742. * @param y Y position on screen
  28743. * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true
  28744. * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
  28745. * @returns an array of PickingInfo
  28746. */
  28747. Scene.prototype.multiPick = function (x, y, predicate, camera) {
  28748. var _this = this;
  28749. return this._internalMultiPick(function (world) { return _this.createPickingRay(x, y, world, camera || null); }, predicate);
  28750. };
  28751. /**
  28752. * Launch a ray to try to pick a mesh in the scene
  28753. * @param ray Ray to use
  28754. * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true
  28755. * @returns an array of PickingInfo
  28756. */
  28757. Scene.prototype.multiPickWithRay = function (ray, predicate) {
  28758. var _this = this;
  28759. return this._internalMultiPick(function (world) {
  28760. if (!_this._pickWithRayInverseMatrix) {
  28761. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  28762. }
  28763. world.invertToRef(_this._pickWithRayInverseMatrix);
  28764. if (!_this._cachedRayForTransform) {
  28765. _this._cachedRayForTransform = BABYLON.Ray.Zero();
  28766. }
  28767. BABYLON.Ray.TransformToRef(ray, _this._pickWithRayInverseMatrix, _this._cachedRayForTransform);
  28768. return _this._cachedRayForTransform;
  28769. }, predicate);
  28770. };
  28771. /**
  28772. * Force the value of meshUnderPointer
  28773. * @param mesh defines the mesh to use
  28774. */
  28775. Scene.prototype.setPointerOverMesh = function (mesh) {
  28776. if (this._pointerOverMesh === mesh) {
  28777. return;
  28778. }
  28779. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  28780. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  28781. }
  28782. this._pointerOverMesh = mesh;
  28783. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  28784. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  28785. }
  28786. };
  28787. /**
  28788. * Gets the mesh under the pointer
  28789. * @returns a Mesh or null if no mesh is under the pointer
  28790. */
  28791. Scene.prototype.getPointerOverMesh = function () {
  28792. return this._pointerOverMesh;
  28793. };
  28794. /**
  28795. * Force the sprite under the pointer
  28796. * @param sprite defines the sprite to use
  28797. */
  28798. Scene.prototype.setPointerOverSprite = function (sprite) {
  28799. if (this._pointerOverSprite === sprite) {
  28800. return;
  28801. }
  28802. if (this._pointerOverSprite && this._pointerOverSprite.actionManager) {
  28803. this._pointerOverSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNewFromSprite(this._pointerOverSprite, this));
  28804. }
  28805. this._pointerOverSprite = sprite;
  28806. if (this._pointerOverSprite && this._pointerOverSprite.actionManager) {
  28807. this._pointerOverSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNewFromSprite(this._pointerOverSprite, this));
  28808. }
  28809. };
  28810. /**
  28811. * Gets the sprite under the pointer
  28812. * @returns a Sprite or null if no sprite is under the pointer
  28813. */
  28814. Scene.prototype.getPointerOverSprite = function () {
  28815. return this._pointerOverSprite;
  28816. };
  28817. // Physics
  28818. /**
  28819. * Gets the current physics engine
  28820. * @returns a PhysicsEngine or null if none attached
  28821. */
  28822. Scene.prototype.getPhysicsEngine = function () {
  28823. return this._physicsEngine;
  28824. };
  28825. /**
  28826. * Enables physics to the current scene
  28827. * @param gravity defines the scene's gravity for the physics engine
  28828. * @param plugin defines the physics engine to be used. defaults to OimoJS.
  28829. * @return a boolean indicating if the physics engine was initialized
  28830. */
  28831. Scene.prototype.enablePhysics = function (gravity, plugin) {
  28832. if (gravity === void 0) { gravity = null; }
  28833. if (this._physicsEngine) {
  28834. return true;
  28835. }
  28836. try {
  28837. this._physicsEngine = new BABYLON.PhysicsEngine(gravity, plugin);
  28838. return true;
  28839. }
  28840. catch (e) {
  28841. BABYLON.Tools.Error(e.message);
  28842. return false;
  28843. }
  28844. };
  28845. /**
  28846. * Disables and disposes the physics engine associated with the scene
  28847. */
  28848. Scene.prototype.disablePhysicsEngine = function () {
  28849. if (!this._physicsEngine) {
  28850. return;
  28851. }
  28852. this._physicsEngine.dispose();
  28853. this._physicsEngine = null;
  28854. };
  28855. /**
  28856. * Gets a boolean indicating if there is an active physics engine
  28857. * @returns a boolean indicating if there is an active physics engine
  28858. */
  28859. Scene.prototype.isPhysicsEnabled = function () {
  28860. return this._physicsEngine !== undefined;
  28861. };
  28862. /**
  28863. * Deletes a physics compound impostor
  28864. * @param compound defines the compound to delete
  28865. */
  28866. Scene.prototype.deleteCompoundImpostor = function (compound) {
  28867. var mesh = compound.parts[0].mesh;
  28868. if (mesh.physicsImpostor) {
  28869. mesh.physicsImpostor.dispose( /*true*/);
  28870. mesh.physicsImpostor = null;
  28871. }
  28872. };
  28873. // Misc.
  28874. /** @hidden */
  28875. Scene.prototype._rebuildGeometries = function () {
  28876. for (var _i = 0, _a = this._geometries; _i < _a.length; _i++) {
  28877. var geometry = _a[_i];
  28878. geometry._rebuild();
  28879. }
  28880. for (var _b = 0, _c = this.meshes; _b < _c.length; _b++) {
  28881. var mesh = _c[_b];
  28882. mesh._rebuild();
  28883. }
  28884. if (this.postProcessManager) {
  28885. this.postProcessManager._rebuild();
  28886. }
  28887. for (var _d = 0, _e = this.layers; _d < _e.length; _d++) {
  28888. var layer = _e[_d];
  28889. layer._rebuild();
  28890. }
  28891. for (var _f = 0, _g = this.effectLayers; _f < _g.length; _f++) {
  28892. var effectLayer = _g[_f];
  28893. effectLayer._rebuild();
  28894. }
  28895. if (this._boundingBoxRenderer) {
  28896. this._boundingBoxRenderer._rebuild();
  28897. }
  28898. for (var _h = 0, _j = this.particleSystems; _h < _j.length; _h++) {
  28899. var system = _j[_h];
  28900. system.rebuild();
  28901. }
  28902. if (this._postProcessRenderPipelineManager) {
  28903. this._postProcessRenderPipelineManager._rebuild();
  28904. }
  28905. };
  28906. /** @hidden */
  28907. Scene.prototype._rebuildTextures = function () {
  28908. for (var _i = 0, _a = this.textures; _i < _a.length; _i++) {
  28909. var texture = _a[_i];
  28910. texture._rebuild();
  28911. }
  28912. this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  28913. };
  28914. /**
  28915. * Creates a default light for the scene.
  28916. * @param replace Whether to replace the existing lights in the scene.
  28917. */
  28918. Scene.prototype.createDefaultLight = function (replace) {
  28919. if (replace === void 0) { replace = false; }
  28920. // Dispose existing light in replace mode.
  28921. if (replace) {
  28922. if (this.lights) {
  28923. for (var i = 0; i < this.lights.length; i++) {
  28924. this.lights[i].dispose();
  28925. }
  28926. }
  28927. }
  28928. // Light
  28929. if (this.lights.length === 0) {
  28930. new BABYLON.HemisphericLight("default light", BABYLON.Vector3.Up(), this);
  28931. }
  28932. };
  28933. /**
  28934. * Creates a default camera for the scene.
  28935. * @param createArcRotateCamera Whether to create an arc rotate or a free camera.
  28936. * @param replace Whether to replace the existing active camera in the scene.
  28937. * @param attachCameraControls Whether to attach camera controls to the canvas.
  28938. */
  28939. Scene.prototype.createDefaultCamera = function (createArcRotateCamera, replace, attachCameraControls) {
  28940. if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
  28941. if (replace === void 0) { replace = false; }
  28942. if (attachCameraControls === void 0) { attachCameraControls = false; }
  28943. // Dispose existing camera in replace mode.
  28944. if (replace) {
  28945. if (this.activeCamera) {
  28946. this.activeCamera.dispose();
  28947. this.activeCamera = null;
  28948. }
  28949. }
  28950. // Camera
  28951. if (!this.activeCamera) {
  28952. var worldExtends = this.getWorldExtends();
  28953. var worldSize = worldExtends.max.subtract(worldExtends.min);
  28954. var worldCenter = worldExtends.min.add(worldSize.scale(0.5));
  28955. var camera;
  28956. var radius = worldSize.length() * 1.5;
  28957. // empty scene scenario!
  28958. if (!isFinite(radius)) {
  28959. radius = 1;
  28960. worldCenter.copyFromFloats(0, 0, 0);
  28961. }
  28962. if (createArcRotateCamera) {
  28963. var arcRotateCamera = new BABYLON.ArcRotateCamera("default camera", -(Math.PI / 2), Math.PI / 2, radius, worldCenter, this);
  28964. arcRotateCamera.lowerRadiusLimit = radius * 0.01;
  28965. arcRotateCamera.wheelPrecision = 100 / radius;
  28966. camera = arcRotateCamera;
  28967. }
  28968. else {
  28969. var freeCamera = new BABYLON.FreeCamera("default camera", new BABYLON.Vector3(worldCenter.x, worldCenter.y, -radius), this);
  28970. freeCamera.setTarget(worldCenter);
  28971. camera = freeCamera;
  28972. }
  28973. camera.minZ = radius * 0.01;
  28974. camera.maxZ = radius * 1000;
  28975. camera.speed = radius * 0.2;
  28976. this.activeCamera = camera;
  28977. var canvas = this.getEngine().getRenderingCanvas();
  28978. if (attachCameraControls && canvas) {
  28979. camera.attachControl(canvas);
  28980. }
  28981. }
  28982. };
  28983. /**
  28984. * Creates a default camera and a default light
  28985. * @param createArcRotateCamera defines that the camera will be an ArcRotateCamera
  28986. * @param replace defines if the camera and/or light will replace the existing ones
  28987. * @param attachCameraControls defines if attachControl will be called on the new camera
  28988. */
  28989. Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera, replace, attachCameraControls) {
  28990. if (createArcRotateCamera === void 0) { createArcRotateCamera = false; }
  28991. if (replace === void 0) { replace = false; }
  28992. if (attachCameraControls === void 0) { attachCameraControls = false; }
  28993. this.createDefaultLight(replace);
  28994. this.createDefaultCamera(createArcRotateCamera, replace, attachCameraControls);
  28995. };
  28996. /**
  28997. * Creates a new sky box
  28998. * @see http://doc.babylonjs.com/babylon101/environment#skybox
  28999. * @param environmentTexture defines the texture to use as environment texture
  29000. * @param pbr defines if PBRMaterial must be used instead of StandardMaterial
  29001. * @param scale defines the overall scale of the skybox
  29002. * @param blur defines if blurring must be applied to the environment texture (works only with pbr === true)
  29003. * @param setGlobalEnvTexture defines a boolean indicating that scene.environmentTexture must match the current skybox texture (true by default)
  29004. * @returns a new mesh holding the sky box
  29005. */
  29006. Scene.prototype.createDefaultSkybox = function (environmentTexture, pbr, scale, blur, setGlobalEnvTexture) {
  29007. if (pbr === void 0) { pbr = false; }
  29008. if (scale === void 0) { scale = 1000; }
  29009. if (blur === void 0) { blur = 0; }
  29010. if (setGlobalEnvTexture === void 0) { setGlobalEnvTexture = true; }
  29011. if (!environmentTexture) {
  29012. BABYLON.Tools.Warn("Can not create default skybox without environment texture.");
  29013. return null;
  29014. }
  29015. if (setGlobalEnvTexture) {
  29016. if (environmentTexture) {
  29017. this.environmentTexture = environmentTexture;
  29018. }
  29019. }
  29020. // Skybox
  29021. var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", scale, this);
  29022. if (pbr) {
  29023. var hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", this);
  29024. hdrSkyboxMaterial.backFaceCulling = false;
  29025. hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();
  29026. if (hdrSkyboxMaterial.reflectionTexture) {
  29027. hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  29028. }
  29029. hdrSkyboxMaterial.microSurface = 1.0 - blur;
  29030. hdrSkyboxMaterial.disableLighting = true;
  29031. hdrSkyboxMaterial.twoSidedLighting = true;
  29032. hdrSkybox.infiniteDistance = true;
  29033. hdrSkybox.material = hdrSkyboxMaterial;
  29034. }
  29035. else {
  29036. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", this);
  29037. skyboxMaterial.backFaceCulling = false;
  29038. skyboxMaterial.reflectionTexture = environmentTexture.clone();
  29039. if (skyboxMaterial.reflectionTexture) {
  29040. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  29041. }
  29042. skyboxMaterial.disableLighting = true;
  29043. hdrSkybox.infiniteDistance = true;
  29044. hdrSkybox.material = skyboxMaterial;
  29045. }
  29046. return hdrSkybox;
  29047. };
  29048. /**
  29049. * Creates a new environment
  29050. * @see http://doc.babylonjs.com/babylon101/environment#skybox
  29051. * @param options defines the options you can use to configure the environment
  29052. * @returns the new EnvironmentHelper
  29053. */
  29054. Scene.prototype.createDefaultEnvironment = function (options) {
  29055. if (BABYLON.EnvironmentHelper) {
  29056. return new BABYLON.EnvironmentHelper(options, this);
  29057. }
  29058. return null;
  29059. };
  29060. /**
  29061. * Creates a new VREXperienceHelper
  29062. * @see http://doc.babylonjs.com/how_to/webvr_helper
  29063. * @param webVROptions defines the options used to create the new VREXperienceHelper
  29064. * @returns a new VREXperienceHelper
  29065. */
  29066. Scene.prototype.createDefaultVRExperience = function (webVROptions) {
  29067. if (webVROptions === void 0) { webVROptions = {}; }
  29068. return new BABYLON.VRExperienceHelper(this, webVROptions);
  29069. };
  29070. // Tags
  29071. Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
  29072. if (tagsQuery === undefined) {
  29073. // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
  29074. return list;
  29075. }
  29076. var listByTags = [];
  29077. forEach = forEach || (function (item) { return; });
  29078. for (var i in list) {
  29079. var item = list[i];
  29080. if (BABYLON.Tags && BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
  29081. listByTags.push(item);
  29082. forEach(item);
  29083. }
  29084. }
  29085. return listByTags;
  29086. };
  29087. /**
  29088. * Get a list of meshes by tags
  29089. * @param tagsQuery defines the tags query to use
  29090. * @param forEach defines a predicate used to filter results
  29091. * @returns an array of Mesh
  29092. */
  29093. Scene.prototype.getMeshesByTags = function (tagsQuery, forEach) {
  29094. return this._getByTags(this.meshes, tagsQuery, forEach);
  29095. };
  29096. /**
  29097. * Get a list of cameras by tags
  29098. * @param tagsQuery defines the tags query to use
  29099. * @param forEach defines a predicate used to filter results
  29100. * @returns an array of Camera
  29101. */
  29102. Scene.prototype.getCamerasByTags = function (tagsQuery, forEach) {
  29103. return this._getByTags(this.cameras, tagsQuery, forEach);
  29104. };
  29105. /**
  29106. * Get a list of lights by tags
  29107. * @param tagsQuery defines the tags query to use
  29108. * @param forEach defines a predicate used to filter results
  29109. * @returns an array of Light
  29110. */
  29111. Scene.prototype.getLightsByTags = function (tagsQuery, forEach) {
  29112. return this._getByTags(this.lights, tagsQuery, forEach);
  29113. };
  29114. /**
  29115. * Get a list of materials by tags
  29116. * @param tagsQuery defines the tags query to use
  29117. * @param forEach defines a predicate used to filter results
  29118. * @returns an array of Material
  29119. */
  29120. Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
  29121. return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
  29122. };
  29123. /**
  29124. * Overrides the default sort function applied in the renderging group to prepare the meshes.
  29125. * This allowed control for front to back rendering or reversly depending of the special needs.
  29126. *
  29127. * @param renderingGroupId The rendering group id corresponding to its index
  29128. * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
  29129. * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
  29130. * @param transparentSortCompareFn The transparent queue comparison function use to sort.
  29131. */
  29132. Scene.prototype.setRenderingOrder = function (renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn) {
  29133. if (opaqueSortCompareFn === void 0) { opaqueSortCompareFn = null; }
  29134. if (alphaTestSortCompareFn === void 0) { alphaTestSortCompareFn = null; }
  29135. if (transparentSortCompareFn === void 0) { transparentSortCompareFn = null; }
  29136. this._renderingManager.setRenderingOrder(renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn);
  29137. };
  29138. /**
  29139. * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
  29140. *
  29141. * @param renderingGroupId The rendering group id corresponding to its index
  29142. * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
  29143. * @param depth Automatically clears depth between groups if true and autoClear is true.
  29144. * @param stencil Automatically clears stencil between groups if true and autoClear is true.
  29145. */
  29146. Scene.prototype.setRenderingAutoClearDepthStencil = function (renderingGroupId, autoClearDepthStencil, depth, stencil) {
  29147. if (depth === void 0) { depth = true; }
  29148. if (stencil === void 0) { stencil = true; }
  29149. this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth, stencil);
  29150. };
  29151. /**
  29152. * Will flag all materials as dirty to trigger new shader compilation
  29153. * @param flag defines the flag used to specify which material part must be marked as dirty
  29154. * @param predicate If not null, it will be used to specifiy if a material has to be marked as dirty
  29155. */
  29156. Scene.prototype.markAllMaterialsAsDirty = function (flag, predicate) {
  29157. for (var _i = 0, _a = this.materials; _i < _a.length; _i++) {
  29158. var material = _a[_i];
  29159. if (predicate && !predicate(material)) {
  29160. continue;
  29161. }
  29162. material.markAsDirty(flag);
  29163. }
  29164. };
  29165. /** @hidden */
  29166. Scene.prototype._loadFile = function (url, onSuccess, onProgress, useDatabase, useArrayBuffer, onError) {
  29167. var _this = this;
  29168. var request = BABYLON.Tools.LoadFile(url, onSuccess, onProgress, useDatabase ? this.database : undefined, useArrayBuffer, onError);
  29169. this._activeRequests.push(request);
  29170. request.onCompleteObservable.add(function (request) {
  29171. _this._activeRequests.splice(_this._activeRequests.indexOf(request), 1);
  29172. });
  29173. return request;
  29174. };
  29175. /** @hidden */
  29176. Scene.prototype._loadFileAsync = function (url, useDatabase, useArrayBuffer) {
  29177. var _this = this;
  29178. return new Promise(function (resolve, reject) {
  29179. _this._loadFile(url, function (data) {
  29180. resolve(data);
  29181. }, undefined, useDatabase, useArrayBuffer, function (request, exception) {
  29182. reject(exception);
  29183. });
  29184. });
  29185. };
  29186. // Statics
  29187. Scene._FOGMODE_NONE = 0;
  29188. Scene._FOGMODE_EXP = 1;
  29189. Scene._FOGMODE_EXP2 = 2;
  29190. Scene._FOGMODE_LINEAR = 3;
  29191. Scene._uniqueIdCounter = 0;
  29192. /**
  29193. * Gets or sets the minimum deltatime when deterministic lock step is enabled
  29194. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  29195. */
  29196. Scene.MinDeltaTime = 1.0;
  29197. /**
  29198. * Gets or sets the maximum deltatime when deterministic lock step is enabled
  29199. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  29200. */
  29201. Scene.MaxDeltaTime = 1000.0;
  29202. /** The distance in pixel that you have to move to prevent some events */
  29203. Scene.DragMovementThreshold = 10; // in pixels
  29204. /** Time in milliseconds to wait to raise long press events if button is still pressed */
  29205. Scene.LongPressDelay = 500; // in milliseconds
  29206. /** Time in milliseconds with two consecutive clicks will be considered as a double click */
  29207. Scene.DoubleClickDelay = 300; // in milliseconds
  29208. /** If you need to check double click without raising a single click at first click, enable this flag */
  29209. Scene.ExclusiveDoubleClickMode = false;
  29210. return Scene;
  29211. }());
  29212. BABYLON.Scene = Scene;
  29213. })(BABYLON || (BABYLON = {}));
  29214. //# sourceMappingURL=babylon.scene.js.map
  29215. var BABYLON;
  29216. (function (BABYLON) {
  29217. /**
  29218. * Set of assets to keep when moving a scene into an asset container.
  29219. */
  29220. var KeepAssets = /** @class */ (function () {
  29221. function KeepAssets() {
  29222. /**
  29223. * Cameras to keep.
  29224. */
  29225. this.cameras = new Array();
  29226. /**
  29227. * Lights to keep.
  29228. */
  29229. this.lights = new Array();
  29230. /**
  29231. * Meshes to keep.
  29232. */
  29233. this.meshes = new Array();
  29234. /**
  29235. * Skeletons to keep.
  29236. */
  29237. this.skeletons = new Array();
  29238. /**
  29239. * ParticleSystems to keep.
  29240. */
  29241. this.particleSystems = new Array();
  29242. /**
  29243. * Animations to keep.
  29244. */
  29245. this.animations = new Array();
  29246. /**
  29247. * AnimationGroups to keep.
  29248. */
  29249. this.animationGroups = new Array();
  29250. /**
  29251. * MultiMaterials to keep.
  29252. */
  29253. this.multiMaterials = new Array();
  29254. /**
  29255. * Materials to keep.
  29256. */
  29257. this.materials = new Array();
  29258. /**
  29259. * MorphTargetManagers to keep.
  29260. */
  29261. this.morphTargetManagers = new Array();
  29262. /**
  29263. * Geometries to keep.
  29264. */
  29265. this.geometries = new Array();
  29266. /**
  29267. * TransformNodes to keep.
  29268. */
  29269. this.transformNodes = new Array();
  29270. /**
  29271. * LensFlareSystems to keep.
  29272. */
  29273. this.lensFlareSystems = new Array();
  29274. /**
  29275. * ShadowGenerators to keep.
  29276. */
  29277. this.shadowGenerators = new Array();
  29278. /**
  29279. * ActionManagers to keep.
  29280. */
  29281. this.actionManagers = new Array();
  29282. /**
  29283. * Sounds to keep.
  29284. */
  29285. this.sounds = new Array();
  29286. /**
  29287. * Textures to keep.
  29288. */
  29289. this.textures = new Array();
  29290. /**
  29291. * Effect layers to keep.
  29292. */
  29293. this.effectLayers = new Array();
  29294. }
  29295. return KeepAssets;
  29296. }());
  29297. BABYLON.KeepAssets = KeepAssets;
  29298. /**
  29299. * Container with a set of assets that can be added or removed from a scene.
  29300. */
  29301. var AssetContainer = /** @class */ (function () {
  29302. /**
  29303. * Instantiates an AssetContainer.
  29304. * @param scene The scene the AssetContainer belongs to.
  29305. */
  29306. function AssetContainer(scene) {
  29307. // Objects
  29308. /**
  29309. * Cameras populated in the container.
  29310. */
  29311. this.cameras = new Array();
  29312. /**
  29313. * Lights populated in the container.
  29314. */
  29315. this.lights = new Array();
  29316. /**
  29317. * Meshes populated in the container.
  29318. */
  29319. this.meshes = new Array();
  29320. /**
  29321. * Skeletons populated in the container.
  29322. */
  29323. this.skeletons = new Array();
  29324. /**
  29325. * ParticleSystems populated in the container.
  29326. */
  29327. this.particleSystems = new Array();
  29328. /**
  29329. * Animations populated in the container.
  29330. */
  29331. this.animations = new Array();
  29332. /**
  29333. * AnimationGroups populated in the container.
  29334. */
  29335. this.animationGroups = new Array();
  29336. /**
  29337. * MultiMaterials populated in the container.
  29338. */
  29339. this.multiMaterials = new Array();
  29340. /**
  29341. * Materials populated in the container.
  29342. */
  29343. this.materials = new Array();
  29344. /**
  29345. * MorphTargetManagers populated in the container.
  29346. */
  29347. this.morphTargetManagers = new Array();
  29348. /**
  29349. * Geometries populated in the container.
  29350. */
  29351. this.geometries = new Array();
  29352. /**
  29353. * TransformNodes populated in the container.
  29354. */
  29355. this.transformNodes = new Array();
  29356. /**
  29357. * LensFlareSystems populated in the container.
  29358. */
  29359. this.lensFlareSystems = new Array();
  29360. /**
  29361. * ShadowGenerators populated in the container.
  29362. */
  29363. this.shadowGenerators = new Array();
  29364. /**
  29365. * ActionManagers populated in the container.
  29366. */
  29367. this.actionManagers = new Array();
  29368. /**
  29369. * Sounds populated in the container.
  29370. */
  29371. this.sounds = new Array();
  29372. /**
  29373. * Textures populated in the container.
  29374. */
  29375. this.textures = new Array();
  29376. /**
  29377. * Effect layers populated in the container.
  29378. */
  29379. this.effectLayers = new Array();
  29380. this.scene = scene;
  29381. }
  29382. /**
  29383. * Adds all the assets from the container to the scene.
  29384. */
  29385. AssetContainer.prototype.addAllToScene = function () {
  29386. var _this = this;
  29387. this.cameras.forEach(function (o) {
  29388. _this.scene.addCamera(o);
  29389. });
  29390. this.lights.forEach(function (o) {
  29391. _this.scene.addLight(o);
  29392. });
  29393. this.meshes.forEach(function (o) {
  29394. _this.scene.addMesh(o);
  29395. });
  29396. this.skeletons.forEach(function (o) {
  29397. _this.scene.addSkeleton(o);
  29398. });
  29399. this.particleSystems.forEach(function (o) {
  29400. _this.scene.addParticleSystem(o);
  29401. });
  29402. this.animations.forEach(function (o) {
  29403. _this.scene.addAnimation(o);
  29404. });
  29405. this.animationGroups.forEach(function (o) {
  29406. _this.scene.addAnimationGroup(o);
  29407. });
  29408. this.multiMaterials.forEach(function (o) {
  29409. _this.scene.addMultiMaterial(o);
  29410. });
  29411. this.materials.forEach(function (o) {
  29412. _this.scene.addMaterial(o);
  29413. });
  29414. this.morphTargetManagers.forEach(function (o) {
  29415. _this.scene.addMorphTargetManager(o);
  29416. });
  29417. this.geometries.forEach(function (o) {
  29418. _this.scene.addGeometry(o);
  29419. });
  29420. this.transformNodes.forEach(function (o) {
  29421. _this.scene.addTransformNode(o);
  29422. });
  29423. this.lensFlareSystems.forEach(function (o) {
  29424. _this.scene.addLensFlareSystem(o);
  29425. });
  29426. this.actionManagers.forEach(function (o) {
  29427. _this.scene.addActionManager(o);
  29428. });
  29429. this.sounds.forEach(function (o) {
  29430. o.play();
  29431. o.autoplay = true;
  29432. _this.scene.mainSoundTrack.AddSound(o);
  29433. });
  29434. this.textures.forEach(function (o) {
  29435. _this.scene.addTexture(o);
  29436. });
  29437. this.effectLayers.forEach(function (o) {
  29438. _this.scene.addEffectLayer(o);
  29439. });
  29440. };
  29441. /**
  29442. * Removes all the assets in the container from the scene
  29443. */
  29444. AssetContainer.prototype.removeAllFromScene = function () {
  29445. var _this = this;
  29446. this.cameras.forEach(function (o) {
  29447. _this.scene.removeCamera(o);
  29448. });
  29449. this.lights.forEach(function (o) {
  29450. _this.scene.removeLight(o);
  29451. });
  29452. this.meshes.forEach(function (o) {
  29453. _this.scene.removeMesh(o);
  29454. });
  29455. this.skeletons.forEach(function (o) {
  29456. _this.scene.removeSkeleton(o);
  29457. });
  29458. this.particleSystems.forEach(function (o) {
  29459. _this.scene.removeParticleSystem(o);
  29460. });
  29461. this.animations.forEach(function (o) {
  29462. _this.scene.removeAnimation(o);
  29463. });
  29464. this.animationGroups.forEach(function (o) {
  29465. _this.scene.removeAnimationGroup(o);
  29466. });
  29467. this.multiMaterials.forEach(function (o) {
  29468. _this.scene.removeMultiMaterial(o);
  29469. });
  29470. this.materials.forEach(function (o) {
  29471. _this.scene.removeMaterial(o);
  29472. });
  29473. this.morphTargetManagers.forEach(function (o) {
  29474. _this.scene.removeMorphTargetManager(o);
  29475. });
  29476. this.geometries.forEach(function (o) {
  29477. _this.scene.removeGeometry(o);
  29478. });
  29479. this.transformNodes.forEach(function (o) {
  29480. _this.scene.removeTransformNode(o);
  29481. });
  29482. this.lensFlareSystems.forEach(function (o) {
  29483. _this.scene.removeLensFlareSystem(o);
  29484. });
  29485. this.actionManagers.forEach(function (o) {
  29486. _this.scene.removeActionManager(o);
  29487. });
  29488. this.sounds.forEach(function (o) {
  29489. o.stop();
  29490. o.autoplay = false;
  29491. _this.scene.mainSoundTrack.RemoveSound(o);
  29492. });
  29493. this.textures.forEach(function (o) {
  29494. _this.scene.removeTexture(o);
  29495. });
  29496. this.effectLayers.forEach(function (o) {
  29497. _this.scene.removeEffectLayer(o);
  29498. });
  29499. };
  29500. AssetContainer.prototype._moveAssets = function (sourceAssets, targetAssets, keepAssets) {
  29501. for (var _i = 0, sourceAssets_1 = sourceAssets; _i < sourceAssets_1.length; _i++) {
  29502. var asset = sourceAssets_1[_i];
  29503. var move = true;
  29504. for (var _a = 0, keepAssets_1 = keepAssets; _a < keepAssets_1.length; _a++) {
  29505. var keepAsset = keepAssets_1[_a];
  29506. if (asset === keepAsset) {
  29507. move = false;
  29508. break;
  29509. }
  29510. }
  29511. if (move) {
  29512. targetAssets.push(asset);
  29513. }
  29514. }
  29515. };
  29516. /**
  29517. * Removes all the assets contained in the scene and adds them to the container.
  29518. * @param keepAssets Set of assets to keep in the scene. (default: empty)
  29519. */
  29520. AssetContainer.prototype.moveAllFromScene = function (keepAssets) {
  29521. if (keepAssets === undefined) {
  29522. keepAssets = new KeepAssets();
  29523. }
  29524. this._moveAssets(this.scene.cameras, this.cameras, keepAssets.cameras);
  29525. this._moveAssets(this.scene.meshes, this.meshes, keepAssets.meshes);
  29526. this._moveAssets(this.scene.getGeometries(), this.geometries, keepAssets.geometries);
  29527. this._moveAssets(this.scene.materials, this.materials, keepAssets.materials);
  29528. this._moveAssets(this.scene._actionManagers, this.actionManagers, keepAssets.actionManagers);
  29529. this._moveAssets(this.scene.animations, this.animations, keepAssets.animations);
  29530. this._moveAssets(this.scene.animationGroups, this.animationGroups, keepAssets.animationGroups);
  29531. this._moveAssets(this.scene.lensFlareSystems, this.lensFlareSystems, keepAssets.lensFlareSystems);
  29532. this._moveAssets(this.scene.lights, this.lights, keepAssets.lights);
  29533. this._moveAssets(this.scene.morphTargetManagers, this.morphTargetManagers, keepAssets.morphTargetManagers);
  29534. this._moveAssets(this.scene.multiMaterials, this.multiMaterials, keepAssets.multiMaterials);
  29535. this._moveAssets(this.scene.skeletons, this.skeletons, keepAssets.skeletons);
  29536. this._moveAssets(this.scene.particleSystems, this.particleSystems, keepAssets.particleSystems);
  29537. this._moveAssets(this.scene.mainSoundTrack.soundCollection, this.sounds, keepAssets.sounds);
  29538. this._moveAssets(this.scene.transformNodes, this.transformNodes, keepAssets.transformNodes);
  29539. this._moveAssets(this.scene.textures, this.textures, keepAssets.textures);
  29540. this._moveAssets(this.scene.effectLayers, this.effectLayers, keepAssets.effectLayers);
  29541. this.removeAllFromScene();
  29542. };
  29543. /**
  29544. * Adds all meshes in the asset container to a root mesh that can be used to position all the contained meshes. The root mesh is then added to the front of the meshes in the assetContainer.
  29545. * @returns the root mesh
  29546. */
  29547. AssetContainer.prototype.createRootMesh = function () {
  29548. var rootMesh = new BABYLON.Mesh("assetContainerRootMesh", this.scene);
  29549. this.meshes.forEach(function (m) {
  29550. if (!m.parent) {
  29551. rootMesh.addChild(m);
  29552. }
  29553. });
  29554. this.meshes.unshift(rootMesh);
  29555. return rootMesh;
  29556. };
  29557. return AssetContainer;
  29558. }());
  29559. BABYLON.AssetContainer = AssetContainer;
  29560. })(BABYLON || (BABYLON = {}));
  29561. //# sourceMappingURL=babylon.assetContainer.js.map
  29562. var BABYLON;
  29563. (function (BABYLON) {
  29564. var Buffer = /** @class */ (function () {
  29565. /**
  29566. * Constructor
  29567. * @param engine the engine
  29568. * @param data the data to use for this buffer
  29569. * @param updatable whether the data is updatable
  29570. * @param stride the stride (optional)
  29571. * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
  29572. * @param instanced whether the buffer is instanced (optional)
  29573. * @param useBytes set to true if the stride in in bytes (optional)
  29574. */
  29575. function Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes) {
  29576. if (stride === void 0) { stride = 0; }
  29577. if (postponeInternalCreation === void 0) { postponeInternalCreation = false; }
  29578. if (instanced === void 0) { instanced = false; }
  29579. if (useBytes === void 0) { useBytes = false; }
  29580. if (engine instanceof BABYLON.Mesh) { // old versions of BABYLON.VertexBuffer accepted 'mesh' instead of 'engine'
  29581. this._engine = engine.getScene().getEngine();
  29582. }
  29583. else {
  29584. this._engine = engine;
  29585. }
  29586. this._updatable = updatable;
  29587. this._instanced = instanced;
  29588. this._data = data;
  29589. this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;
  29590. if (!postponeInternalCreation) { // by default
  29591. this.create();
  29592. }
  29593. }
  29594. /**
  29595. * Create a new {BABYLON.VertexBuffer} based on the current buffer
  29596. * @param kind defines the vertex buffer kind (position, normal, etc.)
  29597. * @param offset defines offset in the buffer (0 by default)
  29598. * @param size defines the size in floats of attributes (position is 3 for instance)
  29599. * @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)
  29600. * @param instanced defines if the vertex buffer contains indexed data
  29601. * @param useBytes defines if the offset and stride are in bytes
  29602. * @returns the new vertex buffer
  29603. */
  29604. Buffer.prototype.createVertexBuffer = function (kind, offset, size, stride, instanced, useBytes) {
  29605. if (useBytes === void 0) { useBytes = false; }
  29606. var byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;
  29607. var byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;
  29608. // a lot of these parameters are ignored as they are overriden by the buffer
  29609. return new BABYLON.VertexBuffer(this._engine, this, kind, this._updatable, true, byteStride, instanced === undefined ? this._instanced : instanced, byteOffset, size, undefined, undefined, true);
  29610. };
  29611. // Properties
  29612. Buffer.prototype.isUpdatable = function () {
  29613. return this._updatable;
  29614. };
  29615. Buffer.prototype.getData = function () {
  29616. return this._data;
  29617. };
  29618. Buffer.prototype.getBuffer = function () {
  29619. return this._buffer;
  29620. };
  29621. /**
  29622. * Gets the stride in float32 units (i.e. byte stride / 4).
  29623. * May not be an integer if the byte stride is not divisible by 4.
  29624. * DEPRECATED. Use byteStride instead.
  29625. * @returns the stride in float32 units
  29626. */
  29627. Buffer.prototype.getStrideSize = function () {
  29628. return this.byteStride / Float32Array.BYTES_PER_ELEMENT;
  29629. };
  29630. // Methods
  29631. Buffer.prototype.create = function (data) {
  29632. if (data === void 0) { data = null; }
  29633. if (!data && this._buffer) {
  29634. return; // nothing to do
  29635. }
  29636. data = data || this._data;
  29637. if (!data) {
  29638. return;
  29639. }
  29640. if (!this._buffer) { // create buffer
  29641. if (this._updatable) {
  29642. this._buffer = this._engine.createDynamicVertexBuffer(data);
  29643. this._data = data;
  29644. }
  29645. else {
  29646. this._buffer = this._engine.createVertexBuffer(data);
  29647. }
  29648. }
  29649. else if (this._updatable) { // update buffer
  29650. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  29651. this._data = data;
  29652. }
  29653. };
  29654. Buffer.prototype._rebuild = function () {
  29655. this._buffer = null;
  29656. this.create(this._data);
  29657. };
  29658. Buffer.prototype.update = function (data) {
  29659. this.create(data);
  29660. };
  29661. /**
  29662. * Updates the data directly.
  29663. * @param data the new data
  29664. * @param offset the new offset
  29665. * @param vertexCount the vertex count (optional)
  29666. * @param useBytes set to true if the offset is in bytes
  29667. */
  29668. Buffer.prototype.updateDirectly = function (data, offset, vertexCount, useBytes) {
  29669. if (useBytes === void 0) { useBytes = false; }
  29670. if (!this._buffer) {
  29671. return;
  29672. }
  29673. if (this._updatable) { // update buffer
  29674. this._engine.updateDynamicVertexBuffer(this._buffer, data, useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT, (vertexCount ? vertexCount * this.byteStride : undefined));
  29675. this._data = null;
  29676. }
  29677. };
  29678. Buffer.prototype.dispose = function () {
  29679. if (!this._buffer) {
  29680. return;
  29681. }
  29682. if (this._engine._releaseBuffer(this._buffer)) {
  29683. this._buffer = null;
  29684. }
  29685. };
  29686. return Buffer;
  29687. }());
  29688. BABYLON.Buffer = Buffer;
  29689. })(BABYLON || (BABYLON = {}));
  29690. //# sourceMappingURL=babylon.buffer.js.map
  29691. var BABYLON;
  29692. (function (BABYLON) {
  29693. var VertexBuffer = /** @class */ (function () {
  29694. /**
  29695. * Constructor
  29696. * @param engine the engine
  29697. * @param data the data to use for this vertex buffer
  29698. * @param kind the vertex buffer kind
  29699. * @param updatable whether the data is updatable
  29700. * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
  29701. * @param stride the stride (optional)
  29702. * @param instanced whether the buffer is instanced (optional)
  29703. * @param offset the offset of the data (optional)
  29704. * @param size the number of components (optional)
  29705. * @param type the type of the component (optional)
  29706. * @param normalized whether the data contains normalized data (optional)
  29707. * @param useBytes set to true if stride and offset are in bytes (optional)
  29708. */
  29709. function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation, stride, instanced, offset, size, type, normalized, useBytes) {
  29710. if (normalized === void 0) { normalized = false; }
  29711. if (useBytes === void 0) { useBytes = false; }
  29712. if (data instanceof BABYLON.Buffer) {
  29713. this._buffer = data;
  29714. this._ownsBuffer = false;
  29715. }
  29716. else {
  29717. this._buffer = new BABYLON.Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);
  29718. this._ownsBuffer = true;
  29719. }
  29720. this._kind = kind;
  29721. if (type == undefined) {
  29722. var data_1 = this.getData();
  29723. this.type = VertexBuffer.FLOAT;
  29724. if (data_1 instanceof Int8Array)
  29725. this.type = VertexBuffer.BYTE;
  29726. else if (data_1 instanceof Uint8Array)
  29727. this.type = VertexBuffer.UNSIGNED_BYTE;
  29728. else if (data_1 instanceof Int16Array)
  29729. this.type = VertexBuffer.SHORT;
  29730. else if (data_1 instanceof Uint16Array)
  29731. this.type = VertexBuffer.UNSIGNED_SHORT;
  29732. else if (data_1 instanceof Int32Array)
  29733. this.type = VertexBuffer.INT;
  29734. else if (data_1 instanceof Uint32Array)
  29735. this.type = VertexBuffer.UNSIGNED_INT;
  29736. }
  29737. else {
  29738. this.type = type;
  29739. }
  29740. var typeByteLength = VertexBuffer.GetTypeByteLength(this.type);
  29741. if (useBytes) {
  29742. this._size = size || (stride ? (stride / typeByteLength) : VertexBuffer.DeduceStride(kind));
  29743. this.byteStride = stride || this._buffer.byteStride || (this._size * typeByteLength);
  29744. this.byteOffset = offset || 0;
  29745. }
  29746. else {
  29747. this._size = size || stride || VertexBuffer.DeduceStride(kind);
  29748. this.byteStride = stride ? (stride * typeByteLength) : (this._buffer.byteStride || (this._size * typeByteLength));
  29749. this.byteOffset = (offset || 0) * typeByteLength;
  29750. }
  29751. this.normalized = normalized;
  29752. this._instanced = instanced !== undefined ? instanced : false;
  29753. this._instanceDivisor = instanced ? 1 : 0;
  29754. }
  29755. Object.defineProperty(VertexBuffer.prototype, "instanceDivisor", {
  29756. /**
  29757. * Gets or sets the instance divisor when in instanced mode
  29758. */
  29759. get: function () {
  29760. return this._instanceDivisor;
  29761. },
  29762. set: function (value) {
  29763. this._instanceDivisor = value;
  29764. if (value == 0) {
  29765. this._instanced = false;
  29766. }
  29767. else {
  29768. this._instanced = true;
  29769. }
  29770. },
  29771. enumerable: true,
  29772. configurable: true
  29773. });
  29774. VertexBuffer.prototype._rebuild = function () {
  29775. if (!this._buffer) {
  29776. return;
  29777. }
  29778. this._buffer._rebuild();
  29779. };
  29780. /**
  29781. * Returns the kind of the VertexBuffer (string).
  29782. */
  29783. VertexBuffer.prototype.getKind = function () {
  29784. return this._kind;
  29785. };
  29786. // Properties
  29787. /**
  29788. * Boolean : is the VertexBuffer updatable ?
  29789. */
  29790. VertexBuffer.prototype.isUpdatable = function () {
  29791. return this._buffer.isUpdatable();
  29792. };
  29793. /**
  29794. * Returns an array of numbers or a typed array containing the VertexBuffer data.
  29795. */
  29796. VertexBuffer.prototype.getData = function () {
  29797. return this._buffer.getData();
  29798. };
  29799. /**
  29800. * Returns the WebGLBuffer associated to the VertexBuffer.
  29801. */
  29802. VertexBuffer.prototype.getBuffer = function () {
  29803. return this._buffer.getBuffer();
  29804. };
  29805. /**
  29806. * Returns the stride as a multiple of the type byte length.
  29807. * DEPRECATED. Use byteStride instead.
  29808. */
  29809. VertexBuffer.prototype.getStrideSize = function () {
  29810. return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);
  29811. };
  29812. /**
  29813. * Returns the offset as a multiple of the type byte length.
  29814. * DEPRECATED. Use byteOffset instead.
  29815. */
  29816. VertexBuffer.prototype.getOffset = function () {
  29817. return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);
  29818. };
  29819. /**
  29820. * Returns the number of components per vertex attribute (integer).
  29821. */
  29822. VertexBuffer.prototype.getSize = function () {
  29823. return this._size;
  29824. };
  29825. /**
  29826. * Boolean : is the WebGLBuffer of the VertexBuffer instanced now ?
  29827. */
  29828. VertexBuffer.prototype.getIsInstanced = function () {
  29829. return this._instanced;
  29830. };
  29831. /**
  29832. * Returns the instancing divisor, zero for non-instanced (integer).
  29833. */
  29834. VertexBuffer.prototype.getInstanceDivisor = function () {
  29835. return this._instanceDivisor;
  29836. };
  29837. // Methods
  29838. /**
  29839. * Creates the underlying WebGLBuffer from the passed numeric array or Float32Array.
  29840. * Returns the created WebGLBuffer.
  29841. */
  29842. VertexBuffer.prototype.create = function (data) {
  29843. return this._buffer.create(data);
  29844. };
  29845. /**
  29846. * Updates the underlying WebGLBuffer according to the passed numeric array or Float32Array.
  29847. * This function will create a new buffer if the current one is not updatable
  29848. * Returns the updated WebGLBuffer.
  29849. */
  29850. VertexBuffer.prototype.update = function (data) {
  29851. return this._buffer.update(data);
  29852. };
  29853. /**
  29854. * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.
  29855. * Returns the directly updated WebGLBuffer.
  29856. * @param data the new data
  29857. * @param offset the new offset
  29858. * @param useBytes set to true if the offset is in bytes
  29859. */
  29860. VertexBuffer.prototype.updateDirectly = function (data, offset, useBytes) {
  29861. if (useBytes === void 0) { useBytes = false; }
  29862. this._buffer.updateDirectly(data, offset, undefined, useBytes);
  29863. };
  29864. /**
  29865. * Disposes the VertexBuffer and the underlying WebGLBuffer.
  29866. */
  29867. VertexBuffer.prototype.dispose = function () {
  29868. if (this._ownsBuffer) {
  29869. this._buffer.dispose();
  29870. }
  29871. };
  29872. /**
  29873. * Enumerates each value of this vertex buffer as numbers.
  29874. * @param count the number of values to enumerate
  29875. * @param callback the callback function called for each value
  29876. */
  29877. VertexBuffer.prototype.forEach = function (count, callback) {
  29878. VertexBuffer.ForEach(this._buffer.getData(), this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);
  29879. };
  29880. Object.defineProperty(VertexBuffer, "PositionKind", {
  29881. get: function () {
  29882. return VertexBuffer._PositionKind;
  29883. },
  29884. enumerable: true,
  29885. configurable: true
  29886. });
  29887. Object.defineProperty(VertexBuffer, "NormalKind", {
  29888. get: function () {
  29889. return VertexBuffer._NormalKind;
  29890. },
  29891. enumerable: true,
  29892. configurable: true
  29893. });
  29894. Object.defineProperty(VertexBuffer, "TangentKind", {
  29895. get: function () {
  29896. return VertexBuffer._TangentKind;
  29897. },
  29898. enumerable: true,
  29899. configurable: true
  29900. });
  29901. Object.defineProperty(VertexBuffer, "UVKind", {
  29902. get: function () {
  29903. return VertexBuffer._UVKind;
  29904. },
  29905. enumerable: true,
  29906. configurable: true
  29907. });
  29908. Object.defineProperty(VertexBuffer, "UV2Kind", {
  29909. get: function () {
  29910. return VertexBuffer._UV2Kind;
  29911. },
  29912. enumerable: true,
  29913. configurable: true
  29914. });
  29915. Object.defineProperty(VertexBuffer, "UV3Kind", {
  29916. get: function () {
  29917. return VertexBuffer._UV3Kind;
  29918. },
  29919. enumerable: true,
  29920. configurable: true
  29921. });
  29922. Object.defineProperty(VertexBuffer, "UV4Kind", {
  29923. get: function () {
  29924. return VertexBuffer._UV4Kind;
  29925. },
  29926. enumerable: true,
  29927. configurable: true
  29928. });
  29929. Object.defineProperty(VertexBuffer, "UV5Kind", {
  29930. get: function () {
  29931. return VertexBuffer._UV5Kind;
  29932. },
  29933. enumerable: true,
  29934. configurable: true
  29935. });
  29936. Object.defineProperty(VertexBuffer, "UV6Kind", {
  29937. get: function () {
  29938. return VertexBuffer._UV6Kind;
  29939. },
  29940. enumerable: true,
  29941. configurable: true
  29942. });
  29943. Object.defineProperty(VertexBuffer, "ColorKind", {
  29944. get: function () {
  29945. return VertexBuffer._ColorKind;
  29946. },
  29947. enumerable: true,
  29948. configurable: true
  29949. });
  29950. Object.defineProperty(VertexBuffer, "MatricesIndicesKind", {
  29951. get: function () {
  29952. return VertexBuffer._MatricesIndicesKind;
  29953. },
  29954. enumerable: true,
  29955. configurable: true
  29956. });
  29957. Object.defineProperty(VertexBuffer, "MatricesWeightsKind", {
  29958. get: function () {
  29959. return VertexBuffer._MatricesWeightsKind;
  29960. },
  29961. enumerable: true,
  29962. configurable: true
  29963. });
  29964. Object.defineProperty(VertexBuffer, "MatricesIndicesExtraKind", {
  29965. get: function () {
  29966. return VertexBuffer._MatricesIndicesExtraKind;
  29967. },
  29968. enumerable: true,
  29969. configurable: true
  29970. });
  29971. Object.defineProperty(VertexBuffer, "MatricesWeightsExtraKind", {
  29972. get: function () {
  29973. return VertexBuffer._MatricesWeightsExtraKind;
  29974. },
  29975. enumerable: true,
  29976. configurable: true
  29977. });
  29978. /**
  29979. * Deduces the stride given a kind.
  29980. * @param kind The kind string to deduce
  29981. * @returns The deduced stride
  29982. */
  29983. VertexBuffer.DeduceStride = function (kind) {
  29984. switch (kind) {
  29985. case VertexBuffer.UVKind:
  29986. case VertexBuffer.UV2Kind:
  29987. case VertexBuffer.UV3Kind:
  29988. case VertexBuffer.UV4Kind:
  29989. case VertexBuffer.UV5Kind:
  29990. case VertexBuffer.UV6Kind:
  29991. return 2;
  29992. case VertexBuffer.NormalKind:
  29993. case VertexBuffer.PositionKind:
  29994. return 3;
  29995. case VertexBuffer.ColorKind:
  29996. case VertexBuffer.MatricesIndicesKind:
  29997. case VertexBuffer.MatricesIndicesExtraKind:
  29998. case VertexBuffer.MatricesWeightsKind:
  29999. case VertexBuffer.MatricesWeightsExtraKind:
  30000. case VertexBuffer.TangentKind:
  30001. return 4;
  30002. default:
  30003. throw new Error("Invalid kind '" + kind + "'");
  30004. }
  30005. };
  30006. /**
  30007. * Gets the byte length of the given type.
  30008. * @param type the type
  30009. * @returns the number of bytes
  30010. */
  30011. VertexBuffer.GetTypeByteLength = function (type) {
  30012. switch (type) {
  30013. case VertexBuffer.BYTE:
  30014. case VertexBuffer.UNSIGNED_BYTE:
  30015. return 1;
  30016. case VertexBuffer.SHORT:
  30017. case VertexBuffer.UNSIGNED_SHORT:
  30018. return 2;
  30019. case VertexBuffer.INT:
  30020. case VertexBuffer.FLOAT:
  30021. return 4;
  30022. default:
  30023. throw new Error("Invalid type '" + type + "'");
  30024. }
  30025. };
  30026. /**
  30027. * Enumerates each value of the given parameters as numbers.
  30028. * @param data the data to enumerate
  30029. * @param byteOffset the byte offset of the data
  30030. * @param byteStride the byte stride of the data
  30031. * @param componentCount the number of components per element
  30032. * @param componentType the type of the component
  30033. * @param count the total number of components
  30034. * @param normalized whether the data is normalized
  30035. * @param callback the callback function called for each value
  30036. */
  30037. VertexBuffer.ForEach = function (data, byteOffset, byteStride, componentCount, componentType, count, normalized, callback) {
  30038. if (data instanceof Array) {
  30039. var offset = byteOffset / 4;
  30040. var stride = byteStride / 4;
  30041. for (var index = 0; index < count; index += componentCount) {
  30042. for (var componentIndex = 0; componentIndex < componentCount; componentIndex++) {
  30043. callback(data[offset + componentIndex], index + componentIndex);
  30044. }
  30045. offset += stride;
  30046. }
  30047. }
  30048. else {
  30049. var dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);
  30050. var componentByteLength = VertexBuffer.GetTypeByteLength(componentType);
  30051. for (var index = 0; index < count; index += componentCount) {
  30052. var componentByteOffset = byteOffset;
  30053. for (var componentIndex = 0; componentIndex < componentCount; componentIndex++) {
  30054. var value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);
  30055. callback(value, index + componentIndex);
  30056. componentByteOffset += componentByteLength;
  30057. }
  30058. byteOffset += byteStride;
  30059. }
  30060. }
  30061. };
  30062. VertexBuffer._GetFloatValue = function (dataView, type, byteOffset, normalized) {
  30063. switch (type) {
  30064. case VertexBuffer.BYTE: {
  30065. var value = dataView.getInt8(byteOffset);
  30066. if (normalized) {
  30067. value = Math.max(value / 127, -1);
  30068. }
  30069. return value;
  30070. }
  30071. case VertexBuffer.UNSIGNED_BYTE: {
  30072. var value = dataView.getUint8(byteOffset);
  30073. if (normalized) {
  30074. value = value / 255;
  30075. }
  30076. return value;
  30077. }
  30078. case VertexBuffer.SHORT: {
  30079. var value = dataView.getInt16(byteOffset, true);
  30080. if (normalized) {
  30081. value = Math.max(value / 16383, -1);
  30082. }
  30083. return value;
  30084. }
  30085. case VertexBuffer.UNSIGNED_SHORT: {
  30086. var value = dataView.getUint16(byteOffset, true);
  30087. if (normalized) {
  30088. value = value / 65535;
  30089. }
  30090. return value;
  30091. }
  30092. case VertexBuffer.FLOAT: {
  30093. return dataView.getFloat32(byteOffset, true);
  30094. }
  30095. default: {
  30096. throw new Error("Invalid component type " + type);
  30097. }
  30098. }
  30099. };
  30100. /**
  30101. * The byte type.
  30102. */
  30103. VertexBuffer.BYTE = 5120;
  30104. /**
  30105. * The unsigned byte type.
  30106. */
  30107. VertexBuffer.UNSIGNED_BYTE = 5121;
  30108. /**
  30109. * The short type.
  30110. */
  30111. VertexBuffer.SHORT = 5122;
  30112. /**
  30113. * The unsigned short type.
  30114. */
  30115. VertexBuffer.UNSIGNED_SHORT = 5123;
  30116. /**
  30117. * The integer type.
  30118. */
  30119. VertexBuffer.INT = 5124;
  30120. /**
  30121. * The unsigned integer type.
  30122. */
  30123. VertexBuffer.UNSIGNED_INT = 5125;
  30124. /**
  30125. * The float type.
  30126. */
  30127. VertexBuffer.FLOAT = 5126;
  30128. // Enums
  30129. VertexBuffer._PositionKind = "position";
  30130. VertexBuffer._NormalKind = "normal";
  30131. VertexBuffer._TangentKind = "tangent";
  30132. VertexBuffer._UVKind = "uv";
  30133. VertexBuffer._UV2Kind = "uv2";
  30134. VertexBuffer._UV3Kind = "uv3";
  30135. VertexBuffer._UV4Kind = "uv4";
  30136. VertexBuffer._UV5Kind = "uv5";
  30137. VertexBuffer._UV6Kind = "uv6";
  30138. VertexBuffer._ColorKind = "color";
  30139. VertexBuffer._MatricesIndicesKind = "matricesIndices";
  30140. VertexBuffer._MatricesWeightsKind = "matricesWeights";
  30141. VertexBuffer._MatricesIndicesExtraKind = "matricesIndicesExtra";
  30142. VertexBuffer._MatricesWeightsExtraKind = "matricesWeightsExtra";
  30143. return VertexBuffer;
  30144. }());
  30145. BABYLON.VertexBuffer = VertexBuffer;
  30146. })(BABYLON || (BABYLON = {}));
  30147. //# sourceMappingURL=babylon.vertexBuffer.js.map
  30148. var BABYLON;
  30149. (function (BABYLON) {
  30150. /**
  30151. * Internal class used by the engine to get list of {BABYLON.InternalTexture} already bound to the GL context
  30152. */
  30153. var DummyInternalTextureTracker = /** @class */ (function () {
  30154. function DummyInternalTextureTracker() {
  30155. /**
  30156. * Gets or set the previous tracker in the list
  30157. */
  30158. this.previous = null;
  30159. /**
  30160. * Gets or set the next tracker in the list
  30161. */
  30162. this.next = null;
  30163. }
  30164. return DummyInternalTextureTracker;
  30165. }());
  30166. BABYLON.DummyInternalTextureTracker = DummyInternalTextureTracker;
  30167. })(BABYLON || (BABYLON = {}));
  30168. //# sourceMappingURL=babylon.internalTextureTracker.js.map
  30169. var BABYLON;
  30170. (function (BABYLON) {
  30171. /**
  30172. * Class used to store data associated with WebGL texture data for the engine
  30173. * This class should not be used directly
  30174. */
  30175. var InternalTexture = /** @class */ (function () {
  30176. /**
  30177. * Creates a new InternalTexture
  30178. * @param engine defines the engine to use
  30179. * @param dataSource defines the type of data that will be used
  30180. */
  30181. function InternalTexture(engine, dataSource) {
  30182. /**
  30183. * Observable called when the texture is loaded
  30184. */
  30185. this.onLoadedObservable = new BABYLON.Observable();
  30186. /**
  30187. * Gets or set the previous tracker in the list
  30188. */
  30189. this.previous = null;
  30190. /**
  30191. * Gets or set the next tracker in the list
  30192. */
  30193. this.next = null;
  30194. // Private
  30195. /** @hidden */
  30196. this._initialSlot = -1;
  30197. /** @hidden */
  30198. this._designatedSlot = -1;
  30199. /** @hidden */
  30200. this._dataSource = InternalTexture.DATASOURCE_UNKNOWN;
  30201. /** @hidden */
  30202. this._comparisonFunction = 0;
  30203. /** @hidden */
  30204. this._isRGBD = false;
  30205. /** @hidden */
  30206. this._references = 1;
  30207. this._engine = engine;
  30208. this._dataSource = dataSource;
  30209. this._webGLTexture = engine._createTexture();
  30210. }
  30211. /**
  30212. * Gets the Engine the texture belongs to.
  30213. * @returns The babylon engine
  30214. */
  30215. InternalTexture.prototype.getEngine = function () {
  30216. return this._engine;
  30217. };
  30218. Object.defineProperty(InternalTexture.prototype, "dataSource", {
  30219. /**
  30220. * Gets the data source type of the texture (can be one of the BABYLON.InternalTexture.DATASOURCE_XXXX)
  30221. */
  30222. get: function () {
  30223. return this._dataSource;
  30224. },
  30225. enumerable: true,
  30226. configurable: true
  30227. });
  30228. /**
  30229. * Increments the number of references (ie. the number of {BABYLON.Texture} that point to it)
  30230. */
  30231. InternalTexture.prototype.incrementReferences = function () {
  30232. this._references++;
  30233. };
  30234. /**
  30235. * Change the size of the texture (not the size of the content)
  30236. * @param width defines the new width
  30237. * @param height defines the new height
  30238. * @param depth defines the new depth (1 by default)
  30239. */
  30240. InternalTexture.prototype.updateSize = function (width, height, depth) {
  30241. if (depth === void 0) { depth = 1; }
  30242. this.width = width;
  30243. this.height = height;
  30244. this.depth = depth;
  30245. this.baseWidth = width;
  30246. this.baseHeight = height;
  30247. this.baseDepth = depth;
  30248. this._size = width * height * depth;
  30249. };
  30250. /** @hidden */
  30251. InternalTexture.prototype._rebuild = function () {
  30252. var _this = this;
  30253. var proxy;
  30254. this.isReady = false;
  30255. this._cachedCoordinatesMode = null;
  30256. this._cachedWrapU = null;
  30257. this._cachedWrapV = null;
  30258. this._cachedAnisotropicFilteringLevel = null;
  30259. switch (this._dataSource) {
  30260. case InternalTexture.DATASOURCE_TEMP:
  30261. return;
  30262. case InternalTexture.DATASOURCE_URL:
  30263. proxy = this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, null, this.samplingMode, function () {
  30264. _this.isReady = true;
  30265. }, null, this._buffer, undefined, this.format);
  30266. proxy._swapAndDie(this);
  30267. return;
  30268. case InternalTexture.DATASOURCE_RAW:
  30269. proxy = this._engine.createRawTexture(this._bufferView, this.baseWidth, this.baseHeight, this.format, this.generateMipMaps, this.invertY, this.samplingMode, this._compression);
  30270. proxy._swapAndDie(this);
  30271. this.isReady = true;
  30272. return;
  30273. case InternalTexture.DATASOURCE_RAW3D:
  30274. proxy = this._engine.createRawTexture3D(this._bufferView, this.baseWidth, this.baseHeight, this.baseDepth, this.format, this.generateMipMaps, this.invertY, this.samplingMode, this._compression);
  30275. proxy._swapAndDie(this);
  30276. this.isReady = true;
  30277. return;
  30278. case InternalTexture.DATASOURCE_DYNAMIC:
  30279. proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode);
  30280. proxy._swapAndDie(this);
  30281. // The engine will make sure to update content so no need to flag it as isReady = true
  30282. return;
  30283. case InternalTexture.DATASOURCE_RENDERTARGET:
  30284. var options = new BABYLON.RenderTargetCreationOptions();
  30285. options.generateDepthBuffer = this._generateDepthBuffer;
  30286. options.generateMipMaps = this.generateMipMaps;
  30287. options.generateStencilBuffer = this._generateStencilBuffer;
  30288. options.samplingMode = this.samplingMode;
  30289. options.type = this.type;
  30290. if (this.isCube) {
  30291. proxy = this._engine.createRenderTargetCubeTexture(this.width, options);
  30292. }
  30293. else {
  30294. var size = {
  30295. width: this.width,
  30296. height: this.height
  30297. };
  30298. proxy = this._engine.createRenderTargetTexture(size, options);
  30299. }
  30300. proxy._swapAndDie(this);
  30301. this.isReady = true;
  30302. return;
  30303. case InternalTexture.DATASOURCE_DEPTHTEXTURE:
  30304. var depthTextureOptions = {
  30305. bilinearFiltering: this.samplingMode !== BABYLON.Texture.BILINEAR_SAMPLINGMODE,
  30306. comparisonFunction: this._comparisonFunction,
  30307. generateStencil: this._generateStencilBuffer,
  30308. isCube: this.isCube
  30309. };
  30310. proxy = this._engine.createDepthStencilTexture({ width: this.width, height: this.height }, depthTextureOptions);
  30311. proxy._swapAndDie(this);
  30312. this.isReady = true;
  30313. return;
  30314. case InternalTexture.DATASOURCE_CUBE:
  30315. proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, function () {
  30316. _this.isReady = true;
  30317. }, null, this.format, this._extension);
  30318. proxy._swapAndDie(this);
  30319. return;
  30320. case InternalTexture.DATASOURCE_CUBERAW:
  30321. proxy = this._engine.createRawCubeTexture(this._bufferViewArray, this.width, this.format, this.type, this.generateMipMaps, this.invertY, this.samplingMode, this._compression);
  30322. proxy._swapAndDie(this);
  30323. this.isReady = true;
  30324. return;
  30325. case InternalTexture.DATASOURCE_CUBEPREFILTERED:
  30326. proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, function (proxy) {
  30327. if (proxy) {
  30328. proxy._swapAndDie(_this);
  30329. }
  30330. _this.isReady = true;
  30331. }, null, this.format, this._extension);
  30332. proxy._sphericalPolynomial = this._sphericalPolynomial;
  30333. return;
  30334. }
  30335. };
  30336. InternalTexture.prototype._swapAndDie = function (target) {
  30337. target._webGLTexture = this._webGLTexture;
  30338. if (this._framebuffer) {
  30339. target._framebuffer = this._framebuffer;
  30340. }
  30341. if (this._depthStencilBuffer) {
  30342. target._depthStencilBuffer = this._depthStencilBuffer;
  30343. }
  30344. if (this._lodTextureHigh) {
  30345. if (target._lodTextureHigh) {
  30346. target._lodTextureHigh.dispose();
  30347. }
  30348. target._lodTextureHigh = this._lodTextureHigh;
  30349. }
  30350. if (this._lodTextureMid) {
  30351. if (target._lodTextureMid) {
  30352. target._lodTextureMid.dispose();
  30353. }
  30354. target._lodTextureMid = this._lodTextureMid;
  30355. }
  30356. if (this._lodTextureLow) {
  30357. if (target._lodTextureLow) {
  30358. target._lodTextureLow.dispose();
  30359. }
  30360. target._lodTextureLow = this._lodTextureLow;
  30361. }
  30362. var cache = this._engine.getLoadedTexturesCache();
  30363. var index = cache.indexOf(this);
  30364. if (index !== -1) {
  30365. cache.splice(index, 1);
  30366. }
  30367. };
  30368. /**
  30369. * Dispose the current allocated resources
  30370. */
  30371. InternalTexture.prototype.dispose = function () {
  30372. if (!this._webGLTexture) {
  30373. return;
  30374. }
  30375. this._references--;
  30376. if (this._references === 0) {
  30377. this._engine._releaseTexture(this);
  30378. this._webGLTexture = null;
  30379. this.previous = null;
  30380. this.next = null;
  30381. }
  30382. };
  30383. /**
  30384. * The source of the texture data is unknown
  30385. */
  30386. InternalTexture.DATASOURCE_UNKNOWN = 0;
  30387. /**
  30388. * Texture data comes from an URL
  30389. */
  30390. InternalTexture.DATASOURCE_URL = 1;
  30391. /**
  30392. * Texture data is only used for temporary storage
  30393. */
  30394. InternalTexture.DATASOURCE_TEMP = 2;
  30395. /**
  30396. * Texture data comes from raw data (ArrayBuffer)
  30397. */
  30398. InternalTexture.DATASOURCE_RAW = 3;
  30399. /**
  30400. * Texture content is dynamic (video or dynamic texture)
  30401. */
  30402. InternalTexture.DATASOURCE_DYNAMIC = 4;
  30403. /**
  30404. * Texture content is generated by rendering to it
  30405. */
  30406. InternalTexture.DATASOURCE_RENDERTARGET = 5;
  30407. /**
  30408. * Texture content is part of a multi render target process
  30409. */
  30410. InternalTexture.DATASOURCE_MULTIRENDERTARGET = 6;
  30411. /**
  30412. * Texture data comes from a cube data file
  30413. */
  30414. InternalTexture.DATASOURCE_CUBE = 7;
  30415. /**
  30416. * Texture data comes from a raw cube data
  30417. */
  30418. InternalTexture.DATASOURCE_CUBERAW = 8;
  30419. /**
  30420. * Texture data come from a prefiltered cube data file
  30421. */
  30422. InternalTexture.DATASOURCE_CUBEPREFILTERED = 9;
  30423. /**
  30424. * Texture content is raw 3D data
  30425. */
  30426. InternalTexture.DATASOURCE_RAW3D = 10;
  30427. /**
  30428. * Texture content is a depth texture
  30429. */
  30430. InternalTexture.DATASOURCE_DEPTHTEXTURE = 11;
  30431. return InternalTexture;
  30432. }());
  30433. BABYLON.InternalTexture = InternalTexture;
  30434. })(BABYLON || (BABYLON = {}));
  30435. //# sourceMappingURL=babylon.internalTexture.js.map
  30436. var BABYLON;
  30437. (function (BABYLON) {
  30438. var BaseTexture = /** @class */ (function () {
  30439. function BaseTexture(scene) {
  30440. this._hasAlpha = false;
  30441. this.getAlphaFromRGB = false;
  30442. this.level = 1;
  30443. this.coordinatesIndex = 0;
  30444. this._coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
  30445. /**
  30446. * | Value | Type | Description |
  30447. * | ----- | ------------------ | ----------- |
  30448. * | 0 | CLAMP_ADDRESSMODE | |
  30449. * | 1 | WRAP_ADDRESSMODE | |
  30450. * | 2 | MIRROR_ADDRESSMODE | |
  30451. */
  30452. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  30453. /**
  30454. * | Value | Type | Description |
  30455. * | ----- | ------------------ | ----------- |
  30456. * | 0 | CLAMP_ADDRESSMODE | |
  30457. * | 1 | WRAP_ADDRESSMODE | |
  30458. * | 2 | MIRROR_ADDRESSMODE | |
  30459. */
  30460. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  30461. /**
  30462. * | Value | Type | Description |
  30463. * | ----- | ------------------ | ----------- |
  30464. * | 0 | CLAMP_ADDRESSMODE | |
  30465. * | 1 | WRAP_ADDRESSMODE | |
  30466. * | 2 | MIRROR_ADDRESSMODE | |
  30467. */
  30468. this.wrapR = BABYLON.Texture.WRAP_ADDRESSMODE;
  30469. this.anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;
  30470. this.isCube = false;
  30471. this.is3D = false;
  30472. this.gammaSpace = true;
  30473. this.invertZ = false;
  30474. this.lodLevelInAlpha = false;
  30475. this.isRenderTarget = false;
  30476. this.animations = new Array();
  30477. /**
  30478. * An event triggered when the texture is disposed.
  30479. */
  30480. this.onDisposeObservable = new BABYLON.Observable();
  30481. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  30482. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  30483. if (this._scene) {
  30484. this._scene.textures.push(this);
  30485. }
  30486. this._uid = null;
  30487. }
  30488. Object.defineProperty(BaseTexture.prototype, "hasAlpha", {
  30489. get: function () {
  30490. return this._hasAlpha;
  30491. },
  30492. set: function (value) {
  30493. if (this._hasAlpha === value) {
  30494. return;
  30495. }
  30496. this._hasAlpha = value;
  30497. if (this._scene) {
  30498. this._scene.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag | BABYLON.Material.MiscDirtyFlag);
  30499. }
  30500. },
  30501. enumerable: true,
  30502. configurable: true
  30503. });
  30504. Object.defineProperty(BaseTexture.prototype, "coordinatesMode", {
  30505. get: function () {
  30506. return this._coordinatesMode;
  30507. },
  30508. /**
  30509. * How a texture is mapped.
  30510. *
  30511. * | Value | Type | Description |
  30512. * | ----- | ----------------------------------- | ----------- |
  30513. * | 0 | EXPLICIT_MODE | |
  30514. * | 1 | SPHERICAL_MODE | |
  30515. * | 2 | PLANAR_MODE | |
  30516. * | 3 | CUBIC_MODE | |
  30517. * | 4 | PROJECTION_MODE | |
  30518. * | 5 | SKYBOX_MODE | |
  30519. * | 6 | INVCUBIC_MODE | |
  30520. * | 7 | EQUIRECTANGULAR_MODE | |
  30521. * | 8 | FIXED_EQUIRECTANGULAR_MODE | |
  30522. * | 9 | FIXED_EQUIRECTANGULAR_MIRRORED_MODE | |
  30523. */
  30524. set: function (value) {
  30525. if (this._coordinatesMode === value) {
  30526. return;
  30527. }
  30528. this._coordinatesMode = value;
  30529. if (this._scene) {
  30530. this._scene.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  30531. }
  30532. },
  30533. enumerable: true,
  30534. configurable: true
  30535. });
  30536. Object.defineProperty(BaseTexture.prototype, "isRGBD", {
  30537. /**
  30538. * Gets whether or not the texture contains RGBD data.
  30539. */
  30540. get: function () {
  30541. return this._texture != null && this._texture._isRGBD;
  30542. },
  30543. enumerable: true,
  30544. configurable: true
  30545. });
  30546. Object.defineProperty(BaseTexture.prototype, "lodGenerationOffset", {
  30547. get: function () {
  30548. if (this._texture)
  30549. return this._texture._lodGenerationOffset;
  30550. return 0.0;
  30551. },
  30552. set: function (value) {
  30553. if (this._texture)
  30554. this._texture._lodGenerationOffset = value;
  30555. },
  30556. enumerable: true,
  30557. configurable: true
  30558. });
  30559. Object.defineProperty(BaseTexture.prototype, "lodGenerationScale", {
  30560. get: function () {
  30561. if (this._texture)
  30562. return this._texture._lodGenerationScale;
  30563. return 0.0;
  30564. },
  30565. set: function (value) {
  30566. if (this._texture)
  30567. this._texture._lodGenerationScale = value;
  30568. },
  30569. enumerable: true,
  30570. configurable: true
  30571. });
  30572. Object.defineProperty(BaseTexture.prototype, "uid", {
  30573. get: function () {
  30574. if (!this._uid) {
  30575. this._uid = BABYLON.Tools.RandomId();
  30576. }
  30577. return this._uid;
  30578. },
  30579. enumerable: true,
  30580. configurable: true
  30581. });
  30582. BaseTexture.prototype.toString = function () {
  30583. return this.name;
  30584. };
  30585. BaseTexture.prototype.getClassName = function () {
  30586. return "BaseTexture";
  30587. };
  30588. Object.defineProperty(BaseTexture.prototype, "onDispose", {
  30589. set: function (callback) {
  30590. if (this._onDisposeObserver) {
  30591. this.onDisposeObservable.remove(this._onDisposeObserver);
  30592. }
  30593. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  30594. },
  30595. enumerable: true,
  30596. configurable: true
  30597. });
  30598. Object.defineProperty(BaseTexture.prototype, "isBlocking", {
  30599. get: function () {
  30600. return true;
  30601. },
  30602. enumerable: true,
  30603. configurable: true
  30604. });
  30605. BaseTexture.prototype.getScene = function () {
  30606. return this._scene;
  30607. };
  30608. BaseTexture.prototype.getTextureMatrix = function () {
  30609. return BABYLON.Matrix.IdentityReadOnly;
  30610. };
  30611. BaseTexture.prototype.getReflectionTextureMatrix = function () {
  30612. return BABYLON.Matrix.IdentityReadOnly;
  30613. };
  30614. BaseTexture.prototype.getInternalTexture = function () {
  30615. return this._texture;
  30616. };
  30617. BaseTexture.prototype.isReadyOrNotBlocking = function () {
  30618. return !this.isBlocking || this.isReady();
  30619. };
  30620. BaseTexture.prototype.isReady = function () {
  30621. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  30622. this.delayLoad();
  30623. return false;
  30624. }
  30625. if (this._texture) {
  30626. return this._texture.isReady;
  30627. }
  30628. return false;
  30629. };
  30630. BaseTexture.prototype.getSize = function () {
  30631. if (this._texture && this._texture.width) {
  30632. return new BABYLON.Size(this._texture.width, this._texture.height);
  30633. }
  30634. if (this._texture && this._texture._size) {
  30635. return new BABYLON.Size(this._texture._size, this._texture._size);
  30636. }
  30637. return BABYLON.Size.Zero();
  30638. };
  30639. BaseTexture.prototype.getBaseSize = function () {
  30640. if (!this.isReady() || !this._texture)
  30641. return BABYLON.Size.Zero();
  30642. if (this._texture._size) {
  30643. return new BABYLON.Size(this._texture._size, this._texture._size);
  30644. }
  30645. return new BABYLON.Size(this._texture.baseWidth, this._texture.baseHeight);
  30646. };
  30647. BaseTexture.prototype.scale = function (ratio) {
  30648. };
  30649. Object.defineProperty(BaseTexture.prototype, "canRescale", {
  30650. get: function () {
  30651. return false;
  30652. },
  30653. enumerable: true,
  30654. configurable: true
  30655. });
  30656. BaseTexture.prototype._getFromCache = function (url, noMipmap, sampling) {
  30657. if (!this._scene) {
  30658. return null;
  30659. }
  30660. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  30661. for (var index = 0; index < texturesCache.length; index++) {
  30662. var texturesCacheEntry = texturesCache[index];
  30663. if (texturesCacheEntry.url === url && texturesCacheEntry.generateMipMaps === !noMipmap) {
  30664. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  30665. texturesCacheEntry.incrementReferences();
  30666. return texturesCacheEntry;
  30667. }
  30668. }
  30669. }
  30670. return null;
  30671. };
  30672. BaseTexture.prototype._rebuild = function () {
  30673. };
  30674. BaseTexture.prototype.delayLoad = function () {
  30675. };
  30676. BaseTexture.prototype.clone = function () {
  30677. return null;
  30678. };
  30679. Object.defineProperty(BaseTexture.prototype, "textureType", {
  30680. get: function () {
  30681. if (!this._texture) {
  30682. return BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT;
  30683. }
  30684. return (this._texture.type !== undefined) ? this._texture.type : BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT;
  30685. },
  30686. enumerable: true,
  30687. configurable: true
  30688. });
  30689. Object.defineProperty(BaseTexture.prototype, "textureFormat", {
  30690. get: function () {
  30691. if (!this._texture) {
  30692. return BABYLON.Engine.TEXTUREFORMAT_RGBA;
  30693. }
  30694. return (this._texture.format !== undefined) ? this._texture.format : BABYLON.Engine.TEXTUREFORMAT_RGBA;
  30695. },
  30696. enumerable: true,
  30697. configurable: true
  30698. });
  30699. /**
  30700. * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.
  30701. * This will returns an RGBA array buffer containing either in values (0-255) or
  30702. * float values (0-1) depending of the underlying buffer type.
  30703. * @param faceIndex The face of the texture to read (in case of cube texture)
  30704. * @param level The LOD level of the texture to read (in case of Mip Maps)
  30705. * @returns The Array buffer containing the pixels data.
  30706. */
  30707. BaseTexture.prototype.readPixels = function (faceIndex, level) {
  30708. if (faceIndex === void 0) { faceIndex = 0; }
  30709. if (level === void 0) { level = 0; }
  30710. if (!this._texture) {
  30711. return null;
  30712. }
  30713. var size = this.getSize();
  30714. var width = size.width;
  30715. var height = size.height;
  30716. var scene = this.getScene();
  30717. if (!scene) {
  30718. return null;
  30719. }
  30720. var engine = scene.getEngine();
  30721. if (level != 0) {
  30722. width = width / Math.pow(2, level);
  30723. height = height / Math.pow(2, level);
  30724. width = Math.round(width);
  30725. height = Math.round(height);
  30726. }
  30727. if (this._texture.isCube) {
  30728. return engine._readTexturePixels(this._texture, width, height, faceIndex, level);
  30729. }
  30730. return engine._readTexturePixels(this._texture, width, height, -1, level);
  30731. };
  30732. BaseTexture.prototype.releaseInternalTexture = function () {
  30733. if (this._texture) {
  30734. this._texture.dispose();
  30735. this._texture = null;
  30736. }
  30737. };
  30738. Object.defineProperty(BaseTexture.prototype, "sphericalPolynomial", {
  30739. get: function () {
  30740. if (!this._texture || !BABYLON.CubeMapToSphericalPolynomialTools || !this.isReady()) {
  30741. return null;
  30742. }
  30743. if (!this._texture._sphericalPolynomial) {
  30744. this._texture._sphericalPolynomial =
  30745. BABYLON.CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this);
  30746. }
  30747. return this._texture._sphericalPolynomial;
  30748. },
  30749. set: function (value) {
  30750. if (this._texture) {
  30751. this._texture._sphericalPolynomial = value;
  30752. }
  30753. },
  30754. enumerable: true,
  30755. configurable: true
  30756. });
  30757. Object.defineProperty(BaseTexture.prototype, "_lodTextureHigh", {
  30758. get: function () {
  30759. if (this._texture) {
  30760. return this._texture._lodTextureHigh;
  30761. }
  30762. return null;
  30763. },
  30764. enumerable: true,
  30765. configurable: true
  30766. });
  30767. Object.defineProperty(BaseTexture.prototype, "_lodTextureMid", {
  30768. get: function () {
  30769. if (this._texture) {
  30770. return this._texture._lodTextureMid;
  30771. }
  30772. return null;
  30773. },
  30774. enumerable: true,
  30775. configurable: true
  30776. });
  30777. Object.defineProperty(BaseTexture.prototype, "_lodTextureLow", {
  30778. get: function () {
  30779. if (this._texture) {
  30780. return this._texture._lodTextureLow;
  30781. }
  30782. return null;
  30783. },
  30784. enumerable: true,
  30785. configurable: true
  30786. });
  30787. BaseTexture.prototype.dispose = function () {
  30788. if (!this._scene) {
  30789. return;
  30790. }
  30791. // Animations
  30792. this._scene.stopAnimation(this);
  30793. // Remove from scene
  30794. this._scene._removePendingData(this);
  30795. var index = this._scene.textures.indexOf(this);
  30796. if (index >= 0) {
  30797. this._scene.textures.splice(index, 1);
  30798. }
  30799. if (this._texture === undefined) {
  30800. return;
  30801. }
  30802. // Release
  30803. this.releaseInternalTexture();
  30804. // Callback
  30805. this.onDisposeObservable.notifyObservers(this);
  30806. this.onDisposeObservable.clear();
  30807. };
  30808. BaseTexture.prototype.serialize = function () {
  30809. if (!this.name) {
  30810. return null;
  30811. }
  30812. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  30813. // Animations
  30814. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  30815. return serializationObject;
  30816. };
  30817. BaseTexture.WhenAllReady = function (textures, callback) {
  30818. var numRemaining = textures.length;
  30819. if (numRemaining === 0) {
  30820. callback();
  30821. return;
  30822. }
  30823. var _loop_1 = function () {
  30824. texture = textures[i];
  30825. if (texture.isReady()) {
  30826. if (--numRemaining === 0) {
  30827. callback();
  30828. }
  30829. }
  30830. else {
  30831. onLoadObservable = texture.onLoadObservable;
  30832. var onLoadCallback_1 = function () {
  30833. onLoadObservable.removeCallback(onLoadCallback_1);
  30834. if (--numRemaining === 0) {
  30835. callback();
  30836. }
  30837. };
  30838. onLoadObservable.add(onLoadCallback_1);
  30839. }
  30840. };
  30841. var texture, onLoadObservable;
  30842. for (var i = 0; i < textures.length; i++) {
  30843. _loop_1();
  30844. }
  30845. };
  30846. BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL = 4;
  30847. __decorate([
  30848. BABYLON.serialize()
  30849. ], BaseTexture.prototype, "name", void 0);
  30850. __decorate([
  30851. BABYLON.serialize("hasAlpha")
  30852. ], BaseTexture.prototype, "_hasAlpha", void 0);
  30853. __decorate([
  30854. BABYLON.serialize()
  30855. ], BaseTexture.prototype, "getAlphaFromRGB", void 0);
  30856. __decorate([
  30857. BABYLON.serialize()
  30858. ], BaseTexture.prototype, "level", void 0);
  30859. __decorate([
  30860. BABYLON.serialize()
  30861. ], BaseTexture.prototype, "coordinatesIndex", void 0);
  30862. __decorate([
  30863. BABYLON.serialize("coordinatesMode")
  30864. ], BaseTexture.prototype, "_coordinatesMode", void 0);
  30865. __decorate([
  30866. BABYLON.serialize()
  30867. ], BaseTexture.prototype, "wrapU", void 0);
  30868. __decorate([
  30869. BABYLON.serialize()
  30870. ], BaseTexture.prototype, "wrapV", void 0);
  30871. __decorate([
  30872. BABYLON.serialize()
  30873. ], BaseTexture.prototype, "wrapR", void 0);
  30874. __decorate([
  30875. BABYLON.serialize()
  30876. ], BaseTexture.prototype, "anisotropicFilteringLevel", void 0);
  30877. __decorate([
  30878. BABYLON.serialize()
  30879. ], BaseTexture.prototype, "isCube", void 0);
  30880. __decorate([
  30881. BABYLON.serialize()
  30882. ], BaseTexture.prototype, "is3D", void 0);
  30883. __decorate([
  30884. BABYLON.serialize()
  30885. ], BaseTexture.prototype, "gammaSpace", void 0);
  30886. __decorate([
  30887. BABYLON.serialize()
  30888. ], BaseTexture.prototype, "invertZ", void 0);
  30889. __decorate([
  30890. BABYLON.serialize()
  30891. ], BaseTexture.prototype, "lodLevelInAlpha", void 0);
  30892. __decorate([
  30893. BABYLON.serialize()
  30894. ], BaseTexture.prototype, "lodGenerationOffset", null);
  30895. __decorate([
  30896. BABYLON.serialize()
  30897. ], BaseTexture.prototype, "lodGenerationScale", null);
  30898. __decorate([
  30899. BABYLON.serialize()
  30900. ], BaseTexture.prototype, "isRenderTarget", void 0);
  30901. return BaseTexture;
  30902. }());
  30903. BABYLON.BaseTexture = BaseTexture;
  30904. })(BABYLON || (BABYLON = {}));
  30905. //# sourceMappingURL=babylon.baseTexture.js.map
  30906. var BABYLON;
  30907. (function (BABYLON) {
  30908. var Texture = /** @class */ (function (_super) {
  30909. __extends(Texture, _super);
  30910. function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer, format) {
  30911. if (noMipmap === void 0) { noMipmap = false; }
  30912. if (invertY === void 0) { invertY = true; }
  30913. if (samplingMode === void 0) { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
  30914. if (onLoad === void 0) { onLoad = null; }
  30915. if (onError === void 0) { onError = null; }
  30916. if (buffer === void 0) { buffer = null; }
  30917. if (deleteBuffer === void 0) { deleteBuffer = false; }
  30918. var _this = _super.call(this, scene) || this;
  30919. _this.uOffset = 0;
  30920. _this.vOffset = 0;
  30921. _this.uScale = 1.0;
  30922. _this.vScale = 1.0;
  30923. _this.uAng = 0;
  30924. _this.vAng = 0;
  30925. _this.wAng = 0;
  30926. /**
  30927. * Defines the center of rotation (U)
  30928. */
  30929. _this.uRotationCenter = 0.5;
  30930. /**
  30931. * Defines the center of rotation (V)
  30932. */
  30933. _this.vRotationCenter = 0.5;
  30934. /**
  30935. * Defines the center of rotation (W)
  30936. */
  30937. _this.wRotationCenter = 0.5;
  30938. _this._isBlocking = true;
  30939. _this.name = url || "";
  30940. _this.url = url;
  30941. _this._noMipmap = noMipmap;
  30942. _this._invertY = invertY;
  30943. _this._samplingMode = samplingMode;
  30944. _this._buffer = buffer;
  30945. _this._deleteBuffer = deleteBuffer;
  30946. if (format) {
  30947. _this._format = format;
  30948. }
  30949. scene = _this.getScene();
  30950. if (!scene) {
  30951. return _this;
  30952. }
  30953. scene.getEngine().onBeforeTextureInitObservable.notifyObservers(_this);
  30954. var load = function () {
  30955. if (_this._onLoadObservable && _this._onLoadObservable.hasObservers()) {
  30956. _this.onLoadObservable.notifyObservers(_this);
  30957. }
  30958. if (onLoad) {
  30959. onLoad();
  30960. }
  30961. if (!_this.isBlocking && scene) {
  30962. scene.resetCachedMaterial();
  30963. }
  30964. };
  30965. if (!_this.url) {
  30966. _this._delayedOnLoad = load;
  30967. _this._delayedOnError = onError;
  30968. return _this;
  30969. }
  30970. _this._texture = _this._getFromCache(_this.url, noMipmap, samplingMode);
  30971. if (!_this._texture) {
  30972. if (!scene.useDelayedTextureLoading) {
  30973. _this._texture = scene.getEngine().createTexture(_this.url, noMipmap, invertY, scene, _this._samplingMode, load, onError, _this._buffer, undefined, _this._format);
  30974. if (deleteBuffer) {
  30975. delete _this._buffer;
  30976. }
  30977. }
  30978. else {
  30979. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  30980. _this._delayedOnLoad = load;
  30981. _this._delayedOnError = onError;
  30982. }
  30983. }
  30984. else {
  30985. if (_this._texture.isReady) {
  30986. BABYLON.Tools.SetImmediate(function () { return load(); });
  30987. }
  30988. else {
  30989. _this._texture.onLoadedObservable.add(load);
  30990. }
  30991. }
  30992. return _this;
  30993. }
  30994. Object.defineProperty(Texture.prototype, "noMipmap", {
  30995. get: function () {
  30996. return this._noMipmap;
  30997. },
  30998. enumerable: true,
  30999. configurable: true
  31000. });
  31001. Object.defineProperty(Texture.prototype, "isBlocking", {
  31002. get: function () {
  31003. return this._isBlocking;
  31004. },
  31005. set: function (value) {
  31006. this._isBlocking = value;
  31007. },
  31008. enumerable: true,
  31009. configurable: true
  31010. });
  31011. Object.defineProperty(Texture.prototype, "samplingMode", {
  31012. get: function () {
  31013. return this._samplingMode;
  31014. },
  31015. enumerable: true,
  31016. configurable: true
  31017. });
  31018. /**
  31019. * Update the url (and optional buffer) of this texture if url was null during construction.
  31020. * @param url the url of the texture
  31021. * @param buffer the buffer of the texture (defaults to null)
  31022. */
  31023. Texture.prototype.updateURL = function (url, buffer) {
  31024. if (buffer === void 0) { buffer = null; }
  31025. if (this.url) {
  31026. throw new Error("URL is already set");
  31027. }
  31028. this.url = url;
  31029. this._buffer = buffer;
  31030. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  31031. this.delayLoad();
  31032. };
  31033. Texture.prototype.delayLoad = function () {
  31034. if (this.delayLoadState !== BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  31035. return;
  31036. }
  31037. var scene = this.getScene();
  31038. if (!scene) {
  31039. return;
  31040. }
  31041. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  31042. this._texture = this._getFromCache(this.url, this._noMipmap, this._samplingMode);
  31043. if (!this._texture) {
  31044. this._texture = scene.getEngine().createTexture(this.url, this._noMipmap, this._invertY, scene, this._samplingMode, this._delayedOnLoad, this._delayedOnError, this._buffer, null, this._format);
  31045. if (this._deleteBuffer) {
  31046. delete this._buffer;
  31047. }
  31048. }
  31049. else {
  31050. if (this._delayedOnLoad) {
  31051. if (this._texture.isReady) {
  31052. BABYLON.Tools.SetImmediate(this._delayedOnLoad);
  31053. }
  31054. else {
  31055. this._texture.onLoadedObservable.add(this._delayedOnLoad);
  31056. }
  31057. }
  31058. }
  31059. this._delayedOnLoad = null;
  31060. this._delayedOnError = null;
  31061. };
  31062. Texture.prototype.updateSamplingMode = function (samplingMode) {
  31063. if (!this._texture) {
  31064. return;
  31065. }
  31066. var scene = this.getScene();
  31067. if (!scene) {
  31068. return;
  31069. }
  31070. this._samplingMode = samplingMode;
  31071. scene.getEngine().updateTextureSamplingMode(samplingMode, this._texture);
  31072. };
  31073. Texture.prototype._prepareRowForTextureGeneration = function (x, y, z, t) {
  31074. x *= this.uScale;
  31075. y *= this.vScale;
  31076. x -= this.uRotationCenter * this.uScale;
  31077. y -= this.vRotationCenter * this.vScale;
  31078. z -= this.wRotationCenter;
  31079. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix, t);
  31080. t.x += this.uRotationCenter * this.uScale + this.uOffset;
  31081. t.y += this.vRotationCenter * this.vScale + this.vOffset;
  31082. t.z += this.wRotationCenter;
  31083. };
  31084. Texture.prototype.getTextureMatrix = function () {
  31085. var _this = this;
  31086. if (this.uOffset === this._cachedUOffset &&
  31087. this.vOffset === this._cachedVOffset &&
  31088. this.uScale === this._cachedUScale &&
  31089. this.vScale === this._cachedVScale &&
  31090. this.uAng === this._cachedUAng &&
  31091. this.vAng === this._cachedVAng &&
  31092. this.wAng === this._cachedWAng) {
  31093. return this._cachedTextureMatrix;
  31094. }
  31095. this._cachedUOffset = this.uOffset;
  31096. this._cachedVOffset = this.vOffset;
  31097. this._cachedUScale = this.uScale;
  31098. this._cachedVScale = this.vScale;
  31099. this._cachedUAng = this.uAng;
  31100. this._cachedVAng = this.vAng;
  31101. this._cachedWAng = this.wAng;
  31102. if (!this._cachedTextureMatrix) {
  31103. this._cachedTextureMatrix = BABYLON.Matrix.Zero();
  31104. this._rowGenerationMatrix = new BABYLON.Matrix();
  31105. this._t0 = BABYLON.Vector3.Zero();
  31106. this._t1 = BABYLON.Vector3.Zero();
  31107. this._t2 = BABYLON.Vector3.Zero();
  31108. }
  31109. BABYLON.Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);
  31110. this._prepareRowForTextureGeneration(0, 0, 0, this._t0);
  31111. this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1);
  31112. this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2);
  31113. this._t1.subtractInPlace(this._t0);
  31114. this._t2.subtractInPlace(this._t0);
  31115. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  31116. this._cachedTextureMatrix.m[0] = this._t1.x;
  31117. this._cachedTextureMatrix.m[1] = this._t1.y;
  31118. this._cachedTextureMatrix.m[2] = this._t1.z;
  31119. this._cachedTextureMatrix.m[4] = this._t2.x;
  31120. this._cachedTextureMatrix.m[5] = this._t2.y;
  31121. this._cachedTextureMatrix.m[6] = this._t2.z;
  31122. this._cachedTextureMatrix.m[8] = this._t0.x;
  31123. this._cachedTextureMatrix.m[9] = this._t0.y;
  31124. this._cachedTextureMatrix.m[10] = this._t0.z;
  31125. var scene = this.getScene();
  31126. if (!scene) {
  31127. return this._cachedTextureMatrix;
  31128. }
  31129. scene.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag, function (mat) {
  31130. return mat.hasTexture(_this);
  31131. });
  31132. return this._cachedTextureMatrix;
  31133. };
  31134. Texture.prototype.getReflectionTextureMatrix = function () {
  31135. var _this = this;
  31136. var scene = this.getScene();
  31137. if (!scene) {
  31138. return this._cachedTextureMatrix;
  31139. }
  31140. if (this.uOffset === this._cachedUOffset &&
  31141. this.vOffset === this._cachedVOffset &&
  31142. this.uScale === this._cachedUScale &&
  31143. this.vScale === this._cachedVScale &&
  31144. this.coordinatesMode === this._cachedCoordinatesMode) {
  31145. if (this.coordinatesMode === Texture.PROJECTION_MODE) {
  31146. if (this._cachedProjectionMatrixId === scene.getProjectionMatrix().updateFlag) {
  31147. return this._cachedTextureMatrix;
  31148. }
  31149. }
  31150. else {
  31151. return this._cachedTextureMatrix;
  31152. }
  31153. }
  31154. if (!this._cachedTextureMatrix) {
  31155. this._cachedTextureMatrix = BABYLON.Matrix.Zero();
  31156. }
  31157. if (!this._projectionModeMatrix) {
  31158. this._projectionModeMatrix = BABYLON.Matrix.Zero();
  31159. }
  31160. this._cachedUOffset = this.uOffset;
  31161. this._cachedVOffset = this.vOffset;
  31162. this._cachedUScale = this.uScale;
  31163. this._cachedVScale = this.vScale;
  31164. this._cachedCoordinatesMode = this.coordinatesMode;
  31165. switch (this.coordinatesMode) {
  31166. case Texture.PLANAR_MODE:
  31167. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  31168. this._cachedTextureMatrix[0] = this.uScale;
  31169. this._cachedTextureMatrix[5] = this.vScale;
  31170. this._cachedTextureMatrix[12] = this.uOffset;
  31171. this._cachedTextureMatrix[13] = this.vOffset;
  31172. break;
  31173. case Texture.PROJECTION_MODE:
  31174. BABYLON.Matrix.IdentityToRef(this._projectionModeMatrix);
  31175. this._projectionModeMatrix.m[0] = 0.5;
  31176. this._projectionModeMatrix.m[5] = -0.5;
  31177. this._projectionModeMatrix.m[10] = 0.0;
  31178. this._projectionModeMatrix.m[12] = 0.5;
  31179. this._projectionModeMatrix.m[13] = 0.5;
  31180. this._projectionModeMatrix.m[14] = 1.0;
  31181. this._projectionModeMatrix.m[15] = 1.0;
  31182. var projectionMatrix = scene.getProjectionMatrix();
  31183. this._cachedProjectionMatrixId = projectionMatrix.updateFlag;
  31184. projectionMatrix.multiplyToRef(this._projectionModeMatrix, this._cachedTextureMatrix);
  31185. break;
  31186. default:
  31187. BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
  31188. break;
  31189. }
  31190. scene.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag, function (mat) {
  31191. return (mat.getActiveTextures().indexOf(_this) !== -1);
  31192. });
  31193. return this._cachedTextureMatrix;
  31194. };
  31195. Texture.prototype.clone = function () {
  31196. var _this = this;
  31197. return BABYLON.SerializationHelper.Clone(function () {
  31198. return new Texture(_this._texture ? _this._texture.url : null, _this.getScene(), _this._noMipmap, _this._invertY, _this._samplingMode);
  31199. }, this);
  31200. };
  31201. Object.defineProperty(Texture.prototype, "onLoadObservable", {
  31202. get: function () {
  31203. if (!this._onLoadObservable) {
  31204. this._onLoadObservable = new BABYLON.Observable();
  31205. }
  31206. return this._onLoadObservable;
  31207. },
  31208. enumerable: true,
  31209. configurable: true
  31210. });
  31211. Texture.prototype.serialize = function () {
  31212. var serializationObject = _super.prototype.serialize.call(this);
  31213. if (typeof this._buffer === "string" && this._buffer.substr(0, 5) === "data:") {
  31214. serializationObject.base64String = this._buffer;
  31215. serializationObject.name = serializationObject.name.replace("data:", "");
  31216. }
  31217. serializationObject.invertY = this._invertY;
  31218. serializationObject.samplingMode = this.samplingMode;
  31219. return serializationObject;
  31220. };
  31221. Texture.prototype.getClassName = function () {
  31222. return "Texture";
  31223. };
  31224. Texture.prototype.dispose = function () {
  31225. _super.prototype.dispose.call(this);
  31226. if (this.onLoadObservable) {
  31227. this.onLoadObservable.clear();
  31228. this._onLoadObservable = null;
  31229. }
  31230. this._delayedOnLoad = null;
  31231. this._delayedOnError = null;
  31232. };
  31233. // Statics
  31234. Texture.CreateFromBase64String = function (data, name, scene, noMipmap, invertY, samplingMode, onLoad, onError, format) {
  31235. if (samplingMode === void 0) { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
  31236. if (onLoad === void 0) { onLoad = null; }
  31237. if (onError === void 0) { onError = null; }
  31238. if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
  31239. return new Texture("data:" + name, scene, noMipmap, invertY, samplingMode, onLoad, onError, data, false, format);
  31240. };
  31241. Texture.Parse = function (parsedTexture, scene, rootUrl) {
  31242. if (parsedTexture.customType) {
  31243. var customTexture = BABYLON.Tools.Instantiate(parsedTexture.customType);
  31244. // Update Sampling Mode
  31245. var parsedCustomTexture = customTexture.Parse(parsedTexture, scene, rootUrl);
  31246. if (parsedTexture.samplingMode && parsedCustomTexture.updateSamplingMode && parsedCustomTexture._samplingMode) {
  31247. if (parsedCustomTexture._samplingMode !== parsedTexture.samplingMode) {
  31248. parsedCustomTexture.updateSamplingMode(parsedTexture.samplingMode);
  31249. }
  31250. }
  31251. return parsedCustomTexture;
  31252. }
  31253. if (parsedTexture.isCube) {
  31254. return BABYLON.CubeTexture.Parse(parsedTexture, scene, rootUrl);
  31255. }
  31256. if (!parsedTexture.name && !parsedTexture.isRenderTarget) {
  31257. return null;
  31258. }
  31259. var texture = BABYLON.SerializationHelper.Parse(function () {
  31260. var generateMipMaps = true;
  31261. if (parsedTexture.noMipmap) {
  31262. generateMipMaps = false;
  31263. }
  31264. if (parsedTexture.mirrorPlane) {
  31265. var mirrorTexture = new BABYLON.MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
  31266. mirrorTexture._waitingRenderList = parsedTexture.renderList;
  31267. mirrorTexture.mirrorPlane = BABYLON.Plane.FromArray(parsedTexture.mirrorPlane);
  31268. return mirrorTexture;
  31269. }
  31270. else if (parsedTexture.isRenderTarget) {
  31271. var renderTargetTexture = new BABYLON.RenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
  31272. renderTargetTexture._waitingRenderList = parsedTexture.renderList;
  31273. return renderTargetTexture;
  31274. }
  31275. else {
  31276. var texture;
  31277. if (parsedTexture.base64String) {
  31278. texture = Texture.CreateFromBase64String(parsedTexture.base64String, parsedTexture.name, scene, !generateMipMaps);
  31279. }
  31280. else {
  31281. var url = rootUrl + parsedTexture.name;
  31282. if (Texture.UseSerializedUrlIfAny && parsedTexture.url) {
  31283. url = parsedTexture.url;
  31284. }
  31285. texture = new Texture(url, scene, !generateMipMaps, parsedTexture.invertY);
  31286. }
  31287. return texture;
  31288. }
  31289. }, parsedTexture, scene);
  31290. // Update Sampling Mode
  31291. if (parsedTexture.samplingMode) {
  31292. var sampling = parsedTexture.samplingMode;
  31293. if (texture._samplingMode !== sampling) {
  31294. texture.updateSamplingMode(sampling);
  31295. }
  31296. }
  31297. // Animations
  31298. if (parsedTexture.animations) {
  31299. for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
  31300. var parsedAnimation = parsedTexture.animations[animationIndex];
  31301. texture.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  31302. }
  31303. }
  31304. return texture;
  31305. };
  31306. Texture.LoadFromDataString = function (name, buffer, scene, deleteBuffer, noMipmap, invertY, samplingMode, onLoad, onError, format) {
  31307. if (deleteBuffer === void 0) { deleteBuffer = false; }
  31308. if (noMipmap === void 0) { noMipmap = false; }
  31309. if (invertY === void 0) { invertY = true; }
  31310. if (samplingMode === void 0) { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
  31311. if (onLoad === void 0) { onLoad = null; }
  31312. if (onError === void 0) { onError = null; }
  31313. if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
  31314. if (name.substr(0, 5) !== "data:") {
  31315. name = "data:" + name;
  31316. }
  31317. return new Texture(name, scene, noMipmap, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer, format);
  31318. };
  31319. // Constants
  31320. Texture.NEAREST_SAMPLINGMODE = 1;
  31321. Texture.NEAREST_NEAREST_MIPLINEAR = 1; // nearest is mag = nearest and min = nearest and mip = linear
  31322. Texture.BILINEAR_SAMPLINGMODE = 2;
  31323. Texture.LINEAR_LINEAR_MIPNEAREST = 2; // Bilinear is mag = linear and min = linear and mip = nearest
  31324. Texture.TRILINEAR_SAMPLINGMODE = 3;
  31325. Texture.LINEAR_LINEAR_MIPLINEAR = 3; // Trilinear is mag = linear and min = linear and mip = linear
  31326. Texture.NEAREST_NEAREST_MIPNEAREST = 4;
  31327. Texture.NEAREST_LINEAR_MIPNEAREST = 5;
  31328. Texture.NEAREST_LINEAR_MIPLINEAR = 6;
  31329. Texture.NEAREST_LINEAR = 7;
  31330. Texture.NEAREST_NEAREST = 8;
  31331. Texture.LINEAR_NEAREST_MIPNEAREST = 9;
  31332. Texture.LINEAR_NEAREST_MIPLINEAR = 10;
  31333. Texture.LINEAR_LINEAR = 11;
  31334. Texture.LINEAR_NEAREST = 12;
  31335. Texture.EXPLICIT_MODE = 0;
  31336. Texture.SPHERICAL_MODE = 1;
  31337. Texture.PLANAR_MODE = 2;
  31338. Texture.CUBIC_MODE = 3;
  31339. Texture.PROJECTION_MODE = 4;
  31340. Texture.SKYBOX_MODE = 5;
  31341. Texture.INVCUBIC_MODE = 6;
  31342. Texture.EQUIRECTANGULAR_MODE = 7;
  31343. Texture.FIXED_EQUIRECTANGULAR_MODE = 8;
  31344. Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;
  31345. Texture.CLAMP_ADDRESSMODE = 0;
  31346. Texture.WRAP_ADDRESSMODE = 1;
  31347. Texture.MIRROR_ADDRESSMODE = 2;
  31348. /**
  31349. * Gets or sets a boolean which defines if the texture url must be build from the serialized URL instead of just using the name and loading them side by side with the scene file
  31350. */
  31351. Texture.UseSerializedUrlIfAny = false;
  31352. __decorate([
  31353. BABYLON.serialize()
  31354. ], Texture.prototype, "url", void 0);
  31355. __decorate([
  31356. BABYLON.serialize()
  31357. ], Texture.prototype, "uOffset", void 0);
  31358. __decorate([
  31359. BABYLON.serialize()
  31360. ], Texture.prototype, "vOffset", void 0);
  31361. __decorate([
  31362. BABYLON.serialize()
  31363. ], Texture.prototype, "uScale", void 0);
  31364. __decorate([
  31365. BABYLON.serialize()
  31366. ], Texture.prototype, "vScale", void 0);
  31367. __decorate([
  31368. BABYLON.serialize()
  31369. ], Texture.prototype, "uAng", void 0);
  31370. __decorate([
  31371. BABYLON.serialize()
  31372. ], Texture.prototype, "vAng", void 0);
  31373. __decorate([
  31374. BABYLON.serialize()
  31375. ], Texture.prototype, "wAng", void 0);
  31376. __decorate([
  31377. BABYLON.serialize()
  31378. ], Texture.prototype, "uRotationCenter", void 0);
  31379. __decorate([
  31380. BABYLON.serialize()
  31381. ], Texture.prototype, "vRotationCenter", void 0);
  31382. __decorate([
  31383. BABYLON.serialize()
  31384. ], Texture.prototype, "wRotationCenter", void 0);
  31385. __decorate([
  31386. BABYLON.serialize()
  31387. ], Texture.prototype, "isBlocking", null);
  31388. return Texture;
  31389. }(BABYLON.BaseTexture));
  31390. BABYLON.Texture = Texture;
  31391. })(BABYLON || (BABYLON = {}));
  31392. //# sourceMappingURL=babylon.texture.js.map
  31393. var BABYLON;
  31394. (function (BABYLON) {
  31395. /**
  31396. * @hidden
  31397. **/
  31398. var _InstancesBatch = /** @class */ (function () {
  31399. function _InstancesBatch() {
  31400. this.mustReturn = false;
  31401. this.visibleInstances = new Array();
  31402. this.renderSelf = new Array();
  31403. }
  31404. return _InstancesBatch;
  31405. }());
  31406. BABYLON._InstancesBatch = _InstancesBatch;
  31407. var Mesh = /** @class */ (function (_super) {
  31408. __extends(Mesh, _super);
  31409. /**
  31410. * @constructor
  31411. * @param {string} name The value used by scene.getMeshByName() to do a lookup.
  31412. * @param {Scene} scene The scene to add this mesh to.
  31413. * @param {Node} parent The parent of this mesh, if it has one
  31414. * @param {Mesh} source An optional Mesh from which geometry is shared, cloned.
  31415. * @param {boolean} doNotCloneChildren When cloning, skip cloning child meshes of source, default False.
  31416. * When false, achieved by calling a clone(), also passing False.
  31417. * This will make creation of children, recursive.
  31418. * @param {boolean} clonePhysicsImpostor When cloning, include cloning mesh physics impostor, default True.
  31419. */
  31420. function Mesh(name, scene, parent, source, doNotCloneChildren, clonePhysicsImpostor) {
  31421. if (scene === void 0) { scene = null; }
  31422. if (parent === void 0) { parent = null; }
  31423. if (source === void 0) { source = null; }
  31424. if (clonePhysicsImpostor === void 0) { clonePhysicsImpostor = true; }
  31425. var _this = _super.call(this, name, scene) || this;
  31426. // Events
  31427. /**
  31428. * An event triggered before rendering the mesh
  31429. */
  31430. _this.onBeforeRenderObservable = new BABYLON.Observable();
  31431. /**
  31432. * An event triggered after rendering the mesh
  31433. */
  31434. _this.onAfterRenderObservable = new BABYLON.Observable();
  31435. /**
  31436. * An event triggered before drawing the mesh
  31437. */
  31438. _this.onBeforeDrawObservable = new BABYLON.Observable();
  31439. // Members
  31440. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  31441. _this.instances = new Array();
  31442. _this._LODLevels = new Array();
  31443. _this._visibleInstances = {};
  31444. _this._renderIdForInstances = new Array();
  31445. _this._batchCache = new _InstancesBatch();
  31446. _this._instancesBufferSize = 32 * 16 * 4; // let's start with a maximum of 32 instances
  31447. // Use by builder only to know what orientation were the mesh build in.
  31448. _this._originalBuilderSideOrientation = Mesh._DEFAULTSIDE;
  31449. _this.overrideMaterialSideOrientation = null;
  31450. _this._areNormalsFrozen = false; // Will be used by ribbons mainly
  31451. // Will be used to save a source mesh reference, If any
  31452. _this._source = null;
  31453. scene = _this.getScene();
  31454. if (source) {
  31455. // Geometry
  31456. if (source._geometry) {
  31457. source._geometry.applyToMesh(_this);
  31458. }
  31459. // Deep copy
  31460. BABYLON.Tools.DeepCopy(source, _this, ["name", "material", "skeleton", "instances", "parent", "uniqueId",
  31461. "source", "metadata", "hasLODLevels", "geometry", "isBlocked", "areNormalsFrozen"], ["_poseMatrix"]);
  31462. // Source mesh
  31463. _this._source = source;
  31464. // Metadata
  31465. if (source.metadata && source.metadata.clone) {
  31466. _this.metadata = source.metadata.clone();
  31467. }
  31468. else {
  31469. _this.metadata = source.metadata;
  31470. }
  31471. // Tags
  31472. if (BABYLON.Tags && BABYLON.Tags.HasTags(source)) {
  31473. BABYLON.Tags.AddTagsTo(_this, BABYLON.Tags.GetTags(source, true));
  31474. }
  31475. // Parent
  31476. _this.parent = source.parent;
  31477. // Pivot
  31478. _this.setPivotMatrix(source.getPivotMatrix());
  31479. _this.id = name + "." + source.id;
  31480. // Material
  31481. _this.material = source.material;
  31482. var index;
  31483. if (!doNotCloneChildren) {
  31484. // Children
  31485. var directDescendants = source.getDescendants(true);
  31486. for (var index_1 = 0; index_1 < directDescendants.length; index_1++) {
  31487. var child = directDescendants[index_1];
  31488. if (child.clone) {
  31489. child.clone(name + "." + child.name, _this);
  31490. }
  31491. }
  31492. }
  31493. // Physics clone
  31494. var physicsEngine = _this.getScene().getPhysicsEngine();
  31495. if (clonePhysicsImpostor && physicsEngine) {
  31496. var impostor = physicsEngine.getImpostorForPhysicsObject(source);
  31497. if (impostor) {
  31498. _this.physicsImpostor = impostor.clone(_this);
  31499. }
  31500. }
  31501. // Particles
  31502. for (index = 0; index < scene.particleSystems.length; index++) {
  31503. var system = scene.particleSystems[index];
  31504. if (system.emitter === source) {
  31505. system.clone(system.name, _this);
  31506. }
  31507. }
  31508. _this.computeWorldMatrix(true);
  31509. }
  31510. // Parent
  31511. if (parent !== null) {
  31512. _this.parent = parent;
  31513. }
  31514. return _this;
  31515. }
  31516. Object.defineProperty(Mesh, "FRONTSIDE", {
  31517. /**
  31518. * Mesh side orientation : usually the external or front surface
  31519. */
  31520. get: function () {
  31521. return Mesh._FRONTSIDE;
  31522. },
  31523. enumerable: true,
  31524. configurable: true
  31525. });
  31526. Object.defineProperty(Mesh, "BACKSIDE", {
  31527. /**
  31528. * Mesh side orientation : usually the internal or back surface
  31529. */
  31530. get: function () {
  31531. return Mesh._BACKSIDE;
  31532. },
  31533. enumerable: true,
  31534. configurable: true
  31535. });
  31536. Object.defineProperty(Mesh, "DOUBLESIDE", {
  31537. /**
  31538. * Mesh side orientation : both internal and external or front and back surfaces
  31539. */
  31540. get: function () {
  31541. return Mesh._DOUBLESIDE;
  31542. },
  31543. enumerable: true,
  31544. configurable: true
  31545. });
  31546. Object.defineProperty(Mesh, "DEFAULTSIDE", {
  31547. /**
  31548. * Mesh side orientation : by default, `FRONTSIDE`
  31549. */
  31550. get: function () {
  31551. return Mesh._DEFAULTSIDE;
  31552. },
  31553. enumerable: true,
  31554. configurable: true
  31555. });
  31556. Object.defineProperty(Mesh, "NO_CAP", {
  31557. /**
  31558. * Mesh cap setting : no cap
  31559. */
  31560. get: function () {
  31561. return Mesh._NO_CAP;
  31562. },
  31563. enumerable: true,
  31564. configurable: true
  31565. });
  31566. Object.defineProperty(Mesh, "CAP_START", {
  31567. /**
  31568. * Mesh cap setting : one cap at the beginning of the mesh
  31569. */
  31570. get: function () {
  31571. return Mesh._CAP_START;
  31572. },
  31573. enumerable: true,
  31574. configurable: true
  31575. });
  31576. Object.defineProperty(Mesh, "CAP_END", {
  31577. /**
  31578. * Mesh cap setting : one cap at the end of the mesh
  31579. */
  31580. get: function () {
  31581. return Mesh._CAP_END;
  31582. },
  31583. enumerable: true,
  31584. configurable: true
  31585. });
  31586. Object.defineProperty(Mesh, "CAP_ALL", {
  31587. /**
  31588. * Mesh cap setting : two caps, one at the beginning and one at the end of the mesh
  31589. */
  31590. get: function () {
  31591. return Mesh._CAP_ALL;
  31592. },
  31593. enumerable: true,
  31594. configurable: true
  31595. });
  31596. Object.defineProperty(Mesh.prototype, "onBeforeDraw", {
  31597. set: function (callback) {
  31598. if (this._onBeforeDrawObserver) {
  31599. this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver);
  31600. }
  31601. this._onBeforeDrawObserver = this.onBeforeDrawObservable.add(callback);
  31602. },
  31603. enumerable: true,
  31604. configurable: true
  31605. });
  31606. Object.defineProperty(Mesh.prototype, "morphTargetManager", {
  31607. get: function () {
  31608. return this._morphTargetManager;
  31609. },
  31610. set: function (value) {
  31611. if (this._morphTargetManager === value) {
  31612. return;
  31613. }
  31614. this._morphTargetManager = value;
  31615. this._syncGeometryWithMorphTargetManager();
  31616. },
  31617. enumerable: true,
  31618. configurable: true
  31619. });
  31620. Object.defineProperty(Mesh.prototype, "source", {
  31621. get: function () {
  31622. return this._source;
  31623. },
  31624. enumerable: true,
  31625. configurable: true
  31626. });
  31627. Object.defineProperty(Mesh.prototype, "isUnIndexed", {
  31628. get: function () {
  31629. return this._unIndexed;
  31630. },
  31631. set: function (value) {
  31632. if (this._unIndexed !== value) {
  31633. this._unIndexed = value;
  31634. this._markSubMeshesAsAttributesDirty();
  31635. }
  31636. },
  31637. enumerable: true,
  31638. configurable: true
  31639. });
  31640. // Methods
  31641. /**
  31642. * Returns the string "Mesh".
  31643. */
  31644. Mesh.prototype.getClassName = function () {
  31645. return "Mesh";
  31646. };
  31647. /**
  31648. * Returns a string.
  31649. * @param {boolean} fullDetails - support for multiple levels of logging within scene loading
  31650. */
  31651. Mesh.prototype.toString = function (fullDetails) {
  31652. var ret = _super.prototype.toString.call(this, fullDetails);
  31653. ret += ", n vertices: " + this.getTotalVertices();
  31654. ret += ", parent: " + (this._waitingParentId ? this._waitingParentId : (this.parent ? this.parent.name : "NONE"));
  31655. if (this.animations) {
  31656. for (var i = 0; i < this.animations.length; i++) {
  31657. ret += ", animation[0]: " + this.animations[i].toString(fullDetails);
  31658. }
  31659. }
  31660. if (fullDetails) {
  31661. if (this._geometry) {
  31662. var ib = this.getIndices();
  31663. var vb = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  31664. if (vb && ib) {
  31665. ret += ", flat shading: " + (vb.length / 3 === ib.length ? "YES" : "NO");
  31666. }
  31667. }
  31668. else {
  31669. ret += ", flat shading: UNKNOWN";
  31670. }
  31671. }
  31672. return ret;
  31673. };
  31674. Mesh.prototype._unBindEffect = function () {
  31675. _super.prototype._unBindEffect.call(this);
  31676. for (var _i = 0, _a = this.instances; _i < _a.length; _i++) {
  31677. var instance = _a[_i];
  31678. instance._unBindEffect();
  31679. }
  31680. };
  31681. Object.defineProperty(Mesh.prototype, "hasLODLevels", {
  31682. /**
  31683. * True if the mesh has some Levels Of Details (LOD).
  31684. * Returns a boolean.
  31685. */
  31686. get: function () {
  31687. return this._LODLevels.length > 0;
  31688. },
  31689. enumerable: true,
  31690. configurable: true
  31691. });
  31692. /**
  31693. * Gets the list of {BABYLON.MeshLODLevel} associated with the current mesh
  31694. * @returns an array of {BABYLON.MeshLODLevel}
  31695. */
  31696. Mesh.prototype.getLODLevels = function () {
  31697. return this._LODLevels;
  31698. };
  31699. Mesh.prototype._sortLODLevels = function () {
  31700. this._LODLevels.sort(function (a, b) {
  31701. if (a.distance < b.distance) {
  31702. return 1;
  31703. }
  31704. if (a.distance > b.distance) {
  31705. return -1;
  31706. }
  31707. return 0;
  31708. });
  31709. };
  31710. /**
  31711. * Add a mesh as LOD level triggered at the given distance.
  31712. * tuto : http://doc.babylonjs.com/tutorials/How_to_use_LOD
  31713. * @param distance The distance from the center of the object to show this level
  31714. * @param mesh The mesh to be added as LOD level (can be null)
  31715. * @return This mesh (for chaining)
  31716. */
  31717. Mesh.prototype.addLODLevel = function (distance, mesh) {
  31718. if (mesh && mesh._masterMesh) {
  31719. BABYLON.Tools.Warn("You cannot use a mesh as LOD level twice");
  31720. return this;
  31721. }
  31722. var level = new BABYLON.MeshLODLevel(distance, mesh);
  31723. this._LODLevels.push(level);
  31724. if (mesh) {
  31725. mesh._masterMesh = this;
  31726. }
  31727. this._sortLODLevels();
  31728. return this;
  31729. };
  31730. /**
  31731. * Returns the LOD level mesh at the passed distance or null if not found.
  31732. * It is related to the method `addLODLevel(distance, mesh)`.
  31733. * tuto : http://doc.babylonjs.com/tutorials/How_to_use_LOD
  31734. * Returns an object Mesh or `null`.
  31735. */
  31736. Mesh.prototype.getLODLevelAtDistance = function (distance) {
  31737. for (var index = 0; index < this._LODLevels.length; index++) {
  31738. var level = this._LODLevels[index];
  31739. if (level.distance === distance) {
  31740. return level.mesh;
  31741. }
  31742. }
  31743. return null;
  31744. };
  31745. /**
  31746. * Remove a mesh from the LOD array
  31747. * tuto : http://doc.babylonjs.com/tutorials/How_to_use_LOD
  31748. * @param {Mesh} mesh The mesh to be removed.
  31749. * @return {Mesh} This mesh (for chaining)
  31750. */
  31751. Mesh.prototype.removeLODLevel = function (mesh) {
  31752. for (var index = 0; index < this._LODLevels.length; index++) {
  31753. if (this._LODLevels[index].mesh === mesh) {
  31754. this._LODLevels.splice(index, 1);
  31755. if (mesh) {
  31756. mesh._masterMesh = null;
  31757. }
  31758. }
  31759. }
  31760. this._sortLODLevels();
  31761. return this;
  31762. };
  31763. /**
  31764. * Returns the registered LOD mesh distant from the parameter `camera` position if any, else returns the current mesh.
  31765. * tuto : http://doc.babylonjs.com/how_to/how_to_use_lod
  31766. */
  31767. Mesh.prototype.getLOD = function (camera, boundingSphere) {
  31768. if (!this._LODLevels || this._LODLevels.length === 0) {
  31769. return this;
  31770. }
  31771. var bSphere;
  31772. if (boundingSphere) {
  31773. bSphere = boundingSphere;
  31774. }
  31775. else {
  31776. var boundingInfo = this.getBoundingInfo();
  31777. bSphere = boundingInfo.boundingSphere;
  31778. }
  31779. var distanceToCamera = bSphere.centerWorld.subtract(camera.globalPosition).length();
  31780. if (this._LODLevels[this._LODLevels.length - 1].distance > distanceToCamera) {
  31781. if (this.onLODLevelSelection) {
  31782. this.onLODLevelSelection(distanceToCamera, this, this._LODLevels[this._LODLevels.length - 1].mesh);
  31783. }
  31784. return this;
  31785. }
  31786. for (var index = 0; index < this._LODLevels.length; index++) {
  31787. var level = this._LODLevels[index];
  31788. if (level.distance < distanceToCamera) {
  31789. if (level.mesh) {
  31790. level.mesh._preActivate();
  31791. level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
  31792. }
  31793. if (this.onLODLevelSelection) {
  31794. this.onLODLevelSelection(distanceToCamera, this, level.mesh);
  31795. }
  31796. return level.mesh;
  31797. }
  31798. }
  31799. if (this.onLODLevelSelection) {
  31800. this.onLODLevelSelection(distanceToCamera, this, this);
  31801. }
  31802. return this;
  31803. };
  31804. Object.defineProperty(Mesh.prototype, "geometry", {
  31805. /**
  31806. * Returns the mesh internal Geometry object.
  31807. */
  31808. get: function () {
  31809. return this._geometry;
  31810. },
  31811. enumerable: true,
  31812. configurable: true
  31813. });
  31814. /**
  31815. * Returns a positive integer : the total number of vertices within the mesh geometry or zero if the mesh has no geometry.
  31816. */
  31817. Mesh.prototype.getTotalVertices = function () {
  31818. if (this._geometry === null || this._geometry === undefined) {
  31819. return 0;
  31820. }
  31821. return this._geometry.getTotalVertices();
  31822. };
  31823. /**
  31824. * Returns an array of integers or floats, or a Float32Array, depending on the requested `kind` (positions, indices, normals, etc).
  31825. * If `copywhenShared` is true (default false) and if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one.
  31826. * You can force the copy with forceCopy === true
  31827. * Returns null if the mesh has no geometry or no vertex buffer.
  31828. * Possible `kind` values :
  31829. * - BABYLON.VertexBuffer.PositionKind
  31830. * - BABYLON.VertexBuffer.UVKind
  31831. * - BABYLON.VertexBuffer.UV2Kind
  31832. * - BABYLON.VertexBuffer.UV3Kind
  31833. * - BABYLON.VertexBuffer.UV4Kind
  31834. * - BABYLON.VertexBuffer.UV5Kind
  31835. * - BABYLON.VertexBuffer.UV6Kind
  31836. * - BABYLON.VertexBuffer.ColorKind
  31837. * - BABYLON.VertexBuffer.MatricesIndicesKind
  31838. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  31839. * - BABYLON.VertexBuffer.MatricesWeightsKind
  31840. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  31841. */
  31842. Mesh.prototype.getVerticesData = function (kind, copyWhenShared, forceCopy) {
  31843. if (!this._geometry) {
  31844. return null;
  31845. }
  31846. return this._geometry.getVerticesData(kind, copyWhenShared, forceCopy);
  31847. };
  31848. /**
  31849. * Returns the mesh VertexBuffer object from the requested `kind` : positions, indices, normals, etc.
  31850. * Returns `null` if the mesh has no geometry.
  31851. * Possible `kind` values :
  31852. * - BABYLON.VertexBuffer.PositionKind
  31853. * - BABYLON.VertexBuffer.UVKind
  31854. * - BABYLON.VertexBuffer.UV2Kind
  31855. * - BABYLON.VertexBuffer.UV3Kind
  31856. * - BABYLON.VertexBuffer.UV4Kind
  31857. * - BABYLON.VertexBuffer.UV5Kind
  31858. * - BABYLON.VertexBuffer.UV6Kind
  31859. * - BABYLON.VertexBuffer.ColorKind
  31860. * - BABYLON.VertexBuffer.MatricesIndicesKind
  31861. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  31862. * - BABYLON.VertexBuffer.MatricesWeightsKind
  31863. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  31864. */
  31865. Mesh.prototype.getVertexBuffer = function (kind) {
  31866. if (!this._geometry) {
  31867. return null;
  31868. }
  31869. return this._geometry.getVertexBuffer(kind);
  31870. };
  31871. Mesh.prototype.isVerticesDataPresent = function (kind) {
  31872. if (!this._geometry) {
  31873. if (this._delayInfo) {
  31874. return this._delayInfo.indexOf(kind) !== -1;
  31875. }
  31876. return false;
  31877. }
  31878. return this._geometry.isVerticesDataPresent(kind);
  31879. };
  31880. /**
  31881. * Returns a boolean defining if the vertex data for the requested `kind` is updatable.
  31882. * Possible `kind` values :
  31883. * - BABYLON.VertexBuffer.PositionKind
  31884. * - BABYLON.VertexBuffer.UVKind
  31885. * - BABYLON.VertexBuffer.UV2Kind
  31886. * - BABYLON.VertexBuffer.UV3Kind
  31887. * - BABYLON.VertexBuffer.UV4Kind
  31888. * - BABYLON.VertexBuffer.UV5Kind
  31889. * - BABYLON.VertexBuffer.UV6Kind
  31890. * - BABYLON.VertexBuffer.ColorKind
  31891. * - BABYLON.VertexBuffer.MatricesIndicesKind
  31892. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  31893. * - BABYLON.VertexBuffer.MatricesWeightsKind
  31894. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  31895. */
  31896. Mesh.prototype.isVertexBufferUpdatable = function (kind) {
  31897. if (!this._geometry) {
  31898. if (this._delayInfo) {
  31899. return this._delayInfo.indexOf(kind) !== -1;
  31900. }
  31901. return false;
  31902. }
  31903. return this._geometry.isVertexBufferUpdatable(kind);
  31904. };
  31905. /**
  31906. * Returns a string : the list of existing `kinds` of Vertex Data for this mesh.
  31907. * Possible `kind` values :
  31908. * - BABYLON.VertexBuffer.PositionKind
  31909. * - BABYLON.VertexBuffer.UVKind
  31910. * - BABYLON.VertexBuffer.UV2Kind
  31911. * - BABYLON.VertexBuffer.UV3Kind
  31912. * - BABYLON.VertexBuffer.UV4Kind
  31913. * - BABYLON.VertexBuffer.UV5Kind
  31914. * - BABYLON.VertexBuffer.UV6Kind
  31915. * - BABYLON.VertexBuffer.ColorKind
  31916. * - BABYLON.VertexBuffer.MatricesIndicesKind
  31917. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  31918. * - BABYLON.VertexBuffer.MatricesWeightsKind
  31919. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  31920. */
  31921. Mesh.prototype.getVerticesDataKinds = function () {
  31922. if (!this._geometry) {
  31923. var result = new Array();
  31924. if (this._delayInfo) {
  31925. this._delayInfo.forEach(function (kind, index, array) {
  31926. result.push(kind);
  31927. });
  31928. }
  31929. return result;
  31930. }
  31931. return this._geometry.getVerticesDataKinds();
  31932. };
  31933. /**
  31934. * Returns a positive integer : the total number of indices in this mesh geometry.
  31935. * Returns zero if the mesh has no geometry.
  31936. */
  31937. Mesh.prototype.getTotalIndices = function () {
  31938. if (!this._geometry) {
  31939. return 0;
  31940. }
  31941. return this._geometry.getTotalIndices();
  31942. };
  31943. /**
  31944. * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.
  31945. * If the parameter `copyWhenShared` is true (default false) and and if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one.
  31946. * Returns an empty array if the mesh has no geometry.
  31947. */
  31948. Mesh.prototype.getIndices = function (copyWhenShared) {
  31949. if (!this._geometry) {
  31950. return [];
  31951. }
  31952. return this._geometry.getIndices(copyWhenShared);
  31953. };
  31954. Object.defineProperty(Mesh.prototype, "isBlocked", {
  31955. get: function () {
  31956. return this._masterMesh !== null && this._masterMesh !== undefined;
  31957. },
  31958. enumerable: true,
  31959. configurable: true
  31960. });
  31961. /**
  31962. * Determine if the current mesh is ready to be rendered
  31963. * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
  31964. * @param forceInstanceSupport will check if the mesh will be ready when used with instances (false by default)
  31965. * @returns true if all associated assets are ready (material, textures, shaders)
  31966. */
  31967. Mesh.prototype.isReady = function (completeCheck, forceInstanceSupport) {
  31968. if (completeCheck === void 0) { completeCheck = false; }
  31969. if (forceInstanceSupport === void 0) { forceInstanceSupport = false; }
  31970. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  31971. return false;
  31972. }
  31973. if (!_super.prototype.isReady.call(this, completeCheck)) {
  31974. return false;
  31975. }
  31976. if (!this.subMeshes || this.subMeshes.length === 0) {
  31977. return true;
  31978. }
  31979. if (!completeCheck) {
  31980. return true;
  31981. }
  31982. var engine = this.getEngine();
  31983. var scene = this.getScene();
  31984. var hardwareInstancedRendering = forceInstanceSupport || engine.getCaps().instancedArrays && this.instances.length > 0;
  31985. this.computeWorldMatrix();
  31986. var mat = this.material || scene.defaultMaterial;
  31987. if (mat) {
  31988. if (mat.storeEffectOnSubMeshes) {
  31989. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  31990. var subMesh = _a[_i];
  31991. var effectiveMaterial = subMesh.getMaterial();
  31992. if (effectiveMaterial) {
  31993. if (effectiveMaterial.storeEffectOnSubMeshes) {
  31994. if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
  31995. return false;
  31996. }
  31997. }
  31998. else {
  31999. if (!effectiveMaterial.isReady(this, hardwareInstancedRendering)) {
  32000. return false;
  32001. }
  32002. }
  32003. }
  32004. }
  32005. }
  32006. else {
  32007. if (!mat.isReady(this, hardwareInstancedRendering)) {
  32008. return false;
  32009. }
  32010. }
  32011. }
  32012. // Shadows
  32013. for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
  32014. var light = _c[_b];
  32015. var generator = light.getShadowGenerator();
  32016. if (generator) {
  32017. for (var _d = 0, _e = this.subMeshes; _d < _e.length; _d++) {
  32018. var subMesh = _e[_d];
  32019. if (!generator.isReady(subMesh, hardwareInstancedRendering)) {
  32020. return false;
  32021. }
  32022. }
  32023. }
  32024. }
  32025. // LOD
  32026. for (var _f = 0, _g = this._LODLevels; _f < _g.length; _f++) {
  32027. var lod = _g[_f];
  32028. if (lod.mesh && !lod.mesh.isReady(hardwareInstancedRendering)) {
  32029. return false;
  32030. }
  32031. }
  32032. return true;
  32033. };
  32034. Object.defineProperty(Mesh.prototype, "areNormalsFrozen", {
  32035. /**
  32036. * Boolean : true if the normals aren't to be recomputed on next mesh `positions` array update.
  32037. * This property is pertinent only for updatable parametric shapes.
  32038. */
  32039. get: function () {
  32040. return this._areNormalsFrozen;
  32041. },
  32042. enumerable: true,
  32043. configurable: true
  32044. });
  32045. /**
  32046. * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc.
  32047. * It has no effect at all on other shapes.
  32048. * It prevents the mesh normals from being recomputed on next `positions` array update.
  32049. * Returns the Mesh.
  32050. */
  32051. Mesh.prototype.freezeNormals = function () {
  32052. this._areNormalsFrozen = true;
  32053. return this;
  32054. };
  32055. /**
  32056. * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc.
  32057. * It has no effect at all on other shapes.
  32058. * It reactivates the mesh normals computation if it was previously frozen.
  32059. * Returns the Mesh.
  32060. */
  32061. Mesh.prototype.unfreezeNormals = function () {
  32062. this._areNormalsFrozen = false;
  32063. return this;
  32064. };
  32065. Object.defineProperty(Mesh.prototype, "overridenInstanceCount", {
  32066. /**
  32067. * Overrides instance count. Only applicable when custom instanced InterleavedVertexBuffer are used rather than InstancedMeshs
  32068. */
  32069. set: function (count) {
  32070. this._overridenInstanceCount = count;
  32071. },
  32072. enumerable: true,
  32073. configurable: true
  32074. });
  32075. // Methods
  32076. Mesh.prototype._preActivate = function () {
  32077. var sceneRenderId = this.getScene().getRenderId();
  32078. if (this._preActivateId === sceneRenderId) {
  32079. return this;
  32080. }
  32081. this._preActivateId = sceneRenderId;
  32082. this._visibleInstances = null;
  32083. return this;
  32084. };
  32085. Mesh.prototype._preActivateForIntermediateRendering = function (renderId) {
  32086. if (this._visibleInstances) {
  32087. this._visibleInstances.intermediateDefaultRenderId = renderId;
  32088. }
  32089. return this;
  32090. };
  32091. Mesh.prototype._registerInstanceForRenderId = function (instance, renderId) {
  32092. if (!this._visibleInstances) {
  32093. this._visibleInstances = {};
  32094. this._visibleInstances.defaultRenderId = renderId;
  32095. this._visibleInstances.selfDefaultRenderId = this._renderId;
  32096. }
  32097. if (!this._visibleInstances[renderId]) {
  32098. this._visibleInstances[renderId] = new Array();
  32099. }
  32100. this._visibleInstances[renderId].push(instance);
  32101. return this;
  32102. };
  32103. /**
  32104. * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.
  32105. * This means the mesh underlying bounding box and sphere are recomputed.
  32106. * Returns the Mesh.
  32107. */
  32108. Mesh.prototype.refreshBoundingInfo = function () {
  32109. return this._refreshBoundingInfo(false);
  32110. };
  32111. Mesh.prototype._refreshBoundingInfo = function (applySkeleton) {
  32112. if (this._boundingInfo && this._boundingInfo.isLocked) {
  32113. return this;
  32114. }
  32115. var data = this._getPositionData(applySkeleton);
  32116. if (data) {
  32117. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
  32118. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  32119. }
  32120. if (this.subMeshes) {
  32121. for (var index = 0; index < this.subMeshes.length; index++) {
  32122. this.subMeshes[index].refreshBoundingInfo();
  32123. }
  32124. }
  32125. this._updateBoundingInfo();
  32126. return this;
  32127. };
  32128. Mesh.prototype._getPositionData = function (applySkeleton) {
  32129. var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  32130. if (data && applySkeleton && this.skeleton) {
  32131. data = BABYLON.Tools.Slice(data);
  32132. var matricesIndicesData = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
  32133. var matricesWeightsData = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
  32134. if (matricesWeightsData && matricesIndicesData) {
  32135. var needExtras = this.numBoneInfluencers > 4;
  32136. var matricesIndicesExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind) : null;
  32137. var matricesWeightsExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind) : null;
  32138. var skeletonMatrices = this.skeleton.getTransformMatrices(this);
  32139. var tempVector = BABYLON.Tmp.Vector3[0];
  32140. var finalMatrix = BABYLON.Tmp.Matrix[0];
  32141. var tempMatrix = BABYLON.Tmp.Matrix[1];
  32142. var matWeightIdx = 0;
  32143. for (var index = 0; index < data.length; index += 3, matWeightIdx += 4) {
  32144. finalMatrix.reset();
  32145. var inf;
  32146. var weight;
  32147. for (inf = 0; inf < 4; inf++) {
  32148. weight = matricesWeightsData[matWeightIdx + inf];
  32149. if (weight <= 0)
  32150. break;
  32151. BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);
  32152. finalMatrix.addToSelf(tempMatrix);
  32153. }
  32154. if (needExtras) {
  32155. for (inf = 0; inf < 4; inf++) {
  32156. weight = matricesWeightsExtraData[matWeightIdx + inf];
  32157. if (weight <= 0)
  32158. break;
  32159. BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData[matWeightIdx + inf] * 16), weight, tempMatrix);
  32160. finalMatrix.addToSelf(tempMatrix);
  32161. }
  32162. }
  32163. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], finalMatrix, tempVector);
  32164. tempVector.toArray(data, index);
  32165. }
  32166. }
  32167. }
  32168. return data;
  32169. };
  32170. Mesh.prototype._createGlobalSubMesh = function (force) {
  32171. var totalVertices = this.getTotalVertices();
  32172. if (!totalVertices || !this.getIndices()) {
  32173. return null;
  32174. }
  32175. // Check if we need to recreate the submeshes
  32176. if (this.subMeshes && this.subMeshes.length > 0) {
  32177. var ib = this.getIndices();
  32178. if (!ib) {
  32179. return null;
  32180. }
  32181. var totalIndices = ib.length;
  32182. var needToRecreate = false;
  32183. if (force) {
  32184. needToRecreate = true;
  32185. }
  32186. else {
  32187. for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
  32188. var submesh = _a[_i];
  32189. if (submesh.indexStart + submesh.indexCount >= totalIndices) {
  32190. needToRecreate = true;
  32191. break;
  32192. }
  32193. if (submesh.verticesStart + submesh.verticesCount >= totalVertices) {
  32194. needToRecreate = true;
  32195. break;
  32196. }
  32197. }
  32198. }
  32199. if (!needToRecreate) {
  32200. return this.subMeshes[0];
  32201. }
  32202. }
  32203. this.releaseSubMeshes();
  32204. return new BABYLON.SubMesh(0, 0, totalVertices, 0, this.getTotalIndices(), this);
  32205. };
  32206. Mesh.prototype.subdivide = function (count) {
  32207. if (count < 1) {
  32208. return;
  32209. }
  32210. var totalIndices = this.getTotalIndices();
  32211. var subdivisionSize = (totalIndices / count) | 0;
  32212. var offset = 0;
  32213. // Ensure that subdivisionSize is a multiple of 3
  32214. while (subdivisionSize % 3 !== 0) {
  32215. subdivisionSize++;
  32216. }
  32217. this.releaseSubMeshes();
  32218. for (var index = 0; index < count; index++) {
  32219. if (offset >= totalIndices) {
  32220. break;
  32221. }
  32222. BABYLON.SubMesh.CreateFromIndices(0, offset, Math.min(subdivisionSize, totalIndices - offset), this);
  32223. offset += subdivisionSize;
  32224. }
  32225. this.synchronizeInstances();
  32226. };
  32227. Mesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
  32228. if (updatable === void 0) { updatable = false; }
  32229. if (!this._geometry) {
  32230. var vertexData = new BABYLON.VertexData();
  32231. vertexData.set(data, kind);
  32232. var scene = this.getScene();
  32233. new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene, vertexData, updatable, this);
  32234. }
  32235. else {
  32236. this._geometry.setVerticesData(kind, data, updatable, stride);
  32237. }
  32238. return this;
  32239. };
  32240. Mesh.prototype.markVerticesDataAsUpdatable = function (kind, updatable) {
  32241. if (updatable === void 0) { updatable = true; }
  32242. var vb = this.getVertexBuffer(kind);
  32243. if (!vb || vb.isUpdatable() === updatable) {
  32244. return;
  32245. }
  32246. this.setVerticesData(kind, this.getVerticesData(kind), updatable);
  32247. };
  32248. /**
  32249. * Sets the mesh VertexBuffer.
  32250. * Returns the Mesh.
  32251. */
  32252. Mesh.prototype.setVerticesBuffer = function (buffer) {
  32253. if (!this._geometry) {
  32254. this._geometry = BABYLON.Geometry.CreateGeometryForMesh(this);
  32255. }
  32256. this._geometry.setVerticesBuffer(buffer);
  32257. return this;
  32258. };
  32259. Mesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
  32260. if (!this._geometry) {
  32261. return this;
  32262. }
  32263. if (!makeItUnique) {
  32264. this._geometry.updateVerticesData(kind, data, updateExtends);
  32265. }
  32266. else {
  32267. this.makeGeometryUnique();
  32268. this.updateVerticesData(kind, data, updateExtends, false);
  32269. }
  32270. return this;
  32271. };
  32272. /**
  32273. * This method updates the vertex positions of an updatable mesh according to the `positionFunction` returned values.
  32274. * tuto : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#other-shapes-updatemeshpositions
  32275. * The parameter `positionFunction` is a simple JS function what is passed the mesh `positions` array. It doesn't need to return anything.
  32276. * The parameter `computeNormals` is a boolean (default true) to enable/disable the mesh normal recomputation after the vertex position update.
  32277. * Returns the Mesh.
  32278. */
  32279. Mesh.prototype.updateMeshPositions = function (positionFunction, computeNormals) {
  32280. if (computeNormals === void 0) { computeNormals = true; }
  32281. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  32282. if (!positions) {
  32283. return this;
  32284. }
  32285. positionFunction(positions);
  32286. this.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  32287. if (computeNormals) {
  32288. var indices = this.getIndices();
  32289. var normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  32290. if (!normals) {
  32291. return this;
  32292. }
  32293. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  32294. this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
  32295. }
  32296. return this;
  32297. };
  32298. /**
  32299. * Creates a un-shared specific occurence of the geometry for the mesh.
  32300. * Returns the Mesh.
  32301. */
  32302. Mesh.prototype.makeGeometryUnique = function () {
  32303. if (!this._geometry) {
  32304. return this;
  32305. }
  32306. var oldGeometry = this._geometry;
  32307. var geometry = this._geometry.copy(BABYLON.Geometry.RandomId());
  32308. oldGeometry.releaseForMesh(this, true);
  32309. geometry.applyToMesh(this);
  32310. return this;
  32311. };
  32312. Mesh.prototype.setIndices = function (indices, totalVertices, updatable) {
  32313. if (totalVertices === void 0) { totalVertices = null; }
  32314. if (updatable === void 0) { updatable = false; }
  32315. if (!this._geometry) {
  32316. var vertexData = new BABYLON.VertexData();
  32317. vertexData.indices = indices;
  32318. var scene = this.getScene();
  32319. new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene, vertexData, updatable, this);
  32320. }
  32321. else {
  32322. this._geometry.setIndices(indices, totalVertices, updatable);
  32323. }
  32324. return this;
  32325. };
  32326. /**
  32327. * Update the current index buffer
  32328. * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array)
  32329. * Returns the Mesh.
  32330. */
  32331. Mesh.prototype.updateIndices = function (indices, offset) {
  32332. if (!this._geometry) {
  32333. return this;
  32334. }
  32335. this._geometry.updateIndices(indices, offset);
  32336. return this;
  32337. };
  32338. /**
  32339. * Invert the geometry to move from a right handed system to a left handed one.
  32340. * Returns the Mesh.
  32341. */
  32342. Mesh.prototype.toLeftHanded = function () {
  32343. if (!this._geometry) {
  32344. return this;
  32345. }
  32346. this._geometry.toLeftHanded();
  32347. return this;
  32348. };
  32349. Mesh.prototype._bind = function (subMesh, effect, fillMode) {
  32350. if (!this._geometry) {
  32351. return this;
  32352. }
  32353. var engine = this.getScene().getEngine();
  32354. // Wireframe
  32355. var indexToBind;
  32356. if (this._unIndexed) {
  32357. indexToBind = null;
  32358. }
  32359. else {
  32360. switch (fillMode) {
  32361. case BABYLON.Material.PointFillMode:
  32362. indexToBind = null;
  32363. break;
  32364. case BABYLON.Material.WireFrameFillMode:
  32365. indexToBind = subMesh.getLinesIndexBuffer(this.getIndices(), engine);
  32366. break;
  32367. default:
  32368. case BABYLON.Material.TriangleFillMode:
  32369. indexToBind = this._unIndexed ? null : this._geometry.getIndexBuffer();
  32370. break;
  32371. }
  32372. }
  32373. // VBOs
  32374. this._geometry._bind(effect, indexToBind);
  32375. return this;
  32376. };
  32377. Mesh.prototype._draw = function (subMesh, fillMode, instancesCount, alternate) {
  32378. if (alternate === void 0) { alternate = false; }
  32379. if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
  32380. return this;
  32381. }
  32382. this.onBeforeDrawObservable.notifyObservers(this);
  32383. var scene = this.getScene();
  32384. var engine = scene.getEngine();
  32385. if (this._unIndexed || fillMode == BABYLON.Material.PointFillMode) {
  32386. // or triangles as points
  32387. engine.drawArraysType(fillMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);
  32388. }
  32389. else if (fillMode == BABYLON.Material.WireFrameFillMode) {
  32390. // Triangles as wireframe
  32391. engine.drawElementsType(fillMode, 0, subMesh.linesIndexCount, instancesCount);
  32392. }
  32393. else {
  32394. engine.drawElementsType(fillMode, subMesh.indexStart, subMesh.indexCount, instancesCount);
  32395. }
  32396. if (scene._isAlternateRenderingEnabled && !alternate) {
  32397. var effect = subMesh.effect || this._effectiveMaterial.getEffect();
  32398. if (!effect || !scene.activeCamera) {
  32399. return this;
  32400. }
  32401. scene._switchToAlternateCameraConfiguration(true);
  32402. this._effectiveMaterial.bindView(effect);
  32403. this._effectiveMaterial.bindViewProjection(effect);
  32404. engine.setViewport(scene.activeCamera._alternateCamera.viewport);
  32405. this._draw(subMesh, fillMode, instancesCount, true);
  32406. engine.setViewport(scene.activeCamera.viewport);
  32407. scene._switchToAlternateCameraConfiguration(false);
  32408. this._effectiveMaterial.bindView(effect);
  32409. this._effectiveMaterial.bindViewProjection(effect);
  32410. }
  32411. return this;
  32412. };
  32413. /**
  32414. * Registers for this mesh a javascript function called just before the rendering process.
  32415. * This function is passed the current mesh.
  32416. * Return the Mesh.
  32417. */
  32418. Mesh.prototype.registerBeforeRender = function (func) {
  32419. this.onBeforeRenderObservable.add(func);
  32420. return this;
  32421. };
  32422. /**
  32423. * Disposes a previously registered javascript function called before the rendering.
  32424. * This function is passed the current mesh.
  32425. * Returns the Mesh.
  32426. */
  32427. Mesh.prototype.unregisterBeforeRender = function (func) {
  32428. this.onBeforeRenderObservable.removeCallback(func);
  32429. return this;
  32430. };
  32431. /**
  32432. * Registers for this mesh a javascript function called just after the rendering is complete.
  32433. * This function is passed the current mesh.
  32434. * Returns the Mesh.
  32435. */
  32436. Mesh.prototype.registerAfterRender = function (func) {
  32437. this.onAfterRenderObservable.add(func);
  32438. return this;
  32439. };
  32440. /**
  32441. * Disposes a previously registered javascript function called after the rendering.
  32442. * This function is passed the current mesh.
  32443. * Return the Mesh.
  32444. */
  32445. Mesh.prototype.unregisterAfterRender = function (func) {
  32446. this.onAfterRenderObservable.removeCallback(func);
  32447. return this;
  32448. };
  32449. Mesh.prototype._getInstancesRenderList = function (subMeshId) {
  32450. var scene = this.getScene();
  32451. this._batchCache.mustReturn = false;
  32452. this._batchCache.renderSelf[subMeshId] = this.isEnabled() && this.isVisible;
  32453. this._batchCache.visibleInstances[subMeshId] = null;
  32454. if (this._visibleInstances) {
  32455. var currentRenderId = scene.getRenderId();
  32456. var defaultRenderId = (scene._isInIntermediateRendering() ? this._visibleInstances.intermediateDefaultRenderId : this._visibleInstances.defaultRenderId);
  32457. this._batchCache.visibleInstances[subMeshId] = this._visibleInstances[currentRenderId];
  32458. var selfRenderId = this._renderId;
  32459. if (!this._batchCache.visibleInstances[subMeshId] && defaultRenderId) {
  32460. this._batchCache.visibleInstances[subMeshId] = this._visibleInstances[defaultRenderId];
  32461. currentRenderId = Math.max(defaultRenderId, currentRenderId);
  32462. selfRenderId = Math.max(this._visibleInstances.selfDefaultRenderId, currentRenderId);
  32463. }
  32464. var visibleInstancesForSubMesh = this._batchCache.visibleInstances[subMeshId];
  32465. if (visibleInstancesForSubMesh && visibleInstancesForSubMesh.length) {
  32466. if (this._renderIdForInstances[subMeshId] === currentRenderId) {
  32467. this._batchCache.mustReturn = true;
  32468. return this._batchCache;
  32469. }
  32470. if (currentRenderId !== selfRenderId) {
  32471. this._batchCache.renderSelf[subMeshId] = false;
  32472. }
  32473. }
  32474. this._renderIdForInstances[subMeshId] = currentRenderId;
  32475. }
  32476. return this._batchCache;
  32477. };
  32478. Mesh.prototype._renderWithInstances = function (subMesh, fillMode, batch, effect, engine) {
  32479. var visibleInstances = batch.visibleInstances[subMesh._id];
  32480. if (!visibleInstances) {
  32481. return this;
  32482. }
  32483. var matricesCount = visibleInstances.length + 1;
  32484. var bufferSize = matricesCount * 16 * 4;
  32485. var currentInstancesBufferSize = this._instancesBufferSize;
  32486. var instancesBuffer = this._instancesBuffer;
  32487. while (this._instancesBufferSize < bufferSize) {
  32488. this._instancesBufferSize *= 2;
  32489. }
  32490. if (!this._instancesData || currentInstancesBufferSize != this._instancesBufferSize) {
  32491. this._instancesData = new Float32Array(this._instancesBufferSize / 4);
  32492. }
  32493. var offset = 0;
  32494. var instancesCount = 0;
  32495. var world = this.getWorldMatrix();
  32496. if (batch.renderSelf[subMesh._id]) {
  32497. world.copyToArray(this._instancesData, offset);
  32498. offset += 16;
  32499. instancesCount++;
  32500. }
  32501. if (visibleInstances) {
  32502. for (var instanceIndex = 0; instanceIndex < visibleInstances.length; instanceIndex++) {
  32503. var instance = visibleInstances[instanceIndex];
  32504. instance.getWorldMatrix().copyToArray(this._instancesData, offset);
  32505. offset += 16;
  32506. instancesCount++;
  32507. }
  32508. }
  32509. if (!instancesBuffer || currentInstancesBufferSize != this._instancesBufferSize) {
  32510. if (instancesBuffer) {
  32511. instancesBuffer.dispose();
  32512. }
  32513. instancesBuffer = new BABYLON.Buffer(engine, this._instancesData, true, 16, false, true);
  32514. this._instancesBuffer = instancesBuffer;
  32515. this.setVerticesBuffer(instancesBuffer.createVertexBuffer("world0", 0, 4));
  32516. this.setVerticesBuffer(instancesBuffer.createVertexBuffer("world1", 4, 4));
  32517. this.setVerticesBuffer(instancesBuffer.createVertexBuffer("world2", 8, 4));
  32518. this.setVerticesBuffer(instancesBuffer.createVertexBuffer("world3", 12, 4));
  32519. }
  32520. else {
  32521. instancesBuffer.updateDirectly(this._instancesData, 0, instancesCount);
  32522. }
  32523. this._bind(subMesh, effect, fillMode);
  32524. this._draw(subMesh, fillMode, instancesCount);
  32525. engine.unbindInstanceAttributes();
  32526. return this;
  32527. };
  32528. Mesh.prototype._processRendering = function (subMesh, effect, fillMode, batch, hardwareInstancedRendering, onBeforeDraw, effectiveMaterial) {
  32529. var scene = this.getScene();
  32530. var engine = scene.getEngine();
  32531. if (hardwareInstancedRendering) {
  32532. this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
  32533. }
  32534. else {
  32535. if (batch.renderSelf[subMesh._id]) {
  32536. // Draw
  32537. if (onBeforeDraw) {
  32538. onBeforeDraw(false, this.getWorldMatrix(), effectiveMaterial);
  32539. }
  32540. this._draw(subMesh, fillMode, this._overridenInstanceCount);
  32541. }
  32542. var visibleInstancesForSubMesh = batch.visibleInstances[subMesh._id];
  32543. if (visibleInstancesForSubMesh) {
  32544. for (var instanceIndex = 0; instanceIndex < visibleInstancesForSubMesh.length; instanceIndex++) {
  32545. var instance = visibleInstancesForSubMesh[instanceIndex];
  32546. // World
  32547. var world = instance.getWorldMatrix();
  32548. if (onBeforeDraw) {
  32549. onBeforeDraw(true, world, effectiveMaterial);
  32550. }
  32551. // Draw
  32552. this._draw(subMesh, fillMode);
  32553. }
  32554. }
  32555. }
  32556. return this;
  32557. };
  32558. /**
  32559. * Triggers the draw call for the mesh.
  32560. * Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager.
  32561. * Returns the Mesh.
  32562. */
  32563. Mesh.prototype.render = function (subMesh, enableAlphaMode) {
  32564. this._checkOcclusionQuery();
  32565. if (this._isOccluded) {
  32566. return this;
  32567. }
  32568. var scene = this.getScene();
  32569. // Managing instances
  32570. var batch = this._getInstancesRenderList(subMesh._id);
  32571. if (batch.mustReturn) {
  32572. return this;
  32573. }
  32574. // Checking geometry state
  32575. if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
  32576. return this;
  32577. }
  32578. this.onBeforeRenderObservable.notifyObservers(this);
  32579. var engine = scene.getEngine();
  32580. var hardwareInstancedRendering = (engine.getCaps().instancedArrays) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
  32581. // Material
  32582. var material = subMesh.getMaterial();
  32583. if (!material) {
  32584. return this;
  32585. }
  32586. this._effectiveMaterial = material;
  32587. if (this._effectiveMaterial.storeEffectOnSubMeshes) {
  32588. if (!this._effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
  32589. return this;
  32590. }
  32591. }
  32592. else if (!this._effectiveMaterial.isReady(this, hardwareInstancedRendering)) {
  32593. return this;
  32594. }
  32595. // Alpha mode
  32596. if (enableAlphaMode) {
  32597. engine.setAlphaMode(this._effectiveMaterial.alphaMode);
  32598. }
  32599. // Outline - step 1
  32600. var savedDepthWrite = engine.getDepthWrite();
  32601. if (this.renderOutline) {
  32602. engine.setDepthWrite(false);
  32603. scene.getOutlineRenderer().render(subMesh, batch);
  32604. engine.setDepthWrite(savedDepthWrite);
  32605. }
  32606. var effect;
  32607. if (this._effectiveMaterial.storeEffectOnSubMeshes) {
  32608. effect = subMesh.effect;
  32609. }
  32610. else {
  32611. effect = this._effectiveMaterial.getEffect();
  32612. }
  32613. if (!effect) {
  32614. return this;
  32615. }
  32616. var sideOrientation = this.overrideMaterialSideOrientation;
  32617. if (sideOrientation == null) {
  32618. sideOrientation = this._effectiveMaterial.sideOrientation;
  32619. if (this._getWorldMatrixDeterminant() < 0) {
  32620. sideOrientation = (sideOrientation === BABYLON.Material.ClockWiseSideOrientation ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation);
  32621. }
  32622. }
  32623. var reverse = this._effectiveMaterial._preBind(effect, sideOrientation);
  32624. if (this._effectiveMaterial.forceDepthWrite) {
  32625. engine.setDepthWrite(true);
  32626. }
  32627. // Bind
  32628. var fillMode = scene.forcePointsCloud ? BABYLON.Material.PointFillMode : (scene.forceWireframe ? BABYLON.Material.WireFrameFillMode : this._effectiveMaterial.fillMode);
  32629. if (!hardwareInstancedRendering) { // Binding will be done later because we need to add more info to the VB
  32630. this._bind(subMesh, effect, fillMode);
  32631. }
  32632. var world = this.getWorldMatrix();
  32633. if (this._effectiveMaterial.storeEffectOnSubMeshes) {
  32634. this._effectiveMaterial.bindForSubMesh(world, this, subMesh);
  32635. }
  32636. else {
  32637. this._effectiveMaterial.bind(world, this);
  32638. }
  32639. if (!this._effectiveMaterial.backFaceCulling && this._effectiveMaterial.separateCullingPass) {
  32640. engine.setState(true, this._effectiveMaterial.zOffset, false, !reverse);
  32641. this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._effectiveMaterial);
  32642. engine.setState(true, this._effectiveMaterial.zOffset, false, reverse);
  32643. }
  32644. // Draw
  32645. this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._effectiveMaterial);
  32646. // Unbind
  32647. this._effectiveMaterial.unbind();
  32648. // Outline - step 2
  32649. if (this.renderOutline && savedDepthWrite) {
  32650. engine.setDepthWrite(true);
  32651. engine.setColorWrite(false);
  32652. scene.getOutlineRenderer().render(subMesh, batch);
  32653. engine.setColorWrite(true);
  32654. }
  32655. // Overlay
  32656. if (this.renderOverlay) {
  32657. var currentMode = engine.getAlphaMode();
  32658. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
  32659. scene.getOutlineRenderer().render(subMesh, batch, true);
  32660. engine.setAlphaMode(currentMode);
  32661. }
  32662. this.onAfterRenderObservable.notifyObservers(this);
  32663. return this;
  32664. };
  32665. Mesh.prototype._onBeforeDraw = function (isInstance, world, effectiveMaterial) {
  32666. if (isInstance && effectiveMaterial) {
  32667. effectiveMaterial.bindOnlyWorldMatrix(world);
  32668. }
  32669. };
  32670. /**
  32671. * Returns an array populated with ParticleSystem objects whose the mesh is the emitter.
  32672. */
  32673. Mesh.prototype.getEmittedParticleSystems = function () {
  32674. var results = new Array();
  32675. for (var index = 0; index < this.getScene().particleSystems.length; index++) {
  32676. var particleSystem = this.getScene().particleSystems[index];
  32677. if (particleSystem.emitter === this) {
  32678. results.push(particleSystem);
  32679. }
  32680. }
  32681. return results;
  32682. };
  32683. /**
  32684. * Returns an array populated with ParticleSystem objects whose the mesh or its children are the emitter.
  32685. */
  32686. Mesh.prototype.getHierarchyEmittedParticleSystems = function () {
  32687. var results = new Array();
  32688. var descendants = this.getDescendants();
  32689. descendants.push(this);
  32690. for (var index = 0; index < this.getScene().particleSystems.length; index++) {
  32691. var particleSystem = this.getScene().particleSystems[index];
  32692. var emitter = particleSystem.emitter;
  32693. if (emitter.position && descendants.indexOf(emitter) !== -1) {
  32694. results.push(particleSystem);
  32695. }
  32696. }
  32697. return results;
  32698. };
  32699. /**
  32700. * Normalize matrix weights so that all vertices have a total weight set to 1
  32701. */
  32702. Mesh.prototype.cleanMatrixWeights = function () {
  32703. var epsilon = 1e-3;
  32704. var noInfluenceBoneIndex = 0.0;
  32705. if (this.skeleton) {
  32706. noInfluenceBoneIndex = this.skeleton.bones.length;
  32707. }
  32708. else {
  32709. return;
  32710. }
  32711. var matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
  32712. var matricesIndicesExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  32713. var matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
  32714. var matricesWeightsExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
  32715. var influencers = this.numBoneInfluencers;
  32716. var size = matricesWeights.length;
  32717. for (var i = 0; i < size; i += 4) {
  32718. var weight = 0.0;
  32719. var firstZeroWeight = -1;
  32720. for (var j = 0; j < 4; j++) {
  32721. var w = matricesWeights[i + j];
  32722. weight += w;
  32723. if (w < epsilon && firstZeroWeight < 0) {
  32724. firstZeroWeight = j;
  32725. }
  32726. }
  32727. if (matricesWeightsExtra) {
  32728. for (var j = 0; j < 4; j++) {
  32729. var w = matricesWeightsExtra[i + j];
  32730. weight += w;
  32731. if (w < epsilon && firstZeroWeight < 0) {
  32732. firstZeroWeight = j + 4;
  32733. }
  32734. }
  32735. }
  32736. if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
  32737. firstZeroWeight = influencers - 1;
  32738. }
  32739. if (weight > epsilon) {
  32740. var mweight = 1.0 / weight;
  32741. for (var j = 0; j < 4; j++) {
  32742. matricesWeights[i + j] *= mweight;
  32743. }
  32744. if (matricesWeightsExtra) {
  32745. for (var j = 0; j < 4; j++) {
  32746. matricesWeightsExtra[i + j] *= mweight;
  32747. }
  32748. }
  32749. }
  32750. else {
  32751. if (firstZeroWeight >= 4) {
  32752. matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
  32753. matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
  32754. }
  32755. else {
  32756. matricesWeights[i + firstZeroWeight] = 1.0 - weight;
  32757. matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
  32758. }
  32759. }
  32760. }
  32761. this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
  32762. if (matricesIndicesExtra) {
  32763. this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
  32764. }
  32765. this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights);
  32766. if (matricesWeightsExtra) {
  32767. this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
  32768. }
  32769. };
  32770. Mesh.prototype._checkDelayState = function () {
  32771. var scene = this.getScene();
  32772. if (this._geometry) {
  32773. this._geometry.load(scene);
  32774. }
  32775. else if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  32776. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
  32777. this._queueLoad(scene);
  32778. }
  32779. return this;
  32780. };
  32781. Mesh.prototype._queueLoad = function (scene) {
  32782. var _this = this;
  32783. scene._addPendingData(this);
  32784. var getBinaryData = (this.delayLoadingFile.indexOf(".babylonbinarymeshdata") !== -1);
  32785. BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
  32786. if (data instanceof ArrayBuffer) {
  32787. _this._delayLoadingFunction(data, _this);
  32788. }
  32789. else {
  32790. _this._delayLoadingFunction(JSON.parse(data), _this);
  32791. }
  32792. _this.instances.forEach(function (instance) {
  32793. instance._syncSubMeshes();
  32794. });
  32795. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  32796. scene._removePendingData(_this);
  32797. }, function () { }, scene.database, getBinaryData);
  32798. return this;
  32799. };
  32800. /**
  32801. * Boolean, true is the mesh in the frustum defined by the Plane objects from the `frustumPlanes` array parameter.
  32802. */
  32803. Mesh.prototype.isInFrustum = function (frustumPlanes) {
  32804. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  32805. return false;
  32806. }
  32807. if (!_super.prototype.isInFrustum.call(this, frustumPlanes)) {
  32808. return false;
  32809. }
  32810. this._checkDelayState();
  32811. return true;
  32812. };
  32813. /**
  32814. * Sets the mesh material by the material or multiMaterial `id` property.
  32815. * The material `id` is a string identifying the material or the multiMaterial.
  32816. * This method returns the Mesh.
  32817. */
  32818. Mesh.prototype.setMaterialByID = function (id) {
  32819. var materials = this.getScene().materials;
  32820. var index;
  32821. for (index = materials.length - 1; index > -1; index--) {
  32822. if (materials[index].id === id) {
  32823. this.material = materials[index];
  32824. return this;
  32825. }
  32826. }
  32827. // Multi
  32828. var multiMaterials = this.getScene().multiMaterials;
  32829. for (index = multiMaterials.length - 1; index > -1; index--) {
  32830. if (multiMaterials[index].id === id) {
  32831. this.material = multiMaterials[index];
  32832. return this;
  32833. }
  32834. }
  32835. return this;
  32836. };
  32837. /**
  32838. * Returns as a new array populated with the mesh material and/or skeleton, if any.
  32839. */
  32840. Mesh.prototype.getAnimatables = function () {
  32841. var results = new Array();
  32842. if (this.material) {
  32843. results.push(this.material);
  32844. }
  32845. if (this.skeleton) {
  32846. results.push(this.skeleton);
  32847. }
  32848. return results;
  32849. };
  32850. /**
  32851. * Modifies the mesh geometry according to the passed transformation matrix.
  32852. * This method returns nothing but it really modifies the mesh even if it's originally not set as updatable.
  32853. * The mesh normals are modified accordingly the same transformation.
  32854. * tuto : http://doc.babylonjs.com/resources/baking_transformations
  32855. * Note that, under the hood, this method sets a new VertexBuffer each call.
  32856. * Returns the Mesh.
  32857. */
  32858. Mesh.prototype.bakeTransformIntoVertices = function (transform) {
  32859. // Position
  32860. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  32861. return this;
  32862. }
  32863. var submeshes = this.subMeshes.splice(0);
  32864. this._resetPointsArrayCache();
  32865. var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  32866. var temp = new Array();
  32867. var index;
  32868. for (index = 0; index < data.length; index += 3) {
  32869. BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
  32870. }
  32871. this.setVerticesData(BABYLON.VertexBuffer.PositionKind, temp, this.getVertexBuffer(BABYLON.VertexBuffer.PositionKind).isUpdatable());
  32872. // Normals
  32873. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  32874. return this;
  32875. }
  32876. data = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  32877. temp = [];
  32878. for (index = 0; index < data.length; index += 3) {
  32879. BABYLON.Vector3.TransformNormal(BABYLON.Vector3.FromArray(data, index), transform).normalize().toArray(temp, index);
  32880. }
  32881. this.setVerticesData(BABYLON.VertexBuffer.NormalKind, temp, this.getVertexBuffer(BABYLON.VertexBuffer.NormalKind).isUpdatable());
  32882. // flip faces?
  32883. if (transform.m[0] * transform.m[5] * transform.m[10] < 0) {
  32884. this.flipFaces();
  32885. }
  32886. // Restore submeshes
  32887. this.releaseSubMeshes();
  32888. this.subMeshes = submeshes;
  32889. return this;
  32890. };
  32891. /**
  32892. * Modifies the mesh geometry according to its own current World Matrix.
  32893. * The mesh World Matrix is then reset.
  32894. * This method returns nothing but really modifies the mesh even if it's originally not set as updatable.
  32895. * tuto : tuto : http://doc.babylonjs.com/resources/baking_transformations
  32896. * Note that, under the hood, this method sets a new VertexBuffer each call.
  32897. * Returns the Mesh.
  32898. */
  32899. Mesh.prototype.bakeCurrentTransformIntoVertices = function () {
  32900. this.bakeTransformIntoVertices(this.computeWorldMatrix(true));
  32901. this.scaling.copyFromFloats(1, 1, 1);
  32902. this.position.copyFromFloats(0, 0, 0);
  32903. this.rotation.copyFromFloats(0, 0, 0);
  32904. //only if quaternion is already set
  32905. if (this.rotationQuaternion) {
  32906. this.rotationQuaternion = BABYLON.Quaternion.Identity();
  32907. }
  32908. this._worldMatrix = BABYLON.Matrix.Identity();
  32909. return this;
  32910. };
  32911. Object.defineProperty(Mesh.prototype, "_positions", {
  32912. // Cache
  32913. get: function () {
  32914. if (this._geometry) {
  32915. return this._geometry._positions;
  32916. }
  32917. return null;
  32918. },
  32919. enumerable: true,
  32920. configurable: true
  32921. });
  32922. Mesh.prototype._resetPointsArrayCache = function () {
  32923. if (this._geometry) {
  32924. this._geometry._resetPointsArrayCache();
  32925. }
  32926. return this;
  32927. };
  32928. Mesh.prototype._generatePointsArray = function () {
  32929. if (this._geometry) {
  32930. return this._geometry._generatePointsArray();
  32931. }
  32932. return false;
  32933. };
  32934. /**
  32935. * Returns a new Mesh object generated from the current mesh properties.
  32936. * This method must not get confused with createInstance().
  32937. * The parameter `name` is a string, the name given to the new mesh.
  32938. * The optional parameter `newParent` can be any Node object (default `null`).
  32939. * The optional parameter `doNotCloneChildren` (default `false`) allows/denies the recursive cloning of the original mesh children if any.
  32940. * The parameter `clonePhysicsImpostor` (default `true`) allows/denies the cloning in the same time of the original mesh `body` used by the physics engine, if any.
  32941. */
  32942. Mesh.prototype.clone = function (name, newParent, doNotCloneChildren, clonePhysicsImpostor) {
  32943. if (clonePhysicsImpostor === void 0) { clonePhysicsImpostor = true; }
  32944. return new Mesh(name, this.getScene(), newParent, this, doNotCloneChildren, clonePhysicsImpostor);
  32945. };
  32946. /**
  32947. * Releases resources associated with this mesh.
  32948. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  32949. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  32950. */
  32951. Mesh.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  32952. var _this = this;
  32953. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  32954. this.morphTargetManager = null;
  32955. if (this._geometry) {
  32956. this._geometry.releaseForMesh(this, true);
  32957. }
  32958. // Sources
  32959. var meshes = this.getScene().meshes;
  32960. meshes.forEach(function (abstractMesh) {
  32961. var mesh = abstractMesh;
  32962. if (mesh._source && mesh._source === _this) {
  32963. mesh._source = null;
  32964. }
  32965. });
  32966. this._source = null;
  32967. // Instances
  32968. if (this._instancesBuffer) {
  32969. this._instancesBuffer.dispose();
  32970. this._instancesBuffer = null;
  32971. }
  32972. while (this.instances.length) {
  32973. this.instances[0].dispose();
  32974. }
  32975. // Effect layers.
  32976. var effectLayers = this.getScene().effectLayers;
  32977. for (var i = 0; i < effectLayers.length; i++) {
  32978. var effectLayer = effectLayers[i];
  32979. if (effectLayer) {
  32980. effectLayer._disposeMesh(this);
  32981. }
  32982. }
  32983. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  32984. };
  32985. /**
  32986. * Modifies the mesh geometry according to a displacement map.
  32987. * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.
  32988. * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.
  32989. * This method returns nothing.
  32990. * The parameter `url` is a string, the URL from the image file is to be downloaded.
  32991. * The parameters `minHeight` and `maxHeight` are the lower and upper limits of the displacement.
  32992. * The parameter `onSuccess` is an optional Javascript function to be called just after the mesh is modified. It is passed the modified mesh and must return nothing.
  32993. * The parameter `uvOffset` is an optional vector2 used to offset UV.
  32994. * The parameter `uvScale` is an optional vector2 used to scale UV.
  32995. *
  32996. * Returns the Mesh.
  32997. */
  32998. Mesh.prototype.applyDisplacementMap = function (url, minHeight, maxHeight, onSuccess, uvOffset, uvScale) {
  32999. var _this = this;
  33000. var scene = this.getScene();
  33001. var onload = function (img) {
  33002. // Getting height map data
  33003. var canvas = document.createElement("canvas");
  33004. var context = canvas.getContext("2d");
  33005. var heightMapWidth = img.width;
  33006. var heightMapHeight = img.height;
  33007. canvas.width = heightMapWidth;
  33008. canvas.height = heightMapHeight;
  33009. context.drawImage(img, 0, 0);
  33010. // Create VertexData from map data
  33011. //Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949
  33012. var buffer = context.getImageData(0, 0, heightMapWidth, heightMapHeight).data;
  33013. _this.applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale);
  33014. //execute success callback, if set
  33015. if (onSuccess) {
  33016. onSuccess(_this);
  33017. }
  33018. };
  33019. BABYLON.Tools.LoadImage(url, onload, function () { }, scene.database);
  33020. return this;
  33021. };
  33022. /**
  33023. * Modifies the mesh geometry according to a displacementMap buffer.
  33024. * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.
  33025. * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.
  33026. * This method returns nothing.
  33027. * The parameter `buffer` is a `Uint8Array` buffer containing series of `Uint8` lower than 255, the red, green, blue and alpha values of each successive pixel.
  33028. * The parameters `heightMapWidth` and `heightMapHeight` are positive integers to set the width and height of the buffer image.
  33029. * The parameters `minHeight` and `maxHeight` are the lower and upper limits of the displacement.
  33030. * The parameter `uvOffset` is an optional vector2 used to offset UV.
  33031. * The parameter `uvScale` is an optional vector2 used to scale UV.
  33032. *
  33033. * Returns the Mesh.
  33034. */
  33035. Mesh.prototype.applyDisplacementMapFromBuffer = function (buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale) {
  33036. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)
  33037. || !this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)
  33038. || !this.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  33039. BABYLON.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");
  33040. return this;
  33041. }
  33042. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  33043. var normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  33044. var uvs = this.getVerticesData(BABYLON.VertexBuffer.UVKind);
  33045. var position = BABYLON.Vector3.Zero();
  33046. var normal = BABYLON.Vector3.Zero();
  33047. var uv = BABYLON.Vector2.Zero();
  33048. uvOffset = uvOffset || BABYLON.Vector2.Zero();
  33049. uvScale = uvScale || new BABYLON.Vector2(1, 1);
  33050. for (var index = 0; index < positions.length; index += 3) {
  33051. BABYLON.Vector3.FromArrayToRef(positions, index, position);
  33052. BABYLON.Vector3.FromArrayToRef(normals, index, normal);
  33053. BABYLON.Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
  33054. // Compute height
  33055. var u = ((Math.abs(uv.x * uvScale.x + uvOffset.x) * heightMapWidth) % heightMapWidth) | 0;
  33056. var v = ((Math.abs(uv.y * uvScale.y + uvOffset.y) * heightMapHeight) % heightMapHeight) | 0;
  33057. var pos = (u + v * heightMapWidth) * 4;
  33058. var r = buffer[pos] / 255.0;
  33059. var g = buffer[pos + 1] / 255.0;
  33060. var b = buffer[pos + 2] / 255.0;
  33061. var gradient = r * 0.3 + g * 0.59 + b * 0.11;
  33062. normal.normalize();
  33063. normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);
  33064. position = position.add(normal);
  33065. position.toArray(positions, index);
  33066. }
  33067. BABYLON.VertexData.ComputeNormals(positions, this.getIndices(), normals);
  33068. this.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
  33069. this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
  33070. return this;
  33071. };
  33072. /**
  33073. * Modify the mesh to get a flat shading rendering.
  33074. * This means each mesh facet will then have its own normals. Usually new vertices are added in the mesh geometry to get this result.
  33075. * This method returns the Mesh.
  33076. * Warning : the mesh is really modified even if not set originally as updatable and, under the hood, a new VertexBuffer is allocated.
  33077. */
  33078. Mesh.prototype.convertToFlatShadedMesh = function () {
  33079. /// <summary>Update normals and vertices to get a flat shading rendering.</summary>
  33080. /// <summary>Warning: This may imply adding vertices to the mesh in order to get exactly 3 vertices per face</summary>
  33081. var kinds = this.getVerticesDataKinds();
  33082. var vbs = {};
  33083. var data = {};
  33084. var newdata = {};
  33085. var updatableNormals = false;
  33086. var kindIndex;
  33087. var kind;
  33088. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33089. kind = kinds[kindIndex];
  33090. var vertexBuffer = this.getVertexBuffer(kind);
  33091. if (kind === BABYLON.VertexBuffer.NormalKind) {
  33092. updatableNormals = vertexBuffer.isUpdatable();
  33093. kinds.splice(kindIndex, 1);
  33094. kindIndex--;
  33095. continue;
  33096. }
  33097. vbs[kind] = vertexBuffer;
  33098. data[kind] = vbs[kind].getData();
  33099. newdata[kind] = [];
  33100. }
  33101. // Save previous submeshes
  33102. var previousSubmeshes = this.subMeshes.slice(0);
  33103. var indices = this.getIndices();
  33104. var totalIndices = this.getTotalIndices();
  33105. // Generating unique vertices per face
  33106. var index;
  33107. for (index = 0; index < totalIndices; index++) {
  33108. var vertexIndex = indices[index];
  33109. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33110. kind = kinds[kindIndex];
  33111. var stride = vbs[kind].getStrideSize();
  33112. for (var offset = 0; offset < stride; offset++) {
  33113. newdata[kind].push(data[kind][vertexIndex * stride + offset]);
  33114. }
  33115. }
  33116. }
  33117. // Updating faces & normal
  33118. var normals = [];
  33119. var positions = newdata[BABYLON.VertexBuffer.PositionKind];
  33120. for (index = 0; index < totalIndices; index += 3) {
  33121. indices[index] = index;
  33122. indices[index + 1] = index + 1;
  33123. indices[index + 2] = index + 2;
  33124. var p1 = BABYLON.Vector3.FromArray(positions, index * 3);
  33125. var p2 = BABYLON.Vector3.FromArray(positions, (index + 1) * 3);
  33126. var p3 = BABYLON.Vector3.FromArray(positions, (index + 2) * 3);
  33127. var p1p2 = p1.subtract(p2);
  33128. var p3p2 = p3.subtract(p2);
  33129. var normal = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(p1p2, p3p2));
  33130. // Store same normals for every vertex
  33131. for (var localIndex = 0; localIndex < 3; localIndex++) {
  33132. normals.push(normal.x);
  33133. normals.push(normal.y);
  33134. normals.push(normal.z);
  33135. }
  33136. }
  33137. this.setIndices(indices);
  33138. this.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatableNormals);
  33139. // Updating vertex buffers
  33140. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33141. kind = kinds[kindIndex];
  33142. this.setVerticesData(kind, newdata[kind], vbs[kind].isUpdatable());
  33143. }
  33144. // Updating submeshes
  33145. this.releaseSubMeshes();
  33146. for (var submeshIndex = 0; submeshIndex < previousSubmeshes.length; submeshIndex++) {
  33147. var previousOne = previousSubmeshes[submeshIndex];
  33148. BABYLON.SubMesh.AddToMesh(previousOne.materialIndex, previousOne.indexStart, previousOne.indexCount, previousOne.indexStart, previousOne.indexCount, this);
  33149. }
  33150. this.synchronizeInstances();
  33151. return this;
  33152. };
  33153. /**
  33154. * This method removes all the mesh indices and add new vertices (duplication) in order to unfold facets into buffers.
  33155. * In other words, more vertices, no more indices and a single bigger VBO.
  33156. * The mesh is really modified even if not set originally as updatable. Under the hood, a new VertexBuffer is allocated.
  33157. * Returns the Mesh.
  33158. */
  33159. Mesh.prototype.convertToUnIndexedMesh = function () {
  33160. /// <summary>Remove indices by unfolding faces into buffers</summary>
  33161. /// <summary>Warning: This implies adding vertices to the mesh in order to get exactly 3 vertices per face</summary>
  33162. var kinds = this.getVerticesDataKinds();
  33163. var vbs = {};
  33164. var data = {};
  33165. var newdata = {};
  33166. var kindIndex;
  33167. var kind;
  33168. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33169. kind = kinds[kindIndex];
  33170. var vertexBuffer = this.getVertexBuffer(kind);
  33171. vbs[kind] = vertexBuffer;
  33172. data[kind] = vbs[kind].getData();
  33173. newdata[kind] = [];
  33174. }
  33175. // Save previous submeshes
  33176. var previousSubmeshes = this.subMeshes.slice(0);
  33177. var indices = this.getIndices();
  33178. var totalIndices = this.getTotalIndices();
  33179. // Generating unique vertices per face
  33180. var index;
  33181. for (index = 0; index < totalIndices; index++) {
  33182. var vertexIndex = indices[index];
  33183. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33184. kind = kinds[kindIndex];
  33185. var stride = vbs[kind].getStrideSize();
  33186. for (var offset = 0; offset < stride; offset++) {
  33187. newdata[kind].push(data[kind][vertexIndex * stride + offset]);
  33188. }
  33189. }
  33190. }
  33191. // Updating indices
  33192. for (index = 0; index < totalIndices; index += 3) {
  33193. indices[index] = index;
  33194. indices[index + 1] = index + 1;
  33195. indices[index + 2] = index + 2;
  33196. }
  33197. this.setIndices(indices);
  33198. // Updating vertex buffers
  33199. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  33200. kind = kinds[kindIndex];
  33201. this.setVerticesData(kind, newdata[kind], vbs[kind].isUpdatable());
  33202. }
  33203. // Updating submeshes
  33204. this.releaseSubMeshes();
  33205. for (var submeshIndex = 0; submeshIndex < previousSubmeshes.length; submeshIndex++) {
  33206. var previousOne = previousSubmeshes[submeshIndex];
  33207. BABYLON.SubMesh.AddToMesh(previousOne.materialIndex, previousOne.indexStart, previousOne.indexCount, previousOne.indexStart, previousOne.indexCount, this);
  33208. }
  33209. this._unIndexed = true;
  33210. this.synchronizeInstances();
  33211. return this;
  33212. };
  33213. /**
  33214. * Inverses facet orientations and inverts also the normals with `flipNormals` (default `false`) if true.
  33215. * This method returns the Mesh.
  33216. * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.
  33217. */
  33218. Mesh.prototype.flipFaces = function (flipNormals) {
  33219. if (flipNormals === void 0) { flipNormals = false; }
  33220. var vertex_data = BABYLON.VertexData.ExtractFromMesh(this);
  33221. var i;
  33222. if (flipNormals && this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind) && vertex_data.normals) {
  33223. for (i = 0; i < vertex_data.normals.length; i++) {
  33224. vertex_data.normals[i] *= -1;
  33225. }
  33226. }
  33227. if (vertex_data.indices) {
  33228. var temp;
  33229. for (i = 0; i < vertex_data.indices.length; i += 3) {
  33230. // reassign indices
  33231. temp = vertex_data.indices[i + 1];
  33232. vertex_data.indices[i + 1] = vertex_data.indices[i + 2];
  33233. vertex_data.indices[i + 2] = temp;
  33234. }
  33235. }
  33236. vertex_data.applyToMesh(this);
  33237. return this;
  33238. };
  33239. // Instances
  33240. /**
  33241. * Creates a new InstancedMesh object from the mesh model.
  33242. * An instance shares the same properties and the same material than its model.
  33243. * Only these properties of each instance can then be set individually :
  33244. * - position
  33245. * - rotation
  33246. * - rotationQuaternion
  33247. * - setPivotMatrix
  33248. * - scaling
  33249. * tuto : http://doc.babylonjs.com/tutorials/How_to_use_Instances
  33250. * Warning : this method is not supported for Line mesh and LineSystem
  33251. */
  33252. Mesh.prototype.createInstance = function (name) {
  33253. return new BABYLON.InstancedMesh(name, this);
  33254. };
  33255. /**
  33256. * Synchronises all the mesh instance submeshes to the current mesh submeshes, if any.
  33257. * After this call, all the mesh instances have the same submeshes than the current mesh.
  33258. * This method returns the Mesh.
  33259. */
  33260. Mesh.prototype.synchronizeInstances = function () {
  33261. for (var instanceIndex = 0; instanceIndex < this.instances.length; instanceIndex++) {
  33262. var instance = this.instances[instanceIndex];
  33263. instance._syncSubMeshes();
  33264. }
  33265. return this;
  33266. };
  33267. /**
  33268. * Simplify the mesh according to the given array of settings.
  33269. * Function will return immediately and will simplify async. It returns the Mesh.
  33270. * @param settings a collection of simplification settings.
  33271. * @param parallelProcessing should all levels calculate parallel or one after the other.
  33272. * @param type the type of simplification to run.
  33273. * @param successCallback optional success callback to be called after the simplification finished processing all settings.
  33274. */
  33275. Mesh.prototype.simplify = function (settings, parallelProcessing, simplificationType, successCallback) {
  33276. if (parallelProcessing === void 0) { parallelProcessing = true; }
  33277. if (simplificationType === void 0) { simplificationType = BABYLON.SimplificationType.QUADRATIC; }
  33278. this.getScene().simplificationQueue.addTask({
  33279. settings: settings,
  33280. parallelProcessing: parallelProcessing,
  33281. mesh: this,
  33282. simplificationType: simplificationType,
  33283. successCallback: successCallback
  33284. });
  33285. return this;
  33286. };
  33287. /**
  33288. * Optimization of the mesh's indices, in case a mesh has duplicated vertices.
  33289. * The function will only reorder the indices and will not remove unused vertices to avoid problems with submeshes.
  33290. * This should be used together with the simplification to avoid disappearing triangles.
  33291. * Returns the Mesh.
  33292. * @param successCallback an optional success callback to be called after the optimization finished.
  33293. */
  33294. Mesh.prototype.optimizeIndices = function (successCallback) {
  33295. var _this = this;
  33296. var indices = this.getIndices();
  33297. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  33298. if (!positions || !indices) {
  33299. return this;
  33300. }
  33301. var vectorPositions = new Array();
  33302. for (var pos = 0; pos < positions.length; pos = pos + 3) {
  33303. vectorPositions.push(BABYLON.Vector3.FromArray(positions, pos));
  33304. }
  33305. var dupes = new Array();
  33306. BABYLON.AsyncLoop.SyncAsyncForLoop(vectorPositions.length, 40, function (iteration) {
  33307. var realPos = vectorPositions.length - 1 - iteration;
  33308. var testedPosition = vectorPositions[realPos];
  33309. for (var j = 0; j < realPos; ++j) {
  33310. var againstPosition = vectorPositions[j];
  33311. if (testedPosition.equals(againstPosition)) {
  33312. dupes[realPos] = j;
  33313. break;
  33314. }
  33315. }
  33316. }, function () {
  33317. for (var i = 0; i < indices.length; ++i) {
  33318. indices[i] = dupes[indices[i]] || indices[i];
  33319. }
  33320. //indices are now reordered
  33321. var originalSubMeshes = _this.subMeshes.slice(0);
  33322. _this.setIndices(indices);
  33323. _this.subMeshes = originalSubMeshes;
  33324. if (successCallback) {
  33325. successCallback(_this);
  33326. }
  33327. });
  33328. return this;
  33329. };
  33330. Mesh.prototype.serialize = function (serializationObject) {
  33331. serializationObject.name = this.name;
  33332. serializationObject.id = this.id;
  33333. serializationObject.type = this.getClassName();
  33334. if (BABYLON.Tags && BABYLON.Tags.HasTags(this)) {
  33335. serializationObject.tags = BABYLON.Tags.GetTags(this);
  33336. }
  33337. serializationObject.position = this.position.asArray();
  33338. if (this.rotationQuaternion) {
  33339. serializationObject.rotationQuaternion = this.rotationQuaternion.asArray();
  33340. }
  33341. else if (this.rotation) {
  33342. serializationObject.rotation = this.rotation.asArray();
  33343. }
  33344. serializationObject.scaling = this.scaling.asArray();
  33345. serializationObject.localMatrix = this.getPivotMatrix().asArray();
  33346. serializationObject.isEnabled = this.isEnabled(false);
  33347. serializationObject.isVisible = this.isVisible;
  33348. serializationObject.infiniteDistance = this.infiniteDistance;
  33349. serializationObject.pickable = this.isPickable;
  33350. serializationObject.receiveShadows = this.receiveShadows;
  33351. serializationObject.billboardMode = this.billboardMode;
  33352. serializationObject.visibility = this.visibility;
  33353. serializationObject.checkCollisions = this.checkCollisions;
  33354. serializationObject.isBlocker = this.isBlocker;
  33355. // Parent
  33356. if (this.parent) {
  33357. serializationObject.parentId = this.parent.id;
  33358. }
  33359. // Geometry
  33360. serializationObject.isUnIndexed = this.isUnIndexed;
  33361. var geometry = this._geometry;
  33362. if (geometry) {
  33363. var geometryId = geometry.id;
  33364. serializationObject.geometryId = geometryId;
  33365. // SubMeshes
  33366. serializationObject.subMeshes = [];
  33367. for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
  33368. var subMesh = this.subMeshes[subIndex];
  33369. serializationObject.subMeshes.push({
  33370. materialIndex: subMesh.materialIndex,
  33371. verticesStart: subMesh.verticesStart,
  33372. verticesCount: subMesh.verticesCount,
  33373. indexStart: subMesh.indexStart,
  33374. indexCount: subMesh.indexCount
  33375. });
  33376. }
  33377. }
  33378. // Material
  33379. if (this.material) {
  33380. serializationObject.materialId = this.material.id;
  33381. }
  33382. else {
  33383. this.material = null;
  33384. }
  33385. // Morph targets
  33386. if (this.morphTargetManager) {
  33387. serializationObject.morphTargetManagerId = this.morphTargetManager.uniqueId;
  33388. }
  33389. // Skeleton
  33390. if (this.skeleton) {
  33391. serializationObject.skeletonId = this.skeleton.id;
  33392. }
  33393. // Physics
  33394. //TODO implement correct serialization for physics impostors.
  33395. var impostor = this.getPhysicsImpostor();
  33396. if (impostor) {
  33397. serializationObject.physicsMass = impostor.getParam("mass");
  33398. serializationObject.physicsFriction = impostor.getParam("friction");
  33399. serializationObject.physicsRestitution = impostor.getParam("mass");
  33400. serializationObject.physicsImpostor = impostor.type;
  33401. }
  33402. // Metadata
  33403. if (this.metadata) {
  33404. serializationObject.metadata = this.metadata;
  33405. }
  33406. // Instances
  33407. serializationObject.instances = [];
  33408. for (var index = 0; index < this.instances.length; index++) {
  33409. var instance = this.instances[index];
  33410. var serializationInstance = {
  33411. name: instance.name,
  33412. id: instance.id,
  33413. position: instance.position.asArray(),
  33414. scaling: instance.scaling.asArray()
  33415. };
  33416. if (instance.rotationQuaternion) {
  33417. serializationInstance.rotationQuaternion = instance.rotationQuaternion.asArray();
  33418. }
  33419. else if (instance.rotation) {
  33420. serializationInstance.rotation = instance.rotation.asArray();
  33421. }
  33422. serializationObject.instances.push(serializationInstance);
  33423. // Animations
  33424. BABYLON.Animation.AppendSerializedAnimations(instance, serializationInstance);
  33425. serializationInstance.ranges = instance.serializeAnimationRanges();
  33426. }
  33427. //
  33428. // Animations
  33429. BABYLON.Animation.AppendSerializedAnimations(this, serializationObject);
  33430. serializationObject.ranges = this.serializeAnimationRanges();
  33431. // Layer mask
  33432. serializationObject.layerMask = this.layerMask;
  33433. // Alpha
  33434. serializationObject.alphaIndex = this.alphaIndex;
  33435. serializationObject.hasVertexAlpha = this.hasVertexAlpha;
  33436. // Overlay
  33437. serializationObject.overlayAlpha = this.overlayAlpha;
  33438. serializationObject.overlayColor = this.overlayColor.asArray();
  33439. serializationObject.renderOverlay = this.renderOverlay;
  33440. // Fog
  33441. serializationObject.applyFog = this.applyFog;
  33442. // Action Manager
  33443. if (this.actionManager) {
  33444. serializationObject.actions = this.actionManager.serialize(this.name);
  33445. }
  33446. };
  33447. Mesh.prototype._syncGeometryWithMorphTargetManager = function () {
  33448. if (!this.geometry) {
  33449. return;
  33450. }
  33451. this._markSubMeshesAsAttributesDirty();
  33452. var morphTargetManager = this._morphTargetManager;
  33453. if (morphTargetManager && morphTargetManager.vertexCount) {
  33454. if (morphTargetManager.vertexCount !== this.getTotalVertices()) {
  33455. BABYLON.Tools.Error("Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count.");
  33456. this.morphTargetManager = null;
  33457. return;
  33458. }
  33459. for (var index = 0; index < morphTargetManager.numInfluencers; index++) {
  33460. var morphTarget = morphTargetManager.getActiveTarget(index);
  33461. var positions = morphTarget.getPositions();
  33462. if (!positions) {
  33463. BABYLON.Tools.Error("Invalid morph target. Target must have positions.");
  33464. return;
  33465. }
  33466. this.geometry.setVerticesData(BABYLON.VertexBuffer.PositionKind + index, positions, false, 3);
  33467. var normals = morphTarget.getNormals();
  33468. if (normals) {
  33469. this.geometry.setVerticesData(BABYLON.VertexBuffer.NormalKind + index, normals, false, 3);
  33470. }
  33471. var tangents = morphTarget.getTangents();
  33472. if (tangents) {
  33473. this.geometry.setVerticesData(BABYLON.VertexBuffer.TangentKind + index, tangents, false, 3);
  33474. }
  33475. }
  33476. }
  33477. else {
  33478. var index = 0;
  33479. // Positions
  33480. while (this.geometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind + index)) {
  33481. this.geometry.removeVerticesData(BABYLON.VertexBuffer.PositionKind + index);
  33482. if (this.geometry.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind + index)) {
  33483. this.geometry.removeVerticesData(BABYLON.VertexBuffer.NormalKind + index);
  33484. }
  33485. if (this.geometry.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind + index)) {
  33486. this.geometry.removeVerticesData(BABYLON.VertexBuffer.TangentKind + index);
  33487. }
  33488. index++;
  33489. }
  33490. }
  33491. };
  33492. // Statics
  33493. /**
  33494. * Returns a new Mesh object parsed from the source provided.
  33495. * The parameter `parsedMesh` is the source.
  33496. * The parameter `rootUrl` is a string, it's the root URL to prefix the `delayLoadingFile` property with
  33497. */
  33498. Mesh.Parse = function (parsedMesh, scene, rootUrl) {
  33499. var mesh;
  33500. if (parsedMesh.type && parsedMesh.type === "GroundMesh") {
  33501. mesh = BABYLON.GroundMesh.Parse(parsedMesh, scene);
  33502. }
  33503. else {
  33504. mesh = new Mesh(parsedMesh.name, scene);
  33505. }
  33506. mesh.id = parsedMesh.id;
  33507. if (BABYLON.Tags) {
  33508. BABYLON.Tags.AddTagsTo(mesh, parsedMesh.tags);
  33509. }
  33510. mesh.position = BABYLON.Vector3.FromArray(parsedMesh.position);
  33511. if (parsedMesh.metadata !== undefined) {
  33512. mesh.metadata = parsedMesh.metadata;
  33513. }
  33514. if (parsedMesh.rotationQuaternion) {
  33515. mesh.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedMesh.rotationQuaternion);
  33516. }
  33517. else if (parsedMesh.rotation) {
  33518. mesh.rotation = BABYLON.Vector3.FromArray(parsedMesh.rotation);
  33519. }
  33520. mesh.scaling = BABYLON.Vector3.FromArray(parsedMesh.scaling);
  33521. if (parsedMesh.localMatrix) {
  33522. mesh.setPreTransformMatrix(BABYLON.Matrix.FromArray(parsedMesh.localMatrix));
  33523. }
  33524. else if (parsedMesh.pivotMatrix) {
  33525. mesh.setPivotMatrix(BABYLON.Matrix.FromArray(parsedMesh.pivotMatrix));
  33526. }
  33527. mesh.setEnabled(parsedMesh.isEnabled);
  33528. mesh.isVisible = parsedMesh.isVisible;
  33529. mesh.infiniteDistance = parsedMesh.infiniteDistance;
  33530. mesh.showBoundingBox = parsedMesh.showBoundingBox;
  33531. mesh.showSubMeshesBoundingBox = parsedMesh.showSubMeshesBoundingBox;
  33532. if (parsedMesh.applyFog !== undefined) {
  33533. mesh.applyFog = parsedMesh.applyFog;
  33534. }
  33535. if (parsedMesh.pickable !== undefined) {
  33536. mesh.isPickable = parsedMesh.pickable;
  33537. }
  33538. if (parsedMesh.alphaIndex !== undefined) {
  33539. mesh.alphaIndex = parsedMesh.alphaIndex;
  33540. }
  33541. mesh.receiveShadows = parsedMesh.receiveShadows;
  33542. mesh.billboardMode = parsedMesh.billboardMode;
  33543. if (parsedMesh.visibility !== undefined) {
  33544. mesh.visibility = parsedMesh.visibility;
  33545. }
  33546. mesh.checkCollisions = parsedMesh.checkCollisions;
  33547. if (parsedMesh.isBlocker !== undefined) {
  33548. mesh.isBlocker = parsedMesh.isBlocker;
  33549. }
  33550. mesh._shouldGenerateFlatShading = parsedMesh.useFlatShading;
  33551. // freezeWorldMatrix
  33552. if (parsedMesh.freezeWorldMatrix) {
  33553. mesh._waitingFreezeWorldMatrix = parsedMesh.freezeWorldMatrix;
  33554. }
  33555. // Parent
  33556. if (parsedMesh.parentId) {
  33557. mesh._waitingParentId = parsedMesh.parentId;
  33558. }
  33559. // Actions
  33560. if (parsedMesh.actions !== undefined) {
  33561. mesh._waitingActions = parsedMesh.actions;
  33562. }
  33563. // Overlay
  33564. if (parsedMesh.overlayAlpha !== undefined) {
  33565. mesh.overlayAlpha = parsedMesh.overlayAlpha;
  33566. }
  33567. if (parsedMesh.overlayColor !== undefined) {
  33568. mesh.overlayColor = BABYLON.Color3.FromArray(parsedMesh.overlayColor);
  33569. }
  33570. if (parsedMesh.renderOverlay !== undefined) {
  33571. mesh.renderOverlay = parsedMesh.renderOverlay;
  33572. }
  33573. // Geometry
  33574. mesh.isUnIndexed = !!parsedMesh.isUnIndexed;
  33575. mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;
  33576. if (parsedMesh.delayLoadingFile) {
  33577. mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  33578. mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
  33579. mesh._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMaximum));
  33580. if (parsedMesh._binaryInfo) {
  33581. mesh._binaryInfo = parsedMesh._binaryInfo;
  33582. }
  33583. mesh._delayInfo = [];
  33584. if (parsedMesh.hasUVs) {
  33585. mesh._delayInfo.push(BABYLON.VertexBuffer.UVKind);
  33586. }
  33587. if (parsedMesh.hasUVs2) {
  33588. mesh._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
  33589. }
  33590. if (parsedMesh.hasUVs3) {
  33591. mesh._delayInfo.push(BABYLON.VertexBuffer.UV3Kind);
  33592. }
  33593. if (parsedMesh.hasUVs4) {
  33594. mesh._delayInfo.push(BABYLON.VertexBuffer.UV4Kind);
  33595. }
  33596. if (parsedMesh.hasUVs5) {
  33597. mesh._delayInfo.push(BABYLON.VertexBuffer.UV5Kind);
  33598. }
  33599. if (parsedMesh.hasUVs6) {
  33600. mesh._delayInfo.push(BABYLON.VertexBuffer.UV6Kind);
  33601. }
  33602. if (parsedMesh.hasColors) {
  33603. mesh._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
  33604. }
  33605. if (parsedMesh.hasMatricesIndices) {
  33606. mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  33607. }
  33608. if (parsedMesh.hasMatricesWeights) {
  33609. mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  33610. }
  33611. mesh._delayLoadingFunction = BABYLON.Geometry._ImportGeometry;
  33612. if (BABYLON.SceneLoader.ForceFullSceneLoadingForIncremental) {
  33613. mesh._checkDelayState();
  33614. }
  33615. }
  33616. else {
  33617. BABYLON.Geometry._ImportGeometry(parsedMesh, mesh);
  33618. }
  33619. // Material
  33620. if (parsedMesh.materialId) {
  33621. mesh.setMaterialByID(parsedMesh.materialId);
  33622. }
  33623. else {
  33624. mesh.material = null;
  33625. }
  33626. // Morph targets
  33627. if (parsedMesh.morphTargetManagerId > -1) {
  33628. mesh.morphTargetManager = scene.getMorphTargetManagerById(parsedMesh.morphTargetManagerId);
  33629. }
  33630. // Skeleton
  33631. if (parsedMesh.skeletonId > -1) {
  33632. mesh.skeleton = scene.getLastSkeletonByID(parsedMesh.skeletonId);
  33633. if (parsedMesh.numBoneInfluencers) {
  33634. mesh.numBoneInfluencers = parsedMesh.numBoneInfluencers;
  33635. }
  33636. }
  33637. // Animations
  33638. if (parsedMesh.animations) {
  33639. for (var animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {
  33640. var parsedAnimation = parsedMesh.animations[animationIndex];
  33641. mesh.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  33642. }
  33643. BABYLON.Node.ParseAnimationRanges(mesh, parsedMesh, scene);
  33644. }
  33645. if (parsedMesh.autoAnimate) {
  33646. scene.beginAnimation(mesh, parsedMesh.autoAnimateFrom, parsedMesh.autoAnimateTo, parsedMesh.autoAnimateLoop, parsedMesh.autoAnimateSpeed || 1.0);
  33647. }
  33648. // Layer Mask
  33649. if (parsedMesh.layerMask && (!isNaN(parsedMesh.layerMask))) {
  33650. mesh.layerMask = Math.abs(parseInt(parsedMesh.layerMask));
  33651. }
  33652. else {
  33653. mesh.layerMask = 0x0FFFFFFF;
  33654. }
  33655. // Physics
  33656. if (parsedMesh.physicsImpostor) {
  33657. mesh.physicsImpostor = new BABYLON.PhysicsImpostor(mesh, parsedMesh.physicsImpostor, {
  33658. mass: parsedMesh.physicsMass,
  33659. friction: parsedMesh.physicsFriction,
  33660. restitution: parsedMesh.physicsRestitution
  33661. }, scene);
  33662. }
  33663. // Instances
  33664. if (parsedMesh.instances) {
  33665. for (var index = 0; index < parsedMesh.instances.length; index++) {
  33666. var parsedInstance = parsedMesh.instances[index];
  33667. var instance = mesh.createInstance(parsedInstance.name);
  33668. if (parsedInstance.id) {
  33669. instance.id = parsedInstance.id;
  33670. }
  33671. if (BABYLON.Tags) {
  33672. BABYLON.Tags.AddTagsTo(instance, parsedInstance.tags);
  33673. }
  33674. instance.position = BABYLON.Vector3.FromArray(parsedInstance.position);
  33675. if (parsedInstance.parentId) {
  33676. instance._waitingParentId = parsedInstance.parentId;
  33677. }
  33678. if (parsedInstance.rotationQuaternion) {
  33679. instance.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedInstance.rotationQuaternion);
  33680. }
  33681. else if (parsedInstance.rotation) {
  33682. instance.rotation = BABYLON.Vector3.FromArray(parsedInstance.rotation);
  33683. }
  33684. instance.scaling = BABYLON.Vector3.FromArray(parsedInstance.scaling);
  33685. instance.checkCollisions = mesh.checkCollisions;
  33686. if (parsedMesh.animations) {
  33687. for (animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {
  33688. parsedAnimation = parsedMesh.animations[animationIndex];
  33689. instance.animations.push(BABYLON.Animation.Parse(parsedAnimation));
  33690. }
  33691. BABYLON.Node.ParseAnimationRanges(instance, parsedMesh, scene);
  33692. if (parsedMesh.autoAnimate) {
  33693. scene.beginAnimation(instance, parsedMesh.autoAnimateFrom, parsedMesh.autoAnimateTo, parsedMesh.autoAnimateLoop, parsedMesh.autoAnimateSpeed || 1.0);
  33694. }
  33695. }
  33696. }
  33697. }
  33698. return mesh;
  33699. };
  33700. /**
  33701. * Creates a ribbon mesh.
  33702. * Please consider using the same method from the MeshBuilder class instead.
  33703. * The ribbon is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  33704. *
  33705. * Please read this full tutorial to understand how to design a ribbon : http://doc.babylonjs.com/tutorials/Ribbon_Tutorial
  33706. * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry.
  33707. * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array.
  33708. * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array.
  33709. * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path.
  33710. * It's the offset to join together the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11.
  33711. * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#ribbon
  33712. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33713. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33714. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33715. */
  33716. Mesh.CreateRibbon = function (name, pathArray, closeArray, closePath, offset, scene, updatable, sideOrientation, instance) {
  33717. if (closeArray === void 0) { closeArray = false; }
  33718. if (updatable === void 0) { updatable = false; }
  33719. return BABYLON.MeshBuilder.CreateRibbon(name, {
  33720. pathArray: pathArray,
  33721. closeArray: closeArray,
  33722. closePath: closePath,
  33723. offset: offset,
  33724. updatable: updatable,
  33725. sideOrientation: sideOrientation,
  33726. instance: instance
  33727. }, scene);
  33728. };
  33729. /**
  33730. * Creates a plane polygonal mesh. By default, this is a disc.
  33731. * Please consider using the same method from the MeshBuilder class instead.
  33732. * The parameter `radius` sets the radius size (float) of the polygon (default 0.5).
  33733. * The parameter `tessellation` sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc.
  33734. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33735. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33736. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33737. */
  33738. Mesh.CreateDisc = function (name, radius, tessellation, scene, updatable, sideOrientation) {
  33739. if (scene === void 0) { scene = null; }
  33740. var options = {
  33741. radius: radius,
  33742. tessellation: tessellation,
  33743. sideOrientation: sideOrientation,
  33744. updatable: updatable
  33745. };
  33746. return BABYLON.MeshBuilder.CreateDisc(name, options, scene);
  33747. };
  33748. /**
  33749. * Creates a box mesh.
  33750. * Please consider using the same method from the MeshBuilder class instead.
  33751. * The parameter `size` sets the size (float) of each box side (default 1).
  33752. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33753. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33754. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33755. */
  33756. Mesh.CreateBox = function (name, size, scene, updatable, sideOrientation) {
  33757. if (scene === void 0) { scene = null; }
  33758. var options = {
  33759. size: size,
  33760. sideOrientation: sideOrientation,
  33761. updatable: updatable
  33762. };
  33763. return BABYLON.MeshBuilder.CreateBox(name, options, scene);
  33764. };
  33765. /**
  33766. * Creates a sphere mesh.
  33767. * Please consider using the same method from the MeshBuilder class instead.
  33768. * The parameter `diameter` sets the diameter size (float) of the sphere (default 1).
  33769. * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32).
  33770. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33771. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33772. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33773. */
  33774. Mesh.CreateSphere = function (name, segments, diameter, scene, updatable, sideOrientation) {
  33775. var options = {
  33776. segments: segments,
  33777. diameterX: diameter,
  33778. diameterY: diameter,
  33779. diameterZ: diameter,
  33780. sideOrientation: sideOrientation,
  33781. updatable: updatable
  33782. };
  33783. return BABYLON.MeshBuilder.CreateSphere(name, options, scene);
  33784. };
  33785. /**
  33786. * Creates a cylinder or a cone mesh.
  33787. * Please consider using the same method from the MeshBuilder class instead.
  33788. * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).
  33789. * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).
  33790. * The parameters `diameterTop` and `diameterBottom` overwrite the parameter `diameter` and set respectively the top cap and bottom cap diameter (floats, default 1). The parameter "diameterBottom" can't be zero.
  33791. * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.
  33792. * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).
  33793. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33794. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33795. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33796. */
  33797. Mesh.CreateCylinder = function (name, height, diameterTop, diameterBottom, tessellation, subdivisions, scene, updatable, sideOrientation) {
  33798. if (scene === undefined || !(scene instanceof BABYLON.Scene)) {
  33799. if (scene !== undefined) {
  33800. sideOrientation = updatable || Mesh.DEFAULTSIDE;
  33801. updatable = scene;
  33802. }
  33803. scene = subdivisions;
  33804. subdivisions = 1;
  33805. }
  33806. var options = {
  33807. height: height,
  33808. diameterTop: diameterTop,
  33809. diameterBottom: diameterBottom,
  33810. tessellation: tessellation,
  33811. subdivisions: subdivisions,
  33812. sideOrientation: sideOrientation,
  33813. updatable: updatable
  33814. };
  33815. return BABYLON.MeshBuilder.CreateCylinder(name, options, scene);
  33816. };
  33817. // Torus (Code from SharpDX.org)
  33818. /**
  33819. * Creates a torus mesh.
  33820. * Please consider using the same method from the MeshBuilder class instead.
  33821. * The parameter `diameter` sets the diameter size (float) of the torus (default 1).
  33822. * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5).
  33823. * The parameter `tessellation` sets the number of torus sides (postive integer, default 16).
  33824. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33825. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33826. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33827. */
  33828. Mesh.CreateTorus = function (name, diameter, thickness, tessellation, scene, updatable, sideOrientation) {
  33829. var options = {
  33830. diameter: diameter,
  33831. thickness: thickness,
  33832. tessellation: tessellation,
  33833. sideOrientation: sideOrientation,
  33834. updatable: updatable
  33835. };
  33836. return BABYLON.MeshBuilder.CreateTorus(name, options, scene);
  33837. };
  33838. /**
  33839. * Creates a torus knot mesh.
  33840. * Please consider using the same method from the MeshBuilder class instead.
  33841. * The parameter `radius` sets the global radius size (float) of the torus knot (default 2).
  33842. * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32).
  33843. * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32).
  33844. * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3).
  33845. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33846. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33847. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33848. */
  33849. Mesh.CreateTorusKnot = function (name, radius, tube, radialSegments, tubularSegments, p, q, scene, updatable, sideOrientation) {
  33850. var options = {
  33851. radius: radius,
  33852. tube: tube,
  33853. radialSegments: radialSegments,
  33854. tubularSegments: tubularSegments,
  33855. p: p,
  33856. q: q,
  33857. sideOrientation: sideOrientation,
  33858. updatable: updatable
  33859. };
  33860. return BABYLON.MeshBuilder.CreateTorusKnot(name, options, scene);
  33861. };
  33862. /**
  33863. * Creates a line mesh.
  33864. * Please consider using the same method from the MeshBuilder class instead.
  33865. * A line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter.
  33866. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  33867. * The parameter `points` is an array successive Vector3.
  33868. * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  33869. * When updating an instance, remember that only point positions can change, not the number of points.
  33870. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33871. */
  33872. Mesh.CreateLines = function (name, points, scene, updatable, instance) {
  33873. if (scene === void 0) { scene = null; }
  33874. if (updatable === void 0) { updatable = false; }
  33875. if (instance === void 0) { instance = null; }
  33876. var options = {
  33877. points: points,
  33878. updatable: updatable,
  33879. instance: instance
  33880. };
  33881. return BABYLON.MeshBuilder.CreateLines(name, options, scene);
  33882. };
  33883. /**
  33884. * Creates a dashed line mesh.
  33885. * Please consider using the same method from the MeshBuilder class instead.
  33886. * A dashed line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter.
  33887. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  33888. * The parameter `points` is an array successive Vector3.
  33889. * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200).
  33890. * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3).
  33891. * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1).
  33892. * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  33893. * When updating an instance, remember that only point positions can change, not the number of points.
  33894. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33895. */
  33896. Mesh.CreateDashedLines = function (name, points, dashSize, gapSize, dashNb, scene, updatable, instance) {
  33897. if (scene === void 0) { scene = null; }
  33898. var options = {
  33899. points: points,
  33900. dashSize: dashSize,
  33901. gapSize: gapSize,
  33902. dashNb: dashNb,
  33903. updatable: updatable,
  33904. instance: instance
  33905. };
  33906. return BABYLON.MeshBuilder.CreateDashedLines(name, options, scene);
  33907. };
  33908. /**
  33909. * Creates a polygon mesh.
  33910. * Please consider using the same method from the MeshBuilder class instead.
  33911. * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.
  33912. * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
  33913. * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33914. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33915. * Remember you can only change the shape positions, not their number when updating a polygon.
  33916. */
  33917. Mesh.CreatePolygon = function (name, shape, scene, holes, updatable, sideOrientation) {
  33918. var options = {
  33919. shape: shape,
  33920. holes: holes,
  33921. updatable: updatable,
  33922. sideOrientation: sideOrientation
  33923. };
  33924. return BABYLON.MeshBuilder.CreatePolygon(name, options, scene);
  33925. };
  33926. /**
  33927. * Creates an extruded polygon mesh, with depth in the Y direction.
  33928. * Please consider using the same method from the MeshBuilder class instead.
  33929. */
  33930. Mesh.ExtrudePolygon = function (name, shape, depth, scene, holes, updatable, sideOrientation) {
  33931. var options = {
  33932. shape: shape,
  33933. holes: holes,
  33934. depth: depth,
  33935. updatable: updatable,
  33936. sideOrientation: sideOrientation
  33937. };
  33938. return BABYLON.MeshBuilder.ExtrudePolygon(name, options, scene);
  33939. };
  33940. /**
  33941. * Creates an extruded shape mesh.
  33942. * The extrusion is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  33943. * Please consider using the same method from the MeshBuilder class instead.
  33944. *
  33945. * Please read this full tutorial to understand how to design an extruded shape : http://doc.babylonjs.com/how_to/parametric_shapes#extruded-shapes
  33946. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be
  33947. * extruded along the Z axis.
  33948. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  33949. * The parameter `rotation` (float, default 0 radians) is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve.
  33950. * The parameter `scale` (float, default 1) is the value to scale the shape.
  33951. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  33952. * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  33953. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  33954. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  33955. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  33956. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  33957. */
  33958. Mesh.ExtrudeShape = function (name, shape, path, scale, rotation, cap, scene, updatable, sideOrientation, instance) {
  33959. if (scene === void 0) { scene = null; }
  33960. var options = {
  33961. shape: shape,
  33962. path: path,
  33963. scale: scale,
  33964. rotation: rotation,
  33965. cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
  33966. sideOrientation: sideOrientation,
  33967. instance: instance,
  33968. updatable: updatable
  33969. };
  33970. return BABYLON.MeshBuilder.ExtrudeShape(name, options, scene);
  33971. };
  33972. /**
  33973. * Creates an custom extruded shape mesh.
  33974. * The custom extrusion is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  33975. * Please consider using the same method from the MeshBuilder class instead.
  33976. *
  33977. * Please read this full tutorial to understand how to design a custom extruded shape : http://doc.babylonjs.com/how_to/parametric_shapes#extruded-shapes
  33978. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be
  33979. * extruded along the Z axis.
  33980. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  33981. * The parameter `rotationFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path
  33982. * and the distance of this point from the begining of the path :
  33983. * ```javascript
  33984. * var rotationFunction = function(i, distance) {
  33985. * // do things
  33986. * return rotationValue; }
  33987. * ```
  33988. * It must returns a float value that will be the rotation in radians applied to the shape on each path point.
  33989. * The parameter `scaleFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path
  33990. * and the distance of this point from the begining of the path :
  33991. * ```javascript
  33992. * var scaleFunction = function(i, distance) {
  33993. * // do things
  33994. * return scaleValue;}
  33995. * ```
  33996. * It must returns a float value that will be the scale value applied to the shape on each path point.
  33997. * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray`.
  33998. * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray`.
  33999. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  34000. * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  34001. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  34002. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34003. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34004. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34005. */
  34006. Mesh.ExtrudeShapeCustom = function (name, shape, path, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, scene, updatable, sideOrientation, instance) {
  34007. var options = {
  34008. shape: shape,
  34009. path: path,
  34010. scaleFunction: scaleFunction,
  34011. rotationFunction: rotationFunction,
  34012. ribbonCloseArray: ribbonCloseArray,
  34013. ribbonClosePath: ribbonClosePath,
  34014. cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
  34015. sideOrientation: sideOrientation,
  34016. instance: instance,
  34017. updatable: updatable
  34018. };
  34019. return BABYLON.MeshBuilder.ExtrudeShapeCustom(name, options, scene);
  34020. };
  34021. /**
  34022. * Creates lathe mesh.
  34023. * The lathe is a shape with a symetry axis : a 2D model shape is rotated around this axis to design the lathe.
  34024. * Please consider using the same method from the MeshBuilder class instead.
  34025. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be
  34026. * rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero.
  34027. * The parameter `radius` (positive float, default 1) is the radius value of the lathe.
  34028. * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe.
  34029. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34030. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34031. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34032. */
  34033. Mesh.CreateLathe = function (name, shape, radius, tessellation, scene, updatable, sideOrientation) {
  34034. var options = {
  34035. shape: shape,
  34036. radius: radius,
  34037. tessellation: tessellation,
  34038. sideOrientation: sideOrientation,
  34039. updatable: updatable
  34040. };
  34041. return BABYLON.MeshBuilder.CreateLathe(name, options, scene);
  34042. };
  34043. /**
  34044. * Creates a plane mesh.
  34045. * Please consider using the same method from the MeshBuilder class instead.
  34046. * The parameter `size` sets the size (float) of both sides of the plane at once (default 1).
  34047. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34048. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34049. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34050. */
  34051. Mesh.CreatePlane = function (name, size, scene, updatable, sideOrientation) {
  34052. var options = {
  34053. size: size,
  34054. width: size,
  34055. height: size,
  34056. sideOrientation: sideOrientation,
  34057. updatable: updatable
  34058. };
  34059. return BABYLON.MeshBuilder.CreatePlane(name, options, scene);
  34060. };
  34061. /**
  34062. * Creates a ground mesh.
  34063. * Please consider using the same method from the MeshBuilder class instead.
  34064. * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground.
  34065. * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side.
  34066. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34067. */
  34068. Mesh.CreateGround = function (name, width, height, subdivisions, scene, updatable) {
  34069. var options = {
  34070. width: width,
  34071. height: height,
  34072. subdivisions: subdivisions,
  34073. updatable: updatable
  34074. };
  34075. return BABYLON.MeshBuilder.CreateGround(name, options, scene);
  34076. };
  34077. /**
  34078. * Creates a tiled ground mesh.
  34079. * Please consider using the same method from the MeshBuilder class instead.
  34080. * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates.
  34081. * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates.
  34082. * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the
  34083. * numbers of subdivisions on the ground width and height. Each subdivision is called a tile.
  34084. * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the
  34085. * numbers of subdivisions on the ground width and height of each tile.
  34086. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34087. */
  34088. Mesh.CreateTiledGround = function (name, xmin, zmin, xmax, zmax, subdivisions, precision, scene, updatable) {
  34089. var options = {
  34090. xmin: xmin,
  34091. zmin: zmin,
  34092. xmax: xmax,
  34093. zmax: zmax,
  34094. subdivisions: subdivisions,
  34095. precision: precision,
  34096. updatable: updatable
  34097. };
  34098. return BABYLON.MeshBuilder.CreateTiledGround(name, options, scene);
  34099. };
  34100. /**
  34101. * Creates a ground mesh from a height map.
  34102. * tuto : http://doc.babylonjs.com/babylon101/height_map
  34103. * Please consider using the same method from the MeshBuilder class instead.
  34104. * The parameter `url` sets the URL of the height map image resource.
  34105. * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.
  34106. * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.
  34107. * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.
  34108. * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.
  34109. * The parameter `onReady` is a javascript callback function that will be called once the mesh is just built (the height map download can last some time).
  34110. * This function is passed the newly built mesh :
  34111. * ```javascript
  34112. * function(mesh) { // do things
  34113. * return; }
  34114. * ```
  34115. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34116. */
  34117. Mesh.CreateGroundFromHeightMap = function (name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReady) {
  34118. var options = {
  34119. width: width,
  34120. height: height,
  34121. subdivisions: subdivisions,
  34122. minHeight: minHeight,
  34123. maxHeight: maxHeight,
  34124. updatable: updatable,
  34125. onReady: onReady
  34126. };
  34127. return BABYLON.MeshBuilder.CreateGroundFromHeightMap(name, url, options, scene);
  34128. };
  34129. /**
  34130. * Creates a tube mesh.
  34131. * The tube is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  34132. * Please consider using the same method from the MeshBuilder class instead.
  34133. * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube.
  34134. * The parameter `radius` (positive float, default 1) sets the tube radius size.
  34135. * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface.
  34136. * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overwrittes the parameter `radius`.
  34137. * This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path.
  34138. * It must return a radius value (positive float) :
  34139. * ```javascript
  34140. * var radiusFunction = function(i, distance) {
  34141. * // do things
  34142. * return radius; }
  34143. * ```
  34144. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  34145. * The optional parameter `instance` is an instance of an existing Tube object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#tube
  34146. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34147. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34148. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34149. */
  34150. Mesh.CreateTube = function (name, path, radius, tessellation, radiusFunction, cap, scene, updatable, sideOrientation, instance) {
  34151. var options = {
  34152. path: path,
  34153. radius: radius,
  34154. tessellation: tessellation,
  34155. radiusFunction: radiusFunction,
  34156. arc: 1,
  34157. cap: cap,
  34158. updatable: updatable,
  34159. sideOrientation: sideOrientation,
  34160. instance: instance
  34161. };
  34162. return BABYLON.MeshBuilder.CreateTube(name, options, scene);
  34163. };
  34164. /**
  34165. * Creates a polyhedron mesh.
  34166. * Please consider using the same method from the MeshBuilder class instead.
  34167. * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embbeded types. Please refer to the type sheet in the tutorial
  34168. * to choose the wanted type.
  34169. * The parameter `size` (positive float, default 1) sets the polygon size.
  34170. * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value).
  34171. * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overwrittes the parameter `type`.
  34172. * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron
  34173. * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`).
  34174. * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  34175. * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored.
  34176. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34177. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34178. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34179. */
  34180. Mesh.CreatePolyhedron = function (name, options, scene) {
  34181. return BABYLON.MeshBuilder.CreatePolyhedron(name, options, scene);
  34182. };
  34183. /**
  34184. * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided.
  34185. * Please consider using the same method from the MeshBuilder class instead.
  34186. * The parameter `radius` sets the radius size (float) of the icosphere (default 1).
  34187. * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value than `radius`).
  34188. * The parameter `subdivisions` sets the number of subdivisions (postive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size.
  34189. * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface.
  34190. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  34191. * Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  34192. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  34193. */
  34194. Mesh.CreateIcoSphere = function (name, options, scene) {
  34195. return BABYLON.MeshBuilder.CreateIcoSphere(name, options, scene);
  34196. };
  34197. /**
  34198. * Creates a decal mesh.
  34199. * Please consider using the same method from the MeshBuilder class instead.
  34200. * A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal.
  34201. * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates.
  34202. * The parameter `normal` (Vector3, default Vector3.Up) sets the normal of the mesh where the decal is applied onto in World coordinates.
  34203. * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling.
  34204. * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal.
  34205. */
  34206. Mesh.CreateDecal = function (name, sourceMesh, position, normal, size, angle) {
  34207. var options = {
  34208. position: position,
  34209. normal: normal,
  34210. size: size,
  34211. angle: angle
  34212. };
  34213. return BABYLON.MeshBuilder.CreateDecal(name, sourceMesh, options);
  34214. };
  34215. // Skeletons
  34216. /**
  34217. * @returns original positions used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh.
  34218. */
  34219. Mesh.prototype.setPositionsForCPUSkinning = function () {
  34220. if (!this._sourcePositions) {
  34221. var source = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  34222. if (!source) {
  34223. return this._sourcePositions;
  34224. }
  34225. this._sourcePositions = new Float32Array(source);
  34226. if (!this.isVertexBufferUpdatable(BABYLON.VertexBuffer.PositionKind)) {
  34227. this.setVerticesData(BABYLON.VertexBuffer.PositionKind, source, true);
  34228. }
  34229. }
  34230. return this._sourcePositions;
  34231. };
  34232. /**
  34233. * @returns original normals used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh.
  34234. */
  34235. Mesh.prototype.setNormalsForCPUSkinning = function () {
  34236. if (!this._sourceNormals) {
  34237. var source = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  34238. if (!source) {
  34239. return this._sourceNormals;
  34240. }
  34241. this._sourceNormals = new Float32Array(source);
  34242. if (!this.isVertexBufferUpdatable(BABYLON.VertexBuffer.NormalKind)) {
  34243. this.setVerticesData(BABYLON.VertexBuffer.NormalKind, source, true);
  34244. }
  34245. }
  34246. return this._sourceNormals;
  34247. };
  34248. /**
  34249. * Updates the vertex buffer by applying transformation from the bones.
  34250. * Returns the Mesh.
  34251. *
  34252. * @param {skeleton} skeleton to apply
  34253. */
  34254. Mesh.prototype.applySkeleton = function (skeleton) {
  34255. if (!this.geometry) {
  34256. return this;
  34257. }
  34258. if (this.geometry._softwareSkinningRenderId == this.getScene().getRenderId()) {
  34259. return this;
  34260. }
  34261. this.geometry._softwareSkinningRenderId = this.getScene().getRenderId();
  34262. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  34263. return this;
  34264. }
  34265. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  34266. return this;
  34267. }
  34268. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
  34269. return this;
  34270. }
  34271. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  34272. return this;
  34273. }
  34274. if (!this._sourcePositions) {
  34275. var submeshes = this.subMeshes.slice();
  34276. this.setPositionsForCPUSkinning();
  34277. this.subMeshes = submeshes;
  34278. }
  34279. if (!this._sourceNormals) {
  34280. this.setNormalsForCPUSkinning();
  34281. }
  34282. // positionsData checks for not being Float32Array will only pass at most once
  34283. var positionsData = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  34284. if (!positionsData) {
  34285. return this;
  34286. }
  34287. if (!(positionsData instanceof Float32Array)) {
  34288. positionsData = new Float32Array(positionsData);
  34289. }
  34290. // normalsData checks for not being Float32Array will only pass at most once
  34291. var normalsData = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  34292. if (!normalsData) {
  34293. return this;
  34294. }
  34295. if (!(normalsData instanceof Float32Array)) {
  34296. normalsData = new Float32Array(normalsData);
  34297. }
  34298. var matricesIndicesData = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
  34299. var matricesWeightsData = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
  34300. if (!matricesWeightsData || !matricesIndicesData) {
  34301. return this;
  34302. }
  34303. var needExtras = this.numBoneInfluencers > 4;
  34304. var matricesIndicesExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind) : null;
  34305. var matricesWeightsExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind) : null;
  34306. var skeletonMatrices = skeleton.getTransformMatrices(this);
  34307. var tempVector3 = BABYLON.Vector3.Zero();
  34308. var finalMatrix = new BABYLON.Matrix();
  34309. var tempMatrix = new BABYLON.Matrix();
  34310. var matWeightIdx = 0;
  34311. var inf;
  34312. for (var index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {
  34313. var weight;
  34314. for (inf = 0; inf < 4; inf++) {
  34315. weight = matricesWeightsData[matWeightIdx + inf];
  34316. if (weight > 0) {
  34317. BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);
  34318. finalMatrix.addToSelf(tempMatrix);
  34319. }
  34320. else
  34321. break;
  34322. }
  34323. if (needExtras) {
  34324. for (inf = 0; inf < 4; inf++) {
  34325. weight = matricesWeightsExtraData[matWeightIdx + inf];
  34326. if (weight > 0) {
  34327. BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData[matWeightIdx + inf] * 16), weight, tempMatrix);
  34328. finalMatrix.addToSelf(tempMatrix);
  34329. }
  34330. else
  34331. break;
  34332. }
  34333. }
  34334. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[index], this._sourcePositions[index + 1], this._sourcePositions[index + 2], finalMatrix, tempVector3);
  34335. tempVector3.toArray(positionsData, index);
  34336. BABYLON.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[index], this._sourceNormals[index + 1], this._sourceNormals[index + 2], finalMatrix, tempVector3);
  34337. tempVector3.toArray(normalsData, index);
  34338. finalMatrix.reset();
  34339. }
  34340. this.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData);
  34341. this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData);
  34342. return this;
  34343. };
  34344. // Tools
  34345. /**
  34346. * Returns an object `{min:` Vector3`, max:` Vector3`}`
  34347. * This min and max Vector3 are the minimum and maximum vectors of each mesh bounding box from the passed array, in the World system
  34348. */
  34349. Mesh.MinMax = function (meshes) {
  34350. var minVector = null;
  34351. var maxVector = null;
  34352. meshes.forEach(function (mesh, index, array) {
  34353. var boundingInfo = mesh.getBoundingInfo();
  34354. var boundingBox = boundingInfo.boundingBox;
  34355. if (!minVector || !maxVector) {
  34356. minVector = boundingBox.minimumWorld;
  34357. maxVector = boundingBox.maximumWorld;
  34358. }
  34359. else {
  34360. minVector.minimizeInPlace(boundingBox.minimumWorld);
  34361. maxVector.maximizeInPlace(boundingBox.maximumWorld);
  34362. }
  34363. });
  34364. if (!minVector || !maxVector) {
  34365. return {
  34366. min: BABYLON.Vector3.Zero(),
  34367. max: BABYLON.Vector3.Zero()
  34368. };
  34369. }
  34370. return {
  34371. min: minVector,
  34372. max: maxVector
  34373. };
  34374. };
  34375. /**
  34376. * Returns a Vector3, the center of the `{min:` Vector3`, max:` Vector3`}` or the center of MinMax vector3 computed from a mesh array.
  34377. */
  34378. Mesh.Center = function (meshesOrMinMaxVector) {
  34379. var minMaxVector = (meshesOrMinMaxVector instanceof Array) ? Mesh.MinMax(meshesOrMinMaxVector) : meshesOrMinMaxVector;
  34380. return BABYLON.Vector3.Center(minMaxVector.min, minMaxVector.max);
  34381. };
  34382. /**
  34383. * Merge the array of meshes into a single mesh for performance reasons.
  34384. * @param {Array<Mesh>} meshes - The vertices source. They should all be of the same material. Entries can empty
  34385. * @param {boolean} disposeSource - When true (default), dispose of the vertices from the source meshes
  34386. * @param {boolean} allow32BitsIndices - When the sum of the vertices > 64k, this must be set to true.
  34387. * @param {Mesh} meshSubclass - When set, vertices inserted into this Mesh. Meshes can then be merged into a Mesh sub-class.
  34388. * @param {boolean} subdivideWithSubMeshes - When true (false default), subdivide mesh to his subMesh array with meshes source.
  34389. */
  34390. Mesh.MergeMeshes = function (meshes, disposeSource, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes) {
  34391. if (disposeSource === void 0) { disposeSource = true; }
  34392. var index;
  34393. if (!allow32BitsIndices) {
  34394. var totalVertices = 0;
  34395. // Counting vertices
  34396. for (index = 0; index < meshes.length; index++) {
  34397. if (meshes[index]) {
  34398. totalVertices += meshes[index].getTotalVertices();
  34399. if (totalVertices > 65536) {
  34400. BABYLON.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices");
  34401. return null;
  34402. }
  34403. }
  34404. }
  34405. }
  34406. // Merge
  34407. var vertexData = null;
  34408. var otherVertexData;
  34409. var indiceArray = new Array();
  34410. var source = null;
  34411. for (index = 0; index < meshes.length; index++) {
  34412. if (meshes[index]) {
  34413. meshes[index].computeWorldMatrix(true);
  34414. otherVertexData = BABYLON.VertexData.ExtractFromMesh(meshes[index], true, true);
  34415. otherVertexData.transform(meshes[index].getWorldMatrix());
  34416. if (vertexData) {
  34417. vertexData.merge(otherVertexData);
  34418. }
  34419. else {
  34420. vertexData = otherVertexData;
  34421. source = meshes[index];
  34422. }
  34423. if (subdivideWithSubMeshes) {
  34424. indiceArray.push(meshes[index].getTotalIndices());
  34425. }
  34426. }
  34427. }
  34428. source = source;
  34429. if (!meshSubclass) {
  34430. meshSubclass = new Mesh(source.name + "_merged", source.getScene());
  34431. }
  34432. vertexData.applyToMesh(meshSubclass);
  34433. // Setting properties
  34434. meshSubclass.material = source.material;
  34435. meshSubclass.checkCollisions = source.checkCollisions;
  34436. // Cleaning
  34437. if (disposeSource) {
  34438. for (index = 0; index < meshes.length; index++) {
  34439. if (meshes[index]) {
  34440. meshes[index].dispose();
  34441. }
  34442. }
  34443. }
  34444. // Subdivide
  34445. if (subdivideWithSubMeshes) {
  34446. //-- removal of global submesh
  34447. meshSubclass.releaseSubMeshes();
  34448. index = 0;
  34449. var offset = 0;
  34450. //-- apply subdivision according to index table
  34451. while (index < indiceArray.length) {
  34452. BABYLON.SubMesh.CreateFromIndices(0, offset, indiceArray[index], meshSubclass);
  34453. offset += indiceArray[index];
  34454. index++;
  34455. }
  34456. }
  34457. return meshSubclass;
  34458. };
  34459. // Consts
  34460. Mesh._FRONTSIDE = 0;
  34461. Mesh._BACKSIDE = 1;
  34462. Mesh._DOUBLESIDE = 2;
  34463. Mesh._DEFAULTSIDE = 0;
  34464. Mesh._NO_CAP = 0;
  34465. Mesh._CAP_START = 1;
  34466. Mesh._CAP_END = 2;
  34467. Mesh._CAP_ALL = 3;
  34468. return Mesh;
  34469. }(BABYLON.AbstractMesh));
  34470. BABYLON.Mesh = Mesh;
  34471. })(BABYLON || (BABYLON = {}));
  34472. //# sourceMappingURL=babylon.mesh.js.map
  34473. var BABYLON;
  34474. (function (BABYLON) {
  34475. var BaseSubMesh = /** @class */ (function () {
  34476. function BaseSubMesh() {
  34477. }
  34478. Object.defineProperty(BaseSubMesh.prototype, "effect", {
  34479. get: function () {
  34480. return this._materialEffect;
  34481. },
  34482. enumerable: true,
  34483. configurable: true
  34484. });
  34485. BaseSubMesh.prototype.setEffect = function (effect, defines) {
  34486. if (defines === void 0) { defines = null; }
  34487. if (this._materialEffect === effect) {
  34488. if (!effect) {
  34489. this._materialDefines = null;
  34490. }
  34491. return;
  34492. }
  34493. this._materialDefines = defines;
  34494. this._materialEffect = effect;
  34495. };
  34496. return BaseSubMesh;
  34497. }());
  34498. BABYLON.BaseSubMesh = BaseSubMesh;
  34499. var SubMesh = /** @class */ (function (_super) {
  34500. __extends(SubMesh, _super);
  34501. function SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox) {
  34502. if (createBoundingBox === void 0) { createBoundingBox = true; }
  34503. var _this = _super.call(this) || this;
  34504. _this.materialIndex = materialIndex;
  34505. _this.verticesStart = verticesStart;
  34506. _this.verticesCount = verticesCount;
  34507. _this.indexStart = indexStart;
  34508. _this.indexCount = indexCount;
  34509. _this._renderId = 0;
  34510. _this._mesh = mesh;
  34511. _this._renderingMesh = renderingMesh || mesh;
  34512. mesh.subMeshes.push(_this);
  34513. _this._trianglePlanes = [];
  34514. _this._id = mesh.subMeshes.length - 1;
  34515. if (createBoundingBox) {
  34516. _this.refreshBoundingInfo();
  34517. mesh.computeWorldMatrix(true);
  34518. }
  34519. return _this;
  34520. }
  34521. SubMesh.AddToMesh = function (materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox) {
  34522. if (createBoundingBox === void 0) { createBoundingBox = true; }
  34523. return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);
  34524. };
  34525. Object.defineProperty(SubMesh.prototype, "IsGlobal", {
  34526. get: function () {
  34527. return (this.verticesStart === 0 && this.verticesCount == this._mesh.getTotalVertices());
  34528. },
  34529. enumerable: true,
  34530. configurable: true
  34531. });
  34532. /**
  34533. * Returns the submesh BoudingInfo object.
  34534. */
  34535. SubMesh.prototype.getBoundingInfo = function () {
  34536. if (this.IsGlobal) {
  34537. return this._mesh.getBoundingInfo();
  34538. }
  34539. return this._boundingInfo;
  34540. };
  34541. /**
  34542. * Sets the submesh BoundingInfo.
  34543. * Return the SubMesh.
  34544. */
  34545. SubMesh.prototype.setBoundingInfo = function (boundingInfo) {
  34546. this._boundingInfo = boundingInfo;
  34547. return this;
  34548. };
  34549. /**
  34550. * Returns the mesh of the current submesh.
  34551. */
  34552. SubMesh.prototype.getMesh = function () {
  34553. return this._mesh;
  34554. };
  34555. /**
  34556. * Returns the rendering mesh of the submesh.
  34557. */
  34558. SubMesh.prototype.getRenderingMesh = function () {
  34559. return this._renderingMesh;
  34560. };
  34561. /**
  34562. * Returns the submesh material.
  34563. */
  34564. SubMesh.prototype.getMaterial = function () {
  34565. var rootMaterial = this._renderingMesh.material;
  34566. if (rootMaterial === null || rootMaterial === undefined) {
  34567. return this._mesh.getScene().defaultMaterial;
  34568. }
  34569. else if (rootMaterial.getSubMaterial) {
  34570. var multiMaterial = rootMaterial;
  34571. var effectiveMaterial = multiMaterial.getSubMaterial(this.materialIndex);
  34572. if (this._currentMaterial !== effectiveMaterial) {
  34573. this._currentMaterial = effectiveMaterial;
  34574. this._materialDefines = null;
  34575. }
  34576. return effectiveMaterial;
  34577. }
  34578. return rootMaterial;
  34579. };
  34580. // Methods
  34581. /**
  34582. * Sets a new updated BoundingInfo object to the submesh.
  34583. * Returns the SubMesh.
  34584. */
  34585. SubMesh.prototype.refreshBoundingInfo = function () {
  34586. this._lastColliderWorldVertices = null;
  34587. if (this.IsGlobal || !this._renderingMesh || !this._renderingMesh.geometry) {
  34588. return this;
  34589. }
  34590. var data = this._renderingMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  34591. if (!data) {
  34592. this._boundingInfo = this._mesh.getBoundingInfo();
  34593. return this;
  34594. }
  34595. var indices = this._renderingMesh.getIndices();
  34596. var extend;
  34597. //is this the only submesh?
  34598. if (this.indexStart === 0 && this.indexCount === indices.length) {
  34599. var boundingInfo = this._renderingMesh.getBoundingInfo();
  34600. //the rendering mesh's bounding info can be used, it is the standard submesh for all indices.
  34601. extend = { minimum: boundingInfo.minimum.clone(), maximum: boundingInfo.maximum.clone() };
  34602. }
  34603. else {
  34604. extend = BABYLON.Tools.ExtractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount, this._renderingMesh.geometry.boundingBias);
  34605. }
  34606. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  34607. return this;
  34608. };
  34609. SubMesh.prototype._checkCollision = function (collider) {
  34610. var boundingInfo = this.getBoundingInfo();
  34611. return boundingInfo._checkCollision(collider);
  34612. };
  34613. /**
  34614. * Updates the submesh BoundingInfo.
  34615. * Returns the Submesh.
  34616. */
  34617. SubMesh.prototype.updateBoundingInfo = function (world) {
  34618. var boundingInfo = this.getBoundingInfo();
  34619. if (!boundingInfo) {
  34620. this.refreshBoundingInfo();
  34621. boundingInfo = this.getBoundingInfo();
  34622. }
  34623. boundingInfo.update(world);
  34624. return this;
  34625. };
  34626. /**
  34627. * True is the submesh bounding box intersects the frustum defined by the passed array of planes.
  34628. * Boolean returned.
  34629. */
  34630. SubMesh.prototype.isInFrustum = function (frustumPlanes) {
  34631. var boundingInfo = this.getBoundingInfo();
  34632. if (!boundingInfo) {
  34633. return false;
  34634. }
  34635. return boundingInfo.isInFrustum(frustumPlanes);
  34636. };
  34637. /**
  34638. * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes.
  34639. * Boolean returned.
  34640. */
  34641. SubMesh.prototype.isCompletelyInFrustum = function (frustumPlanes) {
  34642. var boundingInfo = this.getBoundingInfo();
  34643. if (!boundingInfo) {
  34644. return false;
  34645. }
  34646. return boundingInfo.isCompletelyInFrustum(frustumPlanes);
  34647. };
  34648. /**
  34649. * Renders the submesh.
  34650. * Returns it.
  34651. */
  34652. SubMesh.prototype.render = function (enableAlphaMode) {
  34653. this._renderingMesh.render(this, enableAlphaMode);
  34654. return this;
  34655. };
  34656. /**
  34657. * Returns a new Index Buffer.
  34658. * Type returned : WebGLBuffer.
  34659. */
  34660. SubMesh.prototype.getLinesIndexBuffer = function (indices, engine) {
  34661. if (!this._linesIndexBuffer) {
  34662. var linesIndices = [];
  34663. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
  34664. linesIndices.push(indices[index], indices[index + 1], indices[index + 1], indices[index + 2], indices[index + 2], indices[index]);
  34665. }
  34666. this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);
  34667. this.linesIndexCount = linesIndices.length;
  34668. }
  34669. return this._linesIndexBuffer;
  34670. };
  34671. /**
  34672. * True is the passed Ray intersects the submesh bounding box.
  34673. * Boolean returned.
  34674. */
  34675. SubMesh.prototype.canIntersects = function (ray) {
  34676. var boundingInfo = this.getBoundingInfo();
  34677. if (!boundingInfo) {
  34678. return false;
  34679. }
  34680. return ray.intersectsBox(boundingInfo.boundingBox);
  34681. };
  34682. /**
  34683. * Returns an object IntersectionInfo.
  34684. */
  34685. SubMesh.prototype.intersects = function (ray, positions, indices, fastCheck) {
  34686. var intersectInfo = null;
  34687. var material = this.getMaterial();
  34688. if (!material) {
  34689. return null;
  34690. }
  34691. switch (material.fillMode) {
  34692. case BABYLON.Material.PointListDrawMode:
  34693. case BABYLON.Material.LineListDrawMode:
  34694. case BABYLON.Material.LineLoopDrawMode:
  34695. case BABYLON.Material.LineStripDrawMode:
  34696. case BABYLON.Material.TriangleFanDrawMode:
  34697. case BABYLON.Material.TriangleStripDrawMode:
  34698. return null;
  34699. }
  34700. // LineMesh first as it's also a Mesh...
  34701. if (BABYLON.LinesMesh && this._mesh instanceof BABYLON.LinesMesh) {
  34702. var lineMesh = this._mesh;
  34703. // Line test
  34704. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 2) {
  34705. var p0 = positions[indices[index]];
  34706. var p1 = positions[indices[index + 1]];
  34707. var length = ray.intersectionSegment(p0, p1, lineMesh.intersectionThreshold);
  34708. if (length < 0) {
  34709. continue;
  34710. }
  34711. if (fastCheck || !intersectInfo || length < intersectInfo.distance) {
  34712. intersectInfo = new BABYLON.IntersectionInfo(null, null, length);
  34713. if (fastCheck) {
  34714. break;
  34715. }
  34716. }
  34717. }
  34718. }
  34719. else {
  34720. // Triangles test
  34721. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
  34722. var p0 = positions[indices[index]];
  34723. var p1 = positions[indices[index + 1]];
  34724. var p2 = positions[indices[index + 2]];
  34725. var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
  34726. if (currentIntersectInfo) {
  34727. if (currentIntersectInfo.distance < 0) {
  34728. continue;
  34729. }
  34730. if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
  34731. intersectInfo = currentIntersectInfo;
  34732. intersectInfo.faceId = index / 3;
  34733. if (fastCheck) {
  34734. break;
  34735. }
  34736. }
  34737. }
  34738. }
  34739. }
  34740. return intersectInfo;
  34741. };
  34742. SubMesh.prototype._rebuild = function () {
  34743. if (this._linesIndexBuffer) {
  34744. this._linesIndexBuffer = null;
  34745. }
  34746. };
  34747. // Clone
  34748. /**
  34749. * Creates a new Submesh from the passed Mesh.
  34750. */
  34751. SubMesh.prototype.clone = function (newMesh, newRenderingMesh) {
  34752. var result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);
  34753. if (!this.IsGlobal) {
  34754. var boundingInfo = this.getBoundingInfo();
  34755. if (!boundingInfo) {
  34756. return result;
  34757. }
  34758. result._boundingInfo = new BABYLON.BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);
  34759. }
  34760. return result;
  34761. };
  34762. // Dispose
  34763. /**
  34764. * Disposes the Submesh.
  34765. * Returns nothing.
  34766. */
  34767. SubMesh.prototype.dispose = function () {
  34768. if (this._linesIndexBuffer) {
  34769. this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);
  34770. this._linesIndexBuffer = null;
  34771. }
  34772. // Remove from mesh
  34773. var index = this._mesh.subMeshes.indexOf(this);
  34774. this._mesh.subMeshes.splice(index, 1);
  34775. };
  34776. // Statics
  34777. /**
  34778. * Creates a new Submesh from the passed parameters :
  34779. * - materialIndex (integer) : the index of the main mesh material.
  34780. * - startIndex (integer) : the index where to start the copy in the mesh indices array.
  34781. * - indexCount (integer) : the number of indices to copy then from the startIndex.
  34782. * - mesh (Mesh) : the main mesh to create the submesh from.
  34783. * - renderingMesh (optional Mesh) : rendering mesh.
  34784. */
  34785. SubMesh.CreateFromIndices = function (materialIndex, startIndex, indexCount, mesh, renderingMesh) {
  34786. var minVertexIndex = Number.MAX_VALUE;
  34787. var maxVertexIndex = -Number.MAX_VALUE;
  34788. renderingMesh = (renderingMesh || mesh);
  34789. var indices = renderingMesh.getIndices();
  34790. for (var index = startIndex; index < startIndex + indexCount; index++) {
  34791. var vertexIndex = indices[index];
  34792. if (vertexIndex < minVertexIndex)
  34793. minVertexIndex = vertexIndex;
  34794. if (vertexIndex > maxVertexIndex)
  34795. maxVertexIndex = vertexIndex;
  34796. }
  34797. return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
  34798. };
  34799. return SubMesh;
  34800. }(BaseSubMesh));
  34801. BABYLON.SubMesh = SubMesh;
  34802. })(BABYLON || (BABYLON = {}));
  34803. //# sourceMappingURL=babylon.subMesh.js.map
  34804. var __assign = (this && this.__assign) || Object.assign || function(t) {
  34805. for (var s, i = 1, n = arguments.length; i < n; i++) {
  34806. s = arguments[i];
  34807. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  34808. t[p] = s[p];
  34809. }
  34810. return t;
  34811. };
  34812. var BABYLON;
  34813. (function (BABYLON) {
  34814. /**
  34815. * Manages the defines for the Material
  34816. */
  34817. var MaterialDefines = /** @class */ (function () {
  34818. function MaterialDefines() {
  34819. this._isDirty = true;
  34820. /** @hidden */
  34821. this._areLightsDirty = true;
  34822. /** @hidden */
  34823. this._areAttributesDirty = true;
  34824. /** @hidden */
  34825. this._areTexturesDirty = true;
  34826. /** @hidden */
  34827. this._areFresnelDirty = true;
  34828. /** @hidden */
  34829. this._areMiscDirty = true;
  34830. /** @hidden */
  34831. this._areImageProcessingDirty = true;
  34832. /** @hidden */
  34833. this._normals = false;
  34834. /** @hidden */
  34835. this._uvs = false;
  34836. /** @hidden */
  34837. this._needNormals = false;
  34838. /** @hidden */
  34839. this._needUVs = false;
  34840. }
  34841. Object.defineProperty(MaterialDefines.prototype, "isDirty", {
  34842. /**
  34843. * Specifies if the material needs to be re-calculated
  34844. */
  34845. get: function () {
  34846. return this._isDirty;
  34847. },
  34848. enumerable: true,
  34849. configurable: true
  34850. });
  34851. /**
  34852. * Marks the material to indicate that it has been re-calculated
  34853. */
  34854. MaterialDefines.prototype.markAsProcessed = function () {
  34855. this._isDirty = false;
  34856. this._areAttributesDirty = false;
  34857. this._areTexturesDirty = false;
  34858. this._areFresnelDirty = false;
  34859. this._areLightsDirty = false;
  34860. this._areMiscDirty = false;
  34861. this._areImageProcessingDirty = false;
  34862. };
  34863. /**
  34864. * Marks the material to indicate that it needs to be re-calculated
  34865. */
  34866. MaterialDefines.prototype.markAsUnprocessed = function () {
  34867. this._isDirty = true;
  34868. };
  34869. /**
  34870. * Marks the material to indicate all of its defines need to be re-calculated
  34871. */
  34872. MaterialDefines.prototype.markAllAsDirty = function () {
  34873. this._areTexturesDirty = true;
  34874. this._areAttributesDirty = true;
  34875. this._areLightsDirty = true;
  34876. this._areFresnelDirty = true;
  34877. this._areMiscDirty = true;
  34878. this._areImageProcessingDirty = true;
  34879. this._isDirty = true;
  34880. };
  34881. /**
  34882. * Marks the material to indicate that image processing needs to be re-calculated
  34883. */
  34884. MaterialDefines.prototype.markAsImageProcessingDirty = function () {
  34885. this._areImageProcessingDirty = true;
  34886. this._isDirty = true;
  34887. };
  34888. /**
  34889. * Marks the material to indicate the lights need to be re-calculated
  34890. */
  34891. MaterialDefines.prototype.markAsLightDirty = function () {
  34892. this._areLightsDirty = true;
  34893. this._isDirty = true;
  34894. };
  34895. /**
  34896. * Marks the attribute state as changed
  34897. */
  34898. MaterialDefines.prototype.markAsAttributesDirty = function () {
  34899. this._areAttributesDirty = true;
  34900. this._isDirty = true;
  34901. };
  34902. /**
  34903. * Marks the texture state as changed
  34904. */
  34905. MaterialDefines.prototype.markAsTexturesDirty = function () {
  34906. this._areTexturesDirty = true;
  34907. this._isDirty = true;
  34908. };
  34909. /**
  34910. * Marks the fresnel state as changed
  34911. */
  34912. MaterialDefines.prototype.markAsFresnelDirty = function () {
  34913. this._areFresnelDirty = true;
  34914. this._isDirty = true;
  34915. };
  34916. /**
  34917. * Marks the misc state as changed
  34918. */
  34919. MaterialDefines.prototype.markAsMiscDirty = function () {
  34920. this._areMiscDirty = true;
  34921. this._isDirty = true;
  34922. };
  34923. /**
  34924. * Rebuilds the material defines
  34925. */
  34926. MaterialDefines.prototype.rebuild = function () {
  34927. if (this._keys) {
  34928. delete this._keys;
  34929. }
  34930. this._keys = [];
  34931. for (var _i = 0, _a = Object.keys(this); _i < _a.length; _i++) {
  34932. var key = _a[_i];
  34933. if (key[0] === "_") {
  34934. continue;
  34935. }
  34936. this._keys.push(key);
  34937. }
  34938. };
  34939. /**
  34940. * Specifies if two material defines are equal
  34941. * @param other - A material define instance to compare to
  34942. * @returns - Boolean indicating if the material defines are equal (true) or not (false)
  34943. */
  34944. MaterialDefines.prototype.isEqual = function (other) {
  34945. if (this._keys.length !== other._keys.length) {
  34946. return false;
  34947. }
  34948. for (var index = 0; index < this._keys.length; index++) {
  34949. var prop = this._keys[index];
  34950. if (this[prop] !== other[prop]) {
  34951. return false;
  34952. }
  34953. }
  34954. return true;
  34955. };
  34956. /**
  34957. * Clones this instance's defines to another instance
  34958. * @param other - material defines to clone values to
  34959. */
  34960. MaterialDefines.prototype.cloneTo = function (other) {
  34961. if (this._keys.length !== other._keys.length) {
  34962. other._keys = this._keys.slice(0);
  34963. }
  34964. for (var index = 0; index < this._keys.length; index++) {
  34965. var prop = this._keys[index];
  34966. other[prop] = this[prop];
  34967. }
  34968. };
  34969. /**
  34970. * Resets the material define values
  34971. */
  34972. MaterialDefines.prototype.reset = function () {
  34973. for (var index = 0; index < this._keys.length; index++) {
  34974. var prop = this._keys[index];
  34975. var type = typeof this[prop];
  34976. switch (type) {
  34977. case "number":
  34978. this[prop] = 0;
  34979. break;
  34980. case "string":
  34981. this[prop] = "";
  34982. break;
  34983. default:
  34984. this[prop] = false;
  34985. break;
  34986. }
  34987. }
  34988. };
  34989. /**
  34990. * Converts the material define values to a string
  34991. * @returns - String of material define information
  34992. */
  34993. MaterialDefines.prototype.toString = function () {
  34994. var result = "";
  34995. for (var index = 0; index < this._keys.length; index++) {
  34996. var prop = this._keys[index];
  34997. var value = this[prop];
  34998. var type = typeof value;
  34999. switch (type) {
  35000. case "number":
  35001. case "string":
  35002. result += "#define " + prop + " " + value + "\n";
  35003. break;
  35004. default:
  35005. if (value) {
  35006. result += "#define " + prop + "\n";
  35007. }
  35008. break;
  35009. }
  35010. }
  35011. return result;
  35012. };
  35013. return MaterialDefines;
  35014. }());
  35015. BABYLON.MaterialDefines = MaterialDefines;
  35016. /**
  35017. * Base class for the main features of a material in Babylon.js
  35018. */
  35019. var Material = /** @class */ (function () {
  35020. /**
  35021. * Creates a material instance
  35022. * @param name defines the name of the material
  35023. * @param scene defines the scene to reference
  35024. * @param doNotAdd specifies if the material should be added to the scene
  35025. */
  35026. function Material(name, scene, doNotAdd) {
  35027. /**
  35028. * Specifies if the ready state should be checked on each call
  35029. */
  35030. this.checkReadyOnEveryCall = false;
  35031. /**
  35032. * Specifies if the ready state should be checked once
  35033. */
  35034. this.checkReadyOnlyOnce = false;
  35035. /**
  35036. * The state of the material
  35037. */
  35038. this.state = "";
  35039. /**
  35040. * The alpha value of the material
  35041. */
  35042. this._alpha = 1.0;
  35043. /**
  35044. * Specifies if back face culling is enabled
  35045. */
  35046. this._backFaceCulling = true;
  35047. /**
  35048. * Specifies if the material should be serialized
  35049. */
  35050. this.doNotSerialize = false;
  35051. /**
  35052. * Specifies if the effect should be stored on sub meshes
  35053. */
  35054. this.storeEffectOnSubMeshes = false;
  35055. /**
  35056. * An event triggered when the material is disposed
  35057. */
  35058. this.onDisposeObservable = new BABYLON.Observable();
  35059. /**
  35060. * An event triggered when the material is bound
  35061. */
  35062. this.onBindObservable = new BABYLON.Observable();
  35063. /**
  35064. * An event triggered when the material is unbound
  35065. */
  35066. this.onUnBindObservable = new BABYLON.Observable();
  35067. /**
  35068. * Stores the value of the alpha mode
  35069. */
  35070. this._alphaMode = BABYLON.Engine.ALPHA_COMBINE;
  35071. /**
  35072. * Stores the state of the need depth pre-pass value
  35073. */
  35074. this._needDepthPrePass = false;
  35075. /**
  35076. * Specifies if depth writing should be disabled
  35077. */
  35078. this.disableDepthWrite = false;
  35079. /**
  35080. * Specifies if depth writing should be forced
  35081. */
  35082. this.forceDepthWrite = false;
  35083. /**
  35084. * Specifies if there should be a separate pass for culling
  35085. */
  35086. this.separateCullingPass = false;
  35087. /**
  35088. * Stores the state specifing if fog should be enabled
  35089. */
  35090. this._fogEnabled = true;
  35091. /**
  35092. * Stores the size of points
  35093. */
  35094. this.pointSize = 1.0;
  35095. /**
  35096. * Stores the z offset value
  35097. */
  35098. this.zOffset = 0;
  35099. /**
  35100. * Specifies if the material was previously ready
  35101. */
  35102. this._wasPreviouslyReady = false;
  35103. /**
  35104. * Stores the fill mode state
  35105. */
  35106. this._fillMode = Material.TriangleFillMode;
  35107. this.name = name;
  35108. this.id = name || BABYLON.Tools.RandomId();
  35109. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  35110. this.uniqueId = this._scene.getUniqueId();
  35111. if (this._scene.useRightHandedSystem) {
  35112. this.sideOrientation = Material.ClockWiseSideOrientation;
  35113. }
  35114. else {
  35115. this.sideOrientation = Material.CounterClockWiseSideOrientation;
  35116. }
  35117. this._uniformBuffer = new BABYLON.UniformBuffer(this._scene.getEngine());
  35118. this._useUBO = this.getScene().getEngine().supportsUniformBuffers;
  35119. if (!doNotAdd) {
  35120. this._scene.materials.push(this);
  35121. }
  35122. }
  35123. Object.defineProperty(Material, "TriangleFillMode", {
  35124. /**
  35125. * Returns the triangle fill mode
  35126. */
  35127. get: function () {
  35128. return Material._TriangleFillMode;
  35129. },
  35130. enumerable: true,
  35131. configurable: true
  35132. });
  35133. Object.defineProperty(Material, "WireFrameFillMode", {
  35134. /**
  35135. * Returns the wireframe mode
  35136. */
  35137. get: function () {
  35138. return Material._WireFrameFillMode;
  35139. },
  35140. enumerable: true,
  35141. configurable: true
  35142. });
  35143. Object.defineProperty(Material, "PointFillMode", {
  35144. /**
  35145. * Returns the point fill mode
  35146. */
  35147. get: function () {
  35148. return Material._PointFillMode;
  35149. },
  35150. enumerable: true,
  35151. configurable: true
  35152. });
  35153. Object.defineProperty(Material, "PointListDrawMode", {
  35154. /**
  35155. * Returns the point list draw mode
  35156. */
  35157. get: function () {
  35158. return Material._PointListDrawMode;
  35159. },
  35160. enumerable: true,
  35161. configurable: true
  35162. });
  35163. Object.defineProperty(Material, "LineListDrawMode", {
  35164. /**
  35165. * Returns the line list draw mode
  35166. */
  35167. get: function () {
  35168. return Material._LineListDrawMode;
  35169. },
  35170. enumerable: true,
  35171. configurable: true
  35172. });
  35173. Object.defineProperty(Material, "LineLoopDrawMode", {
  35174. /**
  35175. * Returns the line loop draw mode
  35176. */
  35177. get: function () {
  35178. return Material._LineLoopDrawMode;
  35179. },
  35180. enumerable: true,
  35181. configurable: true
  35182. });
  35183. Object.defineProperty(Material, "LineStripDrawMode", {
  35184. /**
  35185. * Returns the line strip draw mode
  35186. */
  35187. get: function () {
  35188. return Material._LineStripDrawMode;
  35189. },
  35190. enumerable: true,
  35191. configurable: true
  35192. });
  35193. Object.defineProperty(Material, "TriangleStripDrawMode", {
  35194. /**
  35195. * Returns the triangle strip draw mode
  35196. */
  35197. get: function () {
  35198. return Material._TriangleStripDrawMode;
  35199. },
  35200. enumerable: true,
  35201. configurable: true
  35202. });
  35203. Object.defineProperty(Material, "TriangleFanDrawMode", {
  35204. /**
  35205. * Returns the triangle fan draw mode
  35206. */
  35207. get: function () {
  35208. return Material._TriangleFanDrawMode;
  35209. },
  35210. enumerable: true,
  35211. configurable: true
  35212. });
  35213. Object.defineProperty(Material, "ClockWiseSideOrientation", {
  35214. /**
  35215. * Returns the clock-wise side orientation
  35216. */
  35217. get: function () {
  35218. return Material._ClockWiseSideOrientation;
  35219. },
  35220. enumerable: true,
  35221. configurable: true
  35222. });
  35223. Object.defineProperty(Material, "CounterClockWiseSideOrientation", {
  35224. /**
  35225. * Returns the counter clock-wise side orientation
  35226. */
  35227. get: function () {
  35228. return Material._CounterClockWiseSideOrientation;
  35229. },
  35230. enumerable: true,
  35231. configurable: true
  35232. });
  35233. Object.defineProperty(Material, "TextureDirtyFlag", {
  35234. /**
  35235. * Returns the dirty texture flag value
  35236. */
  35237. get: function () {
  35238. return Material._TextureDirtyFlag;
  35239. },
  35240. enumerable: true,
  35241. configurable: true
  35242. });
  35243. Object.defineProperty(Material, "LightDirtyFlag", {
  35244. /**
  35245. * Returns the dirty light flag value
  35246. */
  35247. get: function () {
  35248. return Material._LightDirtyFlag;
  35249. },
  35250. enumerable: true,
  35251. configurable: true
  35252. });
  35253. Object.defineProperty(Material, "FresnelDirtyFlag", {
  35254. /**
  35255. * Returns the dirty fresnel flag value
  35256. */
  35257. get: function () {
  35258. return Material._FresnelDirtyFlag;
  35259. },
  35260. enumerable: true,
  35261. configurable: true
  35262. });
  35263. Object.defineProperty(Material, "AttributesDirtyFlag", {
  35264. /**
  35265. * Returns the dirty attributes flag value
  35266. */
  35267. get: function () {
  35268. return Material._AttributesDirtyFlag;
  35269. },
  35270. enumerable: true,
  35271. configurable: true
  35272. });
  35273. Object.defineProperty(Material, "MiscDirtyFlag", {
  35274. /**
  35275. * Returns the dirty misc flag value
  35276. */
  35277. get: function () {
  35278. return Material._MiscDirtyFlag;
  35279. },
  35280. enumerable: true,
  35281. configurable: true
  35282. });
  35283. Object.defineProperty(Material.prototype, "alpha", {
  35284. /**
  35285. * Gets the alpha value of the material
  35286. */
  35287. get: function () {
  35288. return this._alpha;
  35289. },
  35290. /**
  35291. * Sets the alpha value of the material
  35292. */
  35293. set: function (value) {
  35294. if (this._alpha === value) {
  35295. return;
  35296. }
  35297. this._alpha = value;
  35298. this.markAsDirty(Material.MiscDirtyFlag);
  35299. },
  35300. enumerable: true,
  35301. configurable: true
  35302. });
  35303. Object.defineProperty(Material.prototype, "backFaceCulling", {
  35304. /**
  35305. * Gets the back-face culling state
  35306. */
  35307. get: function () {
  35308. return this._backFaceCulling;
  35309. },
  35310. /**
  35311. * Sets the back-face culling state
  35312. */
  35313. set: function (value) {
  35314. if (this._backFaceCulling === value) {
  35315. return;
  35316. }
  35317. this._backFaceCulling = value;
  35318. this.markAsDirty(Material.TextureDirtyFlag);
  35319. },
  35320. enumerable: true,
  35321. configurable: true
  35322. });
  35323. Object.defineProperty(Material.prototype, "onDispose", {
  35324. /**
  35325. * Called during a dispose event
  35326. */
  35327. set: function (callback) {
  35328. if (this._onDisposeObserver) {
  35329. this.onDisposeObservable.remove(this._onDisposeObserver);
  35330. }
  35331. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  35332. },
  35333. enumerable: true,
  35334. configurable: true
  35335. });
  35336. Object.defineProperty(Material.prototype, "onBind", {
  35337. /**
  35338. * Called during a bind event
  35339. */
  35340. set: function (callback) {
  35341. if (this._onBindObserver) {
  35342. this.onBindObservable.remove(this._onBindObserver);
  35343. }
  35344. this._onBindObserver = this.onBindObservable.add(callback);
  35345. },
  35346. enumerable: true,
  35347. configurable: true
  35348. });
  35349. Object.defineProperty(Material.prototype, "alphaMode", {
  35350. /**
  35351. * Gets the value of the alpha mode
  35352. */
  35353. get: function () {
  35354. return this._alphaMode;
  35355. },
  35356. /**
  35357. * Sets the value of the alpha mode.
  35358. *
  35359. * | Value | Type | Description |
  35360. * | --- | --- | --- |
  35361. * | 0 | ALPHA_DISABLE | |
  35362. * | 1 | ALPHA_ADD | |
  35363. * | 2 | ALPHA_COMBINE | |
  35364. * | 3 | ALPHA_SUBTRACT | |
  35365. * | 4 | ALPHA_MULTIPLY | |
  35366. * | 5 | ALPHA_MAXIMIZED | |
  35367. * | 6 | ALPHA_ONEONE | |
  35368. * | 7 | ALPHA_PREMULTIPLIED | |
  35369. * | 8 | ALPHA_PREMULTIPLIED_PORTERDUFF | |
  35370. * | 9 | ALPHA_INTERPOLATE | |
  35371. * | 10 | ALPHA_SCREENMODE | |
  35372. *
  35373. */
  35374. set: function (value) {
  35375. if (this._alphaMode === value) {
  35376. return;
  35377. }
  35378. this._alphaMode = value;
  35379. this.markAsDirty(Material.TextureDirtyFlag);
  35380. },
  35381. enumerable: true,
  35382. configurable: true
  35383. });
  35384. Object.defineProperty(Material.prototype, "needDepthPrePass", {
  35385. /**
  35386. * Gets the depth pre-pass value
  35387. */
  35388. get: function () {
  35389. return this._needDepthPrePass;
  35390. },
  35391. /**
  35392. * Sets the need depth pre-pass value
  35393. */
  35394. set: function (value) {
  35395. if (this._needDepthPrePass === value) {
  35396. return;
  35397. }
  35398. this._needDepthPrePass = value;
  35399. if (this._needDepthPrePass) {
  35400. this.checkReadyOnEveryCall = true;
  35401. }
  35402. },
  35403. enumerable: true,
  35404. configurable: true
  35405. });
  35406. Object.defineProperty(Material.prototype, "fogEnabled", {
  35407. /**
  35408. * Gets the value of the fog enabled state
  35409. */
  35410. get: function () {
  35411. return this._fogEnabled;
  35412. },
  35413. /**
  35414. * Sets the state for enabling fog
  35415. */
  35416. set: function (value) {
  35417. if (this._fogEnabled === value) {
  35418. return;
  35419. }
  35420. this._fogEnabled = value;
  35421. this.markAsDirty(Material.MiscDirtyFlag);
  35422. },
  35423. enumerable: true,
  35424. configurable: true
  35425. });
  35426. Object.defineProperty(Material.prototype, "wireframe", {
  35427. /**
  35428. * Gets a value specifying if wireframe mode is enabled
  35429. */
  35430. get: function () {
  35431. switch (this._fillMode) {
  35432. case Material.WireFrameFillMode:
  35433. case Material.LineListDrawMode:
  35434. case Material.LineLoopDrawMode:
  35435. case Material.LineStripDrawMode:
  35436. return true;
  35437. }
  35438. return this._scene.forceWireframe;
  35439. },
  35440. /**
  35441. * Sets the state of wireframe mode
  35442. */
  35443. set: function (value) {
  35444. this.fillMode = (value ? Material.WireFrameFillMode : Material.TriangleFillMode);
  35445. },
  35446. enumerable: true,
  35447. configurable: true
  35448. });
  35449. Object.defineProperty(Material.prototype, "pointsCloud", {
  35450. /**
  35451. * Gets the value specifying if point clouds are enabled
  35452. */
  35453. get: function () {
  35454. switch (this._fillMode) {
  35455. case Material.PointFillMode:
  35456. case Material.PointListDrawMode:
  35457. return true;
  35458. }
  35459. return this._scene.forcePointsCloud;
  35460. },
  35461. /**
  35462. * Sets the state of point cloud mode
  35463. */
  35464. set: function (value) {
  35465. this.fillMode = (value ? Material.PointFillMode : Material.TriangleFillMode);
  35466. },
  35467. enumerable: true,
  35468. configurable: true
  35469. });
  35470. Object.defineProperty(Material.prototype, "fillMode", {
  35471. /**
  35472. * Gets the material fill mode
  35473. */
  35474. get: function () {
  35475. return this._fillMode;
  35476. },
  35477. /**
  35478. * Sets the material fill mode
  35479. */
  35480. set: function (value) {
  35481. if (this._fillMode === value) {
  35482. return;
  35483. }
  35484. this._fillMode = value;
  35485. this.markAsDirty(Material.MiscDirtyFlag);
  35486. },
  35487. enumerable: true,
  35488. configurable: true
  35489. });
  35490. /**
  35491. * Returns a string representation of the current material
  35492. * @param fullDetails defines a boolean indicating which levels of logging is desired
  35493. * @returns a string with material information
  35494. */
  35495. Material.prototype.toString = function (fullDetails) {
  35496. var ret = "Name: " + this.name;
  35497. if (fullDetails) {
  35498. }
  35499. return ret;
  35500. };
  35501. /**
  35502. * Gets the class name of the material
  35503. * @returns a string with the class name of the material
  35504. */
  35505. Material.prototype.getClassName = function () {
  35506. return "Material";
  35507. };
  35508. Object.defineProperty(Material.prototype, "isFrozen", {
  35509. /**
  35510. * Specifies if updates for the material been locked
  35511. */
  35512. get: function () {
  35513. return this.checkReadyOnlyOnce;
  35514. },
  35515. enumerable: true,
  35516. configurable: true
  35517. });
  35518. /**
  35519. * Locks updates for the material
  35520. */
  35521. Material.prototype.freeze = function () {
  35522. this.checkReadyOnlyOnce = true;
  35523. };
  35524. /**
  35525. * Unlocks updates for the material
  35526. */
  35527. Material.prototype.unfreeze = function () {
  35528. this.checkReadyOnlyOnce = false;
  35529. };
  35530. /**
  35531. * Specifies if the material is ready to be used
  35532. * @param mesh defines the mesh to check
  35533. * @param useInstances specifies if instances should be used
  35534. * @returns a boolean indicating if the material is ready to be used
  35535. */
  35536. Material.prototype.isReady = function (mesh, useInstances) {
  35537. return true;
  35538. };
  35539. /**
  35540. * Specifies that the submesh is ready to be used
  35541. * @param mesh defines the mesh to check
  35542. * @param subMesh defines which submesh to check
  35543. * @param useInstances specifies that instances should be used
  35544. * @returns a boolean indicating that the submesh is ready or not
  35545. */
  35546. Material.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  35547. return false;
  35548. };
  35549. /**
  35550. * Returns the material effect
  35551. * @returns the effect associated with the material
  35552. */
  35553. Material.prototype.getEffect = function () {
  35554. return this._effect;
  35555. };
  35556. /**
  35557. * Returns the current scene
  35558. * @returns a Scene
  35559. */
  35560. Material.prototype.getScene = function () {
  35561. return this._scene;
  35562. };
  35563. /**
  35564. * Specifies if the material will require alpha blending
  35565. * @returns a boolean specifying if alpha blending is needed
  35566. */
  35567. Material.prototype.needAlphaBlending = function () {
  35568. return (this.alpha < 1.0);
  35569. };
  35570. /**
  35571. * Specifies if the mesh will require alpha blending
  35572. * @param mesh defines the mesh to check
  35573. * @returns a boolean specifying if alpha blending is needed for the mesh
  35574. */
  35575. Material.prototype.needAlphaBlendingForMesh = function (mesh) {
  35576. return this.needAlphaBlending() || (mesh.visibility < 1.0) || mesh.hasVertexAlpha;
  35577. };
  35578. /**
  35579. * Specifies if this material should be rendered in alpha test mode
  35580. * @returns a boolean specifying if an alpha test is needed.
  35581. */
  35582. Material.prototype.needAlphaTesting = function () {
  35583. return false;
  35584. };
  35585. /**
  35586. * Gets the texture used for the alpha test
  35587. * @returns the texture to use for alpha testing
  35588. */
  35589. Material.prototype.getAlphaTestTexture = function () {
  35590. return null;
  35591. };
  35592. /**
  35593. * Marks the material to indicate that it needs to be re-calculated
  35594. */
  35595. Material.prototype.markDirty = function () {
  35596. this._wasPreviouslyReady = false;
  35597. };
  35598. /** @hidden */
  35599. Material.prototype._preBind = function (effect, overrideOrientation) {
  35600. if (overrideOrientation === void 0) { overrideOrientation = null; }
  35601. var engine = this._scene.getEngine();
  35602. var orientation = (overrideOrientation == null) ? this.sideOrientation : overrideOrientation;
  35603. var reverse = orientation === Material.ClockWiseSideOrientation;
  35604. engine.enableEffect(effect ? effect : this._effect);
  35605. engine.setState(this.backFaceCulling, this.zOffset, false, reverse);
  35606. return reverse;
  35607. };
  35608. /**
  35609. * Binds the material to the mesh
  35610. * @param world defines the world transformation matrix
  35611. * @param mesh defines the mesh to bind the material to
  35612. */
  35613. Material.prototype.bind = function (world, mesh) {
  35614. };
  35615. /**
  35616. * Binds the submesh to the material
  35617. * @param world defines the world transformation matrix
  35618. * @param mesh defines the mesh containing the submesh
  35619. * @param subMesh defines the submesh to bind the material to
  35620. */
  35621. Material.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  35622. };
  35623. /**
  35624. * Binds the world matrix to the material
  35625. * @param world defines the world transformation matrix
  35626. */
  35627. Material.prototype.bindOnlyWorldMatrix = function (world) {
  35628. };
  35629. /**
  35630. * Binds the scene's uniform buffer to the effect.
  35631. * @param effect defines the effect to bind to the scene uniform buffer
  35632. * @param sceneUbo defines the uniform buffer storing scene data
  35633. */
  35634. Material.prototype.bindSceneUniformBuffer = function (effect, sceneUbo) {
  35635. sceneUbo.bindToEffect(effect, "Scene");
  35636. };
  35637. /**
  35638. * Binds the view matrix to the effect
  35639. * @param effect defines the effect to bind the view matrix to
  35640. */
  35641. Material.prototype.bindView = function (effect) {
  35642. if (!this._useUBO) {
  35643. effect.setMatrix("view", this.getScene().getViewMatrix());
  35644. }
  35645. else {
  35646. this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
  35647. }
  35648. };
  35649. /**
  35650. * Binds the view projection matrix to the effect
  35651. * @param effect defines the effect to bind the view projection matrix to
  35652. */
  35653. Material.prototype.bindViewProjection = function (effect) {
  35654. if (!this._useUBO) {
  35655. effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
  35656. }
  35657. else {
  35658. this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
  35659. }
  35660. };
  35661. /**
  35662. * Specifies if material alpha testing should be turned on for the mesh
  35663. * @param mesh defines the mesh to check
  35664. */
  35665. Material.prototype._shouldTurnAlphaTestOn = function (mesh) {
  35666. return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
  35667. };
  35668. /**
  35669. * Processes to execute after binding the material to a mesh
  35670. * @param mesh defines the rendered mesh
  35671. */
  35672. Material.prototype._afterBind = function (mesh) {
  35673. this._scene._cachedMaterial = this;
  35674. if (mesh) {
  35675. this._scene._cachedVisibility = mesh.visibility;
  35676. }
  35677. else {
  35678. this._scene._cachedVisibility = 1;
  35679. }
  35680. if (mesh) {
  35681. this.onBindObservable.notifyObservers(mesh);
  35682. }
  35683. if (this.disableDepthWrite) {
  35684. var engine = this._scene.getEngine();
  35685. this._cachedDepthWriteState = engine.getDepthWrite();
  35686. engine.setDepthWrite(false);
  35687. }
  35688. };
  35689. /**
  35690. * Unbinds the material from the mesh
  35691. */
  35692. Material.prototype.unbind = function () {
  35693. this.onUnBindObservable.notifyObservers(this);
  35694. if (this.disableDepthWrite) {
  35695. var engine = this._scene.getEngine();
  35696. engine.setDepthWrite(this._cachedDepthWriteState);
  35697. }
  35698. };
  35699. /**
  35700. * Gets the active textures from the material
  35701. * @returns an array of textures
  35702. */
  35703. Material.prototype.getActiveTextures = function () {
  35704. return [];
  35705. };
  35706. /**
  35707. * Specifies if the material uses a texture
  35708. * @param texture defines the texture to check against the material
  35709. * @returns a boolean specifying if the material uses the texture
  35710. */
  35711. Material.prototype.hasTexture = function (texture) {
  35712. return false;
  35713. };
  35714. /**
  35715. * Makes a duplicate of the material, and gives it a new name
  35716. * @param name defines the new name for the duplicated material
  35717. * @returns the cloned material
  35718. */
  35719. Material.prototype.clone = function (name) {
  35720. return null;
  35721. };
  35722. /**
  35723. * Gets the meshes bound to the material
  35724. * @returns an array of meshes bound to the material
  35725. */
  35726. Material.prototype.getBindedMeshes = function () {
  35727. var result = new Array();
  35728. for (var index = 0; index < this._scene.meshes.length; index++) {
  35729. var mesh = this._scene.meshes[index];
  35730. if (mesh.material === this) {
  35731. result.push(mesh);
  35732. }
  35733. }
  35734. return result;
  35735. };
  35736. /**
  35737. * Force shader compilation
  35738. * @param mesh defines the mesh associated with this material
  35739. * @param onCompiled defines a function to execute once the material is compiled
  35740. * @param options defines the options to configure the compilation
  35741. */
  35742. Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
  35743. var _this = this;
  35744. var localOptions = __assign({ clipPlane: false }, options);
  35745. var subMesh = new BABYLON.BaseSubMesh();
  35746. var scene = this.getScene();
  35747. var checkReady = function () {
  35748. if (!_this._scene || !_this._scene.getEngine()) {
  35749. return;
  35750. }
  35751. if (subMesh._materialDefines) {
  35752. subMesh._materialDefines._renderId = -1;
  35753. }
  35754. var clipPlaneState = scene.clipPlane;
  35755. if (localOptions.clipPlane) {
  35756. scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
  35757. }
  35758. if (_this.storeEffectOnSubMeshes) {
  35759. if (_this.isReadyForSubMesh(mesh, subMesh)) {
  35760. if (onCompiled) {
  35761. onCompiled(_this);
  35762. }
  35763. }
  35764. else {
  35765. setTimeout(checkReady, 16);
  35766. }
  35767. }
  35768. else {
  35769. if (_this.isReady(mesh)) {
  35770. if (onCompiled) {
  35771. onCompiled(_this);
  35772. }
  35773. }
  35774. else {
  35775. setTimeout(checkReady, 16);
  35776. }
  35777. }
  35778. if (localOptions.clipPlane) {
  35779. scene.clipPlane = clipPlaneState;
  35780. }
  35781. };
  35782. checkReady();
  35783. };
  35784. /**
  35785. * Force shader compilation
  35786. * @param mesh defines the mesh that will use this material
  35787. * @param options defines additional options for compiling the shaders
  35788. * @returns a promise that resolves when the compilation completes
  35789. */
  35790. Material.prototype.forceCompilationAsync = function (mesh, options) {
  35791. var _this = this;
  35792. return new Promise(function (resolve) {
  35793. _this.forceCompilation(mesh, function () {
  35794. resolve();
  35795. }, options);
  35796. });
  35797. };
  35798. /**
  35799. * Marks a define in the material to indicate that it needs to be re-computed
  35800. * @param flag defines a flag used to determine which parts of the material have to be marked as dirty
  35801. */
  35802. Material.prototype.markAsDirty = function (flag) {
  35803. if (flag & Material.TextureDirtyFlag) {
  35804. this._markAllSubMeshesAsTexturesDirty();
  35805. }
  35806. if (flag & Material.LightDirtyFlag) {
  35807. this._markAllSubMeshesAsLightsDirty();
  35808. }
  35809. if (flag & Material.FresnelDirtyFlag) {
  35810. this._markAllSubMeshesAsFresnelDirty();
  35811. }
  35812. if (flag & Material.AttributesDirtyFlag) {
  35813. this._markAllSubMeshesAsAttributesDirty();
  35814. }
  35815. if (flag & Material.MiscDirtyFlag) {
  35816. this._markAllSubMeshesAsMiscDirty();
  35817. }
  35818. this.getScene().resetCachedMaterial();
  35819. };
  35820. /**
  35821. * Marks all submeshes of a material to indicate that their material defines need to be re-calculated
  35822. * @param func defines a function which checks material defines against the submeshes
  35823. */
  35824. Material.prototype._markAllSubMeshesAsDirty = function (func) {
  35825. for (var _i = 0, _a = this.getScene().meshes; _i < _a.length; _i++) {
  35826. var mesh = _a[_i];
  35827. if (!mesh.subMeshes) {
  35828. continue;
  35829. }
  35830. for (var _b = 0, _c = mesh.subMeshes; _b < _c.length; _b++) {
  35831. var subMesh = _c[_b];
  35832. if (subMesh.getMaterial() !== this) {
  35833. continue;
  35834. }
  35835. if (!subMesh._materialDefines) {
  35836. continue;
  35837. }
  35838. func(subMesh._materialDefines);
  35839. }
  35840. }
  35841. };
  35842. /**
  35843. * Indicates that image processing needs to be re-calculated for all submeshes
  35844. */
  35845. Material.prototype._markAllSubMeshesAsImageProcessingDirty = function () {
  35846. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsImageProcessingDirty(); });
  35847. };
  35848. /**
  35849. * Indicates that textures need to be re-calculated for all submeshes
  35850. */
  35851. Material.prototype._markAllSubMeshesAsTexturesDirty = function () {
  35852. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsTexturesDirty(); });
  35853. };
  35854. /**
  35855. * Indicates that fresnel needs to be re-calculated for all submeshes
  35856. */
  35857. Material.prototype._markAllSubMeshesAsFresnelDirty = function () {
  35858. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsFresnelDirty(); });
  35859. };
  35860. /**
  35861. * Indicates that fresnel and misc need to be re-calculated for all submeshes
  35862. */
  35863. Material.prototype._markAllSubMeshesAsFresnelAndMiscDirty = function () {
  35864. this._markAllSubMeshesAsDirty(function (defines) {
  35865. defines.markAsFresnelDirty();
  35866. defines.markAsMiscDirty();
  35867. });
  35868. };
  35869. /**
  35870. * Indicates that lights need to be re-calculated for all submeshes
  35871. */
  35872. Material.prototype._markAllSubMeshesAsLightsDirty = function () {
  35873. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsLightDirty(); });
  35874. };
  35875. /**
  35876. * Indicates that attributes need to be re-calculated for all submeshes
  35877. */
  35878. Material.prototype._markAllSubMeshesAsAttributesDirty = function () {
  35879. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsAttributesDirty(); });
  35880. };
  35881. /**
  35882. * Indicates that misc needs to be re-calculated for all submeshes
  35883. */
  35884. Material.prototype._markAllSubMeshesAsMiscDirty = function () {
  35885. this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsMiscDirty(); });
  35886. };
  35887. /**
  35888. * Indicates that textures and misc need to be re-calculated for all submeshes
  35889. */
  35890. Material.prototype._markAllSubMeshesAsTexturesAndMiscDirty = function () {
  35891. this._markAllSubMeshesAsDirty(function (defines) {
  35892. defines.markAsTexturesDirty();
  35893. defines.markAsMiscDirty();
  35894. });
  35895. };
  35896. /**
  35897. * Disposes the material
  35898. * @param forceDisposeEffect specifies if effects should be forcefully disposed
  35899. * @param forceDisposeTextures specifies if textures should be forcefully disposed
  35900. */
  35901. Material.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  35902. // Animations
  35903. this.getScene().stopAnimation(this);
  35904. this.getScene().freeProcessedMaterials();
  35905. // Remove from scene
  35906. var index = this._scene.materials.indexOf(this);
  35907. if (index >= 0) {
  35908. this._scene.materials.splice(index, 1);
  35909. }
  35910. // Remove from meshes
  35911. for (index = 0; index < this._scene.meshes.length; index++) {
  35912. var mesh = this._scene.meshes[index];
  35913. if (mesh.material === this) {
  35914. mesh.material = null;
  35915. if (mesh.geometry) {
  35916. var geometry = (mesh.geometry);
  35917. if (this.storeEffectOnSubMeshes) {
  35918. for (var _i = 0, _a = mesh.subMeshes; _i < _a.length; _i++) {
  35919. var subMesh = _a[_i];
  35920. geometry._releaseVertexArrayObject(subMesh._materialEffect);
  35921. if (forceDisposeEffect && subMesh._materialEffect) {
  35922. this._scene.getEngine()._releaseEffect(subMesh._materialEffect);
  35923. }
  35924. }
  35925. }
  35926. else {
  35927. geometry._releaseVertexArrayObject(this._effect);
  35928. }
  35929. }
  35930. }
  35931. }
  35932. this._uniformBuffer.dispose();
  35933. // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
  35934. if (forceDisposeEffect && this._effect) {
  35935. if (!this.storeEffectOnSubMeshes) {
  35936. this._scene.getEngine()._releaseEffect(this._effect);
  35937. }
  35938. this._effect = null;
  35939. }
  35940. // Callback
  35941. this.onDisposeObservable.notifyObservers(this);
  35942. this.onDisposeObservable.clear();
  35943. this.onBindObservable.clear();
  35944. this.onUnBindObservable.clear();
  35945. };
  35946. /**
  35947. * Serializes this material
  35948. * @returns the serialized material object
  35949. */
  35950. Material.prototype.serialize = function () {
  35951. return BABYLON.SerializationHelper.Serialize(this);
  35952. };
  35953. /**
  35954. * Creates a MultiMaterial from parsed MultiMaterial data.
  35955. * @param parsedMultiMaterial defines parsed MultiMaterial data.
  35956. * @param scene defines the hosting scene
  35957. * @returns a new MultiMaterial
  35958. */
  35959. Material.ParseMultiMaterial = function (parsedMultiMaterial, scene) {
  35960. var multiMaterial = new BABYLON.MultiMaterial(parsedMultiMaterial.name, scene);
  35961. multiMaterial.id = parsedMultiMaterial.id;
  35962. if (BABYLON.Tags) {
  35963. BABYLON.Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);
  35964. }
  35965. for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
  35966. var subMatId = parsedMultiMaterial.materials[matIndex];
  35967. if (subMatId) {
  35968. multiMaterial.subMaterials.push(scene.getMaterialByID(subMatId));
  35969. }
  35970. else {
  35971. multiMaterial.subMaterials.push(null);
  35972. }
  35973. }
  35974. return multiMaterial;
  35975. };
  35976. /**
  35977. * Creates a material from parsed material data
  35978. * @param parsedMaterial defines parsed material data
  35979. * @param scene defines the hosting scene
  35980. * @param rootUrl defines the root URL to use to load textures
  35981. * @returns a new material
  35982. */
  35983. Material.Parse = function (parsedMaterial, scene, rootUrl) {
  35984. if (!parsedMaterial.customType || parsedMaterial.customType === "BABYLON.StandardMaterial") {
  35985. return BABYLON.StandardMaterial.Parse(parsedMaterial, scene, rootUrl);
  35986. }
  35987. if (parsedMaterial.customType === "BABYLON.PBRMaterial" && parsedMaterial.overloadedAlbedo) {
  35988. parsedMaterial.customType = "BABYLON.LegacyPBRMaterial";
  35989. if (!BABYLON.LegacyPBRMaterial) {
  35990. BABYLON.Tools.Error("Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.");
  35991. return;
  35992. }
  35993. }
  35994. var materialType = BABYLON.Tools.Instantiate(parsedMaterial.customType);
  35995. return materialType.Parse(parsedMaterial, scene, rootUrl);
  35996. };
  35997. // Triangle views
  35998. Material._TriangleFillMode = 0;
  35999. Material._WireFrameFillMode = 1;
  36000. Material._PointFillMode = 2;
  36001. // Draw modes
  36002. Material._PointListDrawMode = 3;
  36003. Material._LineListDrawMode = 4;
  36004. Material._LineLoopDrawMode = 5;
  36005. Material._LineStripDrawMode = 6;
  36006. Material._TriangleStripDrawMode = 7;
  36007. Material._TriangleFanDrawMode = 8;
  36008. /**
  36009. * Stores the clock-wise side orientation
  36010. */
  36011. Material._ClockWiseSideOrientation = 0;
  36012. /**
  36013. * Stores the counter clock-wise side orientation
  36014. */
  36015. Material._CounterClockWiseSideOrientation = 1;
  36016. /**
  36017. * The dirty texture flag value
  36018. */
  36019. Material._TextureDirtyFlag = 1;
  36020. /**
  36021. * The dirty light flag value
  36022. */
  36023. Material._LightDirtyFlag = 2;
  36024. /**
  36025. * The dirty fresnel flag value
  36026. */
  36027. Material._FresnelDirtyFlag = 4;
  36028. /**
  36029. * The dirty attribute flag value
  36030. */
  36031. Material._AttributesDirtyFlag = 8;
  36032. /**
  36033. * The dirty misc flag value
  36034. */
  36035. Material._MiscDirtyFlag = 16;
  36036. __decorate([
  36037. BABYLON.serialize()
  36038. ], Material.prototype, "id", void 0);
  36039. __decorate([
  36040. BABYLON.serialize()
  36041. ], Material.prototype, "uniqueId", void 0);
  36042. __decorate([
  36043. BABYLON.serialize()
  36044. ], Material.prototype, "name", void 0);
  36045. __decorate([
  36046. BABYLON.serialize()
  36047. ], Material.prototype, "checkReadyOnEveryCall", void 0);
  36048. __decorate([
  36049. BABYLON.serialize()
  36050. ], Material.prototype, "checkReadyOnlyOnce", void 0);
  36051. __decorate([
  36052. BABYLON.serialize()
  36053. ], Material.prototype, "state", void 0);
  36054. __decorate([
  36055. BABYLON.serialize("alpha")
  36056. ], Material.prototype, "_alpha", void 0);
  36057. __decorate([
  36058. BABYLON.serialize("backFaceCulling")
  36059. ], Material.prototype, "_backFaceCulling", void 0);
  36060. __decorate([
  36061. BABYLON.serialize()
  36062. ], Material.prototype, "sideOrientation", void 0);
  36063. __decorate([
  36064. BABYLON.serialize("alphaMode")
  36065. ], Material.prototype, "_alphaMode", void 0);
  36066. __decorate([
  36067. BABYLON.serialize()
  36068. ], Material.prototype, "_needDepthPrePass", void 0);
  36069. __decorate([
  36070. BABYLON.serialize()
  36071. ], Material.prototype, "disableDepthWrite", void 0);
  36072. __decorate([
  36073. BABYLON.serialize()
  36074. ], Material.prototype, "forceDepthWrite", void 0);
  36075. __decorate([
  36076. BABYLON.serialize()
  36077. ], Material.prototype, "separateCullingPass", void 0);
  36078. __decorate([
  36079. BABYLON.serialize("fogEnabled")
  36080. ], Material.prototype, "_fogEnabled", void 0);
  36081. __decorate([
  36082. BABYLON.serialize()
  36083. ], Material.prototype, "pointSize", void 0);
  36084. __decorate([
  36085. BABYLON.serialize()
  36086. ], Material.prototype, "zOffset", void 0);
  36087. __decorate([
  36088. BABYLON.serialize()
  36089. ], Material.prototype, "wireframe", null);
  36090. __decorate([
  36091. BABYLON.serialize()
  36092. ], Material.prototype, "pointsCloud", null);
  36093. __decorate([
  36094. BABYLON.serialize()
  36095. ], Material.prototype, "fillMode", null);
  36096. return Material;
  36097. }());
  36098. BABYLON.Material = Material;
  36099. })(BABYLON || (BABYLON = {}));
  36100. //# sourceMappingURL=babylon.material.js.map
  36101. var BABYLON;
  36102. (function (BABYLON) {
  36103. var UniformBuffer = /** @class */ (function () {
  36104. /**
  36105. * Uniform buffer objects.
  36106. *
  36107. * Handles blocks of uniform on the GPU.
  36108. *
  36109. * If WebGL 2 is not available, this class falls back on traditionnal setUniformXXX calls.
  36110. *
  36111. * For more information, please refer to :
  36112. * https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object
  36113. */
  36114. function UniformBuffer(engine, data, dynamic) {
  36115. this._engine = engine;
  36116. this._noUBO = !engine.supportsUniformBuffers;
  36117. this._dynamic = dynamic;
  36118. this._data = data || [];
  36119. this._uniformLocations = {};
  36120. this._uniformSizes = {};
  36121. this._uniformLocationPointer = 0;
  36122. this._needSync = false;
  36123. if (this._noUBO) {
  36124. this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;
  36125. this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;
  36126. this.updateFloat = this._updateFloatForEffect;
  36127. this.updateFloat2 = this._updateFloat2ForEffect;
  36128. this.updateFloat3 = this._updateFloat3ForEffect;
  36129. this.updateFloat4 = this._updateFloat4ForEffect;
  36130. this.updateMatrix = this._updateMatrixForEffect;
  36131. this.updateVector3 = this._updateVector3ForEffect;
  36132. this.updateVector4 = this._updateVector4ForEffect;
  36133. this.updateColor3 = this._updateColor3ForEffect;
  36134. this.updateColor4 = this._updateColor4ForEffect;
  36135. }
  36136. else {
  36137. this._engine._uniformBuffers.push(this);
  36138. this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;
  36139. this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;
  36140. this.updateFloat = this._updateFloatForUniform;
  36141. this.updateFloat2 = this._updateFloat2ForUniform;
  36142. this.updateFloat3 = this._updateFloat3ForUniform;
  36143. this.updateFloat4 = this._updateFloat4ForUniform;
  36144. this.updateMatrix = this._updateMatrixForUniform;
  36145. this.updateVector3 = this._updateVector3ForUniform;
  36146. this.updateVector4 = this._updateVector4ForUniform;
  36147. this.updateColor3 = this._updateColor3ForUniform;
  36148. this.updateColor4 = this._updateColor4ForUniform;
  36149. }
  36150. }
  36151. Object.defineProperty(UniformBuffer.prototype, "useUbo", {
  36152. // Properties
  36153. /**
  36154. * Indicates if the buffer is using the WebGL2 UBO implementation,
  36155. * or just falling back on setUniformXXX calls.
  36156. */
  36157. get: function () {
  36158. return !this._noUBO;
  36159. },
  36160. enumerable: true,
  36161. configurable: true
  36162. });
  36163. Object.defineProperty(UniformBuffer.prototype, "isSync", {
  36164. /**
  36165. * Indicates if the WebGL underlying uniform buffer is in sync
  36166. * with the javascript cache data.
  36167. */
  36168. get: function () {
  36169. return !this._needSync;
  36170. },
  36171. enumerable: true,
  36172. configurable: true
  36173. });
  36174. /**
  36175. * Indicates if the WebGL underlying uniform buffer is dynamic.
  36176. * Also, a dynamic UniformBuffer will disable cache verification and always
  36177. * update the underlying WebGL uniform buffer to the GPU.
  36178. */
  36179. UniformBuffer.prototype.isDynamic = function () {
  36180. return this._dynamic !== undefined;
  36181. };
  36182. /**
  36183. * The data cache on JS side.
  36184. */
  36185. UniformBuffer.prototype.getData = function () {
  36186. return this._bufferData;
  36187. };
  36188. /**
  36189. * The underlying WebGL Uniform buffer.
  36190. */
  36191. UniformBuffer.prototype.getBuffer = function () {
  36192. return this._buffer;
  36193. };
  36194. /**
  36195. * std140 layout specifies how to align data within an UBO structure.
  36196. * See https://khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf#page=159
  36197. * for specs.
  36198. */
  36199. UniformBuffer.prototype._fillAlignment = function (size) {
  36200. // This code has been simplified because we only use floats, vectors of 1, 2, 3, 4 components
  36201. // and 4x4 matrices
  36202. // TODO : change if other types are used
  36203. var alignment;
  36204. if (size <= 2) {
  36205. alignment = size;
  36206. }
  36207. else {
  36208. alignment = 4;
  36209. }
  36210. if ((this._uniformLocationPointer % alignment) !== 0) {
  36211. var oldPointer = this._uniformLocationPointer;
  36212. this._uniformLocationPointer += alignment - (this._uniformLocationPointer % alignment);
  36213. var diff = this._uniformLocationPointer - oldPointer;
  36214. for (var i = 0; i < diff; i++) {
  36215. this._data.push(0);
  36216. }
  36217. }
  36218. };
  36219. /**
  36220. * Adds an uniform in the buffer.
  36221. * Warning : the subsequents calls of this function must be in the same order as declared in the shader
  36222. * for the layout to be correct !
  36223. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36224. * @param {number|number[]} size Data size, or data directly.
  36225. */
  36226. UniformBuffer.prototype.addUniform = function (name, size) {
  36227. if (this._noUBO) {
  36228. return;
  36229. }
  36230. if (this._uniformLocations[name] !== undefined) {
  36231. // Already existing uniform
  36232. return;
  36233. }
  36234. // This function must be called in the order of the shader layout !
  36235. // size can be the size of the uniform, or data directly
  36236. var data;
  36237. if (size instanceof Array) {
  36238. data = size;
  36239. size = data.length;
  36240. }
  36241. else {
  36242. size = size;
  36243. data = [];
  36244. // Fill with zeros
  36245. for (var i = 0; i < size; i++) {
  36246. data.push(0);
  36247. }
  36248. }
  36249. this._fillAlignment(size);
  36250. this._uniformSizes[name] = size;
  36251. this._uniformLocations[name] = this._uniformLocationPointer;
  36252. this._uniformLocationPointer += size;
  36253. for (var i = 0; i < size; i++) {
  36254. this._data.push(data[i]);
  36255. }
  36256. this._needSync = true;
  36257. };
  36258. /**
  36259. * Wrapper for addUniform.
  36260. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36261. * @param {Matrix} mat A 4x4 matrix.
  36262. */
  36263. UniformBuffer.prototype.addMatrix = function (name, mat) {
  36264. this.addUniform(name, Array.prototype.slice.call(mat.toArray()));
  36265. };
  36266. /**
  36267. * Wrapper for addUniform.
  36268. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36269. * @param {number} x
  36270. * @param {number} y
  36271. */
  36272. UniformBuffer.prototype.addFloat2 = function (name, x, y) {
  36273. var temp = [x, y];
  36274. this.addUniform(name, temp);
  36275. };
  36276. /**
  36277. * Wrapper for addUniform.
  36278. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36279. * @param {number} x
  36280. * @param {number} y
  36281. * @param {number} z
  36282. */
  36283. UniformBuffer.prototype.addFloat3 = function (name, x, y, z) {
  36284. var temp = [x, y, z];
  36285. this.addUniform(name, temp);
  36286. };
  36287. /**
  36288. * Wrapper for addUniform.
  36289. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36290. * @param {Color3} color
  36291. */
  36292. UniformBuffer.prototype.addColor3 = function (name, color) {
  36293. var temp = new Array();
  36294. color.toArray(temp);
  36295. this.addUniform(name, temp);
  36296. };
  36297. /**
  36298. * Wrapper for addUniform.
  36299. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36300. * @param {Color3} color
  36301. * @param {number} alpha
  36302. */
  36303. UniformBuffer.prototype.addColor4 = function (name, color, alpha) {
  36304. var temp = new Array();
  36305. color.toArray(temp);
  36306. temp.push(alpha);
  36307. this.addUniform(name, temp);
  36308. };
  36309. /**
  36310. * Wrapper for addUniform.
  36311. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36312. * @param {Vector3} vector
  36313. */
  36314. UniformBuffer.prototype.addVector3 = function (name, vector) {
  36315. var temp = new Array();
  36316. vector.toArray(temp);
  36317. this.addUniform(name, temp);
  36318. };
  36319. /**
  36320. * Wrapper for addUniform.
  36321. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36322. */
  36323. UniformBuffer.prototype.addMatrix3x3 = function (name) {
  36324. this.addUniform(name, 12);
  36325. };
  36326. /**
  36327. * Wrapper for addUniform.
  36328. * @param {string} name Name of the uniform, as used in the uniform block in the shader.
  36329. */
  36330. UniformBuffer.prototype.addMatrix2x2 = function (name) {
  36331. this.addUniform(name, 8);
  36332. };
  36333. /**
  36334. * Effectively creates the WebGL Uniform Buffer, once layout is completed with `addUniform`.
  36335. */
  36336. UniformBuffer.prototype.create = function () {
  36337. if (this._noUBO) {
  36338. return;
  36339. }
  36340. if (this._buffer) {
  36341. return; // nothing to do
  36342. }
  36343. // See spec, alignment must be filled as a vec4
  36344. this._fillAlignment(4);
  36345. this._bufferData = new Float32Array(this._data);
  36346. this._rebuild();
  36347. this._needSync = true;
  36348. };
  36349. UniformBuffer.prototype._rebuild = function () {
  36350. if (this._noUBO) {
  36351. return;
  36352. }
  36353. if (this._dynamic) {
  36354. this._buffer = this._engine.createDynamicUniformBuffer(this._bufferData);
  36355. }
  36356. else {
  36357. this._buffer = this._engine.createUniformBuffer(this._bufferData);
  36358. }
  36359. };
  36360. /**
  36361. * Updates the WebGL Uniform Buffer on the GPU.
  36362. * If the `dynamic` flag is set to true, no cache comparison is done.
  36363. * Otherwise, the buffer will be updated only if the cache differs.
  36364. */
  36365. UniformBuffer.prototype.update = function () {
  36366. if (!this._buffer) {
  36367. this.create();
  36368. return;
  36369. }
  36370. if (!this._dynamic && !this._needSync) {
  36371. return;
  36372. }
  36373. this._engine.updateUniformBuffer(this._buffer, this._bufferData);
  36374. this._needSync = false;
  36375. };
  36376. /**
  36377. * Updates the value of an uniform. The `update` method must be called afterwards to make it effective in the GPU.
  36378. * @param {string} uniformName Name of the uniform, as used in the uniform block in the shader.
  36379. * @param {number[]|Float32Array} data Flattened data
  36380. * @param {number} size Size of the data.
  36381. */
  36382. UniformBuffer.prototype.updateUniform = function (uniformName, data, size) {
  36383. var location = this._uniformLocations[uniformName];
  36384. if (location === undefined) {
  36385. if (this._buffer) {
  36386. // Cannot add an uniform if the buffer is already created
  36387. BABYLON.Tools.Error("Cannot add an uniform after UBO has been created.");
  36388. return;
  36389. }
  36390. this.addUniform(uniformName, size);
  36391. location = this._uniformLocations[uniformName];
  36392. }
  36393. if (!this._buffer) {
  36394. this.create();
  36395. }
  36396. if (!this._dynamic) {
  36397. // Cache for static uniform buffers
  36398. var changed = false;
  36399. for (var i = 0; i < size; i++) {
  36400. if (this._bufferData[location + i] !== data[i]) {
  36401. changed = true;
  36402. this._bufferData[location + i] = data[i];
  36403. }
  36404. }
  36405. this._needSync = this._needSync || changed;
  36406. }
  36407. else {
  36408. // No cache for dynamic
  36409. for (var i = 0; i < size; i++) {
  36410. this._bufferData[location + i] = data[i];
  36411. }
  36412. }
  36413. };
  36414. // Update methods
  36415. UniformBuffer.prototype._updateMatrix3x3ForUniform = function (name, matrix) {
  36416. // To match std140, matrix must be realigned
  36417. for (var i = 0; i < 3; i++) {
  36418. UniformBuffer._tempBuffer[i * 4] = matrix[i * 3];
  36419. UniformBuffer._tempBuffer[i * 4 + 1] = matrix[i * 3 + 1];
  36420. UniformBuffer._tempBuffer[i * 4 + 2] = matrix[i * 3 + 2];
  36421. UniformBuffer._tempBuffer[i * 4 + 3] = 0.0;
  36422. }
  36423. this.updateUniform(name, UniformBuffer._tempBuffer, 12);
  36424. };
  36425. UniformBuffer.prototype._updateMatrix3x3ForEffect = function (name, matrix) {
  36426. this._currentEffect.setMatrix3x3(name, matrix);
  36427. };
  36428. UniformBuffer.prototype._updateMatrix2x2ForEffect = function (name, matrix) {
  36429. this._currentEffect.setMatrix2x2(name, matrix);
  36430. };
  36431. UniformBuffer.prototype._updateMatrix2x2ForUniform = function (name, matrix) {
  36432. // To match std140, matrix must be realigned
  36433. for (var i = 0; i < 2; i++) {
  36434. UniformBuffer._tempBuffer[i * 4] = matrix[i * 2];
  36435. UniformBuffer._tempBuffer[i * 4 + 1] = matrix[i * 2 + 1];
  36436. UniformBuffer._tempBuffer[i * 4 + 2] = 0.0;
  36437. UniformBuffer._tempBuffer[i * 4 + 3] = 0.0;
  36438. }
  36439. this.updateUniform(name, UniformBuffer._tempBuffer, 8);
  36440. };
  36441. UniformBuffer.prototype._updateFloatForEffect = function (name, x) {
  36442. this._currentEffect.setFloat(name, x);
  36443. };
  36444. UniformBuffer.prototype._updateFloatForUniform = function (name, x) {
  36445. UniformBuffer._tempBuffer[0] = x;
  36446. this.updateUniform(name, UniformBuffer._tempBuffer, 1);
  36447. };
  36448. UniformBuffer.prototype._updateFloat2ForEffect = function (name, x, y, suffix) {
  36449. if (suffix === void 0) { suffix = ""; }
  36450. this._currentEffect.setFloat2(name + suffix, x, y);
  36451. };
  36452. UniformBuffer.prototype._updateFloat2ForUniform = function (name, x, y, suffix) {
  36453. if (suffix === void 0) { suffix = ""; }
  36454. UniformBuffer._tempBuffer[0] = x;
  36455. UniformBuffer._tempBuffer[1] = y;
  36456. this.updateUniform(name, UniformBuffer._tempBuffer, 2);
  36457. };
  36458. UniformBuffer.prototype._updateFloat3ForEffect = function (name, x, y, z, suffix) {
  36459. if (suffix === void 0) { suffix = ""; }
  36460. this._currentEffect.setFloat3(name + suffix, x, y, z);
  36461. };
  36462. UniformBuffer.prototype._updateFloat3ForUniform = function (name, x, y, z, suffix) {
  36463. if (suffix === void 0) { suffix = ""; }
  36464. UniformBuffer._tempBuffer[0] = x;
  36465. UniformBuffer._tempBuffer[1] = y;
  36466. UniformBuffer._tempBuffer[2] = z;
  36467. this.updateUniform(name, UniformBuffer._tempBuffer, 3);
  36468. };
  36469. UniformBuffer.prototype._updateFloat4ForEffect = function (name, x, y, z, w, suffix) {
  36470. if (suffix === void 0) { suffix = ""; }
  36471. this._currentEffect.setFloat4(name + suffix, x, y, z, w);
  36472. };
  36473. UniformBuffer.prototype._updateFloat4ForUniform = function (name, x, y, z, w, suffix) {
  36474. if (suffix === void 0) { suffix = ""; }
  36475. UniformBuffer._tempBuffer[0] = x;
  36476. UniformBuffer._tempBuffer[1] = y;
  36477. UniformBuffer._tempBuffer[2] = z;
  36478. UniformBuffer._tempBuffer[3] = w;
  36479. this.updateUniform(name, UniformBuffer._tempBuffer, 4);
  36480. };
  36481. UniformBuffer.prototype._updateMatrixForEffect = function (name, mat) {
  36482. this._currentEffect.setMatrix(name, mat);
  36483. };
  36484. UniformBuffer.prototype._updateMatrixForUniform = function (name, mat) {
  36485. this.updateUniform(name, mat.toArray(), 16);
  36486. };
  36487. UniformBuffer.prototype._updateVector3ForEffect = function (name, vector) {
  36488. this._currentEffect.setVector3(name, vector);
  36489. };
  36490. UniformBuffer.prototype._updateVector3ForUniform = function (name, vector) {
  36491. vector.toArray(UniformBuffer._tempBuffer);
  36492. this.updateUniform(name, UniformBuffer._tempBuffer, 3);
  36493. };
  36494. UniformBuffer.prototype._updateVector4ForEffect = function (name, vector) {
  36495. this._currentEffect.setVector4(name, vector);
  36496. };
  36497. UniformBuffer.prototype._updateVector4ForUniform = function (name, vector) {
  36498. vector.toArray(UniformBuffer._tempBuffer);
  36499. this.updateUniform(name, UniformBuffer._tempBuffer, 4);
  36500. };
  36501. UniformBuffer.prototype._updateColor3ForEffect = function (name, color, suffix) {
  36502. if (suffix === void 0) { suffix = ""; }
  36503. this._currentEffect.setColor3(name + suffix, color);
  36504. };
  36505. UniformBuffer.prototype._updateColor3ForUniform = function (name, color, suffix) {
  36506. if (suffix === void 0) { suffix = ""; }
  36507. color.toArray(UniformBuffer._tempBuffer);
  36508. this.updateUniform(name, UniformBuffer._tempBuffer, 3);
  36509. };
  36510. UniformBuffer.prototype._updateColor4ForEffect = function (name, color, alpha, suffix) {
  36511. if (suffix === void 0) { suffix = ""; }
  36512. this._currentEffect.setColor4(name + suffix, color, alpha);
  36513. };
  36514. UniformBuffer.prototype._updateColor4ForUniform = function (name, color, alpha, suffix) {
  36515. if (suffix === void 0) { suffix = ""; }
  36516. color.toArray(UniformBuffer._tempBuffer);
  36517. UniformBuffer._tempBuffer[3] = alpha;
  36518. this.updateUniform(name, UniformBuffer._tempBuffer, 4);
  36519. };
  36520. /**
  36521. * Sets a sampler uniform on the effect.
  36522. * @param {string} name Name of the sampler.
  36523. * @param {Texture} texture
  36524. */
  36525. UniformBuffer.prototype.setTexture = function (name, texture) {
  36526. this._currentEffect.setTexture(name, texture);
  36527. };
  36528. /**
  36529. * Directly updates the value of the uniform in the cache AND on the GPU.
  36530. * @param {string} uniformName Name of the uniform, as used in the uniform block in the shader.
  36531. * @param {number[]|Float32Array} data Flattened data
  36532. */
  36533. UniformBuffer.prototype.updateUniformDirectly = function (uniformName, data) {
  36534. this.updateUniform(uniformName, data, data.length);
  36535. this.update();
  36536. };
  36537. /**
  36538. * Binds this uniform buffer to an effect.
  36539. * @param {Effect} effect
  36540. * @param {string} name Name of the uniform block in the shader.
  36541. */
  36542. UniformBuffer.prototype.bindToEffect = function (effect, name) {
  36543. this._currentEffect = effect;
  36544. if (this._noUBO || !this._buffer) {
  36545. return;
  36546. }
  36547. effect.bindUniformBuffer(this._buffer, name);
  36548. };
  36549. /**
  36550. * Disposes the uniform buffer.
  36551. */
  36552. UniformBuffer.prototype.dispose = function () {
  36553. if (this._noUBO) {
  36554. return;
  36555. }
  36556. var index = this._engine._uniformBuffers.indexOf(this);
  36557. if (index !== -1) {
  36558. this._engine._uniformBuffers.splice(index, 1);
  36559. }
  36560. if (!this._buffer) {
  36561. return;
  36562. }
  36563. if (this._engine._releaseBuffer(this._buffer)) {
  36564. this._buffer = null;
  36565. }
  36566. };
  36567. // Pool for avoiding memory leaks
  36568. UniformBuffer._MAX_UNIFORM_SIZE = 256;
  36569. UniformBuffer._tempBuffer = new Float32Array(UniformBuffer._MAX_UNIFORM_SIZE);
  36570. return UniformBuffer;
  36571. }());
  36572. BABYLON.UniformBuffer = UniformBuffer;
  36573. })(BABYLON || (BABYLON = {}));
  36574. //# sourceMappingURL=babylon.uniformBuffer.js.map
  36575. var BABYLON;
  36576. (function (BABYLON) {
  36577. /**
  36578. * This class contains the various kinds of data on every vertex of a mesh used in determining its shape and appearance
  36579. */
  36580. var VertexData = /** @class */ (function () {
  36581. function VertexData() {
  36582. }
  36583. /**
  36584. * Uses the passed data array to set the set the values for the specified kind of data
  36585. * @param data a linear array of floating numbers
  36586. * @param kind the type of data that is being set, eg positions, colors etc
  36587. */
  36588. VertexData.prototype.set = function (data, kind) {
  36589. switch (kind) {
  36590. case BABYLON.VertexBuffer.PositionKind:
  36591. this.positions = data;
  36592. break;
  36593. case BABYLON.VertexBuffer.NormalKind:
  36594. this.normals = data;
  36595. break;
  36596. case BABYLON.VertexBuffer.TangentKind:
  36597. this.tangents = data;
  36598. break;
  36599. case BABYLON.VertexBuffer.UVKind:
  36600. this.uvs = data;
  36601. break;
  36602. case BABYLON.VertexBuffer.UV2Kind:
  36603. this.uvs2 = data;
  36604. break;
  36605. case BABYLON.VertexBuffer.UV3Kind:
  36606. this.uvs3 = data;
  36607. break;
  36608. case BABYLON.VertexBuffer.UV4Kind:
  36609. this.uvs4 = data;
  36610. break;
  36611. case BABYLON.VertexBuffer.UV5Kind:
  36612. this.uvs5 = data;
  36613. break;
  36614. case BABYLON.VertexBuffer.UV6Kind:
  36615. this.uvs6 = data;
  36616. break;
  36617. case BABYLON.VertexBuffer.ColorKind:
  36618. this.colors = data;
  36619. break;
  36620. case BABYLON.VertexBuffer.MatricesIndicesKind:
  36621. this.matricesIndices = data;
  36622. break;
  36623. case BABYLON.VertexBuffer.MatricesWeightsKind:
  36624. this.matricesWeights = data;
  36625. break;
  36626. case BABYLON.VertexBuffer.MatricesIndicesExtraKind:
  36627. this.matricesIndicesExtra = data;
  36628. break;
  36629. case BABYLON.VertexBuffer.MatricesWeightsExtraKind:
  36630. this.matricesWeightsExtra = data;
  36631. break;
  36632. }
  36633. };
  36634. /**
  36635. * Associates the vertexData to the passed Mesh.
  36636. * Sets it as updatable or not (default `false`)
  36637. * @param mesh the mesh the vertexData is applied to
  36638. * @param updatable when used and having the value true allows new data to update the vertexData
  36639. * @returns the VertexData
  36640. */
  36641. VertexData.prototype.applyToMesh = function (mesh, updatable) {
  36642. this._applyTo(mesh, updatable);
  36643. return this;
  36644. };
  36645. /**
  36646. * Associates the vertexData to the passed Geometry.
  36647. * Sets it as updatable or not (default `false`)
  36648. * @param geometry the geometry the vertexData is applied to
  36649. * @param updatable when used and having the value true allows new data to update the vertexData
  36650. * @returns VertexData
  36651. */
  36652. VertexData.prototype.applyToGeometry = function (geometry, updatable) {
  36653. this._applyTo(geometry, updatable);
  36654. return this;
  36655. };
  36656. /**
  36657. * Updates the associated mesh
  36658. * @param mesh the mesh to be updated
  36659. * @param updateExtends when true the mesh BoundingInfo will be renewed when and if position kind is updated, optional with default false
  36660. * @param makeItUnique when true, and when and if position kind is updated, a new global geometry will be created from these positions and set to the mesh, optional with default false
  36661. * @returns VertexData
  36662. */
  36663. VertexData.prototype.updateMesh = function (mesh, updateExtends, makeItUnique) {
  36664. this._update(mesh);
  36665. return this;
  36666. };
  36667. /**
  36668. * Updates the associated geometry
  36669. * @param geometry the geometry to be updated
  36670. * @param updateExtends when true BoundingInfo will be renewed when and if position kind is updated, optional with default false
  36671. * @param makeItUnique when true, and when and if position kind is updated, a new global geometry will be created from these positions and set to the mesh, optional with default false
  36672. * @returns VertexData.
  36673. */
  36674. VertexData.prototype.updateGeometry = function (geometry, updateExtends, makeItUnique) {
  36675. this._update(geometry);
  36676. return this;
  36677. };
  36678. VertexData.prototype._applyTo = function (meshOrGeometry, updatable) {
  36679. if (updatable === void 0) { updatable = false; }
  36680. if (this.positions) {
  36681. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updatable);
  36682. }
  36683. if (this.normals) {
  36684. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updatable);
  36685. }
  36686. if (this.tangents) {
  36687. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.TangentKind, this.tangents, updatable);
  36688. }
  36689. if (this.uvs) {
  36690. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updatable);
  36691. }
  36692. if (this.uvs2) {
  36693. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uvs2, updatable);
  36694. }
  36695. if (this.uvs3) {
  36696. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV3Kind, this.uvs3, updatable);
  36697. }
  36698. if (this.uvs4) {
  36699. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV4Kind, this.uvs4, updatable);
  36700. }
  36701. if (this.uvs5) {
  36702. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV5Kind, this.uvs5, updatable);
  36703. }
  36704. if (this.uvs6) {
  36705. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV6Kind, this.uvs6, updatable);
  36706. }
  36707. if (this.colors) {
  36708. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updatable);
  36709. }
  36710. if (this.matricesIndices) {
  36711. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);
  36712. }
  36713. if (this.matricesWeights) {
  36714. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);
  36715. }
  36716. if (this.matricesIndicesExtra) {
  36717. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updatable);
  36718. }
  36719. if (this.matricesWeightsExtra) {
  36720. meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updatable);
  36721. }
  36722. if (this.indices) {
  36723. meshOrGeometry.setIndices(this.indices, null, updatable);
  36724. }
  36725. else {
  36726. meshOrGeometry.setIndices([], null);
  36727. }
  36728. return this;
  36729. };
  36730. VertexData.prototype._update = function (meshOrGeometry, updateExtends, makeItUnique) {
  36731. if (this.positions) {
  36732. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);
  36733. }
  36734. if (this.normals) {
  36735. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
  36736. }
  36737. if (this.tangents) {
  36738. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.TangentKind, this.tangents, updateExtends, makeItUnique);
  36739. }
  36740. if (this.uvs) {
  36741. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
  36742. }
  36743. if (this.uvs2) {
  36744. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uvs2, updateExtends, makeItUnique);
  36745. }
  36746. if (this.uvs3) {
  36747. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV3Kind, this.uvs3, updateExtends, makeItUnique);
  36748. }
  36749. if (this.uvs4) {
  36750. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV4Kind, this.uvs4, updateExtends, makeItUnique);
  36751. }
  36752. if (this.uvs5) {
  36753. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV5Kind, this.uvs5, updateExtends, makeItUnique);
  36754. }
  36755. if (this.uvs6) {
  36756. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV6Kind, this.uvs6, updateExtends, makeItUnique);
  36757. }
  36758. if (this.colors) {
  36759. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);
  36760. }
  36761. if (this.matricesIndices) {
  36762. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);
  36763. }
  36764. if (this.matricesWeights) {
  36765. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);
  36766. }
  36767. if (this.matricesIndicesExtra) {
  36768. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updateExtends, makeItUnique);
  36769. }
  36770. if (this.matricesWeightsExtra) {
  36771. meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updateExtends, makeItUnique);
  36772. }
  36773. if (this.indices) {
  36774. meshOrGeometry.setIndices(this.indices, null);
  36775. }
  36776. return this;
  36777. };
  36778. /**
  36779. * Transforms each position and each normal of the vertexData according to the passed Matrix
  36780. * @param matrix the transforming matrix
  36781. * @returns the VertexData
  36782. */
  36783. VertexData.prototype.transform = function (matrix) {
  36784. var transformed = BABYLON.Vector3.Zero();
  36785. var index;
  36786. if (this.positions) {
  36787. var position = BABYLON.Vector3.Zero();
  36788. for (index = 0; index < this.positions.length; index += 3) {
  36789. BABYLON.Vector3.FromArrayToRef(this.positions, index, position);
  36790. BABYLON.Vector3.TransformCoordinatesToRef(position, matrix, transformed);
  36791. this.positions[index] = transformed.x;
  36792. this.positions[index + 1] = transformed.y;
  36793. this.positions[index + 2] = transformed.z;
  36794. }
  36795. }
  36796. if (this.normals) {
  36797. var normal = BABYLON.Vector3.Zero();
  36798. for (index = 0; index < this.normals.length; index += 3) {
  36799. BABYLON.Vector3.FromArrayToRef(this.normals, index, normal);
  36800. BABYLON.Vector3.TransformNormalToRef(normal, matrix, transformed);
  36801. this.normals[index] = transformed.x;
  36802. this.normals[index + 1] = transformed.y;
  36803. this.normals[index + 2] = transformed.z;
  36804. }
  36805. }
  36806. if (this.tangents) {
  36807. var tangent = BABYLON.Vector4.Zero();
  36808. var tangentTransformed = BABYLON.Vector4.Zero();
  36809. for (index = 0; index < this.tangents.length; index += 4) {
  36810. BABYLON.Vector4.FromArrayToRef(this.tangents, index, tangent);
  36811. BABYLON.Vector4.TransformNormalToRef(tangent, matrix, tangentTransformed);
  36812. this.tangents[index] = tangentTransformed.x;
  36813. this.tangents[index + 1] = tangentTransformed.y;
  36814. this.tangents[index + 2] = tangentTransformed.z;
  36815. this.tangents[index + 3] = tangentTransformed.w;
  36816. }
  36817. }
  36818. return this;
  36819. };
  36820. /**
  36821. * Merges the passed VertexData into the current one
  36822. * @param other the VertexData to be merged into the current one
  36823. * @returns the modified VertexData
  36824. */
  36825. VertexData.prototype.merge = function (other) {
  36826. this._validate();
  36827. other._validate();
  36828. if (!this.normals !== !other.normals ||
  36829. !this.tangents !== !other.tangents ||
  36830. !this.uvs !== !other.uvs ||
  36831. !this.uvs2 !== !other.uvs2 ||
  36832. !this.uvs3 !== !other.uvs3 ||
  36833. !this.uvs4 !== !other.uvs4 ||
  36834. !this.uvs5 !== !other.uvs5 ||
  36835. !this.uvs6 !== !other.uvs6 ||
  36836. !this.colors !== !other.colors ||
  36837. !this.matricesIndices !== !other.matricesIndices ||
  36838. !this.matricesWeights !== !other.matricesWeights ||
  36839. !this.matricesIndicesExtra !== !other.matricesIndicesExtra ||
  36840. !this.matricesWeightsExtra !== !other.matricesWeightsExtra) {
  36841. throw new Error("Cannot merge vertex data that do not have the same set of attributes");
  36842. }
  36843. if (other.indices) {
  36844. if (!this.indices) {
  36845. this.indices = [];
  36846. }
  36847. var offset = this.positions ? this.positions.length / 3 : 0;
  36848. for (var index = 0; index < other.indices.length; index++) {
  36849. //TODO check type - if Int32Array | Uint32Array | Uint16Array!
  36850. this.indices.push(other.indices[index] + offset);
  36851. }
  36852. }
  36853. this.positions = this._mergeElement(this.positions, other.positions);
  36854. this.normals = this._mergeElement(this.normals, other.normals);
  36855. this.tangents = this._mergeElement(this.tangents, other.tangents);
  36856. this.uvs = this._mergeElement(this.uvs, other.uvs);
  36857. this.uvs2 = this._mergeElement(this.uvs2, other.uvs2);
  36858. this.uvs3 = this._mergeElement(this.uvs3, other.uvs3);
  36859. this.uvs4 = this._mergeElement(this.uvs4, other.uvs4);
  36860. this.uvs5 = this._mergeElement(this.uvs5, other.uvs5);
  36861. this.uvs6 = this._mergeElement(this.uvs6, other.uvs6);
  36862. this.colors = this._mergeElement(this.colors, other.colors);
  36863. this.matricesIndices = this._mergeElement(this.matricesIndices, other.matricesIndices);
  36864. this.matricesWeights = this._mergeElement(this.matricesWeights, other.matricesWeights);
  36865. this.matricesIndicesExtra = this._mergeElement(this.matricesIndicesExtra, other.matricesIndicesExtra);
  36866. this.matricesWeightsExtra = this._mergeElement(this.matricesWeightsExtra, other.matricesWeightsExtra);
  36867. return this;
  36868. };
  36869. VertexData.prototype._mergeElement = function (source, other) {
  36870. if (!source) {
  36871. return other;
  36872. }
  36873. if (!other) {
  36874. return source;
  36875. }
  36876. var len = other.length + source.length;
  36877. var isSrcTypedArray = source instanceof Float32Array;
  36878. var isOthTypedArray = other instanceof Float32Array;
  36879. // use non-loop method when the source is Float32Array
  36880. if (isSrcTypedArray) {
  36881. var ret32 = new Float32Array(len);
  36882. ret32.set(source);
  36883. ret32.set(other, source.length);
  36884. return ret32;
  36885. // source is number[], when other is also use concat
  36886. }
  36887. else if (!isOthTypedArray) {
  36888. return source.concat(other);
  36889. // source is a number[], but other is a Float32Array, loop required
  36890. }
  36891. else {
  36892. var ret = source.slice(0); // copy source to a separate array
  36893. for (var i = 0, len = other.length; i < len; i++) {
  36894. ret.push(other[i]);
  36895. }
  36896. return ret;
  36897. }
  36898. };
  36899. VertexData.prototype._validate = function () {
  36900. if (!this.positions) {
  36901. throw new Error("Positions are required");
  36902. }
  36903. var getElementCount = function (kind, values) {
  36904. var stride = BABYLON.VertexBuffer.DeduceStride(kind);
  36905. if ((values.length % stride) !== 0) {
  36906. throw new Error("The " + kind + "s array count must be a multiple of " + stride);
  36907. }
  36908. return values.length / stride;
  36909. };
  36910. var positionsElementCount = getElementCount(BABYLON.VertexBuffer.PositionKind, this.positions);
  36911. var validateElementCount = function (kind, values) {
  36912. var elementCount = getElementCount(kind, values);
  36913. if (elementCount !== positionsElementCount) {
  36914. throw new Error("The " + kind + "s element count (" + elementCount + ") does not match the positions count (" + positionsElementCount + ")");
  36915. }
  36916. };
  36917. if (this.normals)
  36918. validateElementCount(BABYLON.VertexBuffer.NormalKind, this.normals);
  36919. if (this.tangents)
  36920. validateElementCount(BABYLON.VertexBuffer.TangentKind, this.tangents);
  36921. if (this.uvs)
  36922. validateElementCount(BABYLON.VertexBuffer.UVKind, this.uvs);
  36923. if (this.uvs2)
  36924. validateElementCount(BABYLON.VertexBuffer.UV2Kind, this.uvs2);
  36925. if (this.uvs3)
  36926. validateElementCount(BABYLON.VertexBuffer.UV3Kind, this.uvs3);
  36927. if (this.uvs4)
  36928. validateElementCount(BABYLON.VertexBuffer.UV4Kind, this.uvs4);
  36929. if (this.uvs5)
  36930. validateElementCount(BABYLON.VertexBuffer.UV5Kind, this.uvs5);
  36931. if (this.uvs6)
  36932. validateElementCount(BABYLON.VertexBuffer.UV6Kind, this.uvs6);
  36933. if (this.colors)
  36934. validateElementCount(BABYLON.VertexBuffer.ColorKind, this.colors);
  36935. if (this.matricesIndices)
  36936. validateElementCount(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices);
  36937. if (this.matricesWeights)
  36938. validateElementCount(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights);
  36939. if (this.matricesIndicesExtra)
  36940. validateElementCount(BABYLON.VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra);
  36941. if (this.matricesWeightsExtra)
  36942. validateElementCount(BABYLON.VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra);
  36943. };
  36944. /**
  36945. * Serializes the VertexData
  36946. * @returns a serialized object
  36947. */
  36948. VertexData.prototype.serialize = function () {
  36949. var serializationObject = this.serialize();
  36950. if (this.positions) {
  36951. serializationObject.positions = this.positions;
  36952. }
  36953. if (this.normals) {
  36954. serializationObject.normals = this.normals;
  36955. }
  36956. if (this.tangents) {
  36957. serializationObject.tangents = this.tangents;
  36958. }
  36959. if (this.uvs) {
  36960. serializationObject.uvs = this.uvs;
  36961. }
  36962. if (this.uvs2) {
  36963. serializationObject.uvs2 = this.uvs2;
  36964. }
  36965. if (this.uvs3) {
  36966. serializationObject.uvs3 = this.uvs3;
  36967. }
  36968. if (this.uvs4) {
  36969. serializationObject.uvs4 = this.uvs4;
  36970. }
  36971. if (this.uvs5) {
  36972. serializationObject.uvs5 = this.uvs5;
  36973. }
  36974. if (this.uvs6) {
  36975. serializationObject.uvs6 = this.uvs6;
  36976. }
  36977. if (this.colors) {
  36978. serializationObject.colors = this.colors;
  36979. }
  36980. if (this.matricesIndices) {
  36981. serializationObject.matricesIndices = this.matricesIndices;
  36982. serializationObject.matricesIndices._isExpanded = true;
  36983. }
  36984. if (this.matricesWeights) {
  36985. serializationObject.matricesWeights = this.matricesWeights;
  36986. }
  36987. if (this.matricesIndicesExtra) {
  36988. serializationObject.matricesIndicesExtra = this.matricesIndicesExtra;
  36989. serializationObject.matricesIndicesExtra._isExpanded = true;
  36990. }
  36991. if (this.matricesWeightsExtra) {
  36992. serializationObject.matricesWeightsExtra = this.matricesWeightsExtra;
  36993. }
  36994. serializationObject.indices = this.indices;
  36995. return serializationObject;
  36996. };
  36997. // Statics
  36998. /**
  36999. * Extracts the vertexData from a mesh
  37000. * @param mesh the mesh from which to extract the VertexData
  37001. * @param copyWhenShared defines if the VertexData must be cloned when shared between multiple meshes, optional, default false
  37002. * @param forceCopy indicating that the VertexData must be cloned, optional, default false
  37003. * @returns the object VertexData associated to the passed mesh
  37004. */
  37005. VertexData.ExtractFromMesh = function (mesh, copyWhenShared, forceCopy) {
  37006. return VertexData._ExtractFrom(mesh, copyWhenShared, forceCopy);
  37007. };
  37008. /**
  37009. * Extracts the vertexData from the geometry
  37010. * @param geometry the geometry from which to extract the VertexData
  37011. * @param copyWhenShared defines if the VertexData must be cloned when the geometrty is shared between multiple meshes, optional, default false
  37012. * @param forceCopy indicating that the VertexData must be cloned, optional, default false
  37013. * @returns the object VertexData associated to the passed mesh
  37014. */
  37015. VertexData.ExtractFromGeometry = function (geometry, copyWhenShared, forceCopy) {
  37016. return VertexData._ExtractFrom(geometry, copyWhenShared, forceCopy);
  37017. };
  37018. VertexData._ExtractFrom = function (meshOrGeometry, copyWhenShared, forceCopy) {
  37019. var result = new VertexData();
  37020. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  37021. result.positions = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.PositionKind, copyWhenShared, forceCopy);
  37022. }
  37023. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  37024. result.normals = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.NormalKind, copyWhenShared, forceCopy);
  37025. }
  37026. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
  37027. result.tangents = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.TangentKind, copyWhenShared, forceCopy);
  37028. }
  37029. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  37030. result.uvs = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UVKind, copyWhenShared, forceCopy);
  37031. }
  37032. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  37033. result.uvs2 = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV2Kind, copyWhenShared, forceCopy);
  37034. }
  37035. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV3Kind)) {
  37036. result.uvs3 = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV3Kind, copyWhenShared, forceCopy);
  37037. }
  37038. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV4Kind)) {
  37039. result.uvs4 = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV4Kind, copyWhenShared, forceCopy);
  37040. }
  37041. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV5Kind)) {
  37042. result.uvs5 = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV5Kind, copyWhenShared, forceCopy);
  37043. }
  37044. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV6Kind)) {
  37045. result.uvs6 = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV6Kind, copyWhenShared, forceCopy);
  37046. }
  37047. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  37048. result.colors = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.ColorKind, copyWhenShared, forceCopy);
  37049. }
  37050. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
  37051. result.matricesIndices = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, copyWhenShared, forceCopy);
  37052. }
  37053. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  37054. result.matricesWeights = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, copyWhenShared, forceCopy);
  37055. }
  37056. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesExtraKind)) {
  37057. result.matricesIndicesExtra = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, copyWhenShared, forceCopy);
  37058. }
  37059. if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsExtraKind)) {
  37060. result.matricesWeightsExtra = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, copyWhenShared, forceCopy);
  37061. }
  37062. result.indices = meshOrGeometry.getIndices(copyWhenShared);
  37063. return result;
  37064. };
  37065. /**
  37066. * Creates the VertexData for a Ribbon
  37067. * @param options an object used to set the following optional parameters for the ribbon, required but can be empty
  37068. * * pathArray array of paths, each of which an array of successive Vector3
  37069. * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false
  37070. * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false
  37071. * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length
  37072. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  37073. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  37074. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  37075. * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false
  37076. * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional
  37077. * * colors a linear array, of length 4 * number of vertices, of custom color values, optional
  37078. * @returns the VertexData of the ribbon
  37079. */
  37080. VertexData.CreateRibbon = function (options) {
  37081. var pathArray = options.pathArray;
  37082. var closeArray = options.closeArray || false;
  37083. var closePath = options.closePath || false;
  37084. var invertUV = options.invertUV || false;
  37085. var defaultOffset = Math.floor(pathArray[0].length / 2);
  37086. var offset = options.offset || defaultOffset;
  37087. offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
  37088. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  37089. var customUV = options.uvs;
  37090. var customColors = options.colors;
  37091. var positions = [];
  37092. var indices = [];
  37093. var normals = [];
  37094. var uvs = [];
  37095. var us = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id
  37096. var vs = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutives paths from pathArray
  37097. var uTotalDistance = []; // uTotalDistance[p] : total distance of path p
  37098. var vTotalDistance = []; // vTotalDistance[i] : total distance between points i of first and last path from pathArray
  37099. var minlg; // minimal length among all paths from pathArray
  37100. var lg = []; // array of path lengths : nb of vertex per path
  37101. var idx = []; // array of path indexes : index of each path (first vertex) in the total vertex number
  37102. var p; // path iterator
  37103. var i; // point iterator
  37104. var j; // point iterator
  37105. // if single path in pathArray
  37106. if (pathArray.length < 2) {
  37107. var ar1 = [];
  37108. var ar2 = [];
  37109. for (i = 0; i < pathArray[0].length - offset; i++) {
  37110. ar1.push(pathArray[0][i]);
  37111. ar2.push(pathArray[0][i + offset]);
  37112. }
  37113. pathArray = [ar1, ar2];
  37114. }
  37115. // positions and horizontal distances (u)
  37116. var idc = 0;
  37117. var closePathCorr = (closePath) ? 1 : 0; // the final index will be +1 if closePath
  37118. var path;
  37119. var l;
  37120. minlg = pathArray[0].length;
  37121. var vectlg;
  37122. var dist;
  37123. for (p = 0; p < pathArray.length; p++) {
  37124. uTotalDistance[p] = 0;
  37125. us[p] = [0];
  37126. path = pathArray[p];
  37127. l = path.length;
  37128. minlg = (minlg < l) ? minlg : l;
  37129. j = 0;
  37130. while (j < l) {
  37131. positions.push(path[j].x, path[j].y, path[j].z);
  37132. if (j > 0) {
  37133. vectlg = path[j].subtract(path[j - 1]).length();
  37134. dist = vectlg + uTotalDistance[p];
  37135. us[p].push(dist);
  37136. uTotalDistance[p] = dist;
  37137. }
  37138. j++;
  37139. }
  37140. if (closePath) { // an extra hidden vertex is added in the "positions" array
  37141. j--;
  37142. positions.push(path[0].x, path[0].y, path[0].z);
  37143. vectlg = path[j].subtract(path[0]).length();
  37144. dist = vectlg + uTotalDistance[p];
  37145. us[p].push(dist);
  37146. uTotalDistance[p] = dist;
  37147. }
  37148. lg[p] = l + closePathCorr;
  37149. idx[p] = idc;
  37150. idc += (l + closePathCorr);
  37151. }
  37152. // vertical distances (v)
  37153. var path1;
  37154. var path2;
  37155. var vertex1 = null;
  37156. var vertex2 = null;
  37157. for (i = 0; i < minlg + closePathCorr; i++) {
  37158. vTotalDistance[i] = 0;
  37159. vs[i] = [0];
  37160. for (p = 0; p < pathArray.length - 1; p++) {
  37161. path1 = pathArray[p];
  37162. path2 = pathArray[p + 1];
  37163. if (i === minlg) { // closePath
  37164. vertex1 = path1[0];
  37165. vertex2 = path2[0];
  37166. }
  37167. else {
  37168. vertex1 = path1[i];
  37169. vertex2 = path2[i];
  37170. }
  37171. vectlg = vertex2.subtract(vertex1).length();
  37172. dist = vectlg + vTotalDistance[i];
  37173. vs[i].push(dist);
  37174. vTotalDistance[i] = dist;
  37175. }
  37176. if (closeArray && vertex2 && vertex1) {
  37177. path1 = pathArray[p];
  37178. path2 = pathArray[0];
  37179. if (i === minlg) { // closePath
  37180. vertex2 = path2[0];
  37181. }
  37182. vectlg = vertex2.subtract(vertex1).length();
  37183. dist = vectlg + vTotalDistance[i];
  37184. vTotalDistance[i] = dist;
  37185. }
  37186. }
  37187. // uvs
  37188. var u;
  37189. var v;
  37190. if (customUV) {
  37191. for (p = 0; p < customUV.length; p++) {
  37192. uvs.push(customUV[p].x, customUV[p].y);
  37193. }
  37194. }
  37195. else {
  37196. for (p = 0; p < pathArray.length; p++) {
  37197. for (i = 0; i < minlg + closePathCorr; i++) {
  37198. u = (uTotalDistance[p] != 0.0) ? us[p][i] / uTotalDistance[p] : 0.0;
  37199. v = (vTotalDistance[i] != 0.0) ? vs[i][p] / vTotalDistance[i] : 0.0;
  37200. if (invertUV) {
  37201. uvs.push(v, u);
  37202. }
  37203. else {
  37204. uvs.push(u, v);
  37205. }
  37206. }
  37207. }
  37208. }
  37209. // indices
  37210. p = 0; // path index
  37211. var pi = 0; // positions array index
  37212. var l1 = lg[p] - 1; // path1 length
  37213. var l2 = lg[p + 1] - 1; // path2 length
  37214. var min = (l1 < l2) ? l1 : l2; // current path stop index
  37215. var shft = idx[1] - idx[0]; // shift
  37216. var path1nb = closeArray ? lg.length : lg.length - 1; // number of path1 to iterate on
  37217. while (pi <= min && p < path1nb) { // stay under min and don't go over next to last path
  37218. // draw two triangles between path1 (p1) and path2 (p2) : (p1.pi, p2.pi, p1.pi+1) and (p2.pi+1, p1.pi+1, p2.pi) clockwise
  37219. indices.push(pi, pi + shft, pi + 1);
  37220. indices.push(pi + shft + 1, pi + 1, pi + shft);
  37221. pi += 1;
  37222. if (pi === min) { // if end of one of two consecutive paths reached, go to next existing path
  37223. p++;
  37224. if (p === lg.length - 1) { // last path of pathArray reached <=> closeArray == true
  37225. shft = idx[0] - idx[p];
  37226. l1 = lg[p] - 1;
  37227. l2 = lg[0] - 1;
  37228. }
  37229. else {
  37230. shft = idx[p + 1] - idx[p];
  37231. l1 = lg[p] - 1;
  37232. l2 = lg[p + 1] - 1;
  37233. }
  37234. pi = idx[p];
  37235. min = (l1 < l2) ? l1 + pi : l2 + pi;
  37236. }
  37237. }
  37238. // normals
  37239. VertexData.ComputeNormals(positions, indices, normals);
  37240. if (closePath) { // update both the first and last vertex normals to their average value
  37241. var indexFirst = 0;
  37242. var indexLast = 0;
  37243. for (p = 0; p < pathArray.length; p++) {
  37244. indexFirst = idx[p] * 3;
  37245. if (p + 1 < pathArray.length) {
  37246. indexLast = (idx[p + 1] - 1) * 3;
  37247. }
  37248. else {
  37249. indexLast = normals.length - 3;
  37250. }
  37251. normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;
  37252. normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;
  37253. normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;
  37254. normals[indexLast] = normals[indexFirst];
  37255. normals[indexLast + 1] = normals[indexFirst + 1];
  37256. normals[indexLast + 2] = normals[indexFirst + 2];
  37257. }
  37258. }
  37259. // sides
  37260. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  37261. // Colors
  37262. var colors = null;
  37263. if (customColors) {
  37264. colors = new Float32Array(customColors.length * 4);
  37265. for (var c = 0; c < customColors.length; c++) {
  37266. colors[c * 4] = customColors[c].r;
  37267. colors[c * 4 + 1] = customColors[c].g;
  37268. colors[c * 4 + 2] = customColors[c].b;
  37269. colors[c * 4 + 3] = customColors[c].a;
  37270. }
  37271. }
  37272. // Result
  37273. var vertexData = new VertexData();
  37274. var positions32 = new Float32Array(positions);
  37275. var normals32 = new Float32Array(normals);
  37276. var uvs32 = new Float32Array(uvs);
  37277. vertexData.indices = indices;
  37278. vertexData.positions = positions32;
  37279. vertexData.normals = normals32;
  37280. vertexData.uvs = uvs32;
  37281. if (colors) {
  37282. vertexData.set(colors, BABYLON.VertexBuffer.ColorKind);
  37283. }
  37284. if (closePath) {
  37285. vertexData._idx = idx;
  37286. }
  37287. return vertexData;
  37288. };
  37289. /**
  37290. * Creates the VertexData for a box
  37291. * @param options an object used to set the following optional parameters for the box, required but can be empty
  37292. * * size sets the width, height and depth of the box to the value of size, optional default 1
  37293. * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size
  37294. * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size
  37295. * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size
  37296. * * faceUV an array of 6 Vector4 elements used to set different images to each box side
  37297. * * faceColors an array of 6 Color3 elements used to set different colors to each box side
  37298. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  37299. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  37300. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  37301. * @returns the VertexData of the box
  37302. */
  37303. VertexData.CreateBox = function (options) {
  37304. var normalsSource = [
  37305. new BABYLON.Vector3(0, 0, 1),
  37306. new BABYLON.Vector3(0, 0, -1),
  37307. new BABYLON.Vector3(1, 0, 0),
  37308. new BABYLON.Vector3(-1, 0, 0),
  37309. new BABYLON.Vector3(0, 1, 0),
  37310. new BABYLON.Vector3(0, -1, 0)
  37311. ];
  37312. var indices = [];
  37313. var positions = [];
  37314. var normals = [];
  37315. var uvs = [];
  37316. var width = options.width || options.size || 1;
  37317. var height = options.height || options.size || 1;
  37318. var depth = options.depth || options.size || 1;
  37319. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  37320. var faceUV = options.faceUV || new Array(6);
  37321. var faceColors = options.faceColors;
  37322. var colors = [];
  37323. // default face colors and UV if undefined
  37324. for (var f = 0; f < 6; f++) {
  37325. if (faceUV[f] === undefined) {
  37326. faceUV[f] = new BABYLON.Vector4(0, 0, 1, 1);
  37327. }
  37328. if (faceColors && faceColors[f] === undefined) {
  37329. faceColors[f] = new BABYLON.Color4(1, 1, 1, 1);
  37330. }
  37331. }
  37332. var scaleVector = new BABYLON.Vector3(width / 2, height / 2, depth / 2);
  37333. // Create each face in turn.
  37334. for (var index = 0; index < normalsSource.length; index++) {
  37335. var normal = normalsSource[index];
  37336. // Get two vectors perpendicular to the face normal and to each other.
  37337. var side1 = new BABYLON.Vector3(normal.y, normal.z, normal.x);
  37338. var side2 = BABYLON.Vector3.Cross(normal, side1);
  37339. // Six indices (two triangles) per face.
  37340. var verticesLength = positions.length / 3;
  37341. indices.push(verticesLength);
  37342. indices.push(verticesLength + 1);
  37343. indices.push(verticesLength + 2);
  37344. indices.push(verticesLength);
  37345. indices.push(verticesLength + 2);
  37346. indices.push(verticesLength + 3);
  37347. // Four vertices per face.
  37348. var vertex = normal.subtract(side1).subtract(side2).multiply(scaleVector);
  37349. positions.push(vertex.x, vertex.y, vertex.z);
  37350. normals.push(normal.x, normal.y, normal.z);
  37351. uvs.push(faceUV[index].z, faceUV[index].w);
  37352. if (faceColors) {
  37353. colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);
  37354. }
  37355. vertex = normal.subtract(side1).add(side2).multiply(scaleVector);
  37356. positions.push(vertex.x, vertex.y, vertex.z);
  37357. normals.push(normal.x, normal.y, normal.z);
  37358. uvs.push(faceUV[index].x, faceUV[index].w);
  37359. if (faceColors) {
  37360. colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);
  37361. }
  37362. vertex = normal.add(side1).add(side2).multiply(scaleVector);
  37363. positions.push(vertex.x, vertex.y, vertex.z);
  37364. normals.push(normal.x, normal.y, normal.z);
  37365. uvs.push(faceUV[index].x, faceUV[index].y);
  37366. if (faceColors) {
  37367. colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);
  37368. }
  37369. vertex = normal.add(side1).subtract(side2).multiply(scaleVector);
  37370. positions.push(vertex.x, vertex.y, vertex.z);
  37371. normals.push(normal.x, normal.y, normal.z);
  37372. uvs.push(faceUV[index].z, faceUV[index].y);
  37373. if (faceColors) {
  37374. colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);
  37375. }
  37376. }
  37377. // sides
  37378. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  37379. // Result
  37380. var vertexData = new VertexData();
  37381. vertexData.indices = indices;
  37382. vertexData.positions = positions;
  37383. vertexData.normals = normals;
  37384. vertexData.uvs = uvs;
  37385. if (faceColors) {
  37386. var totalColors = (sideOrientation === BABYLON.Mesh.DOUBLESIDE) ? colors.concat(colors) : colors;
  37387. vertexData.colors = totalColors;
  37388. }
  37389. return vertexData;
  37390. };
  37391. /**
  37392. * Creates the VertexData for an ellipsoid, defaults to a sphere
  37393. * @param options an object used to set the following optional parameters for the box, required but can be empty
  37394. * * segments sets the number of horizontal strips optional, default 32
  37395. * * diameter sets the axes dimensions, diameterX, diameterY and diameterZ to the value of diameter, optional default 1
  37396. * * diameterX sets the diameterX (x direction) of the ellipsoid, overwrites the diameterX set by diameter, optional, default diameter
  37397. * * diameterY sets the diameterY (y direction) of the ellipsoid, overwrites the diameterY set by diameter, optional, default diameter
  37398. * * diameterZ sets the diameterZ (z direction) of the ellipsoid, overwrites the diameterZ set by diameter, optional, default diameter
  37399. * * arc a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the circumference (latitude) given by the arc value, optional, default 1
  37400. * * slice a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the height (latitude) given by the arc value, optional, default 1
  37401. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  37402. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  37403. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  37404. * @returns the VertexData of the ellipsoid
  37405. */
  37406. VertexData.CreateSphere = function (options) {
  37407. var segments = options.segments || 32;
  37408. var diameterX = options.diameterX || options.diameter || 1;
  37409. var diameterY = options.diameterY || options.diameter || 1;
  37410. var diameterZ = options.diameterZ || options.diameter || 1;
  37411. var arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
  37412. var slice = options.slice && (options.slice <= 0) ? 1.0 : options.slice || 1.0;
  37413. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  37414. var radius = new BABYLON.Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);
  37415. var totalZRotationSteps = 2 + segments;
  37416. var totalYRotationSteps = 2 * totalZRotationSteps;
  37417. var indices = [];
  37418. var positions = [];
  37419. var normals = [];
  37420. var uvs = [];
  37421. for (var zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
  37422. var normalizedZ = zRotationStep / totalZRotationSteps;
  37423. var angleZ = normalizedZ * Math.PI * slice;
  37424. for (var yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
  37425. var normalizedY = yRotationStep / totalYRotationSteps;
  37426. var angleY = normalizedY * Math.PI * 2 * arc;
  37427. var rotationZ = BABYLON.Matrix.RotationZ(-angleZ);
  37428. var rotationY = BABYLON.Matrix.RotationY(angleY);
  37429. var afterRotZ = BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.Up(), rotationZ);
  37430. var complete = BABYLON.Vector3.TransformCoordinates(afterRotZ, rotationY);
  37431. var vertex = complete.multiply(radius);
  37432. var normal = complete.divide(radius).normalize();
  37433. positions.push(vertex.x, vertex.y, vertex.z);
  37434. normals.push(normal.x, normal.y, normal.z);
  37435. uvs.push(normalizedY, normalizedZ);
  37436. }
  37437. if (zRotationStep > 0) {
  37438. var verticesCount = positions.length / 3;
  37439. for (var firstIndex = verticesCount - 2 * (totalYRotationSteps + 1); (firstIndex + totalYRotationSteps + 2) < verticesCount; firstIndex++) {
  37440. indices.push((firstIndex));
  37441. indices.push((firstIndex + 1));
  37442. indices.push(firstIndex + totalYRotationSteps + 1);
  37443. indices.push((firstIndex + totalYRotationSteps + 1));
  37444. indices.push((firstIndex + 1));
  37445. indices.push((firstIndex + totalYRotationSteps + 2));
  37446. }
  37447. }
  37448. }
  37449. // Sides
  37450. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  37451. // Result
  37452. var vertexData = new VertexData();
  37453. vertexData.indices = indices;
  37454. vertexData.positions = positions;
  37455. vertexData.normals = normals;
  37456. vertexData.uvs = uvs;
  37457. return vertexData;
  37458. };
  37459. /**
  37460. * Creates the VertexData for a cylinder, cone or prism
  37461. * @param options an object used to set the following optional parameters for the box, required but can be empty
  37462. * * height sets the height (y direction) of the cylinder, optional, default 2
  37463. * * diameterTop sets the diameter of the top of the cone, overwrites diameter, optional, default diameter
  37464. * * diameterBottom sets the diameter of the bottom of the cone, overwrites diameter, optional, default diameter
  37465. * * diameter sets the diameter of the top and bottom of the cone, optional default 1
  37466. * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24
  37467. * * subdivisions` the number of rings along the cylinder height, optional, default 1
  37468. * * arc a number from 0 to 1, to create an unclosed cylinder based on the fraction of the circumference given by the arc value, optional, default 1
  37469. * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively
  37470. * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively
  37471. * * hasRings when true makes each subdivision independantly treated as a face for faceUV and faceColors, optional, default false
  37472. * * enclose when true closes an open cylinder by adding extra flat faces between the height axis and vertical edges, think cut cake
  37473. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  37474. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  37475. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  37476. * @returns the VertexData of the cylinder, cone or prism
  37477. */
  37478. VertexData.CreateCylinder = function (options) {
  37479. var height = options.height || 2;
  37480. var diameterTop = (options.diameterTop === 0) ? 0 : options.diameterTop || options.diameter || 1;
  37481. var diameterBottom = (options.diameterBottom === 0) ? 0 : options.diameterBottom || options.diameter || 1;
  37482. var tessellation = options.tessellation || 24;
  37483. var subdivisions = options.subdivisions || 1;
  37484. var hasRings = options.hasRings ? true : false;
  37485. var enclose = options.enclose ? true : false;
  37486. var arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
  37487. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  37488. var faceUV = options.faceUV || new Array(3);
  37489. var faceColors = options.faceColors;
  37490. // default face colors and UV if undefined
  37491. var quadNb = (arc !== 1 && enclose) ? 2 : 0;
  37492. var ringNb = (hasRings) ? subdivisions : 1;
  37493. var surfaceNb = 2 + (1 + quadNb) * ringNb;
  37494. var f;
  37495. for (f = 0; f < surfaceNb; f++) {
  37496. if (faceColors && faceColors[f] === undefined) {
  37497. faceColors[f] = new BABYLON.Color4(1, 1, 1, 1);
  37498. }
  37499. }
  37500. for (f = 0; f < surfaceNb; f++) {
  37501. if (faceUV && faceUV[f] === undefined) {
  37502. faceUV[f] = new BABYLON.Vector4(0, 0, 1, 1);
  37503. }
  37504. }
  37505. var indices = new Array();
  37506. var positions = new Array();
  37507. var normals = new Array();
  37508. var uvs = new Array();
  37509. var colors = new Array();
  37510. var angle_step = Math.PI * 2 * arc / tessellation;
  37511. var angle;
  37512. var h;
  37513. var radius;
  37514. var tan = (diameterBottom - diameterTop) / 2 / height;
  37515. var ringVertex = BABYLON.Vector3.Zero();
  37516. var ringNormal = BABYLON.Vector3.Zero();
  37517. var ringFirstVertex = BABYLON.Vector3.Zero();
  37518. var ringFirstNormal = BABYLON.Vector3.Zero();
  37519. var quadNormal = BABYLON.Vector3.Zero();
  37520. var Y = BABYLON.Axis.Y;
  37521. // positions, normals, uvs
  37522. var i;
  37523. var j;
  37524. var r;
  37525. var ringIdx = 1;
  37526. var s = 1; // surface index
  37527. var cs = 0;
  37528. var v = 0;
  37529. for (i = 0; i <= subdivisions; i++) {
  37530. h = i / subdivisions;
  37531. radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;
  37532. ringIdx = (hasRings && i !== 0 && i !== subdivisions) ? 2 : 1;
  37533. for (r = 0; r < ringIdx; r++) {
  37534. if (hasRings) {
  37535. s += r;
  37536. }
  37537. if (enclose) {
  37538. s += 2 * r;
  37539. }
  37540. for (j = 0; j <= tessellation; j++) {
  37541. angle = j * angle_step;
  37542. // position
  37543. ringVertex.x = Math.cos(-angle) * radius;
  37544. ringVertex.y = -height / 2 + h * height;
  37545. ringVertex.z = Math.sin(-angle) * radius;
  37546. // normal
  37547. if (diameterTop === 0 && i === subdivisions) {
  37548. // if no top cap, reuse former normals
  37549. ringNormal.x = normals[normals.length - (tessellation + 1) * 3];
  37550. ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];
  37551. ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];
  37552. }
  37553. else {
  37554. ringNormal.x = ringVertex.x;
  37555. ringNormal.z = ringVertex.z;
  37556. ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;
  37557. ringNormal.normalize();
  37558. }
  37559. // keep first ring vertex values for enclose
  37560. if (j === 0) {
  37561. ringFirstVertex.copyFrom(ringVertex);
  37562. ringFirstNormal.copyFrom(ringNormal);
  37563. }
  37564. positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
  37565. normals.push(ringNormal.x, ringNormal.y, ringNormal.z);
  37566. if (hasRings) {
  37567. v = (cs !== s) ? faceUV[s].y : faceUV[s].w;
  37568. }
  37569. else {
  37570. v = faceUV[s].y + (faceUV[s].w - faceUV[s].y) * h;
  37571. }
  37572. uvs.push(faceUV[s].x + (faceUV[s].z - faceUV[s].x) * j / tessellation, v);
  37573. if (faceColors) {
  37574. colors.push(faceColors[s].r, faceColors[s].g, faceColors[s].b, faceColors[s].a);
  37575. }
  37576. }
  37577. // if enclose, add four vertices and their dedicated normals
  37578. if (arc !== 1 && enclose) {
  37579. positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
  37580. positions.push(0, ringVertex.y, 0);
  37581. positions.push(0, ringVertex.y, 0);
  37582. positions.push(ringFirstVertex.x, ringFirstVertex.y, ringFirstVertex.z);
  37583. BABYLON.Vector3.CrossToRef(Y, ringNormal, quadNormal);
  37584. quadNormal.normalize();
  37585. normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);
  37586. BABYLON.Vector3.CrossToRef(ringFirstNormal, Y, quadNormal);
  37587. quadNormal.normalize();
  37588. normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);
  37589. if (hasRings) {
  37590. v = (cs !== s) ? faceUV[s + 1].y : faceUV[s + 1].w;
  37591. }
  37592. else {
  37593. v = faceUV[s + 1].y + (faceUV[s + 1].w - faceUV[s + 1].y) * h;
  37594. }
  37595. uvs.push(faceUV[s + 1].x, v);
  37596. uvs.push(faceUV[s + 1].z, v);
  37597. if (hasRings) {
  37598. v = (cs !== s) ? faceUV[s + 2].y : faceUV[s + 2].w;
  37599. }
  37600. else {
  37601. v = faceUV[s + 2].y + (faceUV[s + 2].w - faceUV[s + 2].y) * h;
  37602. }
  37603. uvs.push(faceUV[s + 2].x, v);
  37604. uvs.push(faceUV[s + 2].z, v);
  37605. if (faceColors) {
  37606. colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);
  37607. colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);
  37608. colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);
  37609. colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);
  37610. }
  37611. }
  37612. if (cs !== s) {
  37613. cs = s;
  37614. }
  37615. }
  37616. }
  37617. // indices
  37618. var e = (arc !== 1 && enclose) ? tessellation + 4 : tessellation; // correction of number of iteration if enclose
  37619. var s;
  37620. i = 0;
  37621. for (s = 0; s < subdivisions; s++) {
  37622. var i0 = 0;
  37623. var i1 = 0;
  37624. var i2 = 0;
  37625. var i3 = 0;
  37626. for (j = 0; j < tessellation; j++) {
  37627. i0 = i * (e + 1) + j;
  37628. i1 = (i + 1) * (e + 1) + j;
  37629. i2 = i * (e + 1) + (j + 1);
  37630. i3 = (i + 1) * (e + 1) + (j + 1);
  37631. indices.push(i0, i1, i2);
  37632. indices.push(i3, i2, i1);
  37633. }
  37634. if (arc !== 1 && enclose) { // if enclose, add two quads
  37635. indices.push(i0 + 2, i1 + 2, i2 + 2);
  37636. indices.push(i3 + 2, i2 + 2, i1 + 2);
  37637. indices.push(i0 + 4, i1 + 4, i2 + 4);
  37638. indices.push(i3 + 4, i2 + 4, i1 + 4);
  37639. }
  37640. i = (hasRings) ? (i + 2) : (i + 1);
  37641. }
  37642. // Caps
  37643. var createCylinderCap = function (isTop) {
  37644. var radius = isTop ? diameterTop / 2 : diameterBottom / 2;
  37645. if (radius === 0) {
  37646. return;
  37647. }
  37648. // Cap positions, normals & uvs
  37649. var angle;
  37650. var circleVector;
  37651. var i;
  37652. var u = (isTop) ? faceUV[surfaceNb - 1] : faceUV[0];
  37653. var c = null;
  37654. if (faceColors) {
  37655. c = (isTop) ? faceColors[surfaceNb - 1] : faceColors[0];
  37656. }
  37657. // cap center
  37658. var vbase = positions.length / 3;
  37659. var offset = isTop ? height / 2 : -height / 2;
  37660. var center = new BABYLON.Vector3(0, offset, 0);
  37661. positions.push(center.x, center.y, center.z);
  37662. normals.push(0, isTop ? 1 : -1, 0);
  37663. uvs.push(u.x + (u.z - u.x) * 0.5, u.y + (u.w - u.y) * 0.5);
  37664. if (c) {
  37665. colors.push(c.r, c.g, c.b, c.a);
  37666. }
  37667. var textureScale = new BABYLON.Vector2(0.5, 0.5);
  37668. for (i = 0; i <= tessellation; i++) {
  37669. angle = Math.PI * 2 * i * arc / tessellation;
  37670. var cos = Math.cos(-angle);
  37671. var sin = Math.sin(-angle);
  37672. circleVector = new BABYLON.Vector3(cos * radius, offset, sin * radius);
  37673. var textureCoordinate = new BABYLON.Vector2(cos * textureScale.x + 0.5, sin * textureScale.y + 0.5);
  37674. positions.push(circleVector.x, circleVector.y, circleVector.z);
  37675. normals.push(0, isTop ? 1 : -1, 0);
  37676. uvs.push(u.x + (u.z - u.x) * textureCoordinate.x, u.y + (u.w - u.y) * textureCoordinate.y);
  37677. if (c) {
  37678. colors.push(c.r, c.g, c.b, c.a);
  37679. }
  37680. }
  37681. // Cap indices
  37682. for (i = 0; i < tessellation; i++) {
  37683. if (!isTop) {
  37684. indices.push(vbase);
  37685. indices.push(vbase + (i + 1));
  37686. indices.push(vbase + (i + 2));
  37687. }
  37688. else {
  37689. indices.push(vbase);
  37690. indices.push(vbase + (i + 2));
  37691. indices.push(vbase + (i + 1));
  37692. }
  37693. }
  37694. };
  37695. // add caps to geometry
  37696. createCylinderCap(false);
  37697. createCylinderCap(true);
  37698. // Sides
  37699. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  37700. var vertexData = new VertexData();
  37701. vertexData.indices = indices;
  37702. vertexData.positions = positions;
  37703. vertexData.normals = normals;
  37704. vertexData.uvs = uvs;
  37705. if (faceColors) {
  37706. vertexData.colors = colors;
  37707. }
  37708. return vertexData;
  37709. };
  37710. /**
  37711. * Creates the VertexData for a torus
  37712. * @param options an object used to set the following optional parameters for the box, required but can be empty
  37713. * * diameter the diameter of the torus, optional default 1
  37714. * * thickness the diameter of the tube forming the torus, optional default 0.5
  37715. * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24
  37716. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  37717. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  37718. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  37719. * @returns the VertexData of the torus
  37720. */
  37721. VertexData.CreateTorus = function (options) {
  37722. var indices = [];
  37723. var positions = [];
  37724. var normals = [];
  37725. var uvs = [];
  37726. var diameter = options.diameter || 1;
  37727. var thickness = options.thickness || 0.5;
  37728. var tessellation = options.tessellation || 16;
  37729. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  37730. var stride = tessellation + 1;
  37731. for (var i = 0; i <= tessellation; i++) {
  37732. var u = i / tessellation;
  37733. var outerAngle = i * Math.PI * 2.0 / tessellation - Math.PI / 2.0;
  37734. var transform = BABYLON.Matrix.Translation(diameter / 2.0, 0, 0).multiply(BABYLON.Matrix.RotationY(outerAngle));
  37735. for (var j = 0; j <= tessellation; j++) {
  37736. var v = 1 - j / tessellation;
  37737. var innerAngle = j * Math.PI * 2.0 / tessellation + Math.PI;
  37738. var dx = Math.cos(innerAngle);
  37739. var dy = Math.sin(innerAngle);
  37740. // Create a vertex.
  37741. var normal = new BABYLON.Vector3(dx, dy, 0);
  37742. var position = normal.scale(thickness / 2);
  37743. var textureCoordinate = new BABYLON.Vector2(u, v);
  37744. position = BABYLON.Vector3.TransformCoordinates(position, transform);
  37745. normal = BABYLON.Vector3.TransformNormal(normal, transform);
  37746. positions.push(position.x, position.y, position.z);
  37747. normals.push(normal.x, normal.y, normal.z);
  37748. uvs.push(textureCoordinate.x, textureCoordinate.y);
  37749. // And create indices for two triangles.
  37750. var nextI = (i + 1) % stride;
  37751. var nextJ = (j + 1) % stride;
  37752. indices.push(i * stride + j);
  37753. indices.push(i * stride + nextJ);
  37754. indices.push(nextI * stride + j);
  37755. indices.push(i * stride + nextJ);
  37756. indices.push(nextI * stride + nextJ);
  37757. indices.push(nextI * stride + j);
  37758. }
  37759. }
  37760. // Sides
  37761. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  37762. // Result
  37763. var vertexData = new VertexData();
  37764. vertexData.indices = indices;
  37765. vertexData.positions = positions;
  37766. vertexData.normals = normals;
  37767. vertexData.uvs = uvs;
  37768. return vertexData;
  37769. };
  37770. /**
  37771. * Creates the VertexData of the LineSystem
  37772. * @param options an object used to set the following optional parameters for the LineSystem, required but can be empty
  37773. * - lines an array of lines, each line being an array of successive Vector3
  37774. * - colors an array of line colors, each of the line colors being an array of successive Color4, one per line point
  37775. * @returns the VertexData of the LineSystem
  37776. */
  37777. VertexData.CreateLineSystem = function (options) {
  37778. var indices = [];
  37779. var positions = [];
  37780. var lines = options.lines;
  37781. var colors = options.colors;
  37782. var vertexColors = [];
  37783. var idx = 0;
  37784. for (var l = 0; l < lines.length; l++) {
  37785. var points = lines[l];
  37786. for (var index = 0; index < points.length; index++) {
  37787. positions.push(points[index].x, points[index].y, points[index].z);
  37788. if (colors) {
  37789. var color = colors[l];
  37790. vertexColors.push(color[index].r, color[index].g, color[index].b, color[index].a);
  37791. }
  37792. if (index > 0) {
  37793. indices.push(idx - 1);
  37794. indices.push(idx);
  37795. }
  37796. idx++;
  37797. }
  37798. }
  37799. var vertexData = new VertexData();
  37800. vertexData.indices = indices;
  37801. vertexData.positions = positions;
  37802. if (colors) {
  37803. vertexData.colors = vertexColors;
  37804. }
  37805. return vertexData;
  37806. };
  37807. /**
  37808. * Create the VertexData for a DashedLines
  37809. * @param options an object used to set the following optional parameters for the DashedLines, required but can be empty
  37810. * - points an array successive Vector3
  37811. * - dashSize the size of the dashes relative to the dash number, optional, default 3
  37812. * - gapSize the size of the gap between two successive dashes relative to the dash number, optional, default 1
  37813. * - dashNb the intended total number of dashes, optional, default 200
  37814. * @returns the VertexData for the DashedLines
  37815. */
  37816. VertexData.CreateDashedLines = function (options) {
  37817. var dashSize = options.dashSize || 3;
  37818. var gapSize = options.gapSize || 1;
  37819. var dashNb = options.dashNb || 200;
  37820. var points = options.points;
  37821. var positions = new Array();
  37822. var indices = new Array();
  37823. var curvect = BABYLON.Vector3.Zero();
  37824. var lg = 0;
  37825. var nb = 0;
  37826. var shft = 0;
  37827. var dashshft = 0;
  37828. var curshft = 0;
  37829. var idx = 0;
  37830. var i = 0;
  37831. for (i = 0; i < points.length - 1; i++) {
  37832. points[i + 1].subtractToRef(points[i], curvect);
  37833. lg += curvect.length();
  37834. }
  37835. shft = lg / dashNb;
  37836. dashshft = dashSize * shft / (dashSize + gapSize);
  37837. for (i = 0; i < points.length - 1; i++) {
  37838. points[i + 1].subtractToRef(points[i], curvect);
  37839. nb = Math.floor(curvect.length() / shft);
  37840. curvect.normalize();
  37841. for (var j = 0; j < nb; j++) {
  37842. curshft = shft * j;
  37843. positions.push(points[i].x + curshft * curvect.x, points[i].y + curshft * curvect.y, points[i].z + curshft * curvect.z);
  37844. positions.push(points[i].x + (curshft + dashshft) * curvect.x, points[i].y + (curshft + dashshft) * curvect.y, points[i].z + (curshft + dashshft) * curvect.z);
  37845. indices.push(idx, idx + 1);
  37846. idx += 2;
  37847. }
  37848. }
  37849. // Result
  37850. var vertexData = new VertexData();
  37851. vertexData.positions = positions;
  37852. vertexData.indices = indices;
  37853. return vertexData;
  37854. };
  37855. /**
  37856. * Creates the VertexData for a Ground
  37857. * @param options an object used to set the following optional parameters for the Ground, required but can be empty
  37858. * - width the width (x direction) of the ground, optional, default 1
  37859. * - height the height (z direction) of the ground, optional, default 1
  37860. * - subdivisions the number of subdivisions per side, optional, default 1
  37861. * @returns the VertexData of the Ground
  37862. */
  37863. VertexData.CreateGround = function (options) {
  37864. var indices = [];
  37865. var positions = [];
  37866. var normals = [];
  37867. var uvs = [];
  37868. var row, col;
  37869. var width = options.width || 1;
  37870. var height = options.height || 1;
  37871. var subdivisionsX = options.subdivisionsX || options.subdivisions || 1;
  37872. var subdivisionsY = options.subdivisionsY || options.subdivisions || 1;
  37873. for (row = 0; row <= subdivisionsY; row++) {
  37874. for (col = 0; col <= subdivisionsX; col++) {
  37875. var position = new BABYLON.Vector3((col * width) / subdivisionsX - (width / 2.0), 0, ((subdivisionsY - row) * height) / subdivisionsY - (height / 2.0));
  37876. var normal = new BABYLON.Vector3(0, 1.0, 0);
  37877. positions.push(position.x, position.y, position.z);
  37878. normals.push(normal.x, normal.y, normal.z);
  37879. uvs.push(col / subdivisionsX, 1.0 - row / subdivisionsY);
  37880. }
  37881. }
  37882. for (row = 0; row < subdivisionsY; row++) {
  37883. for (col = 0; col < subdivisionsX; col++) {
  37884. indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));
  37885. indices.push(col + 1 + row * (subdivisionsX + 1));
  37886. indices.push(col + row * (subdivisionsX + 1));
  37887. indices.push(col + (row + 1) * (subdivisionsX + 1));
  37888. indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));
  37889. indices.push(col + row * (subdivisionsX + 1));
  37890. }
  37891. }
  37892. // Result
  37893. var vertexData = new VertexData();
  37894. vertexData.indices = indices;
  37895. vertexData.positions = positions;
  37896. vertexData.normals = normals;
  37897. vertexData.uvs = uvs;
  37898. return vertexData;
  37899. };
  37900. /**
  37901. * Creates the VertexData for a TiledGround by subdividing the ground into tiles
  37902. * @param options an object used to set the following optional parameters for the Ground, required but can be empty
  37903. * * xmin the ground minimum X coordinate, optional, default -1
  37904. * * zmin the ground minimum Z coordinate, optional, default -1
  37905. * * xmax the ground maximum X coordinate, optional, default 1
  37906. * * zmax the ground maximum Z coordinate, optional, default 1
  37907. * * subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}
  37908. * * precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}
  37909. * @returns the VertexData of the TiledGround
  37910. */
  37911. VertexData.CreateTiledGround = function (options) {
  37912. var xmin = (options.xmin !== undefined && options.xmin !== null) ? options.xmin : -1.0;
  37913. var zmin = (options.zmin !== undefined && options.zmin !== null) ? options.zmin : -1.0;
  37914. var xmax = (options.xmax !== undefined && options.xmax !== null) ? options.xmax : 1.0;
  37915. var zmax = (options.zmax !== undefined && options.zmax !== null) ? options.zmax : 1.0;
  37916. var subdivisions = options.subdivisions || { w: 1, h: 1 };
  37917. var precision = options.precision || { w: 1, h: 1 };
  37918. var indices = new Array();
  37919. var positions = new Array();
  37920. var normals = new Array();
  37921. var uvs = new Array();
  37922. var row, col, tileRow, tileCol;
  37923. subdivisions.h = (subdivisions.h < 1) ? 1 : subdivisions.h;
  37924. subdivisions.w = (subdivisions.w < 1) ? 1 : subdivisions.w;
  37925. precision.w = (precision.w < 1) ? 1 : precision.w;
  37926. precision.h = (precision.h < 1) ? 1 : precision.h;
  37927. var tileSize = {
  37928. 'w': (xmax - xmin) / subdivisions.w,
  37929. 'h': (zmax - zmin) / subdivisions.h
  37930. };
  37931. function applyTile(xTileMin, zTileMin, xTileMax, zTileMax) {
  37932. // Indices
  37933. var base = positions.length / 3;
  37934. var rowLength = precision.w + 1;
  37935. for (row = 0; row < precision.h; row++) {
  37936. for (col = 0; col < precision.w; col++) {
  37937. var square = [
  37938. base + col + row * rowLength,
  37939. base + (col + 1) + row * rowLength,
  37940. base + (col + 1) + (row + 1) * rowLength,
  37941. base + col + (row + 1) * rowLength
  37942. ];
  37943. indices.push(square[1]);
  37944. indices.push(square[2]);
  37945. indices.push(square[3]);
  37946. indices.push(square[0]);
  37947. indices.push(square[1]);
  37948. indices.push(square[3]);
  37949. }
  37950. }
  37951. // Position, normals and uvs
  37952. var position = BABYLON.Vector3.Zero();
  37953. var normal = new BABYLON.Vector3(0, 1.0, 0);
  37954. for (row = 0; row <= precision.h; row++) {
  37955. position.z = (row * (zTileMax - zTileMin)) / precision.h + zTileMin;
  37956. for (col = 0; col <= precision.w; col++) {
  37957. position.x = (col * (xTileMax - xTileMin)) / precision.w + xTileMin;
  37958. position.y = 0;
  37959. positions.push(position.x, position.y, position.z);
  37960. normals.push(normal.x, normal.y, normal.z);
  37961. uvs.push(col / precision.w, row / precision.h);
  37962. }
  37963. }
  37964. }
  37965. for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
  37966. for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
  37967. applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
  37968. }
  37969. }
  37970. // Result
  37971. var vertexData = new VertexData();
  37972. vertexData.indices = indices;
  37973. vertexData.positions = positions;
  37974. vertexData.normals = normals;
  37975. vertexData.uvs = uvs;
  37976. return vertexData;
  37977. };
  37978. /**
  37979. * Creates the VertexData of the Ground designed from a heightmap
  37980. * @param options an object used to set the following parameters for the Ground, required and provided by MeshBuilder.CreateGroundFromHeightMap
  37981. * * width the width (x direction) of the ground
  37982. * * height the height (z direction) of the ground
  37983. * * subdivisions the number of subdivisions per side
  37984. * * minHeight the minimum altitude on the ground, optional, default 0
  37985. * * maxHeight the maximum altitude on the ground, optional default 1
  37986. * * colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)
  37987. * * buffer the array holding the image color data
  37988. * * bufferWidth the width of image
  37989. * * bufferHeight the height of image
  37990. * @returns the VertexData of the Ground designed from a heightmap
  37991. */
  37992. VertexData.CreateGroundFromHeightMap = function (options) {
  37993. var indices = [];
  37994. var positions = [];
  37995. var normals = [];
  37996. var uvs = [];
  37997. var row, col;
  37998. var filter = options.colorFilter || new BABYLON.Color3(0.3, 0.59, 0.11);
  37999. // Vertices
  38000. for (row = 0; row <= options.subdivisions; row++) {
  38001. for (col = 0; col <= options.subdivisions; col++) {
  38002. var position = new BABYLON.Vector3((col * options.width) / options.subdivisions - (options.width / 2.0), 0, ((options.subdivisions - row) * options.height) / options.subdivisions - (options.height / 2.0));
  38003. // Compute height
  38004. var heightMapX = (((position.x + options.width / 2) / options.width) * (options.bufferWidth - 1)) | 0;
  38005. var heightMapY = ((1.0 - (position.z + options.height / 2) / options.height) * (options.bufferHeight - 1)) | 0;
  38006. var pos = (heightMapX + heightMapY * options.bufferWidth) * 4;
  38007. var r = options.buffer[pos] / 255.0;
  38008. var g = options.buffer[pos + 1] / 255.0;
  38009. var b = options.buffer[pos + 2] / 255.0;
  38010. var gradient = r * filter.r + g * filter.g + b * filter.b;
  38011. position.y = options.minHeight + (options.maxHeight - options.minHeight) * gradient;
  38012. // Add vertex
  38013. positions.push(position.x, position.y, position.z);
  38014. normals.push(0, 0, 0);
  38015. uvs.push(col / options.subdivisions, 1.0 - row / options.subdivisions);
  38016. }
  38017. }
  38018. // Indices
  38019. for (row = 0; row < options.subdivisions; row++) {
  38020. for (col = 0; col < options.subdivisions; col++) {
  38021. indices.push(col + 1 + (row + 1) * (options.subdivisions + 1));
  38022. indices.push(col + 1 + row * (options.subdivisions + 1));
  38023. indices.push(col + row * (options.subdivisions + 1));
  38024. indices.push(col + (row + 1) * (options.subdivisions + 1));
  38025. indices.push(col + 1 + (row + 1) * (options.subdivisions + 1));
  38026. indices.push(col + row * (options.subdivisions + 1));
  38027. }
  38028. }
  38029. // Normals
  38030. VertexData.ComputeNormals(positions, indices, normals);
  38031. // Result
  38032. var vertexData = new VertexData();
  38033. vertexData.indices = indices;
  38034. vertexData.positions = positions;
  38035. vertexData.normals = normals;
  38036. vertexData.uvs = uvs;
  38037. return vertexData;
  38038. };
  38039. /**
  38040. * Creates the VertexData for a Plane
  38041. * @param options an object used to set the following optional parameters for the plane, required but can be empty
  38042. * * size sets the width and height of the plane to the value of size, optional default 1
  38043. * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size
  38044. * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size
  38045. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38046. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38047. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38048. * @returns the VertexData of the box
  38049. */
  38050. VertexData.CreatePlane = function (options) {
  38051. var indices = [];
  38052. var positions = [];
  38053. var normals = [];
  38054. var uvs = [];
  38055. var width = options.width || options.size || 1;
  38056. var height = options.height || options.size || 1;
  38057. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38058. // Vertices
  38059. var halfWidth = width / 2.0;
  38060. var halfHeight = height / 2.0;
  38061. positions.push(-halfWidth, -halfHeight, 0);
  38062. normals.push(0, 0, -1.0);
  38063. uvs.push(0.0, 0.0);
  38064. positions.push(halfWidth, -halfHeight, 0);
  38065. normals.push(0, 0, -1.0);
  38066. uvs.push(1.0, 0.0);
  38067. positions.push(halfWidth, halfHeight, 0);
  38068. normals.push(0, 0, -1.0);
  38069. uvs.push(1.0, 1.0);
  38070. positions.push(-halfWidth, halfHeight, 0);
  38071. normals.push(0, 0, -1.0);
  38072. uvs.push(0.0, 1.0);
  38073. // Indices
  38074. indices.push(0);
  38075. indices.push(1);
  38076. indices.push(2);
  38077. indices.push(0);
  38078. indices.push(2);
  38079. indices.push(3);
  38080. // Sides
  38081. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  38082. // Result
  38083. var vertexData = new VertexData();
  38084. vertexData.indices = indices;
  38085. vertexData.positions = positions;
  38086. vertexData.normals = normals;
  38087. vertexData.uvs = uvs;
  38088. return vertexData;
  38089. };
  38090. /**
  38091. * Creates the VertexData of the Disc or regular Polygon
  38092. * @param options an object used to set the following optional parameters for the disc, required but can be empty
  38093. * * radius the radius of the disc, optional default 0.5
  38094. * * tessellation the number of polygon sides, optional, default 64
  38095. * * arc a number from 0 to 1, to create an unclosed polygon based on the fraction of the circumference given by the arc value, optional, default 1
  38096. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38097. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38098. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38099. * @returns the VertexData of the box
  38100. */
  38101. VertexData.CreateDisc = function (options) {
  38102. var positions = new Array();
  38103. var indices = new Array();
  38104. var normals = new Array();
  38105. var uvs = new Array();
  38106. var radius = options.radius || 0.5;
  38107. var tessellation = options.tessellation || 64;
  38108. var arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
  38109. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38110. // positions and uvs
  38111. positions.push(0, 0, 0); // disc center first
  38112. uvs.push(0.5, 0.5);
  38113. var theta = Math.PI * 2 * arc;
  38114. var step = theta / tessellation;
  38115. for (var a = 0; a < theta; a += step) {
  38116. var x = Math.cos(a);
  38117. var y = Math.sin(a);
  38118. var u = (x + 1) / 2;
  38119. var v = (1 - y) / 2;
  38120. positions.push(radius * x, radius * y, 0);
  38121. uvs.push(u, v);
  38122. }
  38123. if (arc === 1) {
  38124. positions.push(positions[3], positions[4], positions[5]); // close the circle
  38125. uvs.push(uvs[2], uvs[3]);
  38126. }
  38127. //indices
  38128. var vertexNb = positions.length / 3;
  38129. for (var i = 1; i < vertexNb - 1; i++) {
  38130. indices.push(i + 1, 0, i);
  38131. }
  38132. // result
  38133. VertexData.ComputeNormals(positions, indices, normals);
  38134. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  38135. var vertexData = new VertexData();
  38136. vertexData.indices = indices;
  38137. vertexData.positions = positions;
  38138. vertexData.normals = normals;
  38139. vertexData.uvs = uvs;
  38140. return vertexData;
  38141. };
  38142. /**
  38143. * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()
  38144. * All parameters are provided by MeshBuilder.CreatePolygon as needed
  38145. * @param polygon a mesh built from polygonTriangulation.build()
  38146. * @param sideOrientation takes the values BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38147. * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively
  38148. * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively
  38149. * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38150. * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38151. * @returns the VertexData of the Polygon
  38152. */
  38153. VertexData.CreatePolygon = function (polygon, sideOrientation, fUV, fColors, frontUVs, backUVs) {
  38154. var faceUV = fUV || new Array(3);
  38155. var faceColors = fColors;
  38156. var colors = [];
  38157. // default face colors and UV if undefined
  38158. for (var f = 0; f < 3; f++) {
  38159. if (faceUV[f] === undefined) {
  38160. faceUV[f] = new BABYLON.Vector4(0, 0, 1, 1);
  38161. }
  38162. if (faceColors && faceColors[f] === undefined) {
  38163. faceColors[f] = new BABYLON.Color4(1, 1, 1, 1);
  38164. }
  38165. }
  38166. var positions = polygon.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  38167. var normals = polygon.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  38168. var uvs = polygon.getVerticesData(BABYLON.VertexBuffer.UVKind);
  38169. var indices = polygon.getIndices();
  38170. // set face colours and textures
  38171. var idx = 0;
  38172. var face = 0;
  38173. for (var index = 0; index < normals.length; index += 3) {
  38174. //Edge Face no. 1
  38175. if (Math.abs(normals[index + 1]) < 0.001) {
  38176. face = 1;
  38177. }
  38178. //Top Face no. 0
  38179. if (Math.abs(normals[index + 1] - 1) < 0.001) {
  38180. face = 0;
  38181. }
  38182. //Bottom Face no. 2
  38183. if (Math.abs(normals[index + 1] + 1) < 0.001) {
  38184. face = 2;
  38185. }
  38186. idx = index / 3;
  38187. uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;
  38188. uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;
  38189. if (faceColors) {
  38190. colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);
  38191. }
  38192. }
  38193. // sides
  38194. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);
  38195. // Result
  38196. var vertexData = new VertexData();
  38197. vertexData.indices = indices;
  38198. vertexData.positions = positions;
  38199. vertexData.normals = normals;
  38200. vertexData.uvs = uvs;
  38201. if (faceColors) {
  38202. var totalColors = (sideOrientation === BABYLON.Mesh.DOUBLESIDE) ? colors.concat(colors) : colors;
  38203. vertexData.colors = totalColors;
  38204. }
  38205. return vertexData;
  38206. };
  38207. /**
  38208. * Creates the VertexData of the IcoSphere
  38209. * @param options an object used to set the following optional parameters for the IcoSphere, required but can be empty
  38210. * * radius the radius of the IcoSphere, optional default 1
  38211. * * radiusX allows stretching in the x direction, optional, default radius
  38212. * * radiusY allows stretching in the y direction, optional, default radius
  38213. * * radiusZ allows stretching in the z direction, optional, default radius
  38214. * * flat when true creates a flat shaded mesh, optional, default true
  38215. * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4
  38216. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38217. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38218. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38219. * @returns the VertexData of the IcoSphere
  38220. */
  38221. VertexData.CreateIcoSphere = function (options) {
  38222. var sideOrientation = options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38223. var radius = options.radius || 1;
  38224. var flat = (options.flat === undefined) ? true : options.flat;
  38225. var subdivisions = options.subdivisions || 4;
  38226. var radiusX = options.radiusX || radius;
  38227. var radiusY = options.radiusY || radius;
  38228. var radiusZ = options.radiusZ || radius;
  38229. var t = (1 + Math.sqrt(5)) / 2;
  38230. // 12 vertex x,y,z
  38231. var ico_vertices = [
  38232. -1, t, -0, 1, t, 0, -1, -t, 0, 1, -t, 0,
  38233. 0, -1, -t, 0, 1, -t, 0, -1, t, 0, 1, t,
  38234. t, 0, 1, t, 0, -1, -t, 0, 1, -t, 0, -1 // v8-11
  38235. ];
  38236. // index of 3 vertex makes a face of icopshere
  38237. var ico_indices = [
  38238. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 12, 22, 23,
  38239. 1, 5, 20, 5, 11, 4, 23, 22, 13, 22, 18, 6, 7, 1, 8,
  38240. 14, 21, 4, 14, 4, 2, 16, 13, 6, 15, 6, 19, 3, 8, 9,
  38241. 4, 21, 5, 13, 17, 23, 6, 13, 22, 19, 6, 18, 9, 8, 1
  38242. ];
  38243. // vertex for uv have aliased position, not for UV
  38244. var vertices_unalias_id = [
  38245. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  38246. // vertex alias
  38247. 0,
  38248. 2,
  38249. 3,
  38250. 3,
  38251. 3,
  38252. 4,
  38253. 7,
  38254. 8,
  38255. 9,
  38256. 9,
  38257. 10,
  38258. 11 // 23: B + 12
  38259. ];
  38260. // uv as integer step (not pixels !)
  38261. var ico_vertexuv = [
  38262. 5, 1, 3, 1, 6, 4, 0, 0,
  38263. 5, 3, 4, 2, 2, 2, 4, 0,
  38264. 2, 0, 1, 1, 6, 0, 6, 2,
  38265. // vertex alias (for same vertex on different faces)
  38266. 0, 4,
  38267. 3, 3,
  38268. 4, 4,
  38269. 3, 1,
  38270. 4, 2,
  38271. 4, 4,
  38272. 0, 2,
  38273. 1, 1,
  38274. 2, 2,
  38275. 3, 3,
  38276. 1, 3,
  38277. 2, 4 // 23: B + 12
  38278. ];
  38279. // Vertices[0, 1, ...9, A, B] : position on UV plane
  38280. // '+' indicate duplicate position to be fixed (3,9:0,2,3,4,7,8,A,B)
  38281. // First island of uv mapping
  38282. // v = 4h 3+ 2
  38283. // v = 3h 9+ 4
  38284. // v = 2h 9+ 5 B
  38285. // v = 1h 9 1 0
  38286. // v = 0h 3 8 7 A
  38287. // u = 0 1 2 3 4 5 6 *a
  38288. // Second island of uv mapping
  38289. // v = 4h 0+ B+ 4+
  38290. // v = 3h A+ 2+
  38291. // v = 2h 7+ 6 3+
  38292. // v = 1h 8+ 3+
  38293. // v = 0h
  38294. // u = 0 1 2 3 4 5 6 *a
  38295. // Face layout on texture UV mapping
  38296. // ============
  38297. // \ 4 /\ 16 / ======
  38298. // \ / \ / /\ 11 /
  38299. // \/ 7 \/ / \ /
  38300. // ======= / 10 \/
  38301. // /\ 17 /\ =======
  38302. // / \ / \ \ 15 /\
  38303. // / 8 \/ 12 \ \ / \
  38304. // ============ \/ 6 \
  38305. // \ 18 /\ ============
  38306. // \ / \ \ 5 /\ 0 /
  38307. // \/ 13 \ \ / \ /
  38308. // ======= \/ 1 \/
  38309. // =============
  38310. // /\ 19 /\ 2 /\
  38311. // / \ / \ / \
  38312. // / 14 \/ 9 \/ 3 \
  38313. // ===================
  38314. // uv step is u:1 or 0.5, v:cos(30)=sqrt(3)/2, ratio approx is 84/97
  38315. var ustep = 138 / 1024;
  38316. var vstep = 239 / 1024;
  38317. var uoffset = 60 / 1024;
  38318. var voffset = 26 / 1024;
  38319. // Second island should have margin, not to touch the first island
  38320. // avoid any borderline artefact in pixel rounding
  38321. var island_u_offset = -40 / 1024;
  38322. var island_v_offset = +20 / 1024;
  38323. // face is either island 0 or 1 :
  38324. // second island is for faces : [4, 7, 8, 12, 13, 16, 17, 18]
  38325. var island = [
  38326. 0, 0, 0, 0, 1,
  38327. 0, 0, 1, 1, 0,
  38328. 0, 0, 1, 1, 0,
  38329. 0, 1, 1, 1, 0 // 15 - 19
  38330. ];
  38331. var indices = new Array();
  38332. var positions = new Array();
  38333. var normals = new Array();
  38334. var uvs = new Array();
  38335. var current_indice = 0;
  38336. // prepare array of 3 vector (empty) (to be worked in place, shared for each face)
  38337. var face_vertex_pos = new Array(3);
  38338. var face_vertex_uv = new Array(3);
  38339. var v012;
  38340. for (v012 = 0; v012 < 3; v012++) {
  38341. face_vertex_pos[v012] = BABYLON.Vector3.Zero();
  38342. face_vertex_uv[v012] = BABYLON.Vector2.Zero();
  38343. }
  38344. // create all with normals
  38345. for (var face = 0; face < 20; face++) {
  38346. // 3 vertex per face
  38347. for (v012 = 0; v012 < 3; v012++) {
  38348. // look up vertex 0,1,2 to its index in 0 to 11 (or 23 including alias)
  38349. var v_id = ico_indices[3 * face + v012];
  38350. // vertex have 3D position (x,y,z)
  38351. face_vertex_pos[v012].copyFromFloats(ico_vertices[3 * vertices_unalias_id[v_id]], ico_vertices[3 * vertices_unalias_id[v_id] + 1], ico_vertices[3 * vertices_unalias_id[v_id] + 2]);
  38352. // Normalize to get normal, then scale to radius
  38353. face_vertex_pos[v012].normalize().scaleInPlace(radius);
  38354. // uv Coordinates from vertex ID
  38355. face_vertex_uv[v012].copyFromFloats(ico_vertexuv[2 * v_id] * ustep + uoffset + island[face] * island_u_offset, ico_vertexuv[2 * v_id + 1] * vstep + voffset + island[face] * island_v_offset);
  38356. }
  38357. // Subdivide the face (interpolate pos, norm, uv)
  38358. // - pos is linear interpolation, then projected to sphere (converge polyhedron to sphere)
  38359. // - norm is linear interpolation of vertex corner normal
  38360. // (to be checked if better to re-calc from face vertex, or if approximation is OK ??? )
  38361. // - uv is linear interpolation
  38362. //
  38363. // Topology is as below for sub-divide by 2
  38364. // vertex shown as v0,v1,v2
  38365. // interp index is i1 to progress in range [v0,v1[
  38366. // interp index is i2 to progress in range [v0,v2[
  38367. // face index as (i1,i2) for /\ : (i1,i2),(i1+1,i2),(i1,i2+1)
  38368. // and (i1,i2)' for \/ : (i1+1,i2),(i1+1,i2+1),(i1,i2+1)
  38369. //
  38370. //
  38371. // i2 v2
  38372. // ^ ^
  38373. // / / \
  38374. // / / \
  38375. // / / \
  38376. // / / (0,1) \
  38377. // / #---------\
  38378. // / / \ (0,0)'/ \
  38379. // / / \ / \
  38380. // / / \ / \
  38381. // / / (0,0) \ / (1,0) \
  38382. // / #---------#---------\
  38383. // v0 v1
  38384. //
  38385. // --------------------> i1
  38386. //
  38387. // interp of (i1,i2):
  38388. // along i2 : x0=lerp(v0,v2, i2/S) <---> x1=lerp(v1,v2, i2/S)
  38389. // along i1 : lerp(x0,x1, i1/(S-i2))
  38390. //
  38391. // centroid of triangle is needed to get help normal computation
  38392. // (c1,c2) are used for centroid location
  38393. var interp_vertex = function (i1, i2, c1, c2) {
  38394. // vertex is interpolated from
  38395. // - face_vertex_pos[0..2]
  38396. // - face_vertex_uv[0..2]
  38397. var pos_x0 = BABYLON.Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], i2 / subdivisions);
  38398. var pos_x1 = BABYLON.Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], i2 / subdivisions);
  38399. var pos_interp = (subdivisions === i2) ? face_vertex_pos[2] : BABYLON.Vector3.Lerp(pos_x0, pos_x1, i1 / (subdivisions - i2));
  38400. pos_interp.normalize();
  38401. var vertex_normal;
  38402. if (flat) {
  38403. // in flat mode, recalculate normal as face centroid normal
  38404. var centroid_x0 = BABYLON.Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], c2 / subdivisions);
  38405. var centroid_x1 = BABYLON.Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], c2 / subdivisions);
  38406. vertex_normal = BABYLON.Vector3.Lerp(centroid_x0, centroid_x1, c1 / (subdivisions - c2));
  38407. }
  38408. else {
  38409. // in smooth mode, recalculate normal from each single vertex position
  38410. vertex_normal = new BABYLON.Vector3(pos_interp.x, pos_interp.y, pos_interp.z);
  38411. }
  38412. // Vertex normal need correction due to X,Y,Z radius scaling
  38413. vertex_normal.x /= radiusX;
  38414. vertex_normal.y /= radiusY;
  38415. vertex_normal.z /= radiusZ;
  38416. vertex_normal.normalize();
  38417. var uv_x0 = BABYLON.Vector2.Lerp(face_vertex_uv[0], face_vertex_uv[2], i2 / subdivisions);
  38418. var uv_x1 = BABYLON.Vector2.Lerp(face_vertex_uv[1], face_vertex_uv[2], i2 / subdivisions);
  38419. var uv_interp = (subdivisions === i2) ? face_vertex_uv[2] : BABYLON.Vector2.Lerp(uv_x0, uv_x1, i1 / (subdivisions - i2));
  38420. positions.push(pos_interp.x * radiusX, pos_interp.y * radiusY, pos_interp.z * radiusZ);
  38421. normals.push(vertex_normal.x, vertex_normal.y, vertex_normal.z);
  38422. uvs.push(uv_interp.x, uv_interp.y);
  38423. // push each vertex has member of a face
  38424. // Same vertex can bleong to multiple face, it is pushed multiple time (duplicate vertex are present)
  38425. indices.push(current_indice);
  38426. current_indice++;
  38427. };
  38428. for (var i2 = 0; i2 < subdivisions; i2++) {
  38429. for (var i1 = 0; i1 + i2 < subdivisions; i1++) {
  38430. // face : (i1,i2) for /\ :
  38431. // interp for : (i1,i2),(i1+1,i2),(i1,i2+1)
  38432. interp_vertex(i1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);
  38433. interp_vertex(i1 + 1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);
  38434. interp_vertex(i1, i2 + 1, i1 + 1.0 / 3, i2 + 1.0 / 3);
  38435. if (i1 + i2 + 1 < subdivisions) {
  38436. // face : (i1,i2)' for \/ :
  38437. // interp for (i1+1,i2),(i1+1,i2+1),(i1,i2+1)
  38438. interp_vertex(i1 + 1, i2, i1 + 2.0 / 3, i2 + 2.0 / 3);
  38439. interp_vertex(i1 + 1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);
  38440. interp_vertex(i1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);
  38441. }
  38442. }
  38443. }
  38444. }
  38445. // Sides
  38446. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  38447. // Result
  38448. var vertexData = new VertexData();
  38449. vertexData.indices = indices;
  38450. vertexData.positions = positions;
  38451. vertexData.normals = normals;
  38452. vertexData.uvs = uvs;
  38453. return vertexData;
  38454. };
  38455. // inspired from // http://stemkoski.github.io/Three.js/Polyhedra.html
  38456. /**
  38457. * Creates the VertexData for a Polyhedron
  38458. * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty
  38459. * * type provided types are:
  38460. * * 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)
  38461. * * 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)
  38462. * * size the size of the IcoSphere, optional default 1
  38463. * * sizeX allows stretching in the x direction, optional, default size
  38464. * * sizeY allows stretching in the y direction, optional, default size
  38465. * * sizeZ allows stretching in the z direction, optional, default size
  38466. * * custom a number that overwrites the type to create from an extended set of polyhedron from https://www.babylonjs-playground.com/#21QRSK#15 with minimised editor
  38467. * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively
  38468. * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively
  38469. * * flat when true creates a flat shaded mesh, optional, default true
  38470. * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4
  38471. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38472. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38473. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38474. * @returns the VertexData of the Polyhedron
  38475. */
  38476. VertexData.CreatePolyhedron = function (options) {
  38477. // provided polyhedron types :
  38478. // 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)
  38479. // 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)
  38480. var polyhedra = [];
  38481. polyhedra[0] = { vertex: [[0, 0, 1.732051], [1.632993, 0, -0.5773503], [-0.8164966, 1.414214, -0.5773503], [-0.8164966, -1.414214, -0.5773503]], face: [[0, 1, 2], [0, 2, 3], [0, 3, 1], [1, 3, 2]] };
  38482. polyhedra[1] = { vertex: [[0, 0, 1.414214], [1.414214, 0, 0], [0, 1.414214, 0], [-1.414214, 0, 0], [0, -1.414214, 0], [0, 0, -1.414214]], face: [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [3, 5, 4]] };
  38483. polyhedra[2] = {
  38484. vertex: [[0, 0, 1.070466], [0.7136442, 0, 0.7978784], [-0.3568221, 0.618034, 0.7978784], [-0.3568221, -0.618034, 0.7978784], [0.7978784, 0.618034, 0.3568221], [0.7978784, -0.618034, 0.3568221], [-0.9341724, 0.381966, 0.3568221], [0.1362939, 1, 0.3568221], [0.1362939, -1, 0.3568221], [-0.9341724, -0.381966, 0.3568221], [0.9341724, 0.381966, -0.3568221], [0.9341724, -0.381966, -0.3568221], [-0.7978784, 0.618034, -0.3568221], [-0.1362939, 1, -0.3568221], [-0.1362939, -1, -0.3568221], [-0.7978784, -0.618034, -0.3568221], [0.3568221, 0.618034, -0.7978784], [0.3568221, -0.618034, -0.7978784], [-0.7136442, 0, -0.7978784], [0, 0, -1.070466]],
  38485. face: [[0, 1, 4, 7, 2], [0, 2, 6, 9, 3], [0, 3, 8, 5, 1], [1, 5, 11, 10, 4], [2, 7, 13, 12, 6], [3, 9, 15, 14, 8], [4, 10, 16, 13, 7], [5, 8, 14, 17, 11], [6, 12, 18, 15, 9], [10, 11, 17, 19, 16], [12, 13, 16, 19, 18], [14, 15, 18, 19, 17]]
  38486. };
  38487. polyhedra[3] = {
  38488. vertex: [[0, 0, 1.175571], [1.051462, 0, 0.5257311], [0.3249197, 1, 0.5257311], [-0.8506508, 0.618034, 0.5257311], [-0.8506508, -0.618034, 0.5257311], [0.3249197, -1, 0.5257311], [0.8506508, 0.618034, -0.5257311], [0.8506508, -0.618034, -0.5257311], [-0.3249197, 1, -0.5257311], [-1.051462, 0, -0.5257311], [-0.3249197, -1, -0.5257311], [0, 0, -1.175571]],
  38489. face: [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 5, 7], [1, 7, 6], [1, 6, 2], [2, 6, 8], [2, 8, 3], [3, 8, 9], [3, 9, 4], [4, 9, 10], [4, 10, 5], [5, 10, 7], [6, 7, 11], [6, 11, 8], [7, 10, 11], [8, 11, 9], [9, 11, 10]]
  38490. };
  38491. polyhedra[4] = {
  38492. vertex: [[0, 0, 1.070722], [0.7148135, 0, 0.7971752], [-0.104682, 0.7071068, 0.7971752], [-0.6841528, 0.2071068, 0.7971752], [-0.104682, -0.7071068, 0.7971752], [0.6101315, 0.7071068, 0.5236279], [1.04156, 0.2071068, 0.1367736], [0.6101315, -0.7071068, 0.5236279], [-0.3574067, 1, 0.1367736], [-0.7888348, -0.5, 0.5236279], [-0.9368776, 0.5, 0.1367736], [-0.3574067, -1, 0.1367736], [0.3574067, 1, -0.1367736], [0.9368776, -0.5, -0.1367736], [0.7888348, 0.5, -0.5236279], [0.3574067, -1, -0.1367736], [-0.6101315, 0.7071068, -0.5236279], [-1.04156, -0.2071068, -0.1367736], [-0.6101315, -0.7071068, -0.5236279], [0.104682, 0.7071068, -0.7971752], [0.6841528, -0.2071068, -0.7971752], [0.104682, -0.7071068, -0.7971752], [-0.7148135, 0, -0.7971752], [0, 0, -1.070722]],
  38493. face: [[0, 2, 3], [1, 6, 5], [4, 9, 11], [7, 15, 13], [8, 16, 10], [12, 14, 19], [17, 22, 18], [20, 21, 23], [0, 1, 5, 2], [0, 3, 9, 4], [0, 4, 7, 1], [1, 7, 13, 6], [2, 5, 12, 8], [2, 8, 10, 3], [3, 10, 17, 9], [4, 11, 15, 7], [5, 6, 14, 12], [6, 13, 20, 14], [8, 12, 19, 16], [9, 17, 18, 11], [10, 16, 22, 17], [11, 18, 21, 15], [13, 15, 21, 20], [14, 20, 23, 19], [16, 19, 23, 22], [18, 22, 23, 21]]
  38494. };
  38495. polyhedra[5] = { vertex: [[0, 0, 1.322876], [1.309307, 0, 0.1889822], [-0.9819805, 0.8660254, 0.1889822], [0.1636634, -1.299038, 0.1889822], [0.3273268, 0.8660254, -0.9449112], [-0.8183171, -0.4330127, -0.9449112]], face: [[0, 3, 1], [2, 4, 5], [0, 1, 4, 2], [0, 2, 5, 3], [1, 3, 5, 4]] };
  38496. polyhedra[6] = { vertex: [[0, 0, 1.159953], [1.013464, 0, 0.5642542], [-0.3501431, 0.9510565, 0.5642542], [-0.7715208, -0.6571639, 0.5642542], [0.6633206, 0.9510565, -0.03144481], [0.8682979, -0.6571639, -0.3996071], [-1.121664, 0.2938926, -0.03144481], [-0.2348831, -1.063314, -0.3996071], [0.5181548, 0.2938926, -0.9953061], [-0.5850262, -0.112257, -0.9953061]], face: [[0, 1, 4, 2], [0, 2, 6, 3], [1, 5, 8, 4], [3, 6, 9, 7], [5, 7, 9, 8], [0, 3, 7, 5, 1], [2, 4, 8, 9, 6]] };
  38497. polyhedra[7] = { vertex: [[0, 0, 1.118034], [0.8944272, 0, 0.6708204], [-0.2236068, 0.8660254, 0.6708204], [-0.7826238, -0.4330127, 0.6708204], [0.6708204, 0.8660254, 0.2236068], [1.006231, -0.4330127, -0.2236068], [-1.006231, 0.4330127, 0.2236068], [-0.6708204, -0.8660254, -0.2236068], [0.7826238, 0.4330127, -0.6708204], [0.2236068, -0.8660254, -0.6708204], [-0.8944272, 0, -0.6708204], [0, 0, -1.118034]], face: [[0, 1, 4, 2], [0, 2, 6, 3], [1, 5, 8, 4], [3, 6, 10, 7], [5, 9, 11, 8], [7, 10, 11, 9], [0, 3, 7, 9, 5, 1], [2, 4, 8, 11, 10, 6]] };
  38498. polyhedra[8] = { vertex: [[-0.729665, 0.670121, 0.319155], [-0.655235, -0.29213, -0.754096], [-0.093922, -0.607123, 0.537818], [0.702196, 0.595691, 0.485187], [0.776626, -0.36656, -0.588064]], face: [[1, 4, 2], [0, 1, 2], [3, 0, 2], [4, 3, 2], [4, 1, 0, 3]] };
  38499. polyhedra[9] = { vertex: [[-0.868849, -0.100041, 0.61257], [-0.329458, 0.976099, 0.28078], [-0.26629, -0.013796, -0.477654], [-0.13392, -1.034115, 0.229829], [0.738834, 0.707117, -0.307018], [0.859683, -0.535264, -0.338508]], face: [[3, 0, 2], [5, 3, 2], [4, 5, 2], [1, 4, 2], [0, 1, 2], [0, 3, 5, 4, 1]] };
  38500. polyhedra[10] = { vertex: [[-0.610389, 0.243975, 0.531213], [-0.187812, -0.48795, -0.664016], [-0.187812, 0.9759, -0.664016], [0.187812, -0.9759, 0.664016], [0.798201, 0.243975, 0.132803]], face: [[1, 3, 0], [3, 4, 0], [3, 1, 4], [0, 2, 1], [0, 4, 2], [2, 4, 1]] };
  38501. polyhedra[11] = { vertex: [[-1.028778, 0.392027, -0.048786], [-0.640503, -0.646161, 0.621837], [-0.125162, -0.395663, -0.540059], [0.004683, 0.888447, -0.651988], [0.125161, 0.395663, 0.540059], [0.632925, -0.791376, 0.433102], [1.031672, 0.157063, -0.354165]], face: [[3, 2, 0], [2, 1, 0], [2, 5, 1], [0, 4, 3], [0, 1, 4], [4, 1, 5], [2, 3, 6], [3, 4, 6], [5, 2, 6], [4, 5, 6]] };
  38502. polyhedra[12] = { vertex: [[-0.669867, 0.334933, -0.529576], [-0.669867, 0.334933, 0.529577], [-0.4043, 1.212901, 0], [-0.334933, -0.669867, -0.529576], [-0.334933, -0.669867, 0.529577], [0.334933, 0.669867, -0.529576], [0.334933, 0.669867, 0.529577], [0.4043, -1.212901, 0], [0.669867, -0.334933, -0.529576], [0.669867, -0.334933, 0.529577]], face: [[8, 9, 7], [6, 5, 2], [3, 8, 7], [5, 0, 2], [4, 3, 7], [0, 1, 2], [9, 4, 7], [1, 6, 2], [9, 8, 5, 6], [8, 3, 0, 5], [3, 4, 1, 0], [4, 9, 6, 1]] };
  38503. polyhedra[13] = { vertex: [[-0.931836, 0.219976, -0.264632], [-0.636706, 0.318353, 0.692816], [-0.613483, -0.735083, -0.264632], [-0.326545, 0.979634, 0], [-0.318353, -0.636706, 0.692816], [-0.159176, 0.477529, -0.856368], [0.159176, -0.477529, -0.856368], [0.318353, 0.636706, 0.692816], [0.326545, -0.979634, 0], [0.613482, 0.735082, -0.264632], [0.636706, -0.318353, 0.692816], [0.931835, -0.219977, -0.264632]], face: [[11, 10, 8], [7, 9, 3], [6, 11, 8], [9, 5, 3], [2, 6, 8], [5, 0, 3], [4, 2, 8], [0, 1, 3], [10, 4, 8], [1, 7, 3], [10, 11, 9, 7], [11, 6, 5, 9], [6, 2, 0, 5], [2, 4, 1, 0], [4, 10, 7, 1]] };
  38504. polyhedra[14] = {
  38505. vertex: [[-0.93465, 0.300459, -0.271185], [-0.838689, -0.260219, -0.516017], [-0.711319, 0.717591, 0.128359], [-0.710334, -0.156922, 0.080946], [-0.599799, 0.556003, -0.725148], [-0.503838, -0.004675, -0.969981], [-0.487004, 0.26021, 0.48049], [-0.460089, -0.750282, -0.512622], [-0.376468, 0.973135, -0.325605], [-0.331735, -0.646985, 0.084342], [-0.254001, 0.831847, 0.530001], [-0.125239, -0.494738, -0.966586], [0.029622, 0.027949, 0.730817], [0.056536, -0.982543, -0.262295], [0.08085, 1.087391, 0.076037], [0.125583, -0.532729, 0.485984], [0.262625, 0.599586, 0.780328], [0.391387, -0.726999, -0.716259], [0.513854, -0.868287, 0.139347], [0.597475, 0.85513, 0.326364], [0.641224, 0.109523, 0.783723], [0.737185, -0.451155, 0.538891], [0.848705, -0.612742, -0.314616], [0.976075, 0.365067, 0.32976], [1.072036, -0.19561, 0.084927]],
  38506. face: [[15, 18, 21], [12, 20, 16], [6, 10, 2], [3, 0, 1], [9, 7, 13], [2, 8, 4, 0], [0, 4, 5, 1], [1, 5, 11, 7], [7, 11, 17, 13], [13, 17, 22, 18], [18, 22, 24, 21], [21, 24, 23, 20], [20, 23, 19, 16], [16, 19, 14, 10], [10, 14, 8, 2], [15, 9, 13, 18], [12, 15, 21, 20], [6, 12, 16, 10], [3, 6, 2, 0], [9, 3, 1, 7], [9, 15, 12, 6, 3], [22, 17, 11, 5, 4, 8, 14, 19, 23, 24]]
  38507. };
  38508. var type = options.type && (options.type < 0 || options.type >= polyhedra.length) ? 0 : options.type || 0;
  38509. var size = options.size;
  38510. var sizeX = options.sizeX || size || 1;
  38511. var sizeY = options.sizeY || size || 1;
  38512. var sizeZ = options.sizeZ || size || 1;
  38513. var data = options.custom || polyhedra[type];
  38514. var nbfaces = data.face.length;
  38515. var faceUV = options.faceUV || new Array(nbfaces);
  38516. var faceColors = options.faceColors;
  38517. var flat = (options.flat === undefined) ? true : options.flat;
  38518. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38519. var positions = new Array();
  38520. var indices = new Array();
  38521. var normals = new Array();
  38522. var uvs = new Array();
  38523. var colors = new Array();
  38524. var index = 0;
  38525. var faceIdx = 0; // face cursor in the array "indexes"
  38526. var indexes = new Array();
  38527. var i = 0;
  38528. var f = 0;
  38529. var u, v, ang, x, y, tmp;
  38530. // default face colors and UV if undefined
  38531. if (flat) {
  38532. for (f = 0; f < nbfaces; f++) {
  38533. if (faceColors && faceColors[f] === undefined) {
  38534. faceColors[f] = new BABYLON.Color4(1, 1, 1, 1);
  38535. }
  38536. if (faceUV && faceUV[f] === undefined) {
  38537. faceUV[f] = new BABYLON.Vector4(0, 0, 1, 1);
  38538. }
  38539. }
  38540. }
  38541. if (!flat) {
  38542. for (i = 0; i < data.vertex.length; i++) {
  38543. positions.push(data.vertex[i][0] * sizeX, data.vertex[i][1] * sizeY, data.vertex[i][2] * sizeZ);
  38544. uvs.push(0, 0);
  38545. }
  38546. for (f = 0; f < nbfaces; f++) {
  38547. for (i = 0; i < data.face[f].length - 2; i++) {
  38548. indices.push(data.face[f][0], data.face[f][i + 2], data.face[f][i + 1]);
  38549. }
  38550. }
  38551. }
  38552. else {
  38553. for (f = 0; f < nbfaces; f++) {
  38554. var fl = data.face[f].length; // number of vertices of the current face
  38555. ang = 2 * Math.PI / fl;
  38556. x = 0.5 * Math.tan(ang / 2);
  38557. y = 0.5;
  38558. // positions, uvs, colors
  38559. for (i = 0; i < fl; i++) {
  38560. // positions
  38561. positions.push(data.vertex[data.face[f][i]][0] * sizeX, data.vertex[data.face[f][i]][1] * sizeY, data.vertex[data.face[f][i]][2] * sizeZ);
  38562. indexes.push(index);
  38563. index++;
  38564. // uvs
  38565. u = faceUV[f].x + (faceUV[f].z - faceUV[f].x) * (0.5 + x);
  38566. v = faceUV[f].y + (faceUV[f].w - faceUV[f].y) * (y - 0.5);
  38567. uvs.push(u, v);
  38568. tmp = x * Math.cos(ang) - y * Math.sin(ang);
  38569. y = x * Math.sin(ang) + y * Math.cos(ang);
  38570. x = tmp;
  38571. // colors
  38572. if (faceColors) {
  38573. colors.push(faceColors[f].r, faceColors[f].g, faceColors[f].b, faceColors[f].a);
  38574. }
  38575. }
  38576. // indices from indexes
  38577. for (i = 0; i < fl - 2; i++) {
  38578. indices.push(indexes[0 + faceIdx], indexes[i + 2 + faceIdx], indexes[i + 1 + faceIdx]);
  38579. }
  38580. faceIdx += fl;
  38581. }
  38582. }
  38583. VertexData.ComputeNormals(positions, indices, normals);
  38584. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  38585. var vertexData = new VertexData();
  38586. vertexData.positions = positions;
  38587. vertexData.indices = indices;
  38588. vertexData.normals = normals;
  38589. vertexData.uvs = uvs;
  38590. if (faceColors && flat) {
  38591. vertexData.colors = colors;
  38592. }
  38593. return vertexData;
  38594. };
  38595. // based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  38596. /**
  38597. * Creates the VertexData for a TorusKnot
  38598. * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty
  38599. * * radius the radius of the torus knot, optional, default 2
  38600. * * tube the thickness of the tube, optional, default 0.5
  38601. * * radialSegments the number of sides on each tube segments, optional, default 32
  38602. * * tubularSegments the number of tubes to decompose the knot into, optional, default 32
  38603. * * p the number of windings around the z axis, optional, default 2
  38604. * * q the number of windings around the x axis, optional, default 3
  38605. * * sideOrientation optional and takes the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  38606. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  38607. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  38608. * @returns the VertexData of the Torus Knot
  38609. */
  38610. VertexData.CreateTorusKnot = function (options) {
  38611. var indices = new Array();
  38612. var positions = new Array();
  38613. var normals = new Array();
  38614. var uvs = new Array();
  38615. var radius = options.radius || 2;
  38616. var tube = options.tube || 0.5;
  38617. var radialSegments = options.radialSegments || 32;
  38618. var tubularSegments = options.tubularSegments || 32;
  38619. var p = options.p || 2;
  38620. var q = options.q || 3;
  38621. var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38622. // Helper
  38623. var getPos = function (angle) {
  38624. var cu = Math.cos(angle);
  38625. var su = Math.sin(angle);
  38626. var quOverP = q / p * angle;
  38627. var cs = Math.cos(quOverP);
  38628. var tx = radius * (2 + cs) * 0.5 * cu;
  38629. var ty = radius * (2 + cs) * su * 0.5;
  38630. var tz = radius * Math.sin(quOverP) * 0.5;
  38631. return new BABYLON.Vector3(tx, ty, tz);
  38632. };
  38633. // Vertices
  38634. var i;
  38635. var j;
  38636. for (i = 0; i <= radialSegments; i++) {
  38637. var modI = i % radialSegments;
  38638. var u = modI / radialSegments * 2 * p * Math.PI;
  38639. var p1 = getPos(u);
  38640. var p2 = getPos(u + 0.01);
  38641. var tang = p2.subtract(p1);
  38642. var n = p2.add(p1);
  38643. var bitan = BABYLON.Vector3.Cross(tang, n);
  38644. n = BABYLON.Vector3.Cross(bitan, tang);
  38645. bitan.normalize();
  38646. n.normalize();
  38647. for (j = 0; j < tubularSegments; j++) {
  38648. var modJ = j % tubularSegments;
  38649. var v = modJ / tubularSegments * 2 * Math.PI;
  38650. var cx = -tube * Math.cos(v);
  38651. var cy = tube * Math.sin(v);
  38652. positions.push(p1.x + cx * n.x + cy * bitan.x);
  38653. positions.push(p1.y + cx * n.y + cy * bitan.y);
  38654. positions.push(p1.z + cx * n.z + cy * bitan.z);
  38655. uvs.push(i / radialSegments);
  38656. uvs.push(j / tubularSegments);
  38657. }
  38658. }
  38659. for (i = 0; i < radialSegments; i++) {
  38660. for (j = 0; j < tubularSegments; j++) {
  38661. var jNext = (j + 1) % tubularSegments;
  38662. var a = i * tubularSegments + j;
  38663. var b = (i + 1) * tubularSegments + j;
  38664. var c = (i + 1) * tubularSegments + jNext;
  38665. var d = i * tubularSegments + jNext;
  38666. indices.push(d);
  38667. indices.push(b);
  38668. indices.push(a);
  38669. indices.push(d);
  38670. indices.push(c);
  38671. indices.push(b);
  38672. }
  38673. }
  38674. // Normals
  38675. VertexData.ComputeNormals(positions, indices, normals);
  38676. // Sides
  38677. VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);
  38678. // Result
  38679. var vertexData = new VertexData();
  38680. vertexData.indices = indices;
  38681. vertexData.positions = positions;
  38682. vertexData.normals = normals;
  38683. vertexData.uvs = uvs;
  38684. return vertexData;
  38685. };
  38686. // Tools
  38687. /**
  38688. * Compute normals for given positions and indices
  38689. * @param positions an array of vertex positions, [...., x, y, z, ......]
  38690. * @param indices an array of indices in groups of three for each triangular facet, [...., i, j, k, ......]
  38691. * @param normals an array of vertex normals, [...., x, y, z, ......]
  38692. * @param options an object used to set the following optional parameters for the TorusKnot, optional
  38693. * * facetNormals : optional array of facet normals (vector3)
  38694. * * facetPositions : optional array of facet positions (vector3)
  38695. * * facetPartitioning : optional partitioning array. facetPositions is required for facetPartitioning computation
  38696. * * ratio : optional partitioning ratio / bounding box, required for facetPartitioning computation
  38697. * * bInfo : optional bounding info, required for facetPartitioning computation
  38698. * * bbSize : optional bounding box size data, required for facetPartitioning computation
  38699. * * subDiv : optional partitioning data about subdivsions on each axis (int), required for facetPartitioning computation
  38700. * * useRightHandedSystem: optional boolean to for right handed system computation
  38701. * * depthSort : optional boolean to enable the facet depth sort computation
  38702. * * distanceTo : optional Vector3 to compute the facet depth from this location
  38703. * * depthSortedFacets : optional array of depthSortedFacets to store the facet distances from the reference location
  38704. */
  38705. VertexData.ComputeNormals = function (positions, indices, normals, options) {
  38706. // temporary scalar variables
  38707. var index = 0; // facet index
  38708. var p1p2x = 0.0; // p1p2 vector x coordinate
  38709. var p1p2y = 0.0; // p1p2 vector y coordinate
  38710. var p1p2z = 0.0; // p1p2 vector z coordinate
  38711. var p3p2x = 0.0; // p3p2 vector x coordinate
  38712. var p3p2y = 0.0; // p3p2 vector y coordinate
  38713. var p3p2z = 0.0; // p3p2 vector z coordinate
  38714. var faceNormalx = 0.0; // facet normal x coordinate
  38715. var faceNormaly = 0.0; // facet normal y coordinate
  38716. var faceNormalz = 0.0; // facet normal z coordinate
  38717. var length = 0.0; // facet normal length before normalization
  38718. var v1x = 0; // vector1 x index in the positions array
  38719. var v1y = 0; // vector1 y index in the positions array
  38720. var v1z = 0; // vector1 z index in the positions array
  38721. var v2x = 0; // vector2 x index in the positions array
  38722. var v2y = 0; // vector2 y index in the positions array
  38723. var v2z = 0; // vector2 z index in the positions array
  38724. var v3x = 0; // vector3 x index in the positions array
  38725. var v3y = 0; // vector3 y index in the positions array
  38726. var v3z = 0; // vector3 z index in the positions array
  38727. var computeFacetNormals = false;
  38728. var computeFacetPositions = false;
  38729. var computeFacetPartitioning = false;
  38730. var computeDepthSort = false;
  38731. var faceNormalSign = 1;
  38732. var ratio = 0;
  38733. var distanceTo = null;
  38734. if (options) {
  38735. computeFacetNormals = (options.facetNormals) ? true : false;
  38736. computeFacetPositions = (options.facetPositions) ? true : false;
  38737. computeFacetPartitioning = (options.facetPartitioning) ? true : false;
  38738. faceNormalSign = (options.useRightHandedSystem === true) ? -1 : 1;
  38739. ratio = options.ratio || 0;
  38740. computeDepthSort = (options.depthSort) ? true : false;
  38741. distanceTo = (options.distanceTo);
  38742. if (computeDepthSort) {
  38743. if (distanceTo === undefined) {
  38744. distanceTo = BABYLON.Vector3.Zero();
  38745. }
  38746. var depthSortedFacets = options.depthSortedFacets;
  38747. }
  38748. }
  38749. // facetPartitioning reinit if needed
  38750. var xSubRatio = 0;
  38751. var ySubRatio = 0;
  38752. var zSubRatio = 0;
  38753. var subSq = 0;
  38754. if (computeFacetPartitioning && options && options.bbSize) {
  38755. var ox = 0; // X partitioning index for facet position
  38756. var oy = 0; // Y partinioning index for facet position
  38757. var oz = 0; // Z partinioning index for facet position
  38758. var b1x = 0; // X partitioning index for facet v1 vertex
  38759. var b1y = 0; // Y partitioning index for facet v1 vertex
  38760. var b1z = 0; // z partitioning index for facet v1 vertex
  38761. var b2x = 0; // X partitioning index for facet v2 vertex
  38762. var b2y = 0; // Y partitioning index for facet v2 vertex
  38763. var b2z = 0; // Z partitioning index for facet v2 vertex
  38764. var b3x = 0; // X partitioning index for facet v3 vertex
  38765. var b3y = 0; // Y partitioning index for facet v3 vertex
  38766. var b3z = 0; // Z partitioning index for facet v3 vertex
  38767. var block_idx_o = 0; // facet barycenter block index
  38768. var block_idx_v1 = 0; // v1 vertex block index
  38769. var block_idx_v2 = 0; // v2 vertex block index
  38770. var block_idx_v3 = 0; // v3 vertex block index
  38771. var bbSizeMax = (options.bbSize.x > options.bbSize.y) ? options.bbSize.x : options.bbSize.y;
  38772. bbSizeMax = (bbSizeMax > options.bbSize.z) ? bbSizeMax : options.bbSize.z;
  38773. xSubRatio = options.subDiv.X * ratio / options.bbSize.x;
  38774. ySubRatio = options.subDiv.Y * ratio / options.bbSize.y;
  38775. zSubRatio = options.subDiv.Z * ratio / options.bbSize.z;
  38776. subSq = options.subDiv.max * options.subDiv.max;
  38777. options.facetPartitioning.length = 0;
  38778. }
  38779. // reset the normals
  38780. for (index = 0; index < positions.length; index++) {
  38781. normals[index] = 0.0;
  38782. }
  38783. // Loop : 1 indice triplet = 1 facet
  38784. var nbFaces = (indices.length / 3) | 0;
  38785. for (index = 0; index < nbFaces; index++) {
  38786. // get the indexes of the coordinates of each vertex of the facet
  38787. v1x = indices[index * 3] * 3;
  38788. v1y = v1x + 1;
  38789. v1z = v1x + 2;
  38790. v2x = indices[index * 3 + 1] * 3;
  38791. v2y = v2x + 1;
  38792. v2z = v2x + 2;
  38793. v3x = indices[index * 3 + 2] * 3;
  38794. v3y = v3x + 1;
  38795. v3z = v3x + 2;
  38796. p1p2x = positions[v1x] - positions[v2x]; // compute two vectors per facet : p1p2 and p3p2
  38797. p1p2y = positions[v1y] - positions[v2y];
  38798. p1p2z = positions[v1z] - positions[v2z];
  38799. p3p2x = positions[v3x] - positions[v2x];
  38800. p3p2y = positions[v3y] - positions[v2y];
  38801. p3p2z = positions[v3z] - positions[v2z];
  38802. // compute the face normal with the cross product
  38803. faceNormalx = faceNormalSign * (p1p2y * p3p2z - p1p2z * p3p2y);
  38804. faceNormaly = faceNormalSign * (p1p2z * p3p2x - p1p2x * p3p2z);
  38805. faceNormalz = faceNormalSign * (p1p2x * p3p2y - p1p2y * p3p2x);
  38806. // normalize this normal and store it in the array facetData
  38807. length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);
  38808. length = (length === 0) ? 1.0 : length;
  38809. faceNormalx /= length;
  38810. faceNormaly /= length;
  38811. faceNormalz /= length;
  38812. if (computeFacetNormals && options) {
  38813. options.facetNormals[index].x = faceNormalx;
  38814. options.facetNormals[index].y = faceNormaly;
  38815. options.facetNormals[index].z = faceNormalz;
  38816. }
  38817. if (computeFacetPositions && options) {
  38818. // compute and the facet barycenter coordinates in the array facetPositions
  38819. options.facetPositions[index].x = (positions[v1x] + positions[v2x] + positions[v3x]) / 3.0;
  38820. options.facetPositions[index].y = (positions[v1y] + positions[v2y] + positions[v3y]) / 3.0;
  38821. options.facetPositions[index].z = (positions[v1z] + positions[v2z] + positions[v3z]) / 3.0;
  38822. }
  38823. if (computeFacetPartitioning && options) {
  38824. // store the facet indexes in arrays in the main facetPartitioning array :
  38825. // compute each facet vertex (+ facet barycenter) index in the partiniong array
  38826. ox = Math.floor((options.facetPositions[index].x - options.bInfo.minimum.x * ratio) * xSubRatio);
  38827. oy = Math.floor((options.facetPositions[index].y - options.bInfo.minimum.y * ratio) * ySubRatio);
  38828. oz = Math.floor((options.facetPositions[index].z - options.bInfo.minimum.z * ratio) * zSubRatio);
  38829. b1x = Math.floor((positions[v1x] - options.bInfo.minimum.x * ratio) * xSubRatio);
  38830. b1y = Math.floor((positions[v1y] - options.bInfo.minimum.y * ratio) * ySubRatio);
  38831. b1z = Math.floor((positions[v1z] - options.bInfo.minimum.z * ratio) * zSubRatio);
  38832. b2x = Math.floor((positions[v2x] - options.bInfo.minimum.x * ratio) * xSubRatio);
  38833. b2y = Math.floor((positions[v2y] - options.bInfo.minimum.y * ratio) * ySubRatio);
  38834. b2z = Math.floor((positions[v2z] - options.bInfo.minimum.z * ratio) * zSubRatio);
  38835. b3x = Math.floor((positions[v3x] - options.bInfo.minimum.x * ratio) * xSubRatio);
  38836. b3y = Math.floor((positions[v3y] - options.bInfo.minimum.y * ratio) * ySubRatio);
  38837. b3z = Math.floor((positions[v3z] - options.bInfo.minimum.z * ratio) * zSubRatio);
  38838. block_idx_v1 = b1x + options.subDiv.max * b1y + subSq * b1z;
  38839. block_idx_v2 = b2x + options.subDiv.max * b2y + subSq * b2z;
  38840. block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;
  38841. block_idx_o = ox + options.subDiv.max * oy + subSq * oz;
  38842. options.facetPartitioning[block_idx_o] = options.facetPartitioning[block_idx_o] ? options.facetPartitioning[block_idx_o] : new Array();
  38843. options.facetPartitioning[block_idx_v1] = options.facetPartitioning[block_idx_v1] ? options.facetPartitioning[block_idx_v1] : new Array();
  38844. options.facetPartitioning[block_idx_v2] = options.facetPartitioning[block_idx_v2] ? options.facetPartitioning[block_idx_v2] : new Array();
  38845. options.facetPartitioning[block_idx_v3] = options.facetPartitioning[block_idx_v3] ? options.facetPartitioning[block_idx_v3] : new Array();
  38846. // push each facet index in each block containing the vertex
  38847. options.facetPartitioning[block_idx_v1].push(index);
  38848. if (block_idx_v2 != block_idx_v1) {
  38849. options.facetPartitioning[block_idx_v2].push(index);
  38850. }
  38851. if (!(block_idx_v3 == block_idx_v2 || block_idx_v3 == block_idx_v1)) {
  38852. options.facetPartitioning[block_idx_v3].push(index);
  38853. }
  38854. if (!(block_idx_o == block_idx_v1 || block_idx_o == block_idx_v2 || block_idx_o == block_idx_v3)) {
  38855. options.facetPartitioning[block_idx_o].push(index);
  38856. }
  38857. }
  38858. if (computeDepthSort && options && options.facetPositions) {
  38859. var dsf = depthSortedFacets[index];
  38860. dsf.ind = index * 3;
  38861. dsf.sqDistance = BABYLON.Vector3.DistanceSquared(options.facetPositions[index], distanceTo);
  38862. }
  38863. // compute the normals anyway
  38864. normals[v1x] += faceNormalx; // accumulate all the normals per face
  38865. normals[v1y] += faceNormaly;
  38866. normals[v1z] += faceNormalz;
  38867. normals[v2x] += faceNormalx;
  38868. normals[v2y] += faceNormaly;
  38869. normals[v2z] += faceNormalz;
  38870. normals[v3x] += faceNormalx;
  38871. normals[v3y] += faceNormaly;
  38872. normals[v3z] += faceNormalz;
  38873. }
  38874. // last normalization of each normal
  38875. for (index = 0; index < normals.length / 3; index++) {
  38876. faceNormalx = normals[index * 3];
  38877. faceNormaly = normals[index * 3 + 1];
  38878. faceNormalz = normals[index * 3 + 2];
  38879. length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);
  38880. length = (length === 0) ? 1.0 : length;
  38881. faceNormalx /= length;
  38882. faceNormaly /= length;
  38883. faceNormalz /= length;
  38884. normals[index * 3] = faceNormalx;
  38885. normals[index * 3 + 1] = faceNormaly;
  38886. normals[index * 3 + 2] = faceNormalz;
  38887. }
  38888. };
  38889. VertexData._ComputeSides = function (sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs) {
  38890. var li = indices.length;
  38891. var ln = normals.length;
  38892. var i;
  38893. var n;
  38894. sideOrientation = sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
  38895. switch (sideOrientation) {
  38896. case BABYLON.Mesh.FRONTSIDE:
  38897. // nothing changed
  38898. break;
  38899. case BABYLON.Mesh.BACKSIDE:
  38900. var tmp;
  38901. // indices
  38902. for (i = 0; i < li; i += 3) {
  38903. tmp = indices[i];
  38904. indices[i] = indices[i + 2];
  38905. indices[i + 2] = tmp;
  38906. }
  38907. // normals
  38908. for (n = 0; n < ln; n++) {
  38909. normals[n] = -normals[n];
  38910. }
  38911. break;
  38912. case BABYLON.Mesh.DOUBLESIDE:
  38913. // positions
  38914. var lp = positions.length;
  38915. var l = lp / 3;
  38916. for (var p = 0; p < lp; p++) {
  38917. positions[lp + p] = positions[p];
  38918. }
  38919. // indices
  38920. for (i = 0; i < li; i += 3) {
  38921. indices[i + li] = indices[i + 2] + l;
  38922. indices[i + 1 + li] = indices[i + 1] + l;
  38923. indices[i + 2 + li] = indices[i] + l;
  38924. }
  38925. // normals
  38926. for (n = 0; n < ln; n++) {
  38927. normals[ln + n] = -normals[n];
  38928. }
  38929. // uvs
  38930. var lu = uvs.length;
  38931. var u = 0;
  38932. for (u = 0; u < lu; u++) {
  38933. uvs[u + lu] = uvs[u];
  38934. }
  38935. frontUVs = frontUVs ? frontUVs : new BABYLON.Vector4(0.0, 0.0, 1.0, 1.0);
  38936. backUVs = backUVs ? backUVs : new BABYLON.Vector4(0.0, 0.0, 1.0, 1.0);
  38937. u = 0;
  38938. for (i = 0; i < lu / 2; i++) {
  38939. uvs[u] = frontUVs.x + (frontUVs.z - frontUVs.x) * uvs[u];
  38940. uvs[u + 1] = frontUVs.y + (frontUVs.w - frontUVs.y) * uvs[u + 1];
  38941. uvs[u + lu] = backUVs.x + (backUVs.z - backUVs.x) * uvs[u + lu];
  38942. uvs[u + lu + 1] = backUVs.y + (backUVs.w - backUVs.y) * uvs[u + lu + 1];
  38943. u += 2;
  38944. }
  38945. break;
  38946. }
  38947. };
  38948. /**
  38949. * Applies VertexData created from the imported parameters to the geometry
  38950. * @param parsedVertexData the parsed data from an imported file
  38951. * @param geometry the geometry to apply the VertexData to
  38952. */
  38953. VertexData.ImportVertexData = function (parsedVertexData, geometry) {
  38954. var vertexData = new VertexData();
  38955. // positions
  38956. var positions = parsedVertexData.positions;
  38957. if (positions) {
  38958. vertexData.set(positions, BABYLON.VertexBuffer.PositionKind);
  38959. }
  38960. // normals
  38961. var normals = parsedVertexData.normals;
  38962. if (normals) {
  38963. vertexData.set(normals, BABYLON.VertexBuffer.NormalKind);
  38964. }
  38965. // tangents
  38966. var tangents = parsedVertexData.tangents;
  38967. if (tangents) {
  38968. vertexData.set(tangents, BABYLON.VertexBuffer.TangentKind);
  38969. }
  38970. // uvs
  38971. var uvs = parsedVertexData.uvs;
  38972. if (uvs) {
  38973. vertexData.set(uvs, BABYLON.VertexBuffer.UVKind);
  38974. }
  38975. // uv2s
  38976. var uv2s = parsedVertexData.uv2s;
  38977. if (uv2s) {
  38978. vertexData.set(uv2s, BABYLON.VertexBuffer.UV2Kind);
  38979. }
  38980. // uv3s
  38981. var uv3s = parsedVertexData.uv3s;
  38982. if (uv3s) {
  38983. vertexData.set(uv3s, BABYLON.VertexBuffer.UV3Kind);
  38984. }
  38985. // uv4s
  38986. var uv4s = parsedVertexData.uv4s;
  38987. if (uv4s) {
  38988. vertexData.set(uv4s, BABYLON.VertexBuffer.UV4Kind);
  38989. }
  38990. // uv5s
  38991. var uv5s = parsedVertexData.uv5s;
  38992. if (uv5s) {
  38993. vertexData.set(uv5s, BABYLON.VertexBuffer.UV5Kind);
  38994. }
  38995. // uv6s
  38996. var uv6s = parsedVertexData.uv6s;
  38997. if (uv6s) {
  38998. vertexData.set(uv6s, BABYLON.VertexBuffer.UV6Kind);
  38999. }
  39000. // colors
  39001. var colors = parsedVertexData.colors;
  39002. if (colors) {
  39003. vertexData.set(BABYLON.Color4.CheckColors4(colors, positions.length / 3), BABYLON.VertexBuffer.ColorKind);
  39004. }
  39005. // matricesIndices
  39006. var matricesIndices = parsedVertexData.matricesIndices;
  39007. if (matricesIndices) {
  39008. vertexData.set(matricesIndices, BABYLON.VertexBuffer.MatricesIndicesKind);
  39009. }
  39010. // matricesWeights
  39011. var matricesWeights = parsedVertexData.matricesWeights;
  39012. if (matricesWeights) {
  39013. vertexData.set(matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind);
  39014. }
  39015. // indices
  39016. var indices = parsedVertexData.indices;
  39017. if (indices) {
  39018. vertexData.indices = indices;
  39019. }
  39020. geometry.setAllVerticesData(vertexData, parsedVertexData.updatable);
  39021. };
  39022. return VertexData;
  39023. }());
  39024. BABYLON.VertexData = VertexData;
  39025. })(BABYLON || (BABYLON = {}));
  39026. //# sourceMappingURL=babylon.mesh.vertexData.js.map
  39027. var BABYLON;
  39028. (function (BABYLON) {
  39029. /**
  39030. * Class used to store geometry data (vertex buffers + index buffer)
  39031. */
  39032. var Geometry = /** @class */ (function () {
  39033. /**
  39034. * Creates a new geometry
  39035. * @param id defines the unique ID
  39036. * @param scene defines the hosting scene
  39037. * @param vertexData defines the {BABYLON.VertexData} used to get geometry data
  39038. * @param updatable defines if geometry must be updatable (false by default)
  39039. * @param mesh defines the mesh that will be associated with the geometry
  39040. */
  39041. function Geometry(id, scene, vertexData, updatable, mesh) {
  39042. if (updatable === void 0) { updatable = false; }
  39043. if (mesh === void 0) { mesh = null; }
  39044. /**
  39045. * Gets the delay loading state of the geometry (none by default which means not delayed)
  39046. */
  39047. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  39048. this._totalVertices = 0;
  39049. this._isDisposed = false;
  39050. this._indexBufferIsUpdatable = false;
  39051. this.id = id;
  39052. this._engine = scene.getEngine();
  39053. this._meshes = [];
  39054. this._scene = scene;
  39055. //Init vertex buffer cache
  39056. this._vertexBuffers = {};
  39057. this._indices = [];
  39058. this._updatable = updatable;
  39059. // vertexData
  39060. if (vertexData) {
  39061. this.setAllVerticesData(vertexData, updatable);
  39062. }
  39063. else {
  39064. this._totalVertices = 0;
  39065. this._indices = [];
  39066. }
  39067. if (this._engine.getCaps().vertexArrayObject) {
  39068. this._vertexArrayObjects = {};
  39069. }
  39070. // applyToMesh
  39071. if (mesh) {
  39072. if (mesh.getClassName() === "LinesMesh") {
  39073. this.boundingBias = new BABYLON.Vector2(0, mesh.intersectionThreshold);
  39074. this._updateExtend();
  39075. }
  39076. this.applyToMesh(mesh);
  39077. mesh.computeWorldMatrix(true);
  39078. }
  39079. }
  39080. Object.defineProperty(Geometry.prototype, "boundingBias", {
  39081. /**
  39082. * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y
  39083. */
  39084. get: function () {
  39085. return this._boundingBias;
  39086. },
  39087. /**
  39088. * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y
  39089. */
  39090. set: function (value) {
  39091. if (this._boundingBias && this._boundingBias.equals(value)) {
  39092. return;
  39093. }
  39094. this._boundingBias = value.clone();
  39095. this._updateBoundingInfo(true, null);
  39096. },
  39097. enumerable: true,
  39098. configurable: true
  39099. });
  39100. /**
  39101. * Static function used to attach a new empty geometry to a mesh
  39102. * @param mesh defines the mesh to attach the geometry to
  39103. * @returns the new {BABYLON.Geometry}
  39104. */
  39105. Geometry.CreateGeometryForMesh = function (mesh) {
  39106. var geometry = new Geometry(Geometry.RandomId(), mesh.getScene());
  39107. geometry.applyToMesh(mesh);
  39108. return geometry;
  39109. };
  39110. Object.defineProperty(Geometry.prototype, "extend", {
  39111. /**
  39112. * Gets the current extend of the geometry
  39113. */
  39114. get: function () {
  39115. return this._extend;
  39116. },
  39117. enumerable: true,
  39118. configurable: true
  39119. });
  39120. /**
  39121. * Gets the hosting scene
  39122. * @returns the hosting {BABYLON.Scene}
  39123. */
  39124. Geometry.prototype.getScene = function () {
  39125. return this._scene;
  39126. };
  39127. /**
  39128. * Gets the hosting engine
  39129. * @returns the hosting {BABYLON.Engine}
  39130. */
  39131. Geometry.prototype.getEngine = function () {
  39132. return this._engine;
  39133. };
  39134. /**
  39135. * Defines if the geometry is ready to use
  39136. * @returns true if the geometry is ready to be used
  39137. */
  39138. Geometry.prototype.isReady = function () {
  39139. return this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE;
  39140. };
  39141. Object.defineProperty(Geometry.prototype, "doNotSerialize", {
  39142. /**
  39143. * Gets a value indicating that the geometry should not be serialized
  39144. */
  39145. get: function () {
  39146. for (var index = 0; index < this._meshes.length; index++) {
  39147. if (!this._meshes[index].doNotSerialize) {
  39148. return false;
  39149. }
  39150. }
  39151. return true;
  39152. },
  39153. enumerable: true,
  39154. configurable: true
  39155. });
  39156. /** @hidden */
  39157. Geometry.prototype._rebuild = function () {
  39158. if (this._vertexArrayObjects) {
  39159. this._vertexArrayObjects = {};
  39160. }
  39161. // Index buffer
  39162. if (this._meshes.length !== 0 && this._indices) {
  39163. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  39164. }
  39165. // Vertex buffers
  39166. for (var key in this._vertexBuffers) {
  39167. var vertexBuffer = this._vertexBuffers[key];
  39168. vertexBuffer._rebuild();
  39169. }
  39170. };
  39171. /**
  39172. * Affects all gemetry data in one call
  39173. * @param vertexData defines the geometry data
  39174. * @param updatable defines if the geometry must be flagged as updatable (false as default)
  39175. */
  39176. Geometry.prototype.setAllVerticesData = function (vertexData, updatable) {
  39177. vertexData.applyToGeometry(this, updatable);
  39178. this.notifyUpdate();
  39179. };
  39180. /**
  39181. * Set specific vertex data
  39182. * @param kind defines the data kind (Position, normal, etc...)
  39183. * @param data defines the vertex data to use
  39184. * @param updatable defines if the vertex must be flagged as updatable (false as default)
  39185. * @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified
  39186. */
  39187. Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
  39188. if (updatable === void 0) { updatable = false; }
  39189. var buffer = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
  39190. this.setVerticesBuffer(buffer);
  39191. };
  39192. /**
  39193. * Removes a specific vertex data
  39194. * @param kind defines the data kind (Position, normal, etc...)
  39195. */
  39196. Geometry.prototype.removeVerticesData = function (kind) {
  39197. if (this._vertexBuffers[kind]) {
  39198. this._vertexBuffers[kind].dispose();
  39199. delete this._vertexBuffers[kind];
  39200. }
  39201. };
  39202. /**
  39203. * Affect a vertex buffer to the geometry. the vertexBuffer.getKind() function is used to determine where to store the data
  39204. * @param buffer defines the vertex buffer to use
  39205. * @param totalVertices defines the total number of vertices for position kind (could be null)
  39206. */
  39207. Geometry.prototype.setVerticesBuffer = function (buffer, totalVertices) {
  39208. if (totalVertices === void 0) { totalVertices = null; }
  39209. var kind = buffer.getKind();
  39210. if (this._vertexBuffers[kind]) {
  39211. this._vertexBuffers[kind].dispose();
  39212. }
  39213. this._vertexBuffers[kind] = buffer;
  39214. if (kind === BABYLON.VertexBuffer.PositionKind) {
  39215. var data = buffer.getData();
  39216. if (totalVertices != null) {
  39217. this._totalVertices = totalVertices;
  39218. }
  39219. else {
  39220. if (data != null) {
  39221. this._totalVertices = data.length / (buffer.byteStride / 4);
  39222. }
  39223. }
  39224. this._updateExtend(data);
  39225. this._resetPointsArrayCache();
  39226. var meshes = this._meshes;
  39227. var numOfMeshes = meshes.length;
  39228. for (var index = 0; index < numOfMeshes; index++) {
  39229. var mesh = meshes[index];
  39230. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  39231. mesh._createGlobalSubMesh(false);
  39232. mesh.computeWorldMatrix(true);
  39233. }
  39234. }
  39235. this.notifyUpdate(kind);
  39236. if (this._vertexArrayObjects) {
  39237. this._disposeVertexArrayObjects();
  39238. this._vertexArrayObjects = {}; // Will trigger a rebuild of the VAO if supported
  39239. }
  39240. };
  39241. /**
  39242. * Update a specific vertex buffer
  39243. * This function will directly update the underlying WebGLBuffer according to the passed numeric array or Float32Array
  39244. * It will do nothing if the buffer is not updatable
  39245. * @param kind defines the data kind (Position, normal, etc...)
  39246. * @param data defines the data to use
  39247. * @param offset defines the offset in the target buffer where to store the data
  39248. * @param useBytes set to true if the offset is in bytes
  39249. */
  39250. Geometry.prototype.updateVerticesDataDirectly = function (kind, data, offset, useBytes) {
  39251. if (useBytes === void 0) { useBytes = false; }
  39252. var vertexBuffer = this.getVertexBuffer(kind);
  39253. if (!vertexBuffer) {
  39254. return;
  39255. }
  39256. vertexBuffer.updateDirectly(data, offset, useBytes);
  39257. this.notifyUpdate(kind);
  39258. };
  39259. /**
  39260. * Update a specific vertex buffer
  39261. * This function will create a new buffer if the current one is not updatable
  39262. * @param kind defines the data kind (Position, normal, etc...)
  39263. * @param data defines the data to use
  39264. * @param updateExtends defines if the geometry extends must be recomputed (false by default)
  39265. */
  39266. Geometry.prototype.updateVerticesData = function (kind, data, updateExtends) {
  39267. if (updateExtends === void 0) { updateExtends = false; }
  39268. var vertexBuffer = this.getVertexBuffer(kind);
  39269. if (!vertexBuffer) {
  39270. return;
  39271. }
  39272. vertexBuffer.update(data);
  39273. if (kind === BABYLON.VertexBuffer.PositionKind) {
  39274. this._updateBoundingInfo(updateExtends, data);
  39275. }
  39276. this.notifyUpdate(kind);
  39277. };
  39278. Geometry.prototype._updateBoundingInfo = function (updateExtends, data) {
  39279. if (updateExtends) {
  39280. this._updateExtend(data);
  39281. }
  39282. var meshes = this._meshes;
  39283. var numOfMeshes = meshes.length;
  39284. this._resetPointsArrayCache();
  39285. for (var index = 0; index < numOfMeshes; index++) {
  39286. var mesh = meshes[index];
  39287. if (updateExtends) {
  39288. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  39289. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  39290. var subMesh = mesh.subMeshes[subIndex];
  39291. subMesh.refreshBoundingInfo();
  39292. }
  39293. }
  39294. }
  39295. };
  39296. /** @hidden */
  39297. Geometry.prototype._bind = function (effect, indexToBind) {
  39298. if (!effect) {
  39299. return;
  39300. }
  39301. if (indexToBind === undefined) {
  39302. indexToBind = this._indexBuffer;
  39303. }
  39304. var vbs = this.getVertexBuffers();
  39305. if (!vbs) {
  39306. return;
  39307. }
  39308. if (indexToBind != this._indexBuffer || !this._vertexArrayObjects) {
  39309. this._engine.bindBuffers(vbs, indexToBind, effect);
  39310. return;
  39311. }
  39312. // Using VAO
  39313. if (!this._vertexArrayObjects[effect.key]) {
  39314. this._vertexArrayObjects[effect.key] = this._engine.recordVertexArrayObject(vbs, indexToBind, effect);
  39315. }
  39316. this._engine.bindVertexArrayObject(this._vertexArrayObjects[effect.key], indexToBind);
  39317. };
  39318. /**
  39319. * Gets total number of vertices
  39320. * @returns the total number of vertices
  39321. */
  39322. Geometry.prototype.getTotalVertices = function () {
  39323. if (!this.isReady()) {
  39324. return 0;
  39325. }
  39326. return this._totalVertices;
  39327. };
  39328. /**
  39329. * Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.
  39330. * @param kind defines the data kind (Position, normal, etc...)
  39331. * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes
  39332. * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it
  39333. * @returns a float array containing vertex data
  39334. */
  39335. Geometry.prototype.getVerticesData = function (kind, copyWhenShared, forceCopy) {
  39336. var vertexBuffer = this.getVertexBuffer(kind);
  39337. if (!vertexBuffer) {
  39338. return null;
  39339. }
  39340. var data = vertexBuffer.getData();
  39341. if (!data) {
  39342. return null;
  39343. }
  39344. var tightlyPackedByteStride = vertexBuffer.getSize() * BABYLON.VertexBuffer.GetTypeByteLength(vertexBuffer.type);
  39345. var count = this._totalVertices * vertexBuffer.getSize();
  39346. if (vertexBuffer.type !== BABYLON.VertexBuffer.FLOAT || vertexBuffer.byteStride !== tightlyPackedByteStride) {
  39347. var copy_1 = new Array(count);
  39348. vertexBuffer.forEach(count, function (value, index) {
  39349. copy_1[index] = value;
  39350. });
  39351. return copy_1;
  39352. }
  39353. if (!((data instanceof Array) || (data instanceof Float32Array)) || vertexBuffer.byteOffset !== 0 || data.length !== count) {
  39354. if (data instanceof Array) {
  39355. var offset = vertexBuffer.byteOffset / 4;
  39356. return BABYLON.Tools.Slice(data, offset, offset + count);
  39357. }
  39358. else if (data instanceof ArrayBuffer) {
  39359. return new Float32Array(data, vertexBuffer.byteOffset, count);
  39360. }
  39361. else {
  39362. return new Float32Array(data.buffer, data.byteOffset + vertexBuffer.byteOffset, count);
  39363. }
  39364. }
  39365. if (forceCopy || (copyWhenShared && this._meshes.length !== 1)) {
  39366. return BABYLON.Tools.Slice(data);
  39367. }
  39368. return data;
  39369. };
  39370. /**
  39371. * Returns a boolean defining if the vertex data for the requested `kind` is updatable
  39372. * @param kind defines the data kind (Position, normal, etc...)
  39373. * @returns true if the vertex buffer with the specified kind is updatable
  39374. */
  39375. Geometry.prototype.isVertexBufferUpdatable = function (kind) {
  39376. var vb = this._vertexBuffers[kind];
  39377. if (!vb) {
  39378. return false;
  39379. }
  39380. return vb.isUpdatable();
  39381. };
  39382. /**
  39383. * Gets a specific vertex buffer
  39384. * @param kind defines the data kind (Position, normal, etc...)
  39385. * @returns a {BABYLON.VertexBuffer}
  39386. */
  39387. Geometry.prototype.getVertexBuffer = function (kind) {
  39388. if (!this.isReady()) {
  39389. return null;
  39390. }
  39391. return this._vertexBuffers[kind];
  39392. };
  39393. /**
  39394. * Returns all vertex buffers
  39395. * @return an object holding all vertex buffers indexed by kind
  39396. */
  39397. Geometry.prototype.getVertexBuffers = function () {
  39398. if (!this.isReady()) {
  39399. return null;
  39400. }
  39401. return this._vertexBuffers;
  39402. };
  39403. /**
  39404. * Gets a boolean indicating if specific vertex buffer is present
  39405. * @param kind defines the data kind (Position, normal, etc...)
  39406. * @returns true if data is present
  39407. */
  39408. Geometry.prototype.isVerticesDataPresent = function (kind) {
  39409. if (!this._vertexBuffers) {
  39410. if (this._delayInfo) {
  39411. return this._delayInfo.indexOf(kind) !== -1;
  39412. }
  39413. return false;
  39414. }
  39415. return this._vertexBuffers[kind] !== undefined;
  39416. };
  39417. /**
  39418. * Gets a list of all attached data kinds (Position, normal, etc...)
  39419. * @returns a list of string containing all kinds
  39420. */
  39421. Geometry.prototype.getVerticesDataKinds = function () {
  39422. var result = [];
  39423. var kind;
  39424. if (!this._vertexBuffers && this._delayInfo) {
  39425. for (kind in this._delayInfo) {
  39426. result.push(kind);
  39427. }
  39428. }
  39429. else {
  39430. for (kind in this._vertexBuffers) {
  39431. result.push(kind);
  39432. }
  39433. }
  39434. return result;
  39435. };
  39436. /**
  39437. * Update index buffer
  39438. * @param indices defines the indices to store in the index buffer
  39439. * @param offset defines the offset in the target buffer where to store the data
  39440. */
  39441. Geometry.prototype.updateIndices = function (indices, offset) {
  39442. if (!this._indexBuffer) {
  39443. return;
  39444. }
  39445. if (!this._indexBufferIsUpdatable) {
  39446. this.setIndices(indices, null, true);
  39447. }
  39448. else {
  39449. this._engine.updateDynamicIndexBuffer(this._indexBuffer, indices, offset);
  39450. }
  39451. };
  39452. /**
  39453. * Creates a new index buffer
  39454. * @param indices defines the indices to store in the index buffer
  39455. * @param totalVertices defines the total number of vertices (could be null)
  39456. * @param updatable defines if the index buffer must be flagged as updatable (false by default)
  39457. */
  39458. Geometry.prototype.setIndices = function (indices, totalVertices, updatable) {
  39459. if (totalVertices === void 0) { totalVertices = null; }
  39460. if (updatable === void 0) { updatable = false; }
  39461. if (this._indexBuffer) {
  39462. this._engine._releaseBuffer(this._indexBuffer);
  39463. }
  39464. this._disposeVertexArrayObjects();
  39465. this._indices = indices;
  39466. this._indexBufferIsUpdatable = updatable;
  39467. if (this._meshes.length !== 0 && this._indices) {
  39468. this._indexBuffer = this._engine.createIndexBuffer(this._indices, updatable);
  39469. }
  39470. if (totalVertices != undefined) { // including null and undefined
  39471. this._totalVertices = totalVertices;
  39472. }
  39473. var meshes = this._meshes;
  39474. var numOfMeshes = meshes.length;
  39475. for (var index = 0; index < numOfMeshes; index++) {
  39476. meshes[index]._createGlobalSubMesh(true);
  39477. }
  39478. this.notifyUpdate();
  39479. };
  39480. /**
  39481. * Return the total number of indices
  39482. * @returns the total number of indices
  39483. */
  39484. Geometry.prototype.getTotalIndices = function () {
  39485. if (!this.isReady()) {
  39486. return 0;
  39487. }
  39488. return this._indices.length;
  39489. };
  39490. /**
  39491. * Gets the index buffer array
  39492. * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes
  39493. * @returns the index buffer array
  39494. */
  39495. Geometry.prototype.getIndices = function (copyWhenShared) {
  39496. if (!this.isReady()) {
  39497. return null;
  39498. }
  39499. var orig = this._indices;
  39500. if (!copyWhenShared || this._meshes.length === 1) {
  39501. return orig;
  39502. }
  39503. else {
  39504. var len = orig.length;
  39505. var copy = [];
  39506. for (var i = 0; i < len; i++) {
  39507. copy.push(orig[i]);
  39508. }
  39509. return copy;
  39510. }
  39511. };
  39512. /**
  39513. * Gets the index buffer
  39514. * @return the index buffer
  39515. */
  39516. Geometry.prototype.getIndexBuffer = function () {
  39517. if (!this.isReady()) {
  39518. return null;
  39519. }
  39520. return this._indexBuffer;
  39521. };
  39522. /** @hidden */
  39523. Geometry.prototype._releaseVertexArrayObject = function (effect) {
  39524. if (effect === void 0) { effect = null; }
  39525. if (!effect || !this._vertexArrayObjects) {
  39526. return;
  39527. }
  39528. if (this._vertexArrayObjects[effect.key]) {
  39529. this._engine.releaseVertexArrayObject(this._vertexArrayObjects[effect.key]);
  39530. delete this._vertexArrayObjects[effect.key];
  39531. }
  39532. };
  39533. /**
  39534. * Release the associated resources for a specific mesh
  39535. * @param mesh defines the source mesh
  39536. * @param shouldDispose defines if the geometry must be disposed if there is no more mesh pointing to it
  39537. */
  39538. Geometry.prototype.releaseForMesh = function (mesh, shouldDispose) {
  39539. var meshes = this._meshes;
  39540. var index = meshes.indexOf(mesh);
  39541. if (index === -1) {
  39542. return;
  39543. }
  39544. meshes.splice(index, 1);
  39545. mesh._geometry = null;
  39546. if (meshes.length === 0 && shouldDispose) {
  39547. this.dispose();
  39548. }
  39549. };
  39550. /**
  39551. * Apply current geometry to a given mesh
  39552. * @param mesh defines the mesh to apply geometry to
  39553. */
  39554. Geometry.prototype.applyToMesh = function (mesh) {
  39555. if (mesh._geometry === this) {
  39556. return;
  39557. }
  39558. var previousGeometry = mesh._geometry;
  39559. if (previousGeometry) {
  39560. previousGeometry.releaseForMesh(mesh);
  39561. }
  39562. var meshes = this._meshes;
  39563. // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
  39564. mesh._geometry = this;
  39565. this._scene.pushGeometry(this);
  39566. meshes.push(mesh);
  39567. if (this.isReady()) {
  39568. this._applyToMesh(mesh);
  39569. }
  39570. else {
  39571. mesh._boundingInfo = this._boundingInfo;
  39572. }
  39573. };
  39574. Geometry.prototype._updateExtend = function (data) {
  39575. if (data === void 0) { data = null; }
  39576. if (!data) {
  39577. data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  39578. }
  39579. this._extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices, this.boundingBias, 3);
  39580. };
  39581. Geometry.prototype._applyToMesh = function (mesh) {
  39582. var numOfMeshes = this._meshes.length;
  39583. // vertexBuffers
  39584. for (var kind in this._vertexBuffers) {
  39585. if (numOfMeshes === 1) {
  39586. this._vertexBuffers[kind].create();
  39587. }
  39588. var buffer = this._vertexBuffers[kind].getBuffer();
  39589. if (buffer)
  39590. buffer.references = numOfMeshes;
  39591. if (kind === BABYLON.VertexBuffer.PositionKind) {
  39592. if (!this._extend) {
  39593. this._updateExtend();
  39594. }
  39595. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  39596. mesh._createGlobalSubMesh(false);
  39597. //bounding info was just created again, world matrix should be applied again.
  39598. mesh._updateBoundingInfo();
  39599. }
  39600. }
  39601. // indexBuffer
  39602. if (numOfMeshes === 1 && this._indices && this._indices.length > 0) {
  39603. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  39604. }
  39605. if (this._indexBuffer) {
  39606. this._indexBuffer.references = numOfMeshes;
  39607. }
  39608. };
  39609. Geometry.prototype.notifyUpdate = function (kind) {
  39610. if (this.onGeometryUpdated) {
  39611. this.onGeometryUpdated(this, kind);
  39612. }
  39613. for (var _i = 0, _a = this._meshes; _i < _a.length; _i++) {
  39614. var mesh = _a[_i];
  39615. mesh._markSubMeshesAsAttributesDirty();
  39616. }
  39617. };
  39618. /**
  39619. * Load the geometry if it was flagged as delay loaded
  39620. * @param scene defines the hosting scene
  39621. * @param onLoaded defines a callback called when the geometry is loaded
  39622. */
  39623. Geometry.prototype.load = function (scene, onLoaded) {
  39624. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  39625. return;
  39626. }
  39627. if (this.isReady()) {
  39628. if (onLoaded) {
  39629. onLoaded();
  39630. }
  39631. return;
  39632. }
  39633. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
  39634. this._queueLoad(scene, onLoaded);
  39635. };
  39636. Geometry.prototype._queueLoad = function (scene, onLoaded) {
  39637. var _this = this;
  39638. if (!this.delayLoadingFile) {
  39639. return;
  39640. }
  39641. scene._addPendingData(this);
  39642. scene._loadFile(this.delayLoadingFile, function (data) {
  39643. if (!_this._delayLoadingFunction) {
  39644. return;
  39645. }
  39646. _this._delayLoadingFunction(JSON.parse(data), _this);
  39647. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  39648. _this._delayInfo = [];
  39649. scene._removePendingData(_this);
  39650. var meshes = _this._meshes;
  39651. var numOfMeshes = meshes.length;
  39652. for (var index = 0; index < numOfMeshes; index++) {
  39653. _this._applyToMesh(meshes[index]);
  39654. }
  39655. if (onLoaded) {
  39656. onLoaded();
  39657. }
  39658. }, undefined, true);
  39659. };
  39660. /**
  39661. * Invert the geometry to move from a right handed system to a left handed one.
  39662. */
  39663. Geometry.prototype.toLeftHanded = function () {
  39664. // Flip faces
  39665. var tIndices = this.getIndices(false);
  39666. if (tIndices != null && tIndices.length > 0) {
  39667. for (var i = 0; i < tIndices.length; i += 3) {
  39668. var tTemp = tIndices[i + 0];
  39669. tIndices[i + 0] = tIndices[i + 2];
  39670. tIndices[i + 2] = tTemp;
  39671. }
  39672. this.setIndices(tIndices);
  39673. }
  39674. // Negate position.z
  39675. var tPositions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind, false);
  39676. if (tPositions != null && tPositions.length > 0) {
  39677. for (var i = 0; i < tPositions.length; i += 3) {
  39678. tPositions[i + 2] = -tPositions[i + 2];
  39679. }
  39680. this.setVerticesData(BABYLON.VertexBuffer.PositionKind, tPositions, false);
  39681. }
  39682. // Negate normal.z
  39683. var tNormals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind, false);
  39684. if (tNormals != null && tNormals.length > 0) {
  39685. for (var i = 0; i < tNormals.length; i += 3) {
  39686. tNormals[i + 2] = -tNormals[i + 2];
  39687. }
  39688. this.setVerticesData(BABYLON.VertexBuffer.NormalKind, tNormals, false);
  39689. }
  39690. };
  39691. // Cache
  39692. /** @hidden */
  39693. Geometry.prototype._resetPointsArrayCache = function () {
  39694. this._positions = null;
  39695. };
  39696. /** @hidden */
  39697. Geometry.prototype._generatePointsArray = function () {
  39698. if (this._positions)
  39699. return true;
  39700. var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  39701. if (!data || data.length === 0) {
  39702. return false;
  39703. }
  39704. this._positions = [];
  39705. for (var index = 0; index < data.length; index += 3) {
  39706. this._positions.push(BABYLON.Vector3.FromArray(data, index));
  39707. }
  39708. return true;
  39709. };
  39710. /**
  39711. * Gets a value indicating if the geometry is disposed
  39712. * @returns true if the geometry was disposed
  39713. */
  39714. Geometry.prototype.isDisposed = function () {
  39715. return this._isDisposed;
  39716. };
  39717. Geometry.prototype._disposeVertexArrayObjects = function () {
  39718. if (this._vertexArrayObjects) {
  39719. for (var kind in this._vertexArrayObjects) {
  39720. this._engine.releaseVertexArrayObject(this._vertexArrayObjects[kind]);
  39721. }
  39722. this._vertexArrayObjects = {};
  39723. }
  39724. };
  39725. /**
  39726. * Free all associated resources
  39727. */
  39728. Geometry.prototype.dispose = function () {
  39729. var meshes = this._meshes;
  39730. var numOfMeshes = meshes.length;
  39731. var index;
  39732. for (index = 0; index < numOfMeshes; index++) {
  39733. this.releaseForMesh(meshes[index]);
  39734. }
  39735. this._meshes = [];
  39736. this._disposeVertexArrayObjects();
  39737. for (var kind in this._vertexBuffers) {
  39738. this._vertexBuffers[kind].dispose();
  39739. }
  39740. this._vertexBuffers = {};
  39741. this._totalVertices = 0;
  39742. if (this._indexBuffer) {
  39743. this._engine._releaseBuffer(this._indexBuffer);
  39744. }
  39745. this._indexBuffer = null;
  39746. this._indices = [];
  39747. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  39748. this.delayLoadingFile = null;
  39749. this._delayLoadingFunction = null;
  39750. this._delayInfo = [];
  39751. this._boundingInfo = null;
  39752. this._scene.removeGeometry(this);
  39753. this._isDisposed = true;
  39754. };
  39755. /**
  39756. * Clone the current geometry into a new geometry
  39757. * @param id defines the unique ID of the new geometry
  39758. * @returns a new geometry object
  39759. */
  39760. Geometry.prototype.copy = function (id) {
  39761. var vertexData = new BABYLON.VertexData();
  39762. vertexData.indices = [];
  39763. var indices = this.getIndices();
  39764. if (indices) {
  39765. for (var index = 0; index < indices.length; index++) {
  39766. vertexData.indices.push(indices[index]);
  39767. }
  39768. }
  39769. var updatable = false;
  39770. var stopChecking = false;
  39771. var kind;
  39772. for (kind in this._vertexBuffers) {
  39773. // using slice() to make a copy of the array and not just reference it
  39774. var data = this.getVerticesData(kind);
  39775. if (data instanceof Float32Array) {
  39776. vertexData.set(new Float32Array(data), kind);
  39777. }
  39778. else {
  39779. vertexData.set(data.slice(0), kind);
  39780. }
  39781. if (!stopChecking) {
  39782. var vb = this.getVertexBuffer(kind);
  39783. if (vb) {
  39784. updatable = vb.isUpdatable();
  39785. stopChecking = !updatable;
  39786. }
  39787. }
  39788. }
  39789. var geometry = new Geometry(id, this._scene, vertexData, updatable);
  39790. geometry.delayLoadState = this.delayLoadState;
  39791. geometry.delayLoadingFile = this.delayLoadingFile;
  39792. geometry._delayLoadingFunction = this._delayLoadingFunction;
  39793. for (kind in this._delayInfo) {
  39794. geometry._delayInfo = geometry._delayInfo || [];
  39795. geometry._delayInfo.push(kind);
  39796. }
  39797. // Bounding info
  39798. geometry._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  39799. return geometry;
  39800. };
  39801. /**
  39802. * Serialize the current geometry info (and not the vertices data) into a JSON object
  39803. * @return a JSON representation of the current geometry data (without the vertices data)
  39804. */
  39805. Geometry.prototype.serialize = function () {
  39806. var serializationObject = {};
  39807. serializationObject.id = this.id;
  39808. serializationObject.updatable = this._updatable;
  39809. if (BABYLON.Tags && BABYLON.Tags.HasTags(this)) {
  39810. serializationObject.tags = BABYLON.Tags.GetTags(this);
  39811. }
  39812. return serializationObject;
  39813. };
  39814. Geometry.prototype.toNumberArray = function (origin) {
  39815. if (Array.isArray(origin)) {
  39816. return origin;
  39817. }
  39818. else {
  39819. return Array.prototype.slice.call(origin);
  39820. }
  39821. };
  39822. /**
  39823. * Serialize all vertices data into a JSON oject
  39824. * @returns a JSON representation of the current geometry data
  39825. */
  39826. Geometry.prototype.serializeVerticeData = function () {
  39827. var serializationObject = this.serialize();
  39828. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  39829. serializationObject.positions = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.PositionKind));
  39830. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.PositionKind)) {
  39831. serializationObject.positions._updatable = true;
  39832. }
  39833. }
  39834. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  39835. serializationObject.normals = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.NormalKind));
  39836. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.NormalKind)) {
  39837. serializationObject.normals._updatable = true;
  39838. }
  39839. }
  39840. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
  39841. serializationObject.tangets = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.TangentKind));
  39842. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.TangentKind)) {
  39843. serializationObject.tangets._updatable = true;
  39844. }
  39845. }
  39846. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  39847. serializationObject.uvs = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UVKind));
  39848. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UVKind)) {
  39849. serializationObject.uvs._updatable = true;
  39850. }
  39851. }
  39852. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  39853. serializationObject.uv2s = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UV2Kind));
  39854. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UV2Kind)) {
  39855. serializationObject.uv2s._updatable = true;
  39856. }
  39857. }
  39858. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV3Kind)) {
  39859. serializationObject.uv3s = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UV3Kind));
  39860. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UV3Kind)) {
  39861. serializationObject.uv3s._updatable = true;
  39862. }
  39863. }
  39864. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV4Kind)) {
  39865. serializationObject.uv4s = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UV4Kind));
  39866. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UV4Kind)) {
  39867. serializationObject.uv4s._updatable = true;
  39868. }
  39869. }
  39870. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV5Kind)) {
  39871. serializationObject.uv5s = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UV5Kind));
  39872. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UV5Kind)) {
  39873. serializationObject.uv5s._updatable = true;
  39874. }
  39875. }
  39876. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV6Kind)) {
  39877. serializationObject.uv6s = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.UV6Kind));
  39878. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.UV6Kind)) {
  39879. serializationObject.uv6s._updatable = true;
  39880. }
  39881. }
  39882. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  39883. serializationObject.colors = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.ColorKind));
  39884. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.ColorKind)) {
  39885. serializationObject.colors._updatable = true;
  39886. }
  39887. }
  39888. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
  39889. serializationObject.matricesIndices = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind));
  39890. serializationObject.matricesIndices._isExpanded = true;
  39891. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.MatricesIndicesKind)) {
  39892. serializationObject.matricesIndices._updatable = true;
  39893. }
  39894. }
  39895. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  39896. serializationObject.matricesWeights = this.toNumberArray(this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind));
  39897. if (this.isVertexBufferUpdatable(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  39898. serializationObject.matricesWeights._updatable = true;
  39899. }
  39900. }
  39901. serializationObject.indices = this.toNumberArray(this.getIndices());
  39902. return serializationObject;
  39903. };
  39904. // Statics
  39905. /**
  39906. * Extracts a clone of a mesh geometry
  39907. * @param mesh defines the source mesh
  39908. * @param id defines the unique ID of the new geometry object
  39909. * @returns the new geometry object
  39910. */
  39911. Geometry.ExtractFromMesh = function (mesh, id) {
  39912. var geometry = mesh._geometry;
  39913. if (!geometry) {
  39914. return null;
  39915. }
  39916. return geometry.copy(id);
  39917. };
  39918. /**
  39919. * You should now use Tools.RandomId(), this method is still here for legacy reasons.
  39920. * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  39921. * Be aware Math.random() could cause collisions, but:
  39922. * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"
  39923. * @returns a string containing a new GUID
  39924. */
  39925. Geometry.RandomId = function () {
  39926. return BABYLON.Tools.RandomId();
  39927. };
  39928. /** @hidden */
  39929. Geometry._ImportGeometry = function (parsedGeometry, mesh) {
  39930. var scene = mesh.getScene();
  39931. // Geometry
  39932. var geometryId = parsedGeometry.geometryId;
  39933. if (geometryId) {
  39934. var geometry = scene.getGeometryByID(geometryId);
  39935. if (geometry) {
  39936. geometry.applyToMesh(mesh);
  39937. }
  39938. }
  39939. else if (parsedGeometry instanceof ArrayBuffer) {
  39940. var binaryInfo = mesh._binaryInfo;
  39941. if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {
  39942. var positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);
  39943. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData, false);
  39944. }
  39945. if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {
  39946. var normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);
  39947. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData, false);
  39948. }
  39949. if (binaryInfo.tangetsAttrDesc && binaryInfo.tangetsAttrDesc.count > 0) {
  39950. var tangentsData = new Float32Array(parsedGeometry, binaryInfo.tangetsAttrDesc.offset, binaryInfo.tangetsAttrDesc.count);
  39951. mesh.setVerticesData(BABYLON.VertexBuffer.TangentKind, tangentsData, false);
  39952. }
  39953. if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {
  39954. var uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);
  39955. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvsData, false);
  39956. }
  39957. if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {
  39958. var uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);
  39959. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, uvs2Data, false);
  39960. }
  39961. if (binaryInfo.uvs3AttrDesc && binaryInfo.uvs3AttrDesc.count > 0) {
  39962. var uvs3Data = new Float32Array(parsedGeometry, binaryInfo.uvs3AttrDesc.offset, binaryInfo.uvs3AttrDesc.count);
  39963. mesh.setVerticesData(BABYLON.VertexBuffer.UV3Kind, uvs3Data, false);
  39964. }
  39965. if (binaryInfo.uvs4AttrDesc && binaryInfo.uvs4AttrDesc.count > 0) {
  39966. var uvs4Data = new Float32Array(parsedGeometry, binaryInfo.uvs4AttrDesc.offset, binaryInfo.uvs4AttrDesc.count);
  39967. mesh.setVerticesData(BABYLON.VertexBuffer.UV4Kind, uvs4Data, false);
  39968. }
  39969. if (binaryInfo.uvs5AttrDesc && binaryInfo.uvs5AttrDesc.count > 0) {
  39970. var uvs5Data = new Float32Array(parsedGeometry, binaryInfo.uvs5AttrDesc.offset, binaryInfo.uvs5AttrDesc.count);
  39971. mesh.setVerticesData(BABYLON.VertexBuffer.UV5Kind, uvs5Data, false);
  39972. }
  39973. if (binaryInfo.uvs6AttrDesc && binaryInfo.uvs6AttrDesc.count > 0) {
  39974. var uvs6Data = new Float32Array(parsedGeometry, binaryInfo.uvs6AttrDesc.offset, binaryInfo.uvs6AttrDesc.count);
  39975. mesh.setVerticesData(BABYLON.VertexBuffer.UV6Kind, uvs6Data, false);
  39976. }
  39977. if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
  39978. var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
  39979. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);
  39980. }
  39981. if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
  39982. var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);
  39983. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndicesData, false);
  39984. }
  39985. if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
  39986. var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
  39987. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
  39988. }
  39989. if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {
  39990. var indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);
  39991. mesh.setIndices(indicesData, null);
  39992. }
  39993. if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {
  39994. var subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);
  39995. mesh.subMeshes = [];
  39996. for (var i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {
  39997. var materialIndex = subMeshesData[(i * 5) + 0];
  39998. var verticesStart = subMeshesData[(i * 5) + 1];
  39999. var verticesCount = subMeshesData[(i * 5) + 2];
  40000. var indexStart = subMeshesData[(i * 5) + 3];
  40001. var indexCount = subMeshesData[(i * 5) + 4];
  40002. BABYLON.SubMesh.AddToMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);
  40003. }
  40004. }
  40005. }
  40006. else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
  40007. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, parsedGeometry.positions, parsedGeometry.positions._updatable);
  40008. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, parsedGeometry.normals, parsedGeometry.normals._updatable);
  40009. if (parsedGeometry.tangents) {
  40010. mesh.setVerticesData(BABYLON.VertexBuffer.TangentKind, parsedGeometry.tangents, parsedGeometry.tangents._updatable);
  40011. }
  40012. if (parsedGeometry.uvs) {
  40013. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, parsedGeometry.uvs, parsedGeometry.uvs._updatable);
  40014. }
  40015. if (parsedGeometry.uvs2) {
  40016. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, parsedGeometry.uvs2, parsedGeometry.uvs2._updatable);
  40017. }
  40018. if (parsedGeometry.uvs3) {
  40019. mesh.setVerticesData(BABYLON.VertexBuffer.UV3Kind, parsedGeometry.uvs3, parsedGeometry.uvs3._updatable);
  40020. }
  40021. if (parsedGeometry.uvs4) {
  40022. mesh.setVerticesData(BABYLON.VertexBuffer.UV4Kind, parsedGeometry.uvs4, parsedGeometry.uvs4._updatable);
  40023. }
  40024. if (parsedGeometry.uvs5) {
  40025. mesh.setVerticesData(BABYLON.VertexBuffer.UV5Kind, parsedGeometry.uvs5, parsedGeometry.uvs5._updatable);
  40026. }
  40027. if (parsedGeometry.uvs6) {
  40028. mesh.setVerticesData(BABYLON.VertexBuffer.UV6Kind, parsedGeometry.uvs6, parsedGeometry.uvs6._updatable);
  40029. }
  40030. if (parsedGeometry.colors) {
  40031. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, BABYLON.Color4.CheckColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), parsedGeometry.colors._updatable);
  40032. }
  40033. if (parsedGeometry.matricesIndices) {
  40034. if (!parsedGeometry.matricesIndices._isExpanded) {
  40035. var floatIndices = [];
  40036. for (var i = 0; i < parsedGeometry.matricesIndices.length; i++) {
  40037. var matricesIndex = parsedGeometry.matricesIndices[i];
  40038. floatIndices.push(matricesIndex & 0x000000FF);
  40039. floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
  40040. floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
  40041. floatIndices.push(matricesIndex >> 24);
  40042. }
  40043. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable);
  40044. }
  40045. else {
  40046. delete parsedGeometry.matricesIndices._isExpanded;
  40047. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, parsedGeometry.matricesIndices._updatable);
  40048. }
  40049. }
  40050. if (parsedGeometry.matricesIndicesExtra) {
  40051. if (!parsedGeometry.matricesIndicesExtra._isExpanded) {
  40052. var floatIndices = [];
  40053. for (var i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {
  40054. var matricesIndex = parsedGeometry.matricesIndicesExtra[i];
  40055. floatIndices.push(matricesIndex & 0x000000FF);
  40056. floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
  40057. floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
  40058. floatIndices.push(matricesIndex >> 24);
  40059. }
  40060. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, floatIndices, parsedGeometry.matricesIndicesExtra._updatable);
  40061. }
  40062. else {
  40063. delete parsedGeometry.matricesIndices._isExpanded;
  40064. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, parsedGeometry.matricesIndicesExtra._updatable);
  40065. }
  40066. }
  40067. if (parsedGeometry.matricesWeights) {
  40068. Geometry._CleanMatricesWeights(parsedGeometry, mesh);
  40069. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);
  40070. }
  40071. if (parsedGeometry.matricesWeightsExtra) {
  40072. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);
  40073. }
  40074. mesh.setIndices(parsedGeometry.indices, null);
  40075. }
  40076. // SubMeshes
  40077. if (parsedGeometry.subMeshes) {
  40078. mesh.subMeshes = [];
  40079. for (var subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {
  40080. var parsedSubMesh = parsedGeometry.subMeshes[subIndex];
  40081. BABYLON.SubMesh.AddToMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);
  40082. }
  40083. }
  40084. // Flat shading
  40085. if (mesh._shouldGenerateFlatShading) {
  40086. mesh.convertToFlatShadedMesh();
  40087. delete mesh._shouldGenerateFlatShading;
  40088. }
  40089. // Update
  40090. mesh.computeWorldMatrix(true);
  40091. // Octree
  40092. var sceneOctree = scene.selectionOctree;
  40093. if (sceneOctree !== undefined && sceneOctree !== null) {
  40094. sceneOctree.addMesh(mesh);
  40095. }
  40096. };
  40097. Geometry._CleanMatricesWeights = function (parsedGeometry, mesh) {
  40098. var epsilon = 1e-3;
  40099. if (!BABYLON.SceneLoader.CleanBoneMatrixWeights) {
  40100. return;
  40101. }
  40102. var noInfluenceBoneIndex = 0.0;
  40103. if (parsedGeometry.skeletonId > -1) {
  40104. var skeleton = mesh.getScene().getLastSkeletonByID(parsedGeometry.skeletonId);
  40105. if (!skeleton) {
  40106. return;
  40107. }
  40108. noInfluenceBoneIndex = skeleton.bones.length;
  40109. }
  40110. else {
  40111. return;
  40112. }
  40113. var matricesIndices = mesh.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
  40114. var matricesIndicesExtra = mesh.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  40115. var matricesWeights = parsedGeometry.matricesWeights;
  40116. var matricesWeightsExtra = parsedGeometry.matricesWeightsExtra;
  40117. var influencers = parsedGeometry.numBoneInfluencer;
  40118. var size = matricesWeights.length;
  40119. for (var i = 0; i < size; i += 4) {
  40120. var weight = 0.0;
  40121. var firstZeroWeight = -1;
  40122. for (var j = 0; j < 4; j++) {
  40123. var w = matricesWeights[i + j];
  40124. weight += w;
  40125. if (w < epsilon && firstZeroWeight < 0) {
  40126. firstZeroWeight = j;
  40127. }
  40128. }
  40129. if (matricesWeightsExtra) {
  40130. for (var j = 0; j < 4; j++) {
  40131. var w = matricesWeightsExtra[i + j];
  40132. weight += w;
  40133. if (w < epsilon && firstZeroWeight < 0) {
  40134. firstZeroWeight = j + 4;
  40135. }
  40136. }
  40137. }
  40138. if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
  40139. firstZeroWeight = influencers - 1;
  40140. }
  40141. if (weight > epsilon) {
  40142. var mweight = 1.0 / weight;
  40143. for (var j = 0; j < 4; j++) {
  40144. matricesWeights[i + j] *= mweight;
  40145. }
  40146. if (matricesWeightsExtra) {
  40147. for (var j = 0; j < 4; j++) {
  40148. matricesWeightsExtra[i + j] *= mweight;
  40149. }
  40150. }
  40151. }
  40152. else {
  40153. if (firstZeroWeight >= 4) {
  40154. matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
  40155. matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
  40156. }
  40157. else {
  40158. matricesWeights[i + firstZeroWeight] = 1.0 - weight;
  40159. matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
  40160. }
  40161. }
  40162. }
  40163. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
  40164. if (parsedGeometry.matricesWeightsExtra) {
  40165. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
  40166. }
  40167. };
  40168. /**
  40169. * Create a new geometry from persisted data (Using .babylon file format)
  40170. * @param parsedVertexData defines the persisted data
  40171. * @param scene defines the hosting scene
  40172. * @param rootUrl defines the root url to use to load assets (like delayed data)
  40173. * @returns the new geometry object
  40174. */
  40175. Geometry.Parse = function (parsedVertexData, scene, rootUrl) {
  40176. if (scene.getGeometryByID(parsedVertexData.id)) {
  40177. return null; // null since geometry could be something else than a box...
  40178. }
  40179. var geometry = new Geometry(parsedVertexData.id, scene, undefined, parsedVertexData.updatable);
  40180. if (BABYLON.Tags) {
  40181. BABYLON.Tags.AddTagsTo(geometry, parsedVertexData.tags);
  40182. }
  40183. if (parsedVertexData.delayLoadingFile) {
  40184. geometry.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  40185. geometry.delayLoadingFile = rootUrl + parsedVertexData.delayLoadingFile;
  40186. geometry._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMaximum));
  40187. geometry._delayInfo = [];
  40188. if (parsedVertexData.hasUVs) {
  40189. geometry._delayInfo.push(BABYLON.VertexBuffer.UVKind);
  40190. }
  40191. if (parsedVertexData.hasUVs2) {
  40192. geometry._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
  40193. }
  40194. if (parsedVertexData.hasUVs3) {
  40195. geometry._delayInfo.push(BABYLON.VertexBuffer.UV3Kind);
  40196. }
  40197. if (parsedVertexData.hasUVs4) {
  40198. geometry._delayInfo.push(BABYLON.VertexBuffer.UV4Kind);
  40199. }
  40200. if (parsedVertexData.hasUVs5) {
  40201. geometry._delayInfo.push(BABYLON.VertexBuffer.UV5Kind);
  40202. }
  40203. if (parsedVertexData.hasUVs6) {
  40204. geometry._delayInfo.push(BABYLON.VertexBuffer.UV6Kind);
  40205. }
  40206. if (parsedVertexData.hasColors) {
  40207. geometry._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
  40208. }
  40209. if (parsedVertexData.hasMatricesIndices) {
  40210. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  40211. }
  40212. if (parsedVertexData.hasMatricesWeights) {
  40213. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  40214. }
  40215. geometry._delayLoadingFunction = BABYLON.VertexData.ImportVertexData;
  40216. }
  40217. else {
  40218. BABYLON.VertexData.ImportVertexData(parsedVertexData, geometry);
  40219. }
  40220. scene.pushGeometry(geometry, true);
  40221. return geometry;
  40222. };
  40223. return Geometry;
  40224. }());
  40225. BABYLON.Geometry = Geometry;
  40226. // Primitives
  40227. /// Abstract class
  40228. /**
  40229. * Abstract class used to provide common services for all typed geometries
  40230. * @hidden
  40231. */
  40232. var _PrimitiveGeometry = /** @class */ (function (_super) {
  40233. __extends(_PrimitiveGeometry, _super);
  40234. /**
  40235. * Creates a new typed geometry
  40236. * @param id defines the unique ID of the geometry
  40237. * @param scene defines the hosting scene
  40238. * @param _canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40239. * @param mesh defines the hosting mesh (can be null)
  40240. */
  40241. function _PrimitiveGeometry(id, scene, _canBeRegenerated, mesh) {
  40242. if (_canBeRegenerated === void 0) { _canBeRegenerated = false; }
  40243. if (mesh === void 0) { mesh = null; }
  40244. var _this = _super.call(this, id, scene, undefined, false, mesh) || this;
  40245. _this._canBeRegenerated = _canBeRegenerated;
  40246. _this._beingRegenerated = true;
  40247. _this.regenerate();
  40248. _this._beingRegenerated = false;
  40249. return _this;
  40250. }
  40251. /**
  40252. * Gets a value indicating if the geometry supports being regenerated with new parameters (false by default)
  40253. * @returns true if the geometry can be regenerated
  40254. */
  40255. _PrimitiveGeometry.prototype.canBeRegenerated = function () {
  40256. return this._canBeRegenerated;
  40257. };
  40258. /**
  40259. * If the geometry supports regeneration, the function will recreates the geometry with updated parameter values
  40260. */
  40261. _PrimitiveGeometry.prototype.regenerate = function () {
  40262. if (!this._canBeRegenerated) {
  40263. return;
  40264. }
  40265. this._beingRegenerated = true;
  40266. this.setAllVerticesData(this._regenerateVertexData(), false);
  40267. this._beingRegenerated = false;
  40268. };
  40269. /**
  40270. * Clone the geometry
  40271. * @param id defines the unique ID of the new geometry
  40272. * @returns the new geometry
  40273. */
  40274. _PrimitiveGeometry.prototype.asNewGeometry = function (id) {
  40275. return _super.prototype.copy.call(this, id);
  40276. };
  40277. // overrides
  40278. _PrimitiveGeometry.prototype.setAllVerticesData = function (vertexData, updatable) {
  40279. if (!this._beingRegenerated) {
  40280. return;
  40281. }
  40282. _super.prototype.setAllVerticesData.call(this, vertexData, false);
  40283. };
  40284. _PrimitiveGeometry.prototype.setVerticesData = function (kind, data, updatable) {
  40285. if (!this._beingRegenerated) {
  40286. return;
  40287. }
  40288. _super.prototype.setVerticesData.call(this, kind, data, false);
  40289. };
  40290. // to override
  40291. /** @hidden */
  40292. _PrimitiveGeometry.prototype._regenerateVertexData = function () {
  40293. throw new Error("Abstract method");
  40294. };
  40295. _PrimitiveGeometry.prototype.copy = function (id) {
  40296. throw new Error("Must be overriden in sub-classes.");
  40297. };
  40298. _PrimitiveGeometry.prototype.serialize = function () {
  40299. var serializationObject = _super.prototype.serialize.call(this);
  40300. serializationObject.canBeRegenerated = this.canBeRegenerated();
  40301. return serializationObject;
  40302. };
  40303. return _PrimitiveGeometry;
  40304. }(Geometry));
  40305. BABYLON._PrimitiveGeometry = _PrimitiveGeometry;
  40306. /**
  40307. * Creates a ribbon geometry
  40308. * @description See http://doc.babylonjs.com/how_to/ribbon_tutorial, http://doc.babylonjs.com/resources/maths_make_ribbons
  40309. */
  40310. var RibbonGeometry = /** @class */ (function (_super) {
  40311. __extends(RibbonGeometry, _super);
  40312. /**
  40313. * Creates a ribbon geometry
  40314. * @param id defines the unique ID of the geometry
  40315. * @param scene defines the hosting scene
  40316. * @param pathArray defines the array of paths to use
  40317. * @param closeArray defines if the last path and the first path must be joined
  40318. * @param closePath defines if the last and first points of each path in your pathArray must be joined
  40319. * @param offset defines the offset between points
  40320. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40321. * @param mesh defines the hosting mesh (can be null)
  40322. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40323. */
  40324. function RibbonGeometry(id, scene,
  40325. /**
  40326. * Defines the array of paths to use
  40327. */
  40328. pathArray,
  40329. /**
  40330. * Defines if the last and first points of each path in your pathArray must be joined
  40331. */
  40332. closeArray,
  40333. /**
  40334. * Defines if the last and first points of each path in your pathArray must be joined
  40335. */
  40336. closePath,
  40337. /**
  40338. * Defines the offset between points
  40339. */
  40340. offset, canBeRegenerated, mesh,
  40341. /**
  40342. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40343. */
  40344. side) {
  40345. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40346. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40347. _this.pathArray = pathArray;
  40348. _this.closeArray = closeArray;
  40349. _this.closePath = closePath;
  40350. _this.offset = offset;
  40351. _this.side = side;
  40352. return _this;
  40353. }
  40354. /** @hidden */
  40355. RibbonGeometry.prototype._regenerateVertexData = function () {
  40356. return BABYLON.VertexData.CreateRibbon({ pathArray: this.pathArray, closeArray: this.closeArray, closePath: this.closePath, offset: this.offset, sideOrientation: this.side });
  40357. };
  40358. RibbonGeometry.prototype.copy = function (id) {
  40359. return new RibbonGeometry(id, this.getScene(), this.pathArray, this.closeArray, this.closePath, this.offset, this.canBeRegenerated(), undefined, this.side);
  40360. };
  40361. return RibbonGeometry;
  40362. }(_PrimitiveGeometry));
  40363. BABYLON.RibbonGeometry = RibbonGeometry;
  40364. /**
  40365. * Creates a box geometry
  40366. * @description see http://doc.babylonjs.com/how_to/set_shapes#box
  40367. */
  40368. var BoxGeometry = /** @class */ (function (_super) {
  40369. __extends(BoxGeometry, _super);
  40370. /**
  40371. * Creates a box geometry
  40372. * @param id defines the unique ID of the geometry
  40373. * @param scene defines the hosting scene
  40374. * @param size defines the zise of the box (width, height and depth are the same)
  40375. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40376. * @param mesh defines the hosting mesh (can be null)
  40377. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40378. */
  40379. function BoxGeometry(id, scene,
  40380. /**
  40381. * Defines the zise of the box (width, height and depth are the same)
  40382. */
  40383. size, canBeRegenerated, mesh,
  40384. /**
  40385. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40386. */
  40387. side) {
  40388. if (mesh === void 0) { mesh = null; }
  40389. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40390. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40391. _this.size = size;
  40392. _this.side = side;
  40393. return _this;
  40394. }
  40395. BoxGeometry.prototype._regenerateVertexData = function () {
  40396. return BABYLON.VertexData.CreateBox({ size: this.size, sideOrientation: this.side });
  40397. };
  40398. BoxGeometry.prototype.copy = function (id) {
  40399. return new BoxGeometry(id, this.getScene(), this.size, this.canBeRegenerated(), undefined, this.side);
  40400. };
  40401. BoxGeometry.prototype.serialize = function () {
  40402. var serializationObject = _super.prototype.serialize.call(this);
  40403. serializationObject.size = this.size;
  40404. return serializationObject;
  40405. };
  40406. BoxGeometry.Parse = function (parsedBox, scene) {
  40407. if (scene.getGeometryByID(parsedBox.id)) {
  40408. return null; // null since geometry could be something else than a box...
  40409. }
  40410. var box = new BoxGeometry(parsedBox.id, scene, parsedBox.size, parsedBox.canBeRegenerated, null);
  40411. if (BABYLON.Tags) {
  40412. BABYLON.Tags.AddTagsTo(box, parsedBox.tags);
  40413. }
  40414. scene.pushGeometry(box, true);
  40415. return box;
  40416. };
  40417. return BoxGeometry;
  40418. }(_PrimitiveGeometry));
  40419. BABYLON.BoxGeometry = BoxGeometry;
  40420. /**
  40421. * Creates a sphere geometry
  40422. * @description see http://doc.babylonjs.com/how_to/set_shapes#sphere
  40423. */
  40424. var SphereGeometry = /** @class */ (function (_super) {
  40425. __extends(SphereGeometry, _super);
  40426. /**
  40427. * Create a new sphere geometry
  40428. * @param id defines the unique ID of the geometry
  40429. * @param scene defines the hosting scene
  40430. * @param segments defines the number of segments to use to create the sphere
  40431. * @param diameter defines the diameter of the sphere
  40432. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40433. * @param mesh defines the hosting mesh (can be null)
  40434. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40435. */
  40436. function SphereGeometry(id, scene,
  40437. /**
  40438. * Defines the number of segments to use to create the sphere
  40439. */
  40440. segments,
  40441. /**
  40442. * Defines the diameter of the sphere
  40443. */
  40444. diameter, canBeRegenerated, mesh,
  40445. /**
  40446. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40447. */
  40448. side) {
  40449. if (mesh === void 0) { mesh = null; }
  40450. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40451. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40452. _this.segments = segments;
  40453. _this.diameter = diameter;
  40454. _this.side = side;
  40455. return _this;
  40456. }
  40457. SphereGeometry.prototype._regenerateVertexData = function () {
  40458. return BABYLON.VertexData.CreateSphere({ segments: this.segments, diameter: this.diameter, sideOrientation: this.side });
  40459. };
  40460. SphereGeometry.prototype.copy = function (id) {
  40461. return new SphereGeometry(id, this.getScene(), this.segments, this.diameter, this.canBeRegenerated(), null, this.side);
  40462. };
  40463. SphereGeometry.prototype.serialize = function () {
  40464. var serializationObject = _super.prototype.serialize.call(this);
  40465. serializationObject.segments = this.segments;
  40466. serializationObject.diameter = this.diameter;
  40467. return serializationObject;
  40468. };
  40469. SphereGeometry.Parse = function (parsedSphere, scene) {
  40470. if (scene.getGeometryByID(parsedSphere.id)) {
  40471. return null; // null since geometry could be something else than a sphere...
  40472. }
  40473. var sphere = new SphereGeometry(parsedSphere.id, scene, parsedSphere.segments, parsedSphere.diameter, parsedSphere.canBeRegenerated, null);
  40474. if (BABYLON.Tags) {
  40475. BABYLON.Tags.AddTagsTo(sphere, parsedSphere.tags);
  40476. }
  40477. scene.pushGeometry(sphere, true);
  40478. return sphere;
  40479. };
  40480. return SphereGeometry;
  40481. }(_PrimitiveGeometry));
  40482. BABYLON.SphereGeometry = SphereGeometry;
  40483. /**
  40484. * Creates a disc geometry
  40485. * @description see http://doc.babylonjs.com/how_to/set_shapes#disc-or-regular-polygon
  40486. */
  40487. var DiscGeometry = /** @class */ (function (_super) {
  40488. __extends(DiscGeometry, _super);
  40489. /**
  40490. * Creates a new disc geometry
  40491. * @param id defines the unique ID of the geometry
  40492. * @param scene defines the hosting scene
  40493. * @param radius defines the radius of the disc
  40494. * @param tessellation defines the tesselation factor to apply to the disc
  40495. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40496. * @param mesh defines the hosting mesh (can be null)
  40497. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40498. */
  40499. function DiscGeometry(id, scene,
  40500. /**
  40501. * Defines the radius of the disc
  40502. */
  40503. radius,
  40504. /**
  40505. * Defines the tesselation factor to apply to the disc
  40506. */
  40507. tessellation, canBeRegenerated, mesh,
  40508. /**
  40509. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40510. */
  40511. side) {
  40512. if (mesh === void 0) { mesh = null; }
  40513. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40514. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40515. _this.radius = radius;
  40516. _this.tessellation = tessellation;
  40517. _this.side = side;
  40518. return _this;
  40519. }
  40520. DiscGeometry.prototype._regenerateVertexData = function () {
  40521. return BABYLON.VertexData.CreateDisc({ radius: this.radius, tessellation: this.tessellation, sideOrientation: this.side });
  40522. };
  40523. DiscGeometry.prototype.copy = function (id) {
  40524. return new DiscGeometry(id, this.getScene(), this.radius, this.tessellation, this.canBeRegenerated(), null, this.side);
  40525. };
  40526. return DiscGeometry;
  40527. }(_PrimitiveGeometry));
  40528. BABYLON.DiscGeometry = DiscGeometry;
  40529. /**
  40530. * Creates a new cylinder geometry
  40531. * @description see http://doc.babylonjs.com/how_to/set_shapes#cylinder-or-cone
  40532. */
  40533. var CylinderGeometry = /** @class */ (function (_super) {
  40534. __extends(CylinderGeometry, _super);
  40535. /**
  40536. * Creates a new cylinder geometry
  40537. * @param id defines the unique ID of the geometry
  40538. * @param scene defines the hosting scene
  40539. * @param height defines the height of the cylinder
  40540. * @param diameterTop defines the diameter of the cylinder's top cap
  40541. * @param diameterBottom defines the diameter of the cylinder's bottom cap
  40542. * @param tessellation defines the tessellation factor to apply to the cylinder (number of radial sides)
  40543. * @param subdivisions defines the number of subdivisions to apply to the cylinder (number of rings) (1 by default)
  40544. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40545. * @param mesh defines the hosting mesh (can be null)
  40546. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40547. */
  40548. function CylinderGeometry(id, scene,
  40549. /**
  40550. * Defines the height of the cylinder
  40551. */
  40552. height,
  40553. /**
  40554. * Defines the diameter of the cylinder's top cap
  40555. */
  40556. diameterTop,
  40557. /**
  40558. * Defines the diameter of the cylinder's bottom cap
  40559. */
  40560. diameterBottom,
  40561. /**
  40562. * Defines the tessellation factor to apply to the cylinder
  40563. */
  40564. tessellation,
  40565. /**
  40566. * Defines the number of subdivisions to apply to the cylinder (1 by default)
  40567. */
  40568. subdivisions, canBeRegenerated, mesh,
  40569. /**
  40570. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40571. */
  40572. side) {
  40573. if (subdivisions === void 0) { subdivisions = 1; }
  40574. if (mesh === void 0) { mesh = null; }
  40575. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40576. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40577. _this.height = height;
  40578. _this.diameterTop = diameterTop;
  40579. _this.diameterBottom = diameterBottom;
  40580. _this.tessellation = tessellation;
  40581. _this.subdivisions = subdivisions;
  40582. _this.side = side;
  40583. return _this;
  40584. }
  40585. CylinderGeometry.prototype._regenerateVertexData = function () {
  40586. return BABYLON.VertexData.CreateCylinder({ height: this.height, diameterTop: this.diameterTop, diameterBottom: this.diameterBottom, tessellation: this.tessellation, subdivisions: this.subdivisions, sideOrientation: this.side });
  40587. };
  40588. CylinderGeometry.prototype.copy = function (id) {
  40589. return new CylinderGeometry(id, this.getScene(), this.height, this.diameterTop, this.diameterBottom, this.tessellation, this.subdivisions, this.canBeRegenerated(), null, this.side);
  40590. };
  40591. CylinderGeometry.prototype.serialize = function () {
  40592. var serializationObject = _super.prototype.serialize.call(this);
  40593. serializationObject.height = this.height;
  40594. serializationObject.diameterTop = this.diameterTop;
  40595. serializationObject.diameterBottom = this.diameterBottom;
  40596. serializationObject.tessellation = this.tessellation;
  40597. return serializationObject;
  40598. };
  40599. CylinderGeometry.Parse = function (parsedCylinder, scene) {
  40600. if (scene.getGeometryByID(parsedCylinder.id)) {
  40601. return null; // null since geometry could be something else than a cylinder...
  40602. }
  40603. var cylinder = new CylinderGeometry(parsedCylinder.id, scene, parsedCylinder.height, parsedCylinder.diameterTop, parsedCylinder.diameterBottom, parsedCylinder.tessellation, parsedCylinder.subdivisions, parsedCylinder.canBeRegenerated, null);
  40604. if (BABYLON.Tags) {
  40605. BABYLON.Tags.AddTagsTo(cylinder, parsedCylinder.tags);
  40606. }
  40607. scene.pushGeometry(cylinder, true);
  40608. return cylinder;
  40609. };
  40610. return CylinderGeometry;
  40611. }(_PrimitiveGeometry));
  40612. BABYLON.CylinderGeometry = CylinderGeometry;
  40613. /**
  40614. * Creates a new torus geometry
  40615. * @description see http://doc.babylonjs.com/how_to/set_shapes#torus
  40616. */
  40617. var TorusGeometry = /** @class */ (function (_super) {
  40618. __extends(TorusGeometry, _super);
  40619. /**
  40620. * Creates a new torus geometry
  40621. * @param id defines the unique ID of the geometry
  40622. * @param scene defines the hosting scene
  40623. * @param diameter defines the diameter of the torus
  40624. * @param thickness defines the thickness of the torus (ie. internal diameter)
  40625. * @param tessellation defines the tesselation factor to apply to the torus (number of segments along the circle)
  40626. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40627. * @param mesh defines the hosting mesh (can be null)
  40628. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40629. */
  40630. function TorusGeometry(id, scene,
  40631. /**
  40632. * Defines the diameter of the torus
  40633. */
  40634. diameter,
  40635. /**
  40636. * Defines the thickness of the torus (ie. internal diameter)
  40637. */
  40638. thickness,
  40639. /**
  40640. * Defines the tesselation factor to apply to the torus
  40641. */
  40642. tessellation, canBeRegenerated, mesh,
  40643. /**
  40644. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40645. */
  40646. side) {
  40647. if (mesh === void 0) { mesh = null; }
  40648. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40649. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40650. _this.diameter = diameter;
  40651. _this.thickness = thickness;
  40652. _this.tessellation = tessellation;
  40653. _this.side = side;
  40654. return _this;
  40655. }
  40656. TorusGeometry.prototype._regenerateVertexData = function () {
  40657. return BABYLON.VertexData.CreateTorus({ diameter: this.diameter, thickness: this.thickness, tessellation: this.tessellation, sideOrientation: this.side });
  40658. };
  40659. TorusGeometry.prototype.copy = function (id) {
  40660. return new TorusGeometry(id, this.getScene(), this.diameter, this.thickness, this.tessellation, this.canBeRegenerated(), null, this.side);
  40661. };
  40662. TorusGeometry.prototype.serialize = function () {
  40663. var serializationObject = _super.prototype.serialize.call(this);
  40664. serializationObject.diameter = this.diameter;
  40665. serializationObject.thickness = this.thickness;
  40666. serializationObject.tessellation = this.tessellation;
  40667. return serializationObject;
  40668. };
  40669. TorusGeometry.Parse = function (parsedTorus, scene) {
  40670. if (scene.getGeometryByID(parsedTorus.id)) {
  40671. return null; // null since geometry could be something else than a torus...
  40672. }
  40673. var torus = new TorusGeometry(parsedTorus.id, scene, parsedTorus.diameter, parsedTorus.thickness, parsedTorus.tessellation, parsedTorus.canBeRegenerated, null);
  40674. if (BABYLON.Tags) {
  40675. BABYLON.Tags.AddTagsTo(torus, parsedTorus.tags);
  40676. }
  40677. scene.pushGeometry(torus, true);
  40678. return torus;
  40679. };
  40680. return TorusGeometry;
  40681. }(_PrimitiveGeometry));
  40682. BABYLON.TorusGeometry = TorusGeometry;
  40683. /**
  40684. * Creates a new ground geometry
  40685. * @description see http://doc.babylonjs.com/how_to/set_shapes#ground
  40686. */
  40687. var GroundGeometry = /** @class */ (function (_super) {
  40688. __extends(GroundGeometry, _super);
  40689. /**
  40690. * Creates a new ground geometry
  40691. * @param id defines the unique ID of the geometry
  40692. * @param scene defines the hosting scene
  40693. * @param width defines the width of the ground
  40694. * @param height defines the height of the ground
  40695. * @param subdivisions defines the subdivisions to apply to the ground
  40696. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40697. * @param mesh defines the hosting mesh (can be null)
  40698. */
  40699. function GroundGeometry(id, scene,
  40700. /**
  40701. * Defines the width of the ground
  40702. */
  40703. width,
  40704. /**
  40705. * Defines the height of the ground
  40706. */
  40707. height,
  40708. /**
  40709. * Defines the subdivisions to apply to the ground
  40710. */
  40711. subdivisions, canBeRegenerated, mesh) {
  40712. if (mesh === void 0) { mesh = null; }
  40713. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40714. _this.width = width;
  40715. _this.height = height;
  40716. _this.subdivisions = subdivisions;
  40717. return _this;
  40718. }
  40719. GroundGeometry.prototype._regenerateVertexData = function () {
  40720. return BABYLON.VertexData.CreateGround({ width: this.width, height: this.height, subdivisions: this.subdivisions });
  40721. };
  40722. GroundGeometry.prototype.copy = function (id) {
  40723. return new GroundGeometry(id, this.getScene(), this.width, this.height, this.subdivisions, this.canBeRegenerated(), null);
  40724. };
  40725. GroundGeometry.prototype.serialize = function () {
  40726. var serializationObject = _super.prototype.serialize.call(this);
  40727. serializationObject.width = this.width;
  40728. serializationObject.height = this.height;
  40729. serializationObject.subdivisions = this.subdivisions;
  40730. return serializationObject;
  40731. };
  40732. GroundGeometry.Parse = function (parsedGround, scene) {
  40733. if (scene.getGeometryByID(parsedGround.id)) {
  40734. return null; // null since geometry could be something else than a ground...
  40735. }
  40736. var ground = new GroundGeometry(parsedGround.id, scene, parsedGround.width, parsedGround.height, parsedGround.subdivisions, parsedGround.canBeRegenerated, null);
  40737. if (BABYLON.Tags) {
  40738. BABYLON.Tags.AddTagsTo(ground, parsedGround.tags);
  40739. }
  40740. scene.pushGeometry(ground, true);
  40741. return ground;
  40742. };
  40743. return GroundGeometry;
  40744. }(_PrimitiveGeometry));
  40745. BABYLON.GroundGeometry = GroundGeometry;
  40746. /**
  40747. * Creates a tiled ground geometry
  40748. * @description see http://doc.babylonjs.com/how_to/set_shapes#tiled-ground
  40749. */
  40750. var TiledGroundGeometry = /** @class */ (function (_super) {
  40751. __extends(TiledGroundGeometry, _super);
  40752. /**
  40753. * Creates a tiled ground geometry
  40754. * @param id defines the unique ID of the geometry
  40755. * @param scene defines the hosting scene
  40756. * @param xmin defines the minimum value on X axis
  40757. * @param zmin defines the minimum value on Z axis
  40758. * @param xmax defines the maximum value on X axis
  40759. * @param zmax defines the maximum value on Z axis
  40760. * @param subdivisions defines the subdivisions to apply to the ground (number of subdivisions (tiles) on the height and the width of the map)
  40761. * @param precision defines the precision to use when computing the tiles
  40762. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40763. * @param mesh defines the hosting mesh (can be null)
  40764. */
  40765. function TiledGroundGeometry(id, scene,
  40766. /**
  40767. * Defines the minimum value on X axis
  40768. */
  40769. xmin,
  40770. /**
  40771. * Defines the minimum value on Z axis
  40772. */
  40773. zmin,
  40774. /**
  40775. * Defines the maximum value on X axis
  40776. */
  40777. xmax,
  40778. /**
  40779. * Defines the maximum value on Z axis
  40780. */
  40781. zmax,
  40782. /**
  40783. * Defines the subdivisions to apply to the ground
  40784. */
  40785. subdivisions,
  40786. /**
  40787. * Defines the precision to use when computing the tiles
  40788. */
  40789. precision, canBeRegenerated, mesh) {
  40790. if (mesh === void 0) { mesh = null; }
  40791. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40792. _this.xmin = xmin;
  40793. _this.zmin = zmin;
  40794. _this.xmax = xmax;
  40795. _this.zmax = zmax;
  40796. _this.subdivisions = subdivisions;
  40797. _this.precision = precision;
  40798. return _this;
  40799. }
  40800. TiledGroundGeometry.prototype._regenerateVertexData = function () {
  40801. return BABYLON.VertexData.CreateTiledGround({ xmin: this.xmin, zmin: this.zmin, xmax: this.xmax, zmax: this.zmax, subdivisions: this.subdivisions, precision: this.precision });
  40802. };
  40803. TiledGroundGeometry.prototype.copy = function (id) {
  40804. return new TiledGroundGeometry(id, this.getScene(), this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision, this.canBeRegenerated(), null);
  40805. };
  40806. return TiledGroundGeometry;
  40807. }(_PrimitiveGeometry));
  40808. BABYLON.TiledGroundGeometry = TiledGroundGeometry;
  40809. /**
  40810. * Creates a plane geometry
  40811. * @description see http://doc.babylonjs.com/how_to/set_shapes#plane
  40812. */
  40813. var PlaneGeometry = /** @class */ (function (_super) {
  40814. __extends(PlaneGeometry, _super);
  40815. /**
  40816. * Creates a plane geometry
  40817. * @param id defines the unique ID of the geometry
  40818. * @param scene defines the hosting scene
  40819. * @param size defines the size of the plane (width === height)
  40820. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40821. * @param mesh defines the hosting mesh (can be null)
  40822. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40823. */
  40824. function PlaneGeometry(id, scene,
  40825. /**
  40826. * Defines the size of the plane (width === height)
  40827. */
  40828. size, canBeRegenerated, mesh,
  40829. /**
  40830. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40831. */
  40832. side) {
  40833. if (mesh === void 0) { mesh = null; }
  40834. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40835. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40836. _this.size = size;
  40837. _this.side = side;
  40838. return _this;
  40839. }
  40840. PlaneGeometry.prototype._regenerateVertexData = function () {
  40841. return BABYLON.VertexData.CreatePlane({ size: this.size, sideOrientation: this.side });
  40842. };
  40843. PlaneGeometry.prototype.copy = function (id) {
  40844. return new PlaneGeometry(id, this.getScene(), this.size, this.canBeRegenerated(), null, this.side);
  40845. };
  40846. PlaneGeometry.prototype.serialize = function () {
  40847. var serializationObject = _super.prototype.serialize.call(this);
  40848. serializationObject.size = this.size;
  40849. return serializationObject;
  40850. };
  40851. PlaneGeometry.Parse = function (parsedPlane, scene) {
  40852. if (scene.getGeometryByID(parsedPlane.id)) {
  40853. return null; // null since geometry could be something else than a ground...
  40854. }
  40855. var plane = new PlaneGeometry(parsedPlane.id, scene, parsedPlane.size, parsedPlane.canBeRegenerated, null);
  40856. if (BABYLON.Tags) {
  40857. BABYLON.Tags.AddTagsTo(plane, parsedPlane.tags);
  40858. }
  40859. scene.pushGeometry(plane, true);
  40860. return plane;
  40861. };
  40862. return PlaneGeometry;
  40863. }(_PrimitiveGeometry));
  40864. BABYLON.PlaneGeometry = PlaneGeometry;
  40865. /**
  40866. * Creates a torus knot geometry
  40867. * @description see http://doc.babylonjs.com/how_to/set_shapes#torus-knot
  40868. */
  40869. var TorusKnotGeometry = /** @class */ (function (_super) {
  40870. __extends(TorusKnotGeometry, _super);
  40871. /**
  40872. * Creates a torus knot geometry
  40873. * @param id defines the unique ID of the geometry
  40874. * @param scene defines the hosting scene
  40875. * @param radius defines the radius of the torus knot
  40876. * @param tube defines the thickness of the torus knot tube
  40877. * @param radialSegments defines the number of radial segments
  40878. * @param tubularSegments defines the number of tubular segments
  40879. * @param p defines the first number of windings
  40880. * @param q defines the second number of windings
  40881. * @param canBeRegenerated defines if the geometry supports being regenerated with new parameters (false by default)
  40882. * @param mesh defines the hosting mesh (can be null)
  40883. * @param side defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40884. */
  40885. function TorusKnotGeometry(id, scene,
  40886. /**
  40887. * Defines the radius of the torus knot
  40888. */
  40889. radius,
  40890. /**
  40891. * Defines the thickness of the torus knot tube
  40892. */
  40893. tube,
  40894. /**
  40895. * Defines the number of radial segments
  40896. */
  40897. radialSegments,
  40898. /**
  40899. * Defines the number of tubular segments
  40900. */
  40901. tubularSegments,
  40902. /**
  40903. * Defines the first number of windings
  40904. */
  40905. p,
  40906. /**
  40907. * Defines the second number of windings
  40908. */
  40909. q, canBeRegenerated, mesh,
  40910. /**
  40911. * Defines if the created geometry is double sided or not (default is BABYLON.Mesh.DEFAULTSIDE)
  40912. */
  40913. side) {
  40914. if (mesh === void 0) { mesh = null; }
  40915. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  40916. var _this = _super.call(this, id, scene, canBeRegenerated, mesh) || this;
  40917. _this.radius = radius;
  40918. _this.tube = tube;
  40919. _this.radialSegments = radialSegments;
  40920. _this.tubularSegments = tubularSegments;
  40921. _this.p = p;
  40922. _this.q = q;
  40923. _this.side = side;
  40924. return _this;
  40925. }
  40926. TorusKnotGeometry.prototype._regenerateVertexData = function () {
  40927. return BABYLON.VertexData.CreateTorusKnot({ radius: this.radius, tube: this.tube, radialSegments: this.radialSegments, tubularSegments: this.tubularSegments, p: this.p, q: this.q, sideOrientation: this.side });
  40928. };
  40929. TorusKnotGeometry.prototype.copy = function (id) {
  40930. return new TorusKnotGeometry(id, this.getScene(), this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q, this.canBeRegenerated(), null, this.side);
  40931. };
  40932. TorusKnotGeometry.prototype.serialize = function () {
  40933. var serializationObject = _super.prototype.serialize.call(this);
  40934. serializationObject.radius = this.radius;
  40935. serializationObject.tube = this.tube;
  40936. serializationObject.radialSegments = this.radialSegments;
  40937. serializationObject.tubularSegments = this.tubularSegments;
  40938. serializationObject.p = this.p;
  40939. serializationObject.q = this.q;
  40940. return serializationObject;
  40941. };
  40942. ;
  40943. TorusKnotGeometry.Parse = function (parsedTorusKnot, scene) {
  40944. if (scene.getGeometryByID(parsedTorusKnot.id)) {
  40945. return null; // null since geometry could be something else than a ground...
  40946. }
  40947. var torusKnot = new TorusKnotGeometry(parsedTorusKnot.id, scene, parsedTorusKnot.radius, parsedTorusKnot.tube, parsedTorusKnot.radialSegments, parsedTorusKnot.tubularSegments, parsedTorusKnot.p, parsedTorusKnot.q, parsedTorusKnot.canBeRegenerated, null);
  40948. if (BABYLON.Tags) {
  40949. BABYLON.Tags.AddTagsTo(torusKnot, parsedTorusKnot.tags);
  40950. }
  40951. scene.pushGeometry(torusKnot, true);
  40952. return torusKnot;
  40953. };
  40954. return TorusKnotGeometry;
  40955. }(_PrimitiveGeometry));
  40956. BABYLON.TorusKnotGeometry = TorusKnotGeometry;
  40957. //}
  40958. })(BABYLON || (BABYLON = {}));
  40959. //# sourceMappingURL=babylon.geometry.js.map
  40960. var BABYLON;
  40961. (function (BABYLON) {
  40962. /**
  40963. * PostProcessManager is used to manage one or more post processes or post process pipelines
  40964. * See https://doc.babylonjs.com/how_to/how_to_use_postprocesses
  40965. */
  40966. var PostProcessManager = /** @class */ (function () {
  40967. /**
  40968. * Creates a new instance PostProcess
  40969. * @param scene The scene that the post process is associated with.
  40970. */
  40971. function PostProcessManager(scene) {
  40972. this._vertexBuffers = {};
  40973. this._scene = scene;
  40974. }
  40975. PostProcessManager.prototype._prepareBuffers = function () {
  40976. if (this._vertexBuffers[BABYLON.VertexBuffer.PositionKind]) {
  40977. return;
  40978. }
  40979. // VBO
  40980. var vertices = [];
  40981. vertices.push(1, 1);
  40982. vertices.push(-1, 1);
  40983. vertices.push(-1, -1);
  40984. vertices.push(1, -1);
  40985. this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(this._scene.getEngine(), vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
  40986. this._buildIndexBuffer();
  40987. };
  40988. PostProcessManager.prototype._buildIndexBuffer = function () {
  40989. // Indices
  40990. var indices = [];
  40991. indices.push(0);
  40992. indices.push(1);
  40993. indices.push(2);
  40994. indices.push(0);
  40995. indices.push(2);
  40996. indices.push(3);
  40997. this._indexBuffer = this._scene.getEngine().createIndexBuffer(indices);
  40998. };
  40999. /**
  41000. * Rebuilds the vertex buffers of the manager.
  41001. */
  41002. PostProcessManager.prototype._rebuild = function () {
  41003. var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
  41004. if (!vb) {
  41005. return;
  41006. }
  41007. vb._rebuild();
  41008. this._buildIndexBuffer();
  41009. };
  41010. // Methods
  41011. /**
  41012. * Prepares a frame to be run through a post process.
  41013. * @param sourceTexture The input texture to the post procesess. (default: null)
  41014. * @param postProcesses An array of post processes to be run. (default: null)
  41015. * @returns True if the post processes were able to be run.
  41016. */
  41017. PostProcessManager.prototype._prepareFrame = function (sourceTexture, postProcesses) {
  41018. if (sourceTexture === void 0) { sourceTexture = null; }
  41019. if (postProcesses === void 0) { postProcesses = null; }
  41020. var camera = this._scene.activeCamera;
  41021. if (!camera) {
  41022. return false;
  41023. }
  41024. var postProcesses = postProcesses || camera._postProcesses.filter(function (pp) { return pp != null; });
  41025. if (!postProcesses || postProcesses.length === 0 || !this._scene.postProcessesEnabled) {
  41026. return false;
  41027. }
  41028. postProcesses[0].activate(camera, sourceTexture, postProcesses !== null && postProcesses !== undefined);
  41029. return true;
  41030. };
  41031. /**
  41032. * Manually render a set of post processes to a texture.
  41033. * @param postProcesses An array of post processes to be run.
  41034. * @param targetTexture The target texture to render to.
  41035. * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight
  41036. * @param faceIndex defines the face to render to if a cubemap is defined as the target
  41037. * @param lodLevel defines which lod of the texture to render to
  41038. */
  41039. PostProcessManager.prototype.directRender = function (postProcesses, targetTexture, forceFullscreenViewport, faceIndex, lodLevel) {
  41040. if (targetTexture === void 0) { targetTexture = null; }
  41041. if (forceFullscreenViewport === void 0) { forceFullscreenViewport = false; }
  41042. if (faceIndex === void 0) { faceIndex = 0; }
  41043. if (lodLevel === void 0) { lodLevel = 0; }
  41044. var engine = this._scene.getEngine();
  41045. for (var index = 0; index < postProcesses.length; index++) {
  41046. if (index < postProcesses.length - 1) {
  41047. postProcesses[index + 1].activate(this._scene.activeCamera, targetTexture);
  41048. }
  41049. else {
  41050. if (targetTexture) {
  41051. engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport, undefined, lodLevel);
  41052. }
  41053. else {
  41054. engine.restoreDefaultFramebuffer();
  41055. }
  41056. }
  41057. var pp = postProcesses[index];
  41058. var effect = pp.apply();
  41059. if (effect) {
  41060. pp.onBeforeRenderObservable.notifyObservers(effect);
  41061. // VBOs
  41062. this._prepareBuffers();
  41063. engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);
  41064. // Draw order
  41065. engine.drawElementsType(BABYLON.Material.TriangleFillMode, 0, 6);
  41066. pp.onAfterRenderObservable.notifyObservers(effect);
  41067. }
  41068. }
  41069. // Restore depth buffer
  41070. engine.setDepthBuffer(true);
  41071. engine.setDepthWrite(true);
  41072. };
  41073. /**
  41074. * Finalize the result of the output of the postprocesses.
  41075. * @param doNotPresent If true the result will not be displayed to the screen.
  41076. * @param targetTexture The target texture to render to.
  41077. * @param faceIndex The index of the face to bind the target texture to.
  41078. * @param postProcesses The array of post processes to render.
  41079. * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight (default: false)
  41080. */
  41081. PostProcessManager.prototype._finalizeFrame = function (doNotPresent, targetTexture, faceIndex, postProcesses, forceFullscreenViewport) {
  41082. if (forceFullscreenViewport === void 0) { forceFullscreenViewport = false; }
  41083. var camera = this._scene.activeCamera;
  41084. if (!camera) {
  41085. return;
  41086. }
  41087. postProcesses = postProcesses || camera._postProcesses.filter(function (pp) { return pp != null; });
  41088. if (postProcesses.length === 0 || !this._scene.postProcessesEnabled) {
  41089. return;
  41090. }
  41091. var engine = this._scene.getEngine();
  41092. for (var index = 0, len = postProcesses.length; index < len; index++) {
  41093. var pp = postProcesses[index];
  41094. if (index < len - 1) {
  41095. pp._outputTexture = postProcesses[index + 1].activate(camera, targetTexture);
  41096. }
  41097. else {
  41098. if (targetTexture) {
  41099. engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport);
  41100. pp._outputTexture = targetTexture;
  41101. }
  41102. else {
  41103. engine.restoreDefaultFramebuffer();
  41104. pp._outputTexture = null;
  41105. }
  41106. }
  41107. if (doNotPresent) {
  41108. break;
  41109. }
  41110. var effect = pp.apply();
  41111. if (effect) {
  41112. pp.onBeforeRenderObservable.notifyObservers(effect);
  41113. // VBOs
  41114. this._prepareBuffers();
  41115. engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);
  41116. // Draw order
  41117. engine.drawElementsType(BABYLON.Material.TriangleFillMode, 0, 6);
  41118. pp.onAfterRenderObservable.notifyObservers(effect);
  41119. }
  41120. }
  41121. // Restore states
  41122. engine.setDepthBuffer(true);
  41123. engine.setDepthWrite(true);
  41124. engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
  41125. };
  41126. /**
  41127. * Disposes of the post process manager.
  41128. */
  41129. PostProcessManager.prototype.dispose = function () {
  41130. var buffer = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
  41131. if (buffer) {
  41132. buffer.dispose();
  41133. this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
  41134. }
  41135. if (this._indexBuffer) {
  41136. this._scene.getEngine()._releaseBuffer(this._indexBuffer);
  41137. this._indexBuffer = null;
  41138. }
  41139. };
  41140. return PostProcessManager;
  41141. }());
  41142. BABYLON.PostProcessManager = PostProcessManager;
  41143. })(BABYLON || (BABYLON = {}));
  41144. //# sourceMappingURL=babylon.postProcessManager.js.map
  41145. var BABYLON;
  41146. (function (BABYLON) {
  41147. /**
  41148. * Performance monitor tracks rolling average frame-time and frame-time variance over a user defined sliding-window
  41149. */
  41150. var PerformanceMonitor = /** @class */ (function () {
  41151. /**
  41152. * constructor
  41153. * @param frameSampleSize The number of samples required to saturate the sliding window
  41154. */
  41155. function PerformanceMonitor(frameSampleSize) {
  41156. if (frameSampleSize === void 0) { frameSampleSize = 30; }
  41157. this._enabled = true;
  41158. this._rollingFrameTime = new RollingAverage(frameSampleSize);
  41159. }
  41160. /**
  41161. * Samples current frame
  41162. * @param timeMs A timestamp in milliseconds of the current frame to compare with other frames
  41163. */
  41164. PerformanceMonitor.prototype.sampleFrame = function (timeMs) {
  41165. if (timeMs === void 0) { timeMs = BABYLON.Tools.Now; }
  41166. if (!this._enabled)
  41167. return;
  41168. if (this._lastFrameTimeMs != null) {
  41169. var dt = timeMs - this._lastFrameTimeMs;
  41170. this._rollingFrameTime.add(dt);
  41171. }
  41172. this._lastFrameTimeMs = timeMs;
  41173. };
  41174. Object.defineProperty(PerformanceMonitor.prototype, "averageFrameTime", {
  41175. /**
  41176. * Returns the average frame time in milliseconds over the sliding window (or the subset of frames sampled so far)
  41177. * @return Average frame time in milliseconds
  41178. */
  41179. get: function () {
  41180. return this._rollingFrameTime.average;
  41181. },
  41182. enumerable: true,
  41183. configurable: true
  41184. });
  41185. Object.defineProperty(PerformanceMonitor.prototype, "averageFrameTimeVariance", {
  41186. /**
  41187. * Returns the variance frame time in milliseconds over the sliding window (or the subset of frames sampled so far)
  41188. * @return Frame time variance in milliseconds squared
  41189. */
  41190. get: function () {
  41191. return this._rollingFrameTime.variance;
  41192. },
  41193. enumerable: true,
  41194. configurable: true
  41195. });
  41196. Object.defineProperty(PerformanceMonitor.prototype, "instantaneousFrameTime", {
  41197. /**
  41198. * Returns the frame time of the most recent frame
  41199. * @return Frame time in milliseconds
  41200. */
  41201. get: function () {
  41202. return this._rollingFrameTime.history(0);
  41203. },
  41204. enumerable: true,
  41205. configurable: true
  41206. });
  41207. Object.defineProperty(PerformanceMonitor.prototype, "averageFPS", {
  41208. /**
  41209. * Returns the average framerate in frames per second over the sliding window (or the subset of frames sampled so far)
  41210. * @return Framerate in frames per second
  41211. */
  41212. get: function () {
  41213. return 1000.0 / this._rollingFrameTime.average;
  41214. },
  41215. enumerable: true,
  41216. configurable: true
  41217. });
  41218. Object.defineProperty(PerformanceMonitor.prototype, "instantaneousFPS", {
  41219. /**
  41220. * Returns the average framerate in frames per second using the most recent frame time
  41221. * @return Framerate in frames per second
  41222. */
  41223. get: function () {
  41224. var history = this._rollingFrameTime.history(0);
  41225. if (history === 0) {
  41226. return 0;
  41227. }
  41228. return 1000.0 / history;
  41229. },
  41230. enumerable: true,
  41231. configurable: true
  41232. });
  41233. Object.defineProperty(PerformanceMonitor.prototype, "isSaturated", {
  41234. /**
  41235. * Returns true if enough samples have been taken to completely fill the sliding window
  41236. * @return true if saturated
  41237. */
  41238. get: function () {
  41239. return this._rollingFrameTime.isSaturated();
  41240. },
  41241. enumerable: true,
  41242. configurable: true
  41243. });
  41244. /**
  41245. * Enables contributions to the sliding window sample set
  41246. */
  41247. PerformanceMonitor.prototype.enable = function () {
  41248. this._enabled = true;
  41249. };
  41250. /**
  41251. * Disables contributions to the sliding window sample set
  41252. * Samples will not be interpolated over the disabled period
  41253. */
  41254. PerformanceMonitor.prototype.disable = function () {
  41255. this._enabled = false;
  41256. //clear last sample to avoid interpolating over the disabled period when next enabled
  41257. this._lastFrameTimeMs = null;
  41258. };
  41259. Object.defineProperty(PerformanceMonitor.prototype, "isEnabled", {
  41260. /**
  41261. * Returns true if sampling is enabled
  41262. * @return true if enabled
  41263. */
  41264. get: function () {
  41265. return this._enabled;
  41266. },
  41267. enumerable: true,
  41268. configurable: true
  41269. });
  41270. /**
  41271. * Resets performance monitor
  41272. */
  41273. PerformanceMonitor.prototype.reset = function () {
  41274. //clear last sample to avoid interpolating over the disabled period when next enabled
  41275. this._lastFrameTimeMs = null;
  41276. //wipe record
  41277. this._rollingFrameTime.reset();
  41278. };
  41279. return PerformanceMonitor;
  41280. }());
  41281. BABYLON.PerformanceMonitor = PerformanceMonitor;
  41282. /**
  41283. * RollingAverage
  41284. *
  41285. * Utility to efficiently compute the rolling average and variance over a sliding window of samples
  41286. */
  41287. var RollingAverage = /** @class */ (function () {
  41288. /**
  41289. * constructor
  41290. * @param length The number of samples required to saturate the sliding window
  41291. */
  41292. function RollingAverage(length) {
  41293. this._samples = new Array(length);
  41294. this.reset();
  41295. }
  41296. /**
  41297. * Adds a sample to the sample set
  41298. * @param v The sample value
  41299. */
  41300. RollingAverage.prototype.add = function (v) {
  41301. //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
  41302. var delta;
  41303. //we need to check if we've already wrapped round
  41304. if (this.isSaturated()) {
  41305. //remove bottom of stack from mean
  41306. var bottomValue = this._samples[this._pos];
  41307. delta = bottomValue - this.average;
  41308. this.average -= delta / (this._sampleCount - 1);
  41309. this._m2 -= delta * (bottomValue - this.average);
  41310. }
  41311. else {
  41312. this._sampleCount++;
  41313. }
  41314. //add new value to mean
  41315. delta = v - this.average;
  41316. this.average += delta / (this._sampleCount);
  41317. this._m2 += delta * (v - this.average);
  41318. //set the new variance
  41319. this.variance = this._m2 / (this._sampleCount - 1);
  41320. this._samples[this._pos] = v;
  41321. this._pos++;
  41322. this._pos %= this._samples.length; //positive wrap around
  41323. };
  41324. /**
  41325. * Returns previously added values or null if outside of history or outside the sliding window domain
  41326. * @param i Index in history. For example, pass 0 for the most recent value and 1 for the value before that
  41327. * @return Value previously recorded with add() or null if outside of range
  41328. */
  41329. RollingAverage.prototype.history = function (i) {
  41330. if ((i >= this._sampleCount) || (i >= this._samples.length)) {
  41331. return 0;
  41332. }
  41333. var i0 = this._wrapPosition(this._pos - 1.0);
  41334. return this._samples[this._wrapPosition(i0 - i)];
  41335. };
  41336. /**
  41337. * Returns true if enough samples have been taken to completely fill the sliding window
  41338. * @return true if sample-set saturated
  41339. */
  41340. RollingAverage.prototype.isSaturated = function () {
  41341. return this._sampleCount >= this._samples.length;
  41342. };
  41343. /**
  41344. * Resets the rolling average (equivalent to 0 samples taken so far)
  41345. */
  41346. RollingAverage.prototype.reset = function () {
  41347. this.average = 0;
  41348. this.variance = 0;
  41349. this._sampleCount = 0;
  41350. this._pos = 0;
  41351. this._m2 = 0;
  41352. };
  41353. /**
  41354. * Wraps a value around the sample range boundaries
  41355. * @param i Position in sample range, for example if the sample length is 5, and i is -3, then 2 will be returned.
  41356. * @return Wrapped position in sample range
  41357. */
  41358. RollingAverage.prototype._wrapPosition = function (i) {
  41359. var max = this._samples.length;
  41360. return ((i % max) + max) % max;
  41361. };
  41362. return RollingAverage;
  41363. }());
  41364. BABYLON.RollingAverage = RollingAverage;
  41365. })(BABYLON || (BABYLON = {}));
  41366. //# sourceMappingURL=babylon.performanceMonitor.js.map
  41367. var BABYLON;
  41368. (function (BABYLON) {
  41369. /**
  41370. * This groups together the common properties used for image processing either in direct forward pass
  41371. * or through post processing effect depending on the use of the image processing pipeline in your scene
  41372. * or not.
  41373. */
  41374. var ImageProcessingConfiguration = /** @class */ (function () {
  41375. function ImageProcessingConfiguration() {
  41376. /**
  41377. * Color curves setup used in the effect if colorCurvesEnabled is set to true
  41378. */
  41379. this.colorCurves = new BABYLON.ColorCurves();
  41380. this._colorCurvesEnabled = false;
  41381. this._colorGradingEnabled = false;
  41382. this._colorGradingWithGreenDepth = true;
  41383. this._colorGradingBGR = true;
  41384. this._exposure = 1.0;
  41385. this._toneMappingEnabled = false;
  41386. this._contrast = 1.0;
  41387. /**
  41388. * Vignette stretch size.
  41389. */
  41390. this.vignetteStretch = 0;
  41391. /**
  41392. * Vignette centre X Offset.
  41393. */
  41394. this.vignetteCentreX = 0;
  41395. /**
  41396. * Vignette centre Y Offset.
  41397. */
  41398. this.vignetteCentreY = 0;
  41399. /**
  41400. * Vignette weight or intensity of the vignette effect.
  41401. */
  41402. this.vignetteWeight = 1.5;
  41403. /**
  41404. * Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)
  41405. * if vignetteEnabled is set to true.
  41406. */
  41407. this.vignetteColor = new BABYLON.Color4(0, 0, 0, 0);
  41408. /**
  41409. * Camera field of view used by the Vignette effect.
  41410. */
  41411. this.vignetteCameraFov = 0.5;
  41412. this._vignetteBlendMode = ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;
  41413. this._vignetteEnabled = false;
  41414. this._applyByPostProcess = false;
  41415. this._isEnabled = true;
  41416. /**
  41417. * An event triggered when the configuration changes and requires Shader to Update some parameters.
  41418. */
  41419. this.onUpdateParameters = new BABYLON.Observable();
  41420. }
  41421. Object.defineProperty(ImageProcessingConfiguration.prototype, "colorCurvesEnabled", {
  41422. /**
  41423. * Gets wether the color curves effect is enabled.
  41424. */
  41425. get: function () {
  41426. return this._colorCurvesEnabled;
  41427. },
  41428. /**
  41429. * Sets wether the color curves effect is enabled.
  41430. */
  41431. set: function (value) {
  41432. if (this._colorCurvesEnabled === value) {
  41433. return;
  41434. }
  41435. this._colorCurvesEnabled = value;
  41436. this._updateParameters();
  41437. },
  41438. enumerable: true,
  41439. configurable: true
  41440. });
  41441. Object.defineProperty(ImageProcessingConfiguration.prototype, "colorGradingEnabled", {
  41442. /**
  41443. * Gets wether the color grading effect is enabled.
  41444. */
  41445. get: function () {
  41446. return this._colorGradingEnabled;
  41447. },
  41448. /**
  41449. * Sets wether the color grading effect is enabled.
  41450. */
  41451. set: function (value) {
  41452. if (this._colorGradingEnabled === value) {
  41453. return;
  41454. }
  41455. this._colorGradingEnabled = value;
  41456. this._updateParameters();
  41457. },
  41458. enumerable: true,
  41459. configurable: true
  41460. });
  41461. Object.defineProperty(ImageProcessingConfiguration.prototype, "colorGradingWithGreenDepth", {
  41462. /**
  41463. * Gets wether the color grading effect is using a green depth for the 3d Texture.
  41464. */
  41465. get: function () {
  41466. return this._colorGradingWithGreenDepth;
  41467. },
  41468. /**
  41469. * Sets wether the color grading effect is using a green depth for the 3d Texture.
  41470. */
  41471. set: function (value) {
  41472. if (this._colorGradingWithGreenDepth === value) {
  41473. return;
  41474. }
  41475. this._colorGradingWithGreenDepth = value;
  41476. this._updateParameters();
  41477. },
  41478. enumerable: true,
  41479. configurable: true
  41480. });
  41481. Object.defineProperty(ImageProcessingConfiguration.prototype, "colorGradingBGR", {
  41482. /**
  41483. * Gets wether the color grading texture contains BGR values.
  41484. */
  41485. get: function () {
  41486. return this._colorGradingBGR;
  41487. },
  41488. /**
  41489. * Sets wether the color grading texture contains BGR values.
  41490. */
  41491. set: function (value) {
  41492. if (this._colorGradingBGR === value) {
  41493. return;
  41494. }
  41495. this._colorGradingBGR = value;
  41496. this._updateParameters();
  41497. },
  41498. enumerable: true,
  41499. configurable: true
  41500. });
  41501. Object.defineProperty(ImageProcessingConfiguration.prototype, "exposure", {
  41502. /**
  41503. * Gets the Exposure used in the effect.
  41504. */
  41505. get: function () {
  41506. return this._exposure;
  41507. },
  41508. /**
  41509. * Sets the Exposure used in the effect.
  41510. */
  41511. set: function (value) {
  41512. if (this._exposure === value) {
  41513. return;
  41514. }
  41515. this._exposure = value;
  41516. this._updateParameters();
  41517. },
  41518. enumerable: true,
  41519. configurable: true
  41520. });
  41521. Object.defineProperty(ImageProcessingConfiguration.prototype, "toneMappingEnabled", {
  41522. /**
  41523. * Gets wether the tone mapping effect is enabled.
  41524. */
  41525. get: function () {
  41526. return this._toneMappingEnabled;
  41527. },
  41528. /**
  41529. * Sets wether the tone mapping effect is enabled.
  41530. */
  41531. set: function (value) {
  41532. if (this._toneMappingEnabled === value) {
  41533. return;
  41534. }
  41535. this._toneMappingEnabled = value;
  41536. this._updateParameters();
  41537. },
  41538. enumerable: true,
  41539. configurable: true
  41540. });
  41541. Object.defineProperty(ImageProcessingConfiguration.prototype, "contrast", {
  41542. /**
  41543. * Gets the contrast used in the effect.
  41544. */
  41545. get: function () {
  41546. return this._contrast;
  41547. },
  41548. /**
  41549. * Sets the contrast used in the effect.
  41550. */
  41551. set: function (value) {
  41552. if (this._contrast === value) {
  41553. return;
  41554. }
  41555. this._contrast = value;
  41556. this._updateParameters();
  41557. },
  41558. enumerable: true,
  41559. configurable: true
  41560. });
  41561. Object.defineProperty(ImageProcessingConfiguration.prototype, "vignetteBlendMode", {
  41562. /**
  41563. * Gets the vignette blend mode allowing different kind of effect.
  41564. */
  41565. get: function () {
  41566. return this._vignetteBlendMode;
  41567. },
  41568. /**
  41569. * Sets the vignette blend mode allowing different kind of effect.
  41570. */
  41571. set: function (value) {
  41572. if (this._vignetteBlendMode === value) {
  41573. return;
  41574. }
  41575. this._vignetteBlendMode = value;
  41576. this._updateParameters();
  41577. },
  41578. enumerable: true,
  41579. configurable: true
  41580. });
  41581. Object.defineProperty(ImageProcessingConfiguration.prototype, "vignetteEnabled", {
  41582. /**
  41583. * Gets wether the vignette effect is enabled.
  41584. */
  41585. get: function () {
  41586. return this._vignetteEnabled;
  41587. },
  41588. /**
  41589. * Sets wether the vignette effect is enabled.
  41590. */
  41591. set: function (value) {
  41592. if (this._vignetteEnabled === value) {
  41593. return;
  41594. }
  41595. this._vignetteEnabled = value;
  41596. this._updateParameters();
  41597. },
  41598. enumerable: true,
  41599. configurable: true
  41600. });
  41601. Object.defineProperty(ImageProcessingConfiguration.prototype, "applyByPostProcess", {
  41602. /**
  41603. * Gets wether the image processing is applied through a post process or not.
  41604. */
  41605. get: function () {
  41606. return this._applyByPostProcess;
  41607. },
  41608. /**
  41609. * Sets wether the image processing is applied through a post process or not.
  41610. */
  41611. set: function (value) {
  41612. if (this._applyByPostProcess === value) {
  41613. return;
  41614. }
  41615. this._applyByPostProcess = value;
  41616. this._updateParameters();
  41617. },
  41618. enumerable: true,
  41619. configurable: true
  41620. });
  41621. Object.defineProperty(ImageProcessingConfiguration.prototype, "isEnabled", {
  41622. /**
  41623. * Gets wether the image processing is enabled or not.
  41624. */
  41625. get: function () {
  41626. return this._isEnabled;
  41627. },
  41628. /**
  41629. * Sets wether the image processing is enabled or not.
  41630. */
  41631. set: function (value) {
  41632. if (this._isEnabled === value) {
  41633. return;
  41634. }
  41635. this._isEnabled = value;
  41636. this._updateParameters();
  41637. },
  41638. enumerable: true,
  41639. configurable: true
  41640. });
  41641. /**
  41642. * Method called each time the image processing information changes requires to recompile the effect.
  41643. */
  41644. ImageProcessingConfiguration.prototype._updateParameters = function () {
  41645. this.onUpdateParameters.notifyObservers(this);
  41646. };
  41647. ImageProcessingConfiguration.prototype.getClassName = function () {
  41648. return "ImageProcessingConfiguration";
  41649. };
  41650. /**
  41651. * Prepare the list of uniforms associated with the Image Processing effects.
  41652. * @param uniformsList The list of uniforms used in the effect
  41653. * @param defines the list of defines currently in use
  41654. */
  41655. ImageProcessingConfiguration.PrepareUniforms = function (uniforms, defines) {
  41656. if (defines.EXPOSURE) {
  41657. uniforms.push("exposureLinear");
  41658. }
  41659. if (defines.CONTRAST) {
  41660. uniforms.push("contrast");
  41661. }
  41662. if (defines.COLORGRADING) {
  41663. uniforms.push("colorTransformSettings");
  41664. }
  41665. if (defines.VIGNETTE) {
  41666. uniforms.push("vInverseScreenSize");
  41667. uniforms.push("vignetteSettings1");
  41668. uniforms.push("vignetteSettings2");
  41669. }
  41670. if (defines.COLORCURVES) {
  41671. BABYLON.ColorCurves.PrepareUniforms(uniforms);
  41672. }
  41673. };
  41674. /**
  41675. * Prepare the list of samplers associated with the Image Processing effects.
  41676. * @param uniformsList The list of uniforms used in the effect
  41677. * @param defines the list of defines currently in use
  41678. */
  41679. ImageProcessingConfiguration.PrepareSamplers = function (samplersList, defines) {
  41680. if (defines.COLORGRADING) {
  41681. samplersList.push("txColorTransform");
  41682. }
  41683. };
  41684. /**
  41685. * Prepare the list of defines associated to the shader.
  41686. * @param defines the list of defines to complete
  41687. */
  41688. ImageProcessingConfiguration.prototype.prepareDefines = function (defines, forPostProcess) {
  41689. if (forPostProcess === void 0) { forPostProcess = false; }
  41690. if (forPostProcess !== this.applyByPostProcess || !this._isEnabled) {
  41691. defines.VIGNETTE = false;
  41692. defines.TONEMAPPING = false;
  41693. defines.CONTRAST = false;
  41694. defines.EXPOSURE = false;
  41695. defines.COLORCURVES = false;
  41696. defines.COLORGRADING = false;
  41697. defines.COLORGRADING3D = false;
  41698. defines.IMAGEPROCESSING = false;
  41699. defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess && this._isEnabled;
  41700. return;
  41701. }
  41702. defines.VIGNETTE = this.vignetteEnabled;
  41703. defines.VIGNETTEBLENDMODEMULTIPLY = (this.vignetteBlendMode === ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY);
  41704. defines.VIGNETTEBLENDMODEOPAQUE = !defines.VIGNETTEBLENDMODEMULTIPLY;
  41705. defines.TONEMAPPING = this.toneMappingEnabled;
  41706. defines.CONTRAST = (this.contrast !== 1.0);
  41707. defines.EXPOSURE = (this.exposure !== 1.0);
  41708. defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
  41709. defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
  41710. if (defines.COLORGRADING) {
  41711. defines.COLORGRADING3D = this.colorGradingTexture.is3D;
  41712. }
  41713. else {
  41714. defines.COLORGRADING3D = false;
  41715. }
  41716. defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
  41717. defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
  41718. defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
  41719. defines.IMAGEPROCESSING = defines.VIGNETTE || defines.TONEMAPPING || defines.CONTRAST || defines.EXPOSURE || defines.COLORCURVES || defines.COLORGRADING;
  41720. };
  41721. /**
  41722. * Returns true if all the image processing information are ready.
  41723. */
  41724. ImageProcessingConfiguration.prototype.isReady = function () {
  41725. // Color Grading texure can not be none blocking.
  41726. return !this.colorGradingEnabled || !this.colorGradingTexture || this.colorGradingTexture.isReady();
  41727. };
  41728. /**
  41729. * Binds the image processing to the shader.
  41730. * @param effect The effect to bind to
  41731. */
  41732. ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
  41733. if (aspectRatio === void 0) { aspectRatio = 1; }
  41734. // Color Curves
  41735. if (this._colorCurvesEnabled && this.colorCurves) {
  41736. BABYLON.ColorCurves.Bind(this.colorCurves, effect);
  41737. }
  41738. // Vignette
  41739. if (this._vignetteEnabled) {
  41740. var inverseWidth = 1 / effect.getEngine().getRenderWidth();
  41741. var inverseHeight = 1 / effect.getEngine().getRenderHeight();
  41742. effect.setFloat2("vInverseScreenSize", inverseWidth, inverseHeight);
  41743. var vignetteScaleY = Math.tan(this.vignetteCameraFov * 0.5);
  41744. var vignetteScaleX = vignetteScaleY * aspectRatio;
  41745. var vignetteScaleGeometricMean = Math.sqrt(vignetteScaleX * vignetteScaleY);
  41746. vignetteScaleX = BABYLON.Tools.Mix(vignetteScaleX, vignetteScaleGeometricMean, this.vignetteStretch);
  41747. vignetteScaleY = BABYLON.Tools.Mix(vignetteScaleY, vignetteScaleGeometricMean, this.vignetteStretch);
  41748. effect.setFloat4("vignetteSettings1", vignetteScaleX, vignetteScaleY, -vignetteScaleX * this.vignetteCentreX, -vignetteScaleY * this.vignetteCentreY);
  41749. var vignettePower = -2.0 * this.vignetteWeight;
  41750. effect.setFloat4("vignetteSettings2", this.vignetteColor.r, this.vignetteColor.g, this.vignetteColor.b, vignettePower);
  41751. }
  41752. // Exposure
  41753. effect.setFloat("exposureLinear", this.exposure);
  41754. // Contrast
  41755. effect.setFloat("contrast", this.contrast);
  41756. // Color transform settings
  41757. if (this.colorGradingTexture) {
  41758. effect.setTexture("txColorTransform", this.colorGradingTexture);
  41759. var textureSize = this.colorGradingTexture.getSize().height;
  41760. effect.setFloat4("colorTransformSettings", (textureSize - 1) / textureSize, // textureScale
  41761. 0.5 / textureSize, // textureOffset
  41762. textureSize, // textureSize
  41763. this.colorGradingTexture.level // weight
  41764. );
  41765. }
  41766. };
  41767. /**
  41768. * Clones the current image processing instance.
  41769. * @return The cloned image processing
  41770. */
  41771. ImageProcessingConfiguration.prototype.clone = function () {
  41772. return BABYLON.SerializationHelper.Clone(function () { return new ImageProcessingConfiguration(); }, this);
  41773. };
  41774. /**
  41775. * Serializes the current image processing instance to a json representation.
  41776. * @return a JSON representation
  41777. */
  41778. ImageProcessingConfiguration.prototype.serialize = function () {
  41779. return BABYLON.SerializationHelper.Serialize(this);
  41780. };
  41781. /**
  41782. * Parses the image processing from a json representation.
  41783. * @param source the JSON source to parse
  41784. * @return The parsed image processing
  41785. */
  41786. ImageProcessingConfiguration.Parse = function (source) {
  41787. return BABYLON.SerializationHelper.Parse(function () { return new ImageProcessingConfiguration(); }, source, null, null);
  41788. };
  41789. Object.defineProperty(ImageProcessingConfiguration, "VIGNETTEMODE_MULTIPLY", {
  41790. /**
  41791. * Used to apply the vignette as a mix with the pixel color.
  41792. */
  41793. get: function () {
  41794. return this._VIGNETTEMODE_MULTIPLY;
  41795. },
  41796. enumerable: true,
  41797. configurable: true
  41798. });
  41799. Object.defineProperty(ImageProcessingConfiguration, "VIGNETTEMODE_OPAQUE", {
  41800. /**
  41801. * Used to apply the vignette as a replacement of the pixel color.
  41802. */
  41803. get: function () {
  41804. return this._VIGNETTEMODE_OPAQUE;
  41805. },
  41806. enumerable: true,
  41807. configurable: true
  41808. });
  41809. // Static constants associated to the image processing.
  41810. ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY = 0;
  41811. ImageProcessingConfiguration._VIGNETTEMODE_OPAQUE = 1;
  41812. __decorate([
  41813. BABYLON.serializeAsColorCurves()
  41814. ], ImageProcessingConfiguration.prototype, "colorCurves", void 0);
  41815. __decorate([
  41816. BABYLON.serialize()
  41817. ], ImageProcessingConfiguration.prototype, "_colorCurvesEnabled", void 0);
  41818. __decorate([
  41819. BABYLON.serializeAsTexture()
  41820. ], ImageProcessingConfiguration.prototype, "colorGradingTexture", void 0);
  41821. __decorate([
  41822. BABYLON.serialize()
  41823. ], ImageProcessingConfiguration.prototype, "_colorGradingEnabled", void 0);
  41824. __decorate([
  41825. BABYLON.serialize()
  41826. ], ImageProcessingConfiguration.prototype, "_colorGradingWithGreenDepth", void 0);
  41827. __decorate([
  41828. BABYLON.serialize()
  41829. ], ImageProcessingConfiguration.prototype, "_colorGradingBGR", void 0);
  41830. __decorate([
  41831. BABYLON.serialize()
  41832. ], ImageProcessingConfiguration.prototype, "_exposure", void 0);
  41833. __decorate([
  41834. BABYLON.serialize()
  41835. ], ImageProcessingConfiguration.prototype, "_toneMappingEnabled", void 0);
  41836. __decorate([
  41837. BABYLON.serialize()
  41838. ], ImageProcessingConfiguration.prototype, "_contrast", void 0);
  41839. __decorate([
  41840. BABYLON.serialize()
  41841. ], ImageProcessingConfiguration.prototype, "vignetteStretch", void 0);
  41842. __decorate([
  41843. BABYLON.serialize()
  41844. ], ImageProcessingConfiguration.prototype, "vignetteCentreX", void 0);
  41845. __decorate([
  41846. BABYLON.serialize()
  41847. ], ImageProcessingConfiguration.prototype, "vignetteCentreY", void 0);
  41848. __decorate([
  41849. BABYLON.serialize()
  41850. ], ImageProcessingConfiguration.prototype, "vignetteWeight", void 0);
  41851. __decorate([
  41852. BABYLON.serializeAsColor4()
  41853. ], ImageProcessingConfiguration.prototype, "vignetteColor", void 0);
  41854. __decorate([
  41855. BABYLON.serialize()
  41856. ], ImageProcessingConfiguration.prototype, "vignetteCameraFov", void 0);
  41857. __decorate([
  41858. BABYLON.serialize()
  41859. ], ImageProcessingConfiguration.prototype, "_vignetteBlendMode", void 0);
  41860. __decorate([
  41861. BABYLON.serialize()
  41862. ], ImageProcessingConfiguration.prototype, "_vignetteEnabled", void 0);
  41863. __decorate([
  41864. BABYLON.serialize()
  41865. ], ImageProcessingConfiguration.prototype, "_applyByPostProcess", void 0);
  41866. __decorate([
  41867. BABYLON.serialize()
  41868. ], ImageProcessingConfiguration.prototype, "_isEnabled", void 0);
  41869. return ImageProcessingConfiguration;
  41870. }());
  41871. BABYLON.ImageProcessingConfiguration = ImageProcessingConfiguration;
  41872. })(BABYLON || (BABYLON = {}));
  41873. //# sourceMappingURL=babylon.imageProcessingConfiguration.js.map
  41874. var BABYLON;
  41875. (function (BABYLON) {
  41876. /**
  41877. * This represents a color grading texture. This acts as a lookup table LUT, useful during post process
  41878. * It can help converting any input color in a desired output one. This can then be used to create effects
  41879. * from sepia, black and white to sixties or futuristic rendering...
  41880. *
  41881. * The only supported format is currently 3dl.
  41882. * More information on LUT: https://en.wikipedia.org/wiki/3D_lookup_table/
  41883. */
  41884. var ColorGradingTexture = /** @class */ (function (_super) {
  41885. __extends(ColorGradingTexture, _super);
  41886. /**
  41887. * Instantiates a ColorGradingTexture from the following parameters.
  41888. *
  41889. * @param url The location of the color gradind data (currently only supporting 3dl)
  41890. * @param scene The scene the texture will be used in
  41891. */
  41892. function ColorGradingTexture(url, scene) {
  41893. var _this = _super.call(this, scene) || this;
  41894. if (!url) {
  41895. return _this;
  41896. }
  41897. _this._engine = scene.getEngine();
  41898. _this._textureMatrix = BABYLON.Matrix.Identity();
  41899. _this.name = url;
  41900. _this.url = url;
  41901. _this.hasAlpha = false;
  41902. _this.isCube = false;
  41903. _this.is3D = _this._engine.webGLVersion > 1;
  41904. _this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  41905. _this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  41906. _this.wrapR = BABYLON.Texture.CLAMP_ADDRESSMODE;
  41907. _this.anisotropicFilteringLevel = 1;
  41908. _this._texture = _this._getFromCache(url, true);
  41909. if (!_this._texture) {
  41910. if (!scene.useDelayedTextureLoading) {
  41911. _this.loadTexture();
  41912. }
  41913. else {
  41914. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  41915. }
  41916. }
  41917. return _this;
  41918. }
  41919. /**
  41920. * Returns the texture matrix used in most of the material.
  41921. * This is not used in color grading but keep for troubleshooting purpose (easily swap diffuse by colorgrading to look in).
  41922. */
  41923. ColorGradingTexture.prototype.getTextureMatrix = function () {
  41924. return this._textureMatrix;
  41925. };
  41926. /**
  41927. * Occurs when the file being loaded is a .3dl LUT file.
  41928. */
  41929. ColorGradingTexture.prototype.load3dlTexture = function () {
  41930. var engine = this._engine;
  41931. var texture;
  41932. if (engine.webGLVersion === 1) {
  41933. texture = engine.createRawTexture(null, 1, 1, BABYLON.Engine.TEXTUREFORMAT_RGBA, false, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  41934. }
  41935. else {
  41936. texture = engine.createRawTexture3D(null, 1, 1, 1, BABYLON.Engine.TEXTUREFORMAT_RGBA, false, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  41937. }
  41938. this._texture = texture;
  41939. var callback = function (text) {
  41940. if (typeof text !== "string") {
  41941. return;
  41942. }
  41943. var data = null;
  41944. var tempData = null;
  41945. var line;
  41946. var lines = text.split('\n');
  41947. var size = 0, pixelIndexW = 0, pixelIndexH = 0, pixelIndexSlice = 0;
  41948. var maxColor = 0;
  41949. for (var i = 0; i < lines.length; i++) {
  41950. line = lines[i];
  41951. if (!ColorGradingTexture._noneEmptyLineRegex.test(line))
  41952. continue;
  41953. if (line.indexOf('#') === 0)
  41954. continue;
  41955. var words = line.split(" ");
  41956. if (size === 0) {
  41957. // Number of space + one
  41958. size = words.length;
  41959. data = new Uint8Array(size * size * size * 4); // volume texture of side size and rgb 8
  41960. tempData = new Float32Array(size * size * size * 4);
  41961. continue;
  41962. }
  41963. if (size != 0) {
  41964. var r = Math.max(parseInt(words[0]), 0);
  41965. var g = Math.max(parseInt(words[1]), 0);
  41966. var b = Math.max(parseInt(words[2]), 0);
  41967. maxColor = Math.max(r, maxColor);
  41968. maxColor = Math.max(g, maxColor);
  41969. maxColor = Math.max(b, maxColor);
  41970. var pixelStorageIndex = (pixelIndexW + pixelIndexSlice * size + pixelIndexH * size * size) * 4;
  41971. if (tempData) {
  41972. tempData[pixelStorageIndex + 0] = r;
  41973. tempData[pixelStorageIndex + 1] = g;
  41974. tempData[pixelStorageIndex + 2] = b;
  41975. }
  41976. pixelIndexSlice++;
  41977. if (pixelIndexSlice % size == 0) {
  41978. pixelIndexH++;
  41979. pixelIndexSlice = 0;
  41980. if (pixelIndexH % size == 0) {
  41981. pixelIndexW++;
  41982. pixelIndexH = 0;
  41983. }
  41984. }
  41985. }
  41986. }
  41987. if (tempData && data) {
  41988. for (var i = 0; i < tempData.length; i++) {
  41989. if (i > 0 && (i + 1) % 4 === 0) {
  41990. data[i] = 255;
  41991. }
  41992. else {
  41993. var value = tempData[i];
  41994. data[i] = (value / maxColor * 255);
  41995. }
  41996. }
  41997. }
  41998. if (texture.is3D) {
  41999. texture.updateSize(size, size, size);
  42000. engine.updateRawTexture3D(texture, data, BABYLON.Engine.TEXTUREFORMAT_RGBA, false);
  42001. }
  42002. else {
  42003. texture.updateSize(size * size, size);
  42004. engine.updateRawTexture(texture, data, BABYLON.Engine.TEXTUREFORMAT_RGBA, false);
  42005. }
  42006. };
  42007. var scene = this.getScene();
  42008. if (scene) {
  42009. scene._loadFile(this.url, callback);
  42010. }
  42011. else {
  42012. this._engine._loadFile(this.url, callback);
  42013. }
  42014. return this._texture;
  42015. };
  42016. /**
  42017. * Starts the loading process of the texture.
  42018. */
  42019. ColorGradingTexture.prototype.loadTexture = function () {
  42020. if (this.url && this.url.toLocaleLowerCase().indexOf(".3dl") == (this.url.length - 4)) {
  42021. this.load3dlTexture();
  42022. }
  42023. };
  42024. /**
  42025. * Clones the color gradind texture.
  42026. */
  42027. ColorGradingTexture.prototype.clone = function () {
  42028. var newTexture = new ColorGradingTexture(this.url, this.getScene());
  42029. // Base texture
  42030. newTexture.level = this.level;
  42031. return newTexture;
  42032. };
  42033. /**
  42034. * Called during delayed load for textures.
  42035. */
  42036. ColorGradingTexture.prototype.delayLoad = function () {
  42037. if (this.delayLoadState !== BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  42038. return;
  42039. }
  42040. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  42041. this._texture = this._getFromCache(this.url, true);
  42042. if (!this._texture) {
  42043. this.loadTexture();
  42044. }
  42045. };
  42046. /**
  42047. * Parses a color grading texture serialized by Babylon.
  42048. * @param parsedTexture The texture information being parsedTexture
  42049. * @param scene The scene to load the texture in
  42050. * @param rootUrl The root url of the data assets to load
  42051. * @return A color gradind texture
  42052. */
  42053. ColorGradingTexture.Parse = function (parsedTexture, scene, rootUrl) {
  42054. var texture = null;
  42055. if (parsedTexture.name && !parsedTexture.isRenderTarget) {
  42056. texture = new ColorGradingTexture(parsedTexture.name, scene);
  42057. texture.name = parsedTexture.name;
  42058. texture.level = parsedTexture.level;
  42059. }
  42060. return texture;
  42061. };
  42062. /**
  42063. * Serializes the LUT texture to json format.
  42064. */
  42065. ColorGradingTexture.prototype.serialize = function () {
  42066. if (!this.name) {
  42067. return null;
  42068. }
  42069. var serializationObject = {};
  42070. serializationObject.name = this.name;
  42071. serializationObject.level = this.level;
  42072. serializationObject.customType = "BABYLON.ColorGradingTexture";
  42073. return serializationObject;
  42074. };
  42075. /**
  42076. * Empty line regex stored for GC.
  42077. */
  42078. ColorGradingTexture._noneEmptyLineRegex = /\S+/;
  42079. return ColorGradingTexture;
  42080. }(BABYLON.BaseTexture));
  42081. BABYLON.ColorGradingTexture = ColorGradingTexture;
  42082. })(BABYLON || (BABYLON = {}));
  42083. //# sourceMappingURL=babylon.colorGradingTexture.js.map
  42084. var BABYLON;
  42085. (function (BABYLON) {
  42086. /**
  42087. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  42088. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  42089. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  42090. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  42091. */
  42092. var ColorCurves = /** @class */ (function () {
  42093. function ColorCurves() {
  42094. this._dirty = true;
  42095. this._tempColor = new BABYLON.Color4(0, 0, 0, 0);
  42096. this._globalCurve = new BABYLON.Color4(0, 0, 0, 0);
  42097. this._highlightsCurve = new BABYLON.Color4(0, 0, 0, 0);
  42098. this._midtonesCurve = new BABYLON.Color4(0, 0, 0, 0);
  42099. this._shadowsCurve = new BABYLON.Color4(0, 0, 0, 0);
  42100. this._positiveCurve = new BABYLON.Color4(0, 0, 0, 0);
  42101. this._negativeCurve = new BABYLON.Color4(0, 0, 0, 0);
  42102. this._globalHue = 30;
  42103. this._globalDensity = 0;
  42104. this._globalSaturation = 0;
  42105. this._globalExposure = 0;
  42106. this._highlightsHue = 30;
  42107. this._highlightsDensity = 0;
  42108. this._highlightsSaturation = 0;
  42109. this._highlightsExposure = 0;
  42110. this._midtonesHue = 30;
  42111. this._midtonesDensity = 0;
  42112. this._midtonesSaturation = 0;
  42113. this._midtonesExposure = 0;
  42114. this._shadowsHue = 30;
  42115. this._shadowsDensity = 0;
  42116. this._shadowsSaturation = 0;
  42117. this._shadowsExposure = 0;
  42118. }
  42119. Object.defineProperty(ColorCurves.prototype, "globalHue", {
  42120. /**
  42121. * Gets the global Hue value.
  42122. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42123. */
  42124. get: function () {
  42125. return this._globalHue;
  42126. },
  42127. /**
  42128. * Sets the global Hue value.
  42129. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42130. */
  42131. set: function (value) {
  42132. this._globalHue = value;
  42133. this._dirty = true;
  42134. },
  42135. enumerable: true,
  42136. configurable: true
  42137. });
  42138. Object.defineProperty(ColorCurves.prototype, "globalDensity", {
  42139. /**
  42140. * Gets the global Density value.
  42141. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42142. * Values less than zero provide a filter of opposite hue.
  42143. */
  42144. get: function () {
  42145. return this._globalDensity;
  42146. },
  42147. /**
  42148. * Sets the global Density value.
  42149. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42150. * Values less than zero provide a filter of opposite hue.
  42151. */
  42152. set: function (value) {
  42153. this._globalDensity = value;
  42154. this._dirty = true;
  42155. },
  42156. enumerable: true,
  42157. configurable: true
  42158. });
  42159. Object.defineProperty(ColorCurves.prototype, "globalSaturation", {
  42160. /**
  42161. * Gets the global Saturation value.
  42162. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42163. */
  42164. get: function () {
  42165. return this._globalSaturation;
  42166. },
  42167. /**
  42168. * Sets the global Saturation value.
  42169. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42170. */
  42171. set: function (value) {
  42172. this._globalSaturation = value;
  42173. this._dirty = true;
  42174. },
  42175. enumerable: true,
  42176. configurable: true
  42177. });
  42178. Object.defineProperty(ColorCurves.prototype, "globalExposure", {
  42179. /**
  42180. * Gets the global Exposure value.
  42181. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42182. */
  42183. get: function () {
  42184. return this._globalExposure;
  42185. },
  42186. /**
  42187. * Sets the global Exposure value.
  42188. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42189. */
  42190. set: function (value) {
  42191. this._globalExposure = value;
  42192. this._dirty = true;
  42193. },
  42194. enumerable: true,
  42195. configurable: true
  42196. });
  42197. Object.defineProperty(ColorCurves.prototype, "highlightsHue", {
  42198. /**
  42199. * Gets the highlights Hue value.
  42200. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42201. */
  42202. get: function () {
  42203. return this._highlightsHue;
  42204. },
  42205. /**
  42206. * Sets the highlights Hue value.
  42207. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42208. */
  42209. set: function (value) {
  42210. this._highlightsHue = value;
  42211. this._dirty = true;
  42212. },
  42213. enumerable: true,
  42214. configurable: true
  42215. });
  42216. Object.defineProperty(ColorCurves.prototype, "highlightsDensity", {
  42217. /**
  42218. * Gets the highlights Density value.
  42219. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42220. * Values less than zero provide a filter of opposite hue.
  42221. */
  42222. get: function () {
  42223. return this._highlightsDensity;
  42224. },
  42225. /**
  42226. * Sets the highlights Density value.
  42227. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42228. * Values less than zero provide a filter of opposite hue.
  42229. */
  42230. set: function (value) {
  42231. this._highlightsDensity = value;
  42232. this._dirty = true;
  42233. },
  42234. enumerable: true,
  42235. configurable: true
  42236. });
  42237. Object.defineProperty(ColorCurves.prototype, "highlightsSaturation", {
  42238. /**
  42239. * Gets the highlights Saturation value.
  42240. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42241. */
  42242. get: function () {
  42243. return this._highlightsSaturation;
  42244. },
  42245. /**
  42246. * Sets the highlights Saturation value.
  42247. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42248. */
  42249. set: function (value) {
  42250. this._highlightsSaturation = value;
  42251. this._dirty = true;
  42252. },
  42253. enumerable: true,
  42254. configurable: true
  42255. });
  42256. Object.defineProperty(ColorCurves.prototype, "highlightsExposure", {
  42257. /**
  42258. * Gets the highlights Exposure value.
  42259. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42260. */
  42261. get: function () {
  42262. return this._highlightsExposure;
  42263. },
  42264. /**
  42265. * Sets the highlights Exposure value.
  42266. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42267. */
  42268. set: function (value) {
  42269. this._highlightsExposure = value;
  42270. this._dirty = true;
  42271. },
  42272. enumerable: true,
  42273. configurable: true
  42274. });
  42275. Object.defineProperty(ColorCurves.prototype, "midtonesHue", {
  42276. /**
  42277. * Gets the midtones Hue value.
  42278. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42279. */
  42280. get: function () {
  42281. return this._midtonesHue;
  42282. },
  42283. /**
  42284. * Sets the midtones Hue value.
  42285. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42286. */
  42287. set: function (value) {
  42288. this._midtonesHue = value;
  42289. this._dirty = true;
  42290. },
  42291. enumerable: true,
  42292. configurable: true
  42293. });
  42294. Object.defineProperty(ColorCurves.prototype, "midtonesDensity", {
  42295. /**
  42296. * Gets the midtones Density value.
  42297. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42298. * Values less than zero provide a filter of opposite hue.
  42299. */
  42300. get: function () {
  42301. return this._midtonesDensity;
  42302. },
  42303. /**
  42304. * Sets the midtones Density value.
  42305. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42306. * Values less than zero provide a filter of opposite hue.
  42307. */
  42308. set: function (value) {
  42309. this._midtonesDensity = value;
  42310. this._dirty = true;
  42311. },
  42312. enumerable: true,
  42313. configurable: true
  42314. });
  42315. Object.defineProperty(ColorCurves.prototype, "midtonesSaturation", {
  42316. /**
  42317. * Gets the midtones Saturation value.
  42318. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42319. */
  42320. get: function () {
  42321. return this._midtonesSaturation;
  42322. },
  42323. /**
  42324. * Sets the midtones Saturation value.
  42325. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42326. */
  42327. set: function (value) {
  42328. this._midtonesSaturation = value;
  42329. this._dirty = true;
  42330. },
  42331. enumerable: true,
  42332. configurable: true
  42333. });
  42334. Object.defineProperty(ColorCurves.prototype, "midtonesExposure", {
  42335. /**
  42336. * Gets the midtones Exposure value.
  42337. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42338. */
  42339. get: function () {
  42340. return this._midtonesExposure;
  42341. },
  42342. /**
  42343. * Sets the midtones Exposure value.
  42344. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42345. */
  42346. set: function (value) {
  42347. this._midtonesExposure = value;
  42348. this._dirty = true;
  42349. },
  42350. enumerable: true,
  42351. configurable: true
  42352. });
  42353. Object.defineProperty(ColorCurves.prototype, "shadowsHue", {
  42354. /**
  42355. * Gets the shadows Hue value.
  42356. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42357. */
  42358. get: function () {
  42359. return this._shadowsHue;
  42360. },
  42361. /**
  42362. * Sets the shadows Hue value.
  42363. * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).
  42364. */
  42365. set: function (value) {
  42366. this._shadowsHue = value;
  42367. this._dirty = true;
  42368. },
  42369. enumerable: true,
  42370. configurable: true
  42371. });
  42372. Object.defineProperty(ColorCurves.prototype, "shadowsDensity", {
  42373. /**
  42374. * Gets the shadows Density value.
  42375. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42376. * Values less than zero provide a filter of opposite hue.
  42377. */
  42378. get: function () {
  42379. return this._shadowsDensity;
  42380. },
  42381. /**
  42382. * Sets the shadows Density value.
  42383. * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.
  42384. * Values less than zero provide a filter of opposite hue.
  42385. */
  42386. set: function (value) {
  42387. this._shadowsDensity = value;
  42388. this._dirty = true;
  42389. },
  42390. enumerable: true,
  42391. configurable: true
  42392. });
  42393. Object.defineProperty(ColorCurves.prototype, "shadowsSaturation", {
  42394. /**
  42395. * Gets the shadows Saturation value.
  42396. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42397. */
  42398. get: function () {
  42399. return this._shadowsSaturation;
  42400. },
  42401. /**
  42402. * Sets the shadows Saturation value.
  42403. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.
  42404. */
  42405. set: function (value) {
  42406. this._shadowsSaturation = value;
  42407. this._dirty = true;
  42408. },
  42409. enumerable: true,
  42410. configurable: true
  42411. });
  42412. Object.defineProperty(ColorCurves.prototype, "shadowsExposure", {
  42413. /**
  42414. * Gets the shadows Exposure value.
  42415. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42416. */
  42417. get: function () {
  42418. return this._shadowsExposure;
  42419. },
  42420. /**
  42421. * Sets the shadows Exposure value.
  42422. * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.
  42423. */
  42424. set: function (value) {
  42425. this._shadowsExposure = value;
  42426. this._dirty = true;
  42427. },
  42428. enumerable: true,
  42429. configurable: true
  42430. });
  42431. ColorCurves.prototype.getClassName = function () {
  42432. return "ColorCurves";
  42433. };
  42434. /**
  42435. * Binds the color curves to the shader.
  42436. * @param colorCurves The color curve to bind
  42437. * @param effect The effect to bind to
  42438. */
  42439. ColorCurves.Bind = function (colorCurves, effect, positiveUniform, neutralUniform, negativeUniform) {
  42440. if (positiveUniform === void 0) { positiveUniform = "vCameraColorCurvePositive"; }
  42441. if (neutralUniform === void 0) { neutralUniform = "vCameraColorCurveNeutral"; }
  42442. if (negativeUniform === void 0) { negativeUniform = "vCameraColorCurveNegative"; }
  42443. if (colorCurves._dirty) {
  42444. colorCurves._dirty = false;
  42445. // Fill in global info.
  42446. colorCurves.getColorGradingDataToRef(colorCurves._globalHue, colorCurves._globalDensity, colorCurves._globalSaturation, colorCurves._globalExposure, colorCurves._globalCurve);
  42447. // Compute highlights info.
  42448. colorCurves.getColorGradingDataToRef(colorCurves._highlightsHue, colorCurves._highlightsDensity, colorCurves._highlightsSaturation, colorCurves._highlightsExposure, colorCurves._tempColor);
  42449. colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._highlightsCurve);
  42450. // Compute midtones info.
  42451. colorCurves.getColorGradingDataToRef(colorCurves._midtonesHue, colorCurves._midtonesDensity, colorCurves._midtonesSaturation, colorCurves._midtonesExposure, colorCurves._tempColor);
  42452. colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._midtonesCurve);
  42453. // Compute shadows info.
  42454. colorCurves.getColorGradingDataToRef(colorCurves._shadowsHue, colorCurves._shadowsDensity, colorCurves._shadowsSaturation, colorCurves._shadowsExposure, colorCurves._tempColor);
  42455. colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._shadowsCurve);
  42456. // Compute deltas (neutral is midtones).
  42457. colorCurves._highlightsCurve.subtractToRef(colorCurves._midtonesCurve, colorCurves._positiveCurve);
  42458. colorCurves._midtonesCurve.subtractToRef(colorCurves._shadowsCurve, colorCurves._negativeCurve);
  42459. }
  42460. if (effect) {
  42461. effect.setFloat4(positiveUniform, colorCurves._positiveCurve.r, colorCurves._positiveCurve.g, colorCurves._positiveCurve.b, colorCurves._positiveCurve.a);
  42462. effect.setFloat4(neutralUniform, colorCurves._midtonesCurve.r, colorCurves._midtonesCurve.g, colorCurves._midtonesCurve.b, colorCurves._midtonesCurve.a);
  42463. effect.setFloat4(negativeUniform, colorCurves._negativeCurve.r, colorCurves._negativeCurve.g, colorCurves._negativeCurve.b, colorCurves._negativeCurve.a);
  42464. }
  42465. };
  42466. /**
  42467. * Prepare the list of uniforms associated with the ColorCurves effects.
  42468. * @param uniformsList The list of uniforms used in the effect
  42469. */
  42470. ColorCurves.PrepareUniforms = function (uniformsList) {
  42471. uniformsList.push("vCameraColorCurveNeutral", "vCameraColorCurvePositive", "vCameraColorCurveNegative");
  42472. };
  42473. /**
  42474. * Returns color grading data based on a hue, density, saturation and exposure value.
  42475. * @param filterHue The hue of the color filter.
  42476. * @param filterDensity The density of the color filter.
  42477. * @param saturation The saturation.
  42478. * @param exposure The exposure.
  42479. * @param result The result data container.
  42480. */
  42481. ColorCurves.prototype.getColorGradingDataToRef = function (hue, density, saturation, exposure, result) {
  42482. if (hue == null) {
  42483. return;
  42484. }
  42485. hue = ColorCurves.clamp(hue, 0, 360);
  42486. density = ColorCurves.clamp(density, -100, 100);
  42487. saturation = ColorCurves.clamp(saturation, -100, 100);
  42488. exposure = ColorCurves.clamp(exposure, -100, 100);
  42489. // Remap the slider/config filter density with non-linear mapping and also scale by half
  42490. // so that the maximum filter density is only 50% control. This provides fine control
  42491. // for small values and reasonable range.
  42492. density = ColorCurves.applyColorGradingSliderNonlinear(density);
  42493. density *= 0.5;
  42494. exposure = ColorCurves.applyColorGradingSliderNonlinear(exposure);
  42495. if (density < 0) {
  42496. density *= -1;
  42497. hue = (hue + 180) % 360;
  42498. }
  42499. ColorCurves.fromHSBToRef(hue, density, 50 + 0.25 * exposure, result);
  42500. result.scaleToRef(2, result);
  42501. result.a = 1 + 0.01 * saturation;
  42502. };
  42503. /**
  42504. * Takes an input slider value and returns an adjusted value that provides extra control near the centre.
  42505. * @param value The input slider value in range [-100,100].
  42506. * @returns Adjusted value.
  42507. */
  42508. ColorCurves.applyColorGradingSliderNonlinear = function (value) {
  42509. value /= 100;
  42510. var x = Math.abs(value);
  42511. x = Math.pow(x, 2);
  42512. if (value < 0) {
  42513. x *= -1;
  42514. }
  42515. x *= 100;
  42516. return x;
  42517. };
  42518. /**
  42519. * Returns an RGBA Color4 based on Hue, Saturation and Brightness (also referred to as value, HSV).
  42520. * @param hue The hue (H) input.
  42521. * @param saturation The saturation (S) input.
  42522. * @param brightness The brightness (B) input.
  42523. * @result An RGBA color represented as Vector4.
  42524. */
  42525. ColorCurves.fromHSBToRef = function (hue, saturation, brightness, result) {
  42526. var h = ColorCurves.clamp(hue, 0, 360);
  42527. var s = ColorCurves.clamp(saturation / 100, 0, 1);
  42528. var v = ColorCurves.clamp(brightness / 100, 0, 1);
  42529. if (s === 0) {
  42530. result.r = v;
  42531. result.g = v;
  42532. result.b = v;
  42533. }
  42534. else {
  42535. // sector 0 to 5
  42536. h /= 60;
  42537. var i = Math.floor(h);
  42538. // fractional part of h
  42539. var f = h - i;
  42540. var p = v * (1 - s);
  42541. var q = v * (1 - s * f);
  42542. var t = v * (1 - s * (1 - f));
  42543. switch (i) {
  42544. case 0:
  42545. result.r = v;
  42546. result.g = t;
  42547. result.b = p;
  42548. break;
  42549. case 1:
  42550. result.r = q;
  42551. result.g = v;
  42552. result.b = p;
  42553. break;
  42554. case 2:
  42555. result.r = p;
  42556. result.g = v;
  42557. result.b = t;
  42558. break;
  42559. case 3:
  42560. result.r = p;
  42561. result.g = q;
  42562. result.b = v;
  42563. break;
  42564. case 4:
  42565. result.r = t;
  42566. result.g = p;
  42567. result.b = v;
  42568. break;
  42569. default: // case 5:
  42570. result.r = v;
  42571. result.g = p;
  42572. result.b = q;
  42573. break;
  42574. }
  42575. }
  42576. result.a = 1;
  42577. };
  42578. /**
  42579. * Returns a value clamped between min and max
  42580. * @param value The value to clamp
  42581. * @param min The minimum of value
  42582. * @param max The maximum of value
  42583. * @returns The clamped value.
  42584. */
  42585. ColorCurves.clamp = function (value, min, max) {
  42586. return Math.min(Math.max(value, min), max);
  42587. };
  42588. /**
  42589. * Clones the current color curve instance.
  42590. * @return The cloned curves
  42591. */
  42592. ColorCurves.prototype.clone = function () {
  42593. return BABYLON.SerializationHelper.Clone(function () { return new ColorCurves(); }, this);
  42594. };
  42595. /**
  42596. * Serializes the current color curve instance to a json representation.
  42597. * @return a JSON representation
  42598. */
  42599. ColorCurves.prototype.serialize = function () {
  42600. return BABYLON.SerializationHelper.Serialize(this);
  42601. };
  42602. /**
  42603. * Parses the color curve from a json representation.
  42604. * @param source the JSON source to parse
  42605. * @return The parsed curves
  42606. */
  42607. ColorCurves.Parse = function (source) {
  42608. return BABYLON.SerializationHelper.Parse(function () { return new ColorCurves(); }, source, null, null);
  42609. };
  42610. __decorate([
  42611. BABYLON.serialize()
  42612. ], ColorCurves.prototype, "_globalHue", void 0);
  42613. __decorate([
  42614. BABYLON.serialize()
  42615. ], ColorCurves.prototype, "_globalDensity", void 0);
  42616. __decorate([
  42617. BABYLON.serialize()
  42618. ], ColorCurves.prototype, "_globalSaturation", void 0);
  42619. __decorate([
  42620. BABYLON.serialize()
  42621. ], ColorCurves.prototype, "_globalExposure", void 0);
  42622. __decorate([
  42623. BABYLON.serialize()
  42624. ], ColorCurves.prototype, "_highlightsHue", void 0);
  42625. __decorate([
  42626. BABYLON.serialize()
  42627. ], ColorCurves.prototype, "_highlightsDensity", void 0);
  42628. __decorate([
  42629. BABYLON.serialize()
  42630. ], ColorCurves.prototype, "_highlightsSaturation", void 0);
  42631. __decorate([
  42632. BABYLON.serialize()
  42633. ], ColorCurves.prototype, "_highlightsExposure", void 0);
  42634. __decorate([
  42635. BABYLON.serialize()
  42636. ], ColorCurves.prototype, "_midtonesHue", void 0);
  42637. __decorate([
  42638. BABYLON.serialize()
  42639. ], ColorCurves.prototype, "_midtonesDensity", void 0);
  42640. __decorate([
  42641. BABYLON.serialize()
  42642. ], ColorCurves.prototype, "_midtonesSaturation", void 0);
  42643. __decorate([
  42644. BABYLON.serialize()
  42645. ], ColorCurves.prototype, "_midtonesExposure", void 0);
  42646. return ColorCurves;
  42647. }());
  42648. BABYLON.ColorCurves = ColorCurves;
  42649. })(BABYLON || (BABYLON = {}));
  42650. //# sourceMappingURL=babylon.colorCurves.js.map
  42651. //# sourceMappingURL=babylon.behavior.js.map
  42652. var BABYLON;
  42653. (function (BABYLON) {
  42654. /**
  42655. * "Static Class" containing the most commonly used helper while dealing with material for
  42656. * rendering purpose.
  42657. *
  42658. * It contains the basic tools to help defining defines, binding uniform for the common part of the materials.
  42659. *
  42660. * This works by convention in BabylonJS but is meant to be use only with shader following the in place naming rules and conventions.
  42661. */
  42662. var MaterialHelper = /** @class */ (function () {
  42663. function MaterialHelper() {
  42664. }
  42665. /**
  42666. * Bind the current view position to an effect.
  42667. * @param effect The effect to be bound
  42668. * @param scene The scene the eyes position is used from
  42669. */
  42670. MaterialHelper.BindEyePosition = function (effect, scene) {
  42671. if (scene._forcedViewPosition) {
  42672. effect.setVector3("vEyePosition", scene._forcedViewPosition);
  42673. return;
  42674. }
  42675. effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.globalPosition);
  42676. };
  42677. /**
  42678. * Helps preparing the defines values about the UVs in used in the effect.
  42679. * UVs are shared as much as we can accross chanels in the shaders.
  42680. * @param texture The texture we are preparing the UVs for
  42681. * @param defines The defines to update
  42682. * @param key The chanel key "diffuse", "specular"... used in the shader
  42683. */
  42684. MaterialHelper.PrepareDefinesForMergedUV = function (texture, defines, key) {
  42685. defines._needUVs = true;
  42686. defines[key] = true;
  42687. if (texture.getTextureMatrix().isIdentity(true)) {
  42688. defines[key + "DIRECTUV"] = texture.coordinatesIndex + 1;
  42689. if (texture.coordinatesIndex === 0) {
  42690. defines["MAINUV1"] = true;
  42691. }
  42692. else {
  42693. defines["MAINUV2"] = true;
  42694. }
  42695. }
  42696. else {
  42697. defines[key + "DIRECTUV"] = 0;
  42698. }
  42699. };
  42700. /**
  42701. * Binds a texture matrix value to its corrsponding uniform
  42702. * @param texture The texture to bind the matrix for
  42703. * @param uniformBuffer The uniform buffer receivin the data
  42704. * @param key The chanel key "diffuse", "specular"... used in the shader
  42705. */
  42706. MaterialHelper.BindTextureMatrix = function (texture, uniformBuffer, key) {
  42707. var matrix = texture.getTextureMatrix();
  42708. if (!matrix.isIdentity(true)) {
  42709. uniformBuffer.updateMatrix(key + "Matrix", matrix);
  42710. }
  42711. };
  42712. /**
  42713. * Helper used to prepare the list of defines associated with misc. values for shader compilation
  42714. * @param mesh defines the current mesh
  42715. * @param scene defines the current scene
  42716. * @param useLogarithmicDepth defines if logarithmic depth has to be turned on
  42717. * @param pointsCloud defines if point cloud rendering has to be turned on
  42718. * @param fogEnabled defines if fog has to be turned on
  42719. * @param alphaTest defines if alpha testing has to be turned on
  42720. * @param defines defines the current list of defines
  42721. */
  42722. MaterialHelper.PrepareDefinesForMisc = function (mesh, scene, useLogarithmicDepth, pointsCloud, fogEnabled, alphaTest, defines) {
  42723. if (defines._areMiscDirty) {
  42724. defines["LOGARITHMICDEPTH"] = useLogarithmicDepth;
  42725. defines["POINTSIZE"] = pointsCloud;
  42726. defines["FOG"] = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && fogEnabled);
  42727. defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
  42728. defines["ALPHATEST"] = alphaTest;
  42729. }
  42730. };
  42731. /**
  42732. * Helper used to prepare the list of defines associated with frame values for shader compilation
  42733. * @param scene defines the current scene
  42734. * @param engine defines the current engine
  42735. * @param defines specifies the list of active defines
  42736. * @param useInstances defines if instances have to be turned on
  42737. * @param useClipPlane defines if clip plane have to be turned on
  42738. */
  42739. MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, useClipPlane) {
  42740. if (useClipPlane === void 0) { useClipPlane = null; }
  42741. var changed = false;
  42742. if (useClipPlane == null) {
  42743. useClipPlane = (scene.clipPlane !== undefined && scene.clipPlane !== null);
  42744. }
  42745. if (defines["CLIPPLANE"] !== useClipPlane) {
  42746. defines["CLIPPLANE"] = useClipPlane;
  42747. changed = true;
  42748. }
  42749. if (defines["DEPTHPREPASS"] !== !engine.getColorWrite()) {
  42750. defines["DEPTHPREPASS"] = !defines["DEPTHPREPASS"];
  42751. changed = true;
  42752. }
  42753. if (defines["INSTANCES"] !== useInstances) {
  42754. defines["INSTANCES"] = useInstances;
  42755. changed = true;
  42756. }
  42757. if (changed) {
  42758. defines.markAsUnprocessed();
  42759. }
  42760. };
  42761. /**
  42762. * Prepares the defines used in the shader depending on the attributes data available in the mesh
  42763. * @param mesh The mesh containing the geometry data we will draw
  42764. * @param defines The defines to update
  42765. * @param useVertexColor Precise whether vertex colors should be used or not (override mesh info)
  42766. * @param useBones Precise whether bones should be used or not (override mesh info)
  42767. * @param useMorphTargets Precise whether morph targets should be used or not (override mesh info)
  42768. * @param useVertexAlpha Precise whether vertex alpha should be used or not (override mesh info)
  42769. * @returns false if defines are considered not dirty and have not been checked
  42770. */
  42771. MaterialHelper.PrepareDefinesForAttributes = function (mesh, defines, useVertexColor, useBones, useMorphTargets, useVertexAlpha) {
  42772. if (useMorphTargets === void 0) { useMorphTargets = false; }
  42773. if (useVertexAlpha === void 0) { useVertexAlpha = true; }
  42774. if (!defines._areAttributesDirty && defines._needNormals === defines._normals && defines._needUVs === defines._uvs) {
  42775. return false;
  42776. }
  42777. defines._normals = defines._needNormals;
  42778. defines._uvs = defines._needUVs;
  42779. defines["NORMAL"] = (defines._needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind));
  42780. if (defines._needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
  42781. defines["TANGENT"] = true;
  42782. }
  42783. if (defines._needUVs) {
  42784. defines["UV1"] = mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind);
  42785. defines["UV2"] = mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind);
  42786. }
  42787. else {
  42788. defines["UV1"] = false;
  42789. defines["UV2"] = false;
  42790. }
  42791. if (useVertexColor) {
  42792. var hasVertexColors = mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind);
  42793. defines["VERTEXCOLOR"] = hasVertexColors;
  42794. defines["VERTEXALPHA"] = mesh.hasVertexAlpha && hasVertexColors && useVertexAlpha;
  42795. }
  42796. if (useBones) {
  42797. if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
  42798. defines["NUM_BONE_INFLUENCERS"] = mesh.numBoneInfluencers;
  42799. defines["BonesPerMesh"] = (mesh.skeleton.bones.length + 1);
  42800. }
  42801. else {
  42802. defines["NUM_BONE_INFLUENCERS"] = 0;
  42803. defines["BonesPerMesh"] = 0;
  42804. }
  42805. }
  42806. if (useMorphTargets) {
  42807. var manager = mesh.morphTargetManager;
  42808. if (manager) {
  42809. defines["MORPHTARGETS_TANGENT"] = manager.supportsTangents && defines["TANGENT"];
  42810. defines["MORPHTARGETS_NORMAL"] = manager.supportsNormals && defines["NORMAL"];
  42811. defines["MORPHTARGETS"] = (manager.numInfluencers > 0);
  42812. defines["NUM_MORPH_INFLUENCERS"] = manager.numInfluencers;
  42813. }
  42814. else {
  42815. defines["MORPHTARGETS_TANGENT"] = false;
  42816. defines["MORPHTARGETS_NORMAL"] = false;
  42817. defines["MORPHTARGETS"] = false;
  42818. defines["NUM_MORPH_INFLUENCERS"] = 0;
  42819. }
  42820. }
  42821. return true;
  42822. };
  42823. /**
  42824. * Prepares the defines related to the light information passed in parameter
  42825. * @param scene The scene we are intending to draw
  42826. * @param mesh The mesh the effect is compiling for
  42827. * @param defines The defines to update
  42828. * @param specularSupported Specifies whether specular is supported or not (override lights data)
  42829. * @param maxSimultaneousLights Specfies how manuy lights can be added to the effect at max
  42830. * @param disableLighting Specifies whether the lighting is disabled (override scene and light)
  42831. * @returns true if normals will be required for the rest of the effect
  42832. */
  42833. MaterialHelper.PrepareDefinesForLights = function (scene, mesh, defines, specularSupported, maxSimultaneousLights, disableLighting) {
  42834. if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
  42835. if (disableLighting === void 0) { disableLighting = false; }
  42836. if (!defines._areLightsDirty) {
  42837. return defines._needNormals;
  42838. }
  42839. var lightIndex = 0;
  42840. var needNormals = false;
  42841. var needRebuild = false;
  42842. var lightmapMode = false;
  42843. var shadowEnabled = false;
  42844. var specularEnabled = false;
  42845. if (scene.lightsEnabled && !disableLighting) {
  42846. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  42847. var light = _a[_i];
  42848. needNormals = true;
  42849. if (defines["LIGHT" + lightIndex] === undefined) {
  42850. needRebuild = true;
  42851. }
  42852. defines["LIGHT" + lightIndex] = true;
  42853. defines["SPOTLIGHT" + lightIndex] = false;
  42854. defines["HEMILIGHT" + lightIndex] = false;
  42855. defines["POINTLIGHT" + lightIndex] = false;
  42856. defines["DIRLIGHT" + lightIndex] = false;
  42857. var type;
  42858. if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_SPOTLIGHT) {
  42859. type = "SPOTLIGHT" + lightIndex;
  42860. var spotLight = light;
  42861. defines["PROJECTEDLIGHTTEXTURE" + lightIndex] = spotLight.projectionTexture ? true : false;
  42862. }
  42863. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_HEMISPHERICLIGHT) {
  42864. type = "HEMILIGHT" + lightIndex;
  42865. }
  42866. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_POINTLIGHT) {
  42867. type = "POINTLIGHT" + lightIndex;
  42868. }
  42869. else {
  42870. type = "DIRLIGHT" + lightIndex;
  42871. }
  42872. defines[type] = true;
  42873. // Specular
  42874. if (specularSupported && !light.specular.equalsFloats(0, 0, 0)) {
  42875. specularEnabled = true;
  42876. }
  42877. // Shadows
  42878. defines["SHADOW" + lightIndex] = false;
  42879. defines["SHADOWPCF" + lightIndex] = false;
  42880. defines["SHADOWPCSS" + lightIndex] = false;
  42881. defines["SHADOWPOISSON" + lightIndex] = false;
  42882. defines["SHADOWESM" + lightIndex] = false;
  42883. defines["SHADOWCUBE" + lightIndex] = false;
  42884. defines["SHADOWLOWQUALITY" + lightIndex] = false;
  42885. defines["SHADOWMEDIUMQUALITY" + lightIndex] = false;
  42886. if (mesh && mesh.receiveShadows && scene.shadowsEnabled && light.shadowEnabled) {
  42887. var shadowGenerator = light.getShadowGenerator();
  42888. if (shadowGenerator) {
  42889. shadowEnabled = true;
  42890. shadowGenerator.prepareDefines(defines, lightIndex);
  42891. }
  42892. }
  42893. if (light.lightmapMode != BABYLON.Light.LIGHTMAP_DEFAULT) {
  42894. lightmapMode = true;
  42895. defines["LIGHTMAPEXCLUDED" + lightIndex] = true;
  42896. defines["LIGHTMAPNOSPECULAR" + lightIndex] = (light.lightmapMode == BABYLON.Light.LIGHTMAP_SHADOWSONLY);
  42897. }
  42898. else {
  42899. defines["LIGHTMAPEXCLUDED" + lightIndex] = false;
  42900. defines["LIGHTMAPNOSPECULAR" + lightIndex] = false;
  42901. }
  42902. lightIndex++;
  42903. if (lightIndex === maxSimultaneousLights)
  42904. break;
  42905. }
  42906. }
  42907. defines["SPECULARTERM"] = specularEnabled;
  42908. defines["SHADOWS"] = shadowEnabled;
  42909. // Resetting all other lights if any
  42910. for (var index = lightIndex; index < maxSimultaneousLights; index++) {
  42911. if (defines["LIGHT" + index] !== undefined) {
  42912. defines["LIGHT" + index] = false;
  42913. defines["HEMILIGHT" + lightIndex] = false;
  42914. defines["POINTLIGHT" + lightIndex] = false;
  42915. defines["DIRLIGHT" + lightIndex] = false;
  42916. defines["SPOTLIGHT" + lightIndex] = false;
  42917. defines["SHADOW" + lightIndex] = false;
  42918. }
  42919. }
  42920. var caps = scene.getEngine().getCaps();
  42921. if (defines["SHADOWFLOAT"] === undefined) {
  42922. needRebuild = true;
  42923. }
  42924. defines["SHADOWFLOAT"] = shadowEnabled &&
  42925. ((caps.textureFloatRender && caps.textureFloatLinearFiltering) ||
  42926. (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering));
  42927. defines["LIGHTMAPEXCLUDED"] = lightmapMode;
  42928. if (needRebuild) {
  42929. defines.rebuild();
  42930. }
  42931. return needNormals;
  42932. };
  42933. /**
  42934. * Prepares the uniforms and samplers list to be used in the effect. This can automatically remove from the list uniforms
  42935. * that won t be acctive due to defines being turned off.
  42936. * @param uniformsListOrOptions The uniform names to prepare or an EffectCreationOptions containing the liist and extra information
  42937. * @param samplersList The samplers list
  42938. * @param defines The defines helping in the list generation
  42939. * @param maxSimultaneousLights The maximum number of simultanous light allowed in the effect
  42940. */
  42941. MaterialHelper.PrepareUniformsAndSamplersList = function (uniformsListOrOptions, samplersList, defines, maxSimultaneousLights) {
  42942. if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
  42943. var uniformsList;
  42944. var uniformBuffersList = null;
  42945. if (uniformsListOrOptions.uniformsNames) {
  42946. var options = uniformsListOrOptions;
  42947. uniformsList = options.uniformsNames;
  42948. uniformBuffersList = options.uniformBuffersNames;
  42949. samplersList = options.samplers;
  42950. defines = options.defines;
  42951. maxSimultaneousLights = options.maxSimultaneousLights;
  42952. }
  42953. else {
  42954. uniformsList = uniformsListOrOptions;
  42955. if (!samplersList) {
  42956. samplersList = [];
  42957. }
  42958. }
  42959. for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  42960. if (!defines["LIGHT" + lightIndex]) {
  42961. break;
  42962. }
  42963. uniformsList.push("vLightData" + lightIndex, "vLightDiffuse" + lightIndex, "vLightSpecular" + lightIndex, "vLightDirection" + lightIndex, "vLightGround" + lightIndex, "lightMatrix" + lightIndex, "shadowsInfo" + lightIndex, "depthValues" + lightIndex);
  42964. if (uniformBuffersList) {
  42965. uniformBuffersList.push("Light" + lightIndex);
  42966. }
  42967. samplersList.push("shadowSampler" + lightIndex);
  42968. samplersList.push("depthSampler" + lightIndex);
  42969. if (defines["PROJECTEDLIGHTTEXTURE" + lightIndex]) {
  42970. samplersList.push("projectionLightSampler" + lightIndex);
  42971. uniformsList.push("textureProjectionMatrix" + lightIndex);
  42972. }
  42973. }
  42974. if (defines["NUM_MORPH_INFLUENCERS"]) {
  42975. uniformsList.push("morphTargetInfluences");
  42976. }
  42977. };
  42978. /**
  42979. * This helps decreasing rank by rank the shadow quality (0 being the highest rank and quality)
  42980. * @param defines The defines to update while falling back
  42981. * @param fallbacks The authorized effect fallbacks
  42982. * @param maxSimultaneousLights The maximum number of lights allowed
  42983. * @param rank the current rank of the Effect
  42984. * @returns The newly affected rank
  42985. */
  42986. MaterialHelper.HandleFallbacksForShadows = function (defines, fallbacks, maxSimultaneousLights, rank) {
  42987. if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
  42988. if (rank === void 0) { rank = 0; }
  42989. var lightFallbackRank = 0;
  42990. for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  42991. if (!defines["LIGHT" + lightIndex]) {
  42992. break;
  42993. }
  42994. if (lightIndex > 0) {
  42995. lightFallbackRank = rank + lightIndex;
  42996. fallbacks.addFallback(lightFallbackRank, "LIGHT" + lightIndex);
  42997. }
  42998. if (!defines["SHADOWS"]) {
  42999. if (defines["SHADOW" + lightIndex]) {
  43000. fallbacks.addFallback(rank, "SHADOW" + lightIndex);
  43001. }
  43002. if (defines["SHADOWPCF" + lightIndex]) {
  43003. fallbacks.addFallback(rank, "SHADOWPCF" + lightIndex);
  43004. }
  43005. if (defines["SHADOWPCSS" + lightIndex]) {
  43006. fallbacks.addFallback(rank, "SHADOWPCSS" + lightIndex);
  43007. }
  43008. if (defines["SHADOWPOISSON" + lightIndex]) {
  43009. fallbacks.addFallback(rank, "SHADOWPOISSON" + lightIndex);
  43010. }
  43011. if (defines["SHADOWESM" + lightIndex]) {
  43012. fallbacks.addFallback(rank, "SHADOWESM" + lightIndex);
  43013. }
  43014. }
  43015. }
  43016. return lightFallbackRank++;
  43017. };
  43018. /**
  43019. * Prepares the list of attributes required for morph targets according to the effect defines.
  43020. * @param attribs The current list of supported attribs
  43021. * @param mesh The mesh to prepare the morph targets attributes for
  43022. * @param defines The current Defines of the effect
  43023. */
  43024. MaterialHelper.PrepareAttributesForMorphTargets = function (attribs, mesh, defines) {
  43025. var influencers = defines["NUM_MORPH_INFLUENCERS"];
  43026. if (influencers > 0 && BABYLON.Engine.LastCreatedEngine) {
  43027. var maxAttributesCount = BABYLON.Engine.LastCreatedEngine.getCaps().maxVertexAttribs;
  43028. var manager = mesh.morphTargetManager;
  43029. var normal = manager && manager.supportsNormals && defines["NORMAL"];
  43030. var tangent = manager && manager.supportsTangents && defines["TANGENT"];
  43031. for (var index = 0; index < influencers; index++) {
  43032. attribs.push(BABYLON.VertexBuffer.PositionKind + index);
  43033. if (normal) {
  43034. attribs.push(BABYLON.VertexBuffer.NormalKind + index);
  43035. }
  43036. if (tangent) {
  43037. attribs.push(BABYLON.VertexBuffer.TangentKind + index);
  43038. }
  43039. if (attribs.length > maxAttributesCount) {
  43040. BABYLON.Tools.Error("Cannot add more vertex attributes for mesh " + mesh.name);
  43041. }
  43042. }
  43043. }
  43044. };
  43045. /**
  43046. * Prepares the list of attributes required for bones according to the effect defines.
  43047. * @param attribs The current list of supported attribs
  43048. * @param mesh The mesh to prepare the bones attributes for
  43049. * @param defines The current Defines of the effect
  43050. * @param fallbacks The current efffect fallback strategy
  43051. */
  43052. MaterialHelper.PrepareAttributesForBones = function (attribs, mesh, defines, fallbacks) {
  43053. if (defines["NUM_BONE_INFLUENCERS"] > 0) {
  43054. fallbacks.addCPUSkinningFallback(0, mesh);
  43055. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  43056. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  43057. if (defines["NUM_BONE_INFLUENCERS"] > 4) {
  43058. attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  43059. attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
  43060. }
  43061. }
  43062. };
  43063. /**
  43064. * Prepares the list of attributes required for instances according to the effect defines.
  43065. * @param attribs The current list of supported attribs
  43066. * @param defines The current Defines of the effect
  43067. */
  43068. MaterialHelper.PrepareAttributesForInstances = function (attribs, defines) {
  43069. if (defines["INSTANCES"]) {
  43070. attribs.push("world0");
  43071. attribs.push("world1");
  43072. attribs.push("world2");
  43073. attribs.push("world3");
  43074. }
  43075. };
  43076. /**
  43077. * Binds the light shadow information to the effect for the given mesh.
  43078. * @param light The light containing the generator
  43079. * @param scene The scene the lights belongs to
  43080. * @param mesh The mesh we are binding the information to render
  43081. * @param lightIndex The light index in the effect used to render the mesh
  43082. * @param effect The effect we are binding the data to
  43083. */
  43084. MaterialHelper.BindLightShadow = function (light, scene, mesh, lightIndex, effect) {
  43085. if (light.shadowEnabled && mesh.receiveShadows) {
  43086. var shadowGenerator = light.getShadowGenerator();
  43087. if (shadowGenerator) {
  43088. shadowGenerator.bindShadowLight(lightIndex, effect);
  43089. }
  43090. }
  43091. };
  43092. /**
  43093. * Binds the light information to the effect.
  43094. * @param light The light containing the generator
  43095. * @param effect The effect we are binding the data to
  43096. * @param lightIndex The light index in the effect used to render
  43097. */
  43098. MaterialHelper.BindLightProperties = function (light, effect, lightIndex) {
  43099. light.transferToEffect(effect, lightIndex + "");
  43100. };
  43101. /**
  43102. * Binds the lights information from the scene to the effect for the given mesh.
  43103. * @param scene The scene the lights belongs to
  43104. * @param mesh The mesh we are binding the information to render
  43105. * @param effect The effect we are binding the data to
  43106. * @param defines The generated defines for the effect
  43107. * @param maxSimultaneousLights The maximum number of light that can be bound to the effect
  43108. * @param usePhysicalLightFalloff Specifies whether the light falloff is defined physically or not
  43109. */
  43110. MaterialHelper.BindLights = function (scene, mesh, effect, defines, maxSimultaneousLights, usePhysicalLightFalloff) {
  43111. if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
  43112. if (usePhysicalLightFalloff === void 0) { usePhysicalLightFalloff = false; }
  43113. var len = Math.min(mesh._lightSources.length, maxSimultaneousLights);
  43114. for (var i = 0; i < len; i++) {
  43115. var light = mesh._lightSources[i];
  43116. var iAsString = i.toString();
  43117. var scaledIntensity = light.getScaledIntensity();
  43118. light._uniformBuffer.bindToEffect(effect, "Light" + i);
  43119. MaterialHelper.BindLightProperties(light, effect, i);
  43120. light.diffuse.scaleToRef(scaledIntensity, BABYLON.Tmp.Color3[0]);
  43121. light._uniformBuffer.updateColor4("vLightDiffuse", BABYLON.Tmp.Color3[0], usePhysicalLightFalloff ? light.radius : light.range, iAsString);
  43122. if (defines["SPECULARTERM"]) {
  43123. light.specular.scaleToRef(scaledIntensity, BABYLON.Tmp.Color3[1]);
  43124. light._uniformBuffer.updateColor3("vLightSpecular", BABYLON.Tmp.Color3[1], iAsString);
  43125. }
  43126. // Shadows
  43127. if (scene.shadowsEnabled) {
  43128. this.BindLightShadow(light, scene, mesh, iAsString, effect);
  43129. }
  43130. light._uniformBuffer.update();
  43131. }
  43132. };
  43133. /**
  43134. * Binds the fog information from the scene to the effect for the given mesh.
  43135. * @param scene The scene the lights belongs to
  43136. * @param mesh The mesh we are binding the information to render
  43137. * @param effect The effect we are binding the data to
  43138. */
  43139. MaterialHelper.BindFogParameters = function (scene, mesh, effect) {
  43140. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  43141. effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  43142. effect.setColor3("vFogColor", scene.fogColor);
  43143. }
  43144. };
  43145. /**
  43146. * Binds the bones information from the mesh to the effect.
  43147. * @param mesh The mesh we are binding the information to render
  43148. * @param effect The effect we are binding the data to
  43149. */
  43150. MaterialHelper.BindBonesParameters = function (mesh, effect) {
  43151. if (!effect || !mesh) {
  43152. return;
  43153. }
  43154. if (mesh.computeBonesUsingShaders && effect._bonesComputationForcedToCPU) {
  43155. mesh.computeBonesUsingShaders = false;
  43156. }
  43157. if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
  43158. var matrices = mesh.skeleton.getTransformMatrices(mesh);
  43159. if (matrices) {
  43160. effect.setMatrices("mBones", matrices);
  43161. }
  43162. }
  43163. };
  43164. /**
  43165. * Binds the morph targets information from the mesh to the effect.
  43166. * @param abstractMesh The mesh we are binding the information to render
  43167. * @param effect The effect we are binding the data to
  43168. */
  43169. MaterialHelper.BindMorphTargetParameters = function (abstractMesh, effect) {
  43170. var manager = abstractMesh.morphTargetManager;
  43171. if (!abstractMesh || !manager) {
  43172. return;
  43173. }
  43174. effect.setFloatArray("morphTargetInfluences", manager.influences);
  43175. };
  43176. /**
  43177. * Binds the logarithmic depth information from the scene to the effect for the given defines.
  43178. * @param defines The generated defines used in the effect
  43179. * @param effect The effect we are binding the data to
  43180. * @param scene The scene we are willing to render with logarithmic scale for
  43181. */
  43182. MaterialHelper.BindLogDepth = function (defines, effect, scene) {
  43183. if (defines["LOGARITHMICDEPTH"]) {
  43184. effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
  43185. }
  43186. };
  43187. /**
  43188. * Binds the clip plane information from the scene to the effect.
  43189. * @param scene The scene the clip plane information are extracted from
  43190. * @param effect The effect we are binding the data to
  43191. */
  43192. MaterialHelper.BindClipPlane = function (effect, scene) {
  43193. if (scene.clipPlane) {
  43194. var clipPlane = scene.clipPlane;
  43195. effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  43196. }
  43197. };
  43198. return MaterialHelper;
  43199. }());
  43200. BABYLON.MaterialHelper = MaterialHelper;
  43201. })(BABYLON || (BABYLON = {}));
  43202. //# sourceMappingURL=babylon.materialHelper.js.map
  43203. var BABYLON;
  43204. (function (BABYLON) {
  43205. var PushMaterial = /** @class */ (function (_super) {
  43206. __extends(PushMaterial, _super);
  43207. function PushMaterial(name, scene) {
  43208. var _this = _super.call(this, name, scene) || this;
  43209. _this._normalMatrix = new BABYLON.Matrix();
  43210. _this.storeEffectOnSubMeshes = true;
  43211. return _this;
  43212. }
  43213. PushMaterial.prototype.getEffect = function () {
  43214. return this._activeEffect;
  43215. };
  43216. PushMaterial.prototype.isReady = function (mesh, useInstances) {
  43217. if (!mesh) {
  43218. return false;
  43219. }
  43220. if (!mesh.subMeshes || mesh.subMeshes.length === 0) {
  43221. return true;
  43222. }
  43223. return this.isReadyForSubMesh(mesh, mesh.subMeshes[0], useInstances);
  43224. };
  43225. /**
  43226. * Binds the given world matrix to the active effect
  43227. *
  43228. * @param world the matrix to bind
  43229. */
  43230. PushMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  43231. this._activeEffect.setMatrix("world", world);
  43232. };
  43233. /**
  43234. * Binds the given normal matrix to the active effect
  43235. *
  43236. * @param normalMatrix the matrix to bind
  43237. */
  43238. PushMaterial.prototype.bindOnlyNormalMatrix = function (normalMatrix) {
  43239. this._activeEffect.setMatrix("normalMatrix", normalMatrix);
  43240. };
  43241. PushMaterial.prototype.bind = function (world, mesh) {
  43242. if (!mesh) {
  43243. return;
  43244. }
  43245. this.bindForSubMesh(world, mesh, mesh.subMeshes[0]);
  43246. };
  43247. PushMaterial.prototype._afterBind = function (mesh, effect) {
  43248. if (effect === void 0) { effect = null; }
  43249. _super.prototype._afterBind.call(this, mesh);
  43250. this.getScene()._cachedEffect = effect;
  43251. };
  43252. PushMaterial.prototype._mustRebind = function (scene, effect, visibility) {
  43253. if (visibility === void 0) { visibility = 1; }
  43254. return scene.isCachedMaterialInvalid(this, effect, visibility);
  43255. };
  43256. return PushMaterial;
  43257. }(BABYLON.Material));
  43258. BABYLON.PushMaterial = PushMaterial;
  43259. })(BABYLON || (BABYLON = {}));
  43260. //# sourceMappingURL=babylon.pushMaterial.js.map
  43261. var BABYLON;
  43262. (function (BABYLON) {
  43263. /** @hidden */
  43264. var StandardMaterialDefines = /** @class */ (function (_super) {
  43265. __extends(StandardMaterialDefines, _super);
  43266. function StandardMaterialDefines() {
  43267. var _this = _super.call(this) || this;
  43268. _this.MAINUV1 = false;
  43269. _this.MAINUV2 = false;
  43270. _this.DIFFUSE = false;
  43271. _this.DIFFUSEDIRECTUV = 0;
  43272. _this.AMBIENT = false;
  43273. _this.AMBIENTDIRECTUV = 0;
  43274. _this.OPACITY = false;
  43275. _this.OPACITYDIRECTUV = 0;
  43276. _this.OPACITYRGB = false;
  43277. _this.REFLECTION = false;
  43278. _this.EMISSIVE = false;
  43279. _this.EMISSIVEDIRECTUV = 0;
  43280. _this.SPECULAR = false;
  43281. _this.SPECULARDIRECTUV = 0;
  43282. _this.BUMP = false;
  43283. _this.BUMPDIRECTUV = 0;
  43284. _this.PARALLAX = false;
  43285. _this.PARALLAXOCCLUSION = false;
  43286. _this.SPECULAROVERALPHA = false;
  43287. _this.CLIPPLANE = false;
  43288. _this.ALPHATEST = false;
  43289. _this.DEPTHPREPASS = false;
  43290. _this.ALPHAFROMDIFFUSE = false;
  43291. _this.POINTSIZE = false;
  43292. _this.FOG = false;
  43293. _this.SPECULARTERM = false;
  43294. _this.DIFFUSEFRESNEL = false;
  43295. _this.OPACITYFRESNEL = false;
  43296. _this.REFLECTIONFRESNEL = false;
  43297. _this.REFRACTIONFRESNEL = false;
  43298. _this.EMISSIVEFRESNEL = false;
  43299. _this.FRESNEL = false;
  43300. _this.NORMAL = false;
  43301. _this.UV1 = false;
  43302. _this.UV2 = false;
  43303. _this.VERTEXCOLOR = false;
  43304. _this.VERTEXALPHA = false;
  43305. _this.NUM_BONE_INFLUENCERS = 0;
  43306. _this.BonesPerMesh = 0;
  43307. _this.INSTANCES = false;
  43308. _this.GLOSSINESS = false;
  43309. _this.ROUGHNESS = false;
  43310. _this.EMISSIVEASILLUMINATION = false;
  43311. _this.LINKEMISSIVEWITHDIFFUSE = false;
  43312. _this.REFLECTIONFRESNELFROMSPECULAR = false;
  43313. _this.LIGHTMAP = false;
  43314. _this.LIGHTMAPDIRECTUV = 0;
  43315. _this.OBJECTSPACE_NORMALMAP = false;
  43316. _this.USELIGHTMAPASSHADOWMAP = false;
  43317. _this.REFLECTIONMAP_3D = false;
  43318. _this.REFLECTIONMAP_SPHERICAL = false;
  43319. _this.REFLECTIONMAP_PLANAR = false;
  43320. _this.REFLECTIONMAP_CUBIC = false;
  43321. _this.USE_LOCAL_REFLECTIONMAP_CUBIC = false;
  43322. _this.REFLECTIONMAP_PROJECTION = false;
  43323. _this.REFLECTIONMAP_SKYBOX = false;
  43324. _this.REFLECTIONMAP_EXPLICIT = false;
  43325. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  43326. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  43327. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  43328. _this.INVERTCUBICMAP = false;
  43329. _this.LOGARITHMICDEPTH = false;
  43330. _this.REFRACTION = false;
  43331. _this.REFRACTIONMAP_3D = false;
  43332. _this.REFLECTIONOVERALPHA = false;
  43333. _this.TWOSIDEDLIGHTING = false;
  43334. _this.SHADOWFLOAT = false;
  43335. _this.MORPHTARGETS = false;
  43336. _this.MORPHTARGETS_NORMAL = false;
  43337. _this.MORPHTARGETS_TANGENT = false;
  43338. _this.NUM_MORPH_INFLUENCERS = 0;
  43339. _this.NONUNIFORMSCALING = false; // https://playground.babylonjs.com#V6DWIH
  43340. _this.PREMULTIPLYALPHA = false; // https://playground.babylonjs.com#LNVJJ7
  43341. _this.IMAGEPROCESSING = false;
  43342. _this.VIGNETTE = false;
  43343. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  43344. _this.VIGNETTEBLENDMODEOPAQUE = false;
  43345. _this.TONEMAPPING = false;
  43346. _this.CONTRAST = false;
  43347. _this.COLORCURVES = false;
  43348. _this.COLORGRADING = false;
  43349. _this.COLORGRADING3D = false;
  43350. _this.SAMPLER3DGREENDEPTH = false;
  43351. _this.SAMPLER3DBGRMAP = false;
  43352. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  43353. /**
  43354. * If the reflection texture on this material is in linear color space
  43355. * @hidden
  43356. */
  43357. _this.IS_REFLECTION_LINEAR = false;
  43358. /**
  43359. * If the refraction texture on this material is in linear color space
  43360. * @hidden
  43361. */
  43362. _this.IS_REFRACTION_LINEAR = false;
  43363. _this.EXPOSURE = false;
  43364. _this.rebuild();
  43365. return _this;
  43366. }
  43367. StandardMaterialDefines.prototype.setReflectionMode = function (modeToEnable) {
  43368. var modes = [
  43369. "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
  43370. "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
  43371. "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
  43372. "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
  43373. ];
  43374. for (var _i = 0, modes_1 = modes; _i < modes_1.length; _i++) {
  43375. var mode = modes_1[_i];
  43376. this[mode] = (mode === modeToEnable);
  43377. }
  43378. };
  43379. return StandardMaterialDefines;
  43380. }(BABYLON.MaterialDefines));
  43381. BABYLON.StandardMaterialDefines = StandardMaterialDefines;
  43382. var StandardMaterial = /** @class */ (function (_super) {
  43383. __extends(StandardMaterial, _super);
  43384. function StandardMaterial(name, scene) {
  43385. var _this = _super.call(this, name, scene) || this;
  43386. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  43387. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  43388. _this.specularColor = new BABYLON.Color3(1, 1, 1);
  43389. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  43390. _this.specularPower = 64;
  43391. _this._useAlphaFromDiffuseTexture = false;
  43392. _this._useEmissiveAsIllumination = false;
  43393. _this._linkEmissiveWithDiffuse = false;
  43394. _this._useSpecularOverAlpha = false;
  43395. _this._useReflectionOverAlpha = false;
  43396. _this._disableLighting = false;
  43397. _this._useObjectSpaceNormalMap = false;
  43398. _this._useParallax = false;
  43399. _this._useParallaxOcclusion = false;
  43400. _this.parallaxScaleBias = 0.05;
  43401. _this._roughness = 0;
  43402. _this.indexOfRefraction = 0.98;
  43403. _this.invertRefractionY = true;
  43404. /**
  43405. * Defines the alpha limits in alpha test mode
  43406. */
  43407. _this.alphaCutOff = 0.4;
  43408. _this._useLightmapAsShadowmap = false;
  43409. _this._useReflectionFresnelFromSpecular = false;
  43410. _this._useGlossinessFromSpecularMapAlpha = false;
  43411. _this._maxSimultaneousLights = 4;
  43412. /**
  43413. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  43414. */
  43415. _this._invertNormalMapX = false;
  43416. /**
  43417. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  43418. */
  43419. _this._invertNormalMapY = false;
  43420. /**
  43421. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  43422. */
  43423. _this._twoSidedLighting = false;
  43424. _this._renderTargets = new BABYLON.SmartArray(16);
  43425. _this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  43426. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  43427. // Setup the default processing configuration to the scene.
  43428. _this._attachImageProcessingConfiguration(null);
  43429. _this.getRenderTargetTextures = function () {
  43430. _this._renderTargets.reset();
  43431. if (StandardMaterial.ReflectionTextureEnabled && _this._reflectionTexture && _this._reflectionTexture.isRenderTarget) {
  43432. _this._renderTargets.push(_this._reflectionTexture);
  43433. }
  43434. if (StandardMaterial.RefractionTextureEnabled && _this._refractionTexture && _this._refractionTexture.isRenderTarget) {
  43435. _this._renderTargets.push(_this._refractionTexture);
  43436. }
  43437. return _this._renderTargets;
  43438. };
  43439. return _this;
  43440. }
  43441. Object.defineProperty(StandardMaterial.prototype, "imageProcessingConfiguration", {
  43442. /**
  43443. * Gets the image processing configuration used either in this material.
  43444. */
  43445. get: function () {
  43446. return this._imageProcessingConfiguration;
  43447. },
  43448. /**
  43449. * Sets the Default image processing configuration used either in the this material.
  43450. *
  43451. * If sets to null, the scene one is in use.
  43452. */
  43453. set: function (value) {
  43454. this._attachImageProcessingConfiguration(value);
  43455. // Ensure the effect will be rebuilt.
  43456. this._markAllSubMeshesAsTexturesDirty();
  43457. },
  43458. enumerable: true,
  43459. configurable: true
  43460. });
  43461. /**
  43462. * Attaches a new image processing configuration to the Standard Material.
  43463. * @param configuration
  43464. */
  43465. StandardMaterial.prototype._attachImageProcessingConfiguration = function (configuration) {
  43466. var _this = this;
  43467. if (configuration === this._imageProcessingConfiguration) {
  43468. return;
  43469. }
  43470. // Detaches observer.
  43471. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  43472. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  43473. }
  43474. // Pick the scene configuration if needed.
  43475. if (!configuration) {
  43476. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  43477. }
  43478. else {
  43479. this._imageProcessingConfiguration = configuration;
  43480. }
  43481. // Attaches observer.
  43482. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  43483. _this._markAllSubMeshesAsImageProcessingDirty();
  43484. });
  43485. };
  43486. Object.defineProperty(StandardMaterial.prototype, "cameraColorCurvesEnabled", {
  43487. /**
  43488. * Gets wether the color curves effect is enabled.
  43489. */
  43490. get: function () {
  43491. return this.imageProcessingConfiguration.colorCurvesEnabled;
  43492. },
  43493. /**
  43494. * Sets wether the color curves effect is enabled.
  43495. */
  43496. set: function (value) {
  43497. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  43498. },
  43499. enumerable: true,
  43500. configurable: true
  43501. });
  43502. Object.defineProperty(StandardMaterial.prototype, "cameraColorGradingEnabled", {
  43503. /**
  43504. * Gets wether the color grading effect is enabled.
  43505. */
  43506. get: function () {
  43507. return this.imageProcessingConfiguration.colorGradingEnabled;
  43508. },
  43509. /**
  43510. * Gets wether the color grading effect is enabled.
  43511. */
  43512. set: function (value) {
  43513. this.imageProcessingConfiguration.colorGradingEnabled = value;
  43514. },
  43515. enumerable: true,
  43516. configurable: true
  43517. });
  43518. Object.defineProperty(StandardMaterial.prototype, "cameraToneMappingEnabled", {
  43519. /**
  43520. * Gets wether tonemapping is enabled or not.
  43521. */
  43522. get: function () {
  43523. return this._imageProcessingConfiguration.toneMappingEnabled;
  43524. },
  43525. /**
  43526. * Sets wether tonemapping is enabled or not
  43527. */
  43528. set: function (value) {
  43529. this._imageProcessingConfiguration.toneMappingEnabled = value;
  43530. },
  43531. enumerable: true,
  43532. configurable: true
  43533. });
  43534. ;
  43535. ;
  43536. Object.defineProperty(StandardMaterial.prototype, "cameraExposure", {
  43537. /**
  43538. * The camera exposure used on this material.
  43539. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  43540. * This corresponds to a photographic exposure.
  43541. */
  43542. get: function () {
  43543. return this._imageProcessingConfiguration.exposure;
  43544. },
  43545. /**
  43546. * The camera exposure used on this material.
  43547. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  43548. * This corresponds to a photographic exposure.
  43549. */
  43550. set: function (value) {
  43551. this._imageProcessingConfiguration.exposure = value;
  43552. },
  43553. enumerable: true,
  43554. configurable: true
  43555. });
  43556. ;
  43557. ;
  43558. Object.defineProperty(StandardMaterial.prototype, "cameraContrast", {
  43559. /**
  43560. * Gets The camera contrast used on this material.
  43561. */
  43562. get: function () {
  43563. return this._imageProcessingConfiguration.contrast;
  43564. },
  43565. /**
  43566. * Sets The camera contrast used on this material.
  43567. */
  43568. set: function (value) {
  43569. this._imageProcessingConfiguration.contrast = value;
  43570. },
  43571. enumerable: true,
  43572. configurable: true
  43573. });
  43574. Object.defineProperty(StandardMaterial.prototype, "cameraColorGradingTexture", {
  43575. /**
  43576. * Gets the Color Grading 2D Lookup Texture.
  43577. */
  43578. get: function () {
  43579. return this._imageProcessingConfiguration.colorGradingTexture;
  43580. },
  43581. /**
  43582. * Sets the Color Grading 2D Lookup Texture.
  43583. */
  43584. set: function (value) {
  43585. this._imageProcessingConfiguration.colorGradingTexture = value;
  43586. },
  43587. enumerable: true,
  43588. configurable: true
  43589. });
  43590. Object.defineProperty(StandardMaterial.prototype, "cameraColorCurves", {
  43591. /**
  43592. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  43593. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  43594. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  43595. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  43596. */
  43597. get: function () {
  43598. return this._imageProcessingConfiguration.colorCurves;
  43599. },
  43600. /**
  43601. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  43602. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  43603. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  43604. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  43605. */
  43606. set: function (value) {
  43607. this._imageProcessingConfiguration.colorCurves = value;
  43608. },
  43609. enumerable: true,
  43610. configurable: true
  43611. });
  43612. StandardMaterial.prototype.getClassName = function () {
  43613. return "StandardMaterial";
  43614. };
  43615. Object.defineProperty(StandardMaterial.prototype, "useLogarithmicDepth", {
  43616. get: function () {
  43617. return this._useLogarithmicDepth;
  43618. },
  43619. set: function (value) {
  43620. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  43621. this._markAllSubMeshesAsMiscDirty();
  43622. },
  43623. enumerable: true,
  43624. configurable: true
  43625. });
  43626. StandardMaterial.prototype.needAlphaBlending = function () {
  43627. return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
  43628. };
  43629. StandardMaterial.prototype.needAlphaTesting = function () {
  43630. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
  43631. };
  43632. StandardMaterial.prototype._shouldUseAlphaFromDiffuseTexture = function () {
  43633. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
  43634. };
  43635. StandardMaterial.prototype.getAlphaTestTexture = function () {
  43636. return this._diffuseTexture;
  43637. };
  43638. /**
  43639. * Child classes can use it to update shaders
  43640. */
  43641. StandardMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  43642. if (useInstances === void 0) { useInstances = false; }
  43643. if (subMesh.effect && this.isFrozen) {
  43644. if (this._wasPreviouslyReady && subMesh.effect) {
  43645. return true;
  43646. }
  43647. }
  43648. if (!subMesh._materialDefines) {
  43649. subMesh._materialDefines = new StandardMaterialDefines();
  43650. }
  43651. var scene = this.getScene();
  43652. var defines = subMesh._materialDefines;
  43653. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  43654. if (defines._renderId === scene.getRenderId()) {
  43655. return true;
  43656. }
  43657. }
  43658. var engine = scene.getEngine();
  43659. // Lights
  43660. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  43661. // Textures
  43662. if (defines._areTexturesDirty) {
  43663. defines._needUVs = false;
  43664. defines.MAINUV1 = false;
  43665. defines.MAINUV2 = false;
  43666. if (scene.texturesEnabled) {
  43667. if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
  43668. if (!this._diffuseTexture.isReadyOrNotBlocking()) {
  43669. return false;
  43670. }
  43671. else {
  43672. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, "DIFFUSE");
  43673. }
  43674. }
  43675. else {
  43676. defines.DIFFUSE = false;
  43677. }
  43678. if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {
  43679. if (!this._ambientTexture.isReadyOrNotBlocking()) {
  43680. return false;
  43681. }
  43682. else {
  43683. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture, defines, "AMBIENT");
  43684. }
  43685. }
  43686. else {
  43687. defines.AMBIENT = false;
  43688. }
  43689. if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {
  43690. if (!this._opacityTexture.isReadyOrNotBlocking()) {
  43691. return false;
  43692. }
  43693. else {
  43694. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, "OPACITY");
  43695. defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
  43696. }
  43697. }
  43698. else {
  43699. defines.OPACITY = false;
  43700. }
  43701. if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
  43702. if (!this._reflectionTexture.isReadyOrNotBlocking()) {
  43703. return false;
  43704. }
  43705. else {
  43706. defines._needNormals = true;
  43707. defines.REFLECTION = true;
  43708. defines.ROUGHNESS = (this._roughness > 0);
  43709. defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;
  43710. defines.INVERTCUBICMAP = (this._reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE);
  43711. defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
  43712. switch (this._reflectionTexture.coordinatesMode) {
  43713. case BABYLON.Texture.EXPLICIT_MODE:
  43714. defines.setReflectionMode("REFLECTIONMAP_EXPLICIT");
  43715. break;
  43716. case BABYLON.Texture.PLANAR_MODE:
  43717. defines.setReflectionMode("REFLECTIONMAP_PLANAR");
  43718. break;
  43719. case BABYLON.Texture.PROJECTION_MODE:
  43720. defines.setReflectionMode("REFLECTIONMAP_PROJECTION");
  43721. break;
  43722. case BABYLON.Texture.SKYBOX_MODE:
  43723. defines.setReflectionMode("REFLECTIONMAP_SKYBOX");
  43724. break;
  43725. case BABYLON.Texture.SPHERICAL_MODE:
  43726. defines.setReflectionMode("REFLECTIONMAP_SPHERICAL");
  43727. break;
  43728. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  43729. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");
  43730. break;
  43731. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  43732. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");
  43733. break;
  43734. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  43735. defines.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED");
  43736. break;
  43737. case BABYLON.Texture.CUBIC_MODE:
  43738. case BABYLON.Texture.INVCUBIC_MODE:
  43739. default:
  43740. defines.setReflectionMode("REFLECTIONMAP_CUBIC");
  43741. break;
  43742. }
  43743. defines.USE_LOCAL_REFLECTIONMAP_CUBIC = this._reflectionTexture.boundingBoxSize ? true : false;
  43744. }
  43745. }
  43746. else {
  43747. defines.REFLECTION = false;
  43748. }
  43749. if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
  43750. if (!this._emissiveTexture.isReadyOrNotBlocking()) {
  43751. return false;
  43752. }
  43753. else {
  43754. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture, defines, "EMISSIVE");
  43755. }
  43756. }
  43757. else {
  43758. defines.EMISSIVE = false;
  43759. }
  43760. if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
  43761. if (!this._lightmapTexture.isReadyOrNotBlocking()) {
  43762. return false;
  43763. }
  43764. else {
  43765. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture, defines, "LIGHTMAP");
  43766. defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;
  43767. }
  43768. }
  43769. else {
  43770. defines.LIGHTMAP = false;
  43771. }
  43772. if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {
  43773. if (!this._specularTexture.isReadyOrNotBlocking()) {
  43774. return false;
  43775. }
  43776. else {
  43777. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._specularTexture, defines, "SPECULAR");
  43778. defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;
  43779. }
  43780. }
  43781. else {
  43782. defines.SPECULAR = false;
  43783. }
  43784. if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial.BumpTextureEnabled) {
  43785. // Bump texure can not be not blocking.
  43786. if (!this._bumpTexture.isReady()) {
  43787. return false;
  43788. }
  43789. else {
  43790. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, "BUMP");
  43791. defines.PARALLAX = this._useParallax;
  43792. defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
  43793. }
  43794. defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;
  43795. }
  43796. else {
  43797. defines.BUMP = false;
  43798. }
  43799. if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {
  43800. if (!this._refractionTexture.isReadyOrNotBlocking()) {
  43801. return false;
  43802. }
  43803. else {
  43804. defines._needUVs = true;
  43805. defines.REFRACTION = true;
  43806. defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;
  43807. }
  43808. }
  43809. else {
  43810. defines.REFRACTION = false;
  43811. }
  43812. defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;
  43813. }
  43814. else {
  43815. defines.DIFFUSE = false;
  43816. defines.AMBIENT = false;
  43817. defines.OPACITY = false;
  43818. defines.REFLECTION = false;
  43819. defines.EMISSIVE = false;
  43820. defines.LIGHTMAP = false;
  43821. defines.BUMP = false;
  43822. defines.REFRACTION = false;
  43823. }
  43824. defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();
  43825. defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
  43826. defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
  43827. defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
  43828. defines.PREMULTIPLYALPHA = (this.alphaMode === BABYLON.Engine.ALPHA_PREMULTIPLIED || this.alphaMode === BABYLON.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF);
  43829. }
  43830. if (defines._areImageProcessingDirty) {
  43831. if (!this._imageProcessingConfiguration.isReady()) {
  43832. return false;
  43833. }
  43834. this._imageProcessingConfiguration.prepareDefines(defines);
  43835. defines.IS_REFLECTION_LINEAR = (this.reflectionTexture != null && !this.reflectionTexture.gammaSpace);
  43836. defines.IS_REFRACTION_LINEAR = (this.refractionTexture != null && !this.refractionTexture.gammaSpace);
  43837. }
  43838. if (defines._areFresnelDirty) {
  43839. if (StandardMaterial.FresnelEnabled) {
  43840. // Fresnel
  43841. if (this._diffuseFresnelParameters || this._opacityFresnelParameters ||
  43842. this._emissiveFresnelParameters || this._refractionFresnelParameters ||
  43843. this._reflectionFresnelParameters) {
  43844. defines.DIFFUSEFRESNEL = (this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled);
  43845. defines.OPACITYFRESNEL = (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled);
  43846. defines.REFLECTIONFRESNEL = (this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled);
  43847. defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
  43848. defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled);
  43849. defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled);
  43850. defines._needNormals = true;
  43851. defines.FRESNEL = true;
  43852. }
  43853. }
  43854. else {
  43855. defines.FRESNEL = false;
  43856. }
  43857. }
  43858. // Misc.
  43859. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  43860. // Attribs
  43861. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
  43862. // Values that need to be evaluated on every frame
  43863. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
  43864. // Get correct effect
  43865. if (defines.isDirty) {
  43866. defines.markAsProcessed();
  43867. scene.resetCachedMaterial();
  43868. // Fallbacks
  43869. var fallbacks = new BABYLON.EffectFallbacks();
  43870. if (defines.REFLECTION) {
  43871. fallbacks.addFallback(0, "REFLECTION");
  43872. }
  43873. if (defines.SPECULAR) {
  43874. fallbacks.addFallback(0, "SPECULAR");
  43875. }
  43876. if (defines.BUMP) {
  43877. fallbacks.addFallback(0, "BUMP");
  43878. }
  43879. if (defines.PARALLAX) {
  43880. fallbacks.addFallback(1, "PARALLAX");
  43881. }
  43882. if (defines.PARALLAXOCCLUSION) {
  43883. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  43884. }
  43885. if (defines.SPECULAROVERALPHA) {
  43886. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  43887. }
  43888. if (defines.FOG) {
  43889. fallbacks.addFallback(1, "FOG");
  43890. }
  43891. if (defines.POINTSIZE) {
  43892. fallbacks.addFallback(0, "POINTSIZE");
  43893. }
  43894. if (defines.LOGARITHMICDEPTH) {
  43895. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  43896. }
  43897. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  43898. if (defines.SPECULARTERM) {
  43899. fallbacks.addFallback(0, "SPECULARTERM");
  43900. }
  43901. if (defines.DIFFUSEFRESNEL) {
  43902. fallbacks.addFallback(1, "DIFFUSEFRESNEL");
  43903. }
  43904. if (defines.OPACITYFRESNEL) {
  43905. fallbacks.addFallback(2, "OPACITYFRESNEL");
  43906. }
  43907. if (defines.REFLECTIONFRESNEL) {
  43908. fallbacks.addFallback(3, "REFLECTIONFRESNEL");
  43909. }
  43910. if (defines.EMISSIVEFRESNEL) {
  43911. fallbacks.addFallback(4, "EMISSIVEFRESNEL");
  43912. }
  43913. if (defines.FRESNEL) {
  43914. fallbacks.addFallback(4, "FRESNEL");
  43915. }
  43916. //Attributes
  43917. var attribs = [BABYLON.VertexBuffer.PositionKind];
  43918. if (defines.NORMAL) {
  43919. attribs.push(BABYLON.VertexBuffer.NormalKind);
  43920. }
  43921. if (defines.UV1) {
  43922. attribs.push(BABYLON.VertexBuffer.UVKind);
  43923. }
  43924. if (defines.UV2) {
  43925. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  43926. }
  43927. if (defines.VERTEXCOLOR) {
  43928. attribs.push(BABYLON.VertexBuffer.ColorKind);
  43929. }
  43930. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  43931. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  43932. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
  43933. var shaderName = "default";
  43934. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
  43935. "vFogInfos", "vFogColor", "pointSize",
  43936. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  43937. "mBones",
  43938. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "normalMatrix", "lightmapMatrix", "refractionMatrix",
  43939. "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
  43940. "vReflectionPosition", "vReflectionSize",
  43941. "logarithmicDepthConstant", "vTangentSpaceParams", "alphaCutOff"
  43942. ];
  43943. var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  43944. var uniformBuffers = ["Material", "Scene"];
  43945. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  43946. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  43947. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  43948. uniformsNames: uniforms,
  43949. uniformBuffersNames: uniformBuffers,
  43950. samplers: samplers,
  43951. defines: defines,
  43952. maxSimultaneousLights: this._maxSimultaneousLights
  43953. });
  43954. if (this.customShaderNameResolve) {
  43955. shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines);
  43956. }
  43957. var join = defines.toString();
  43958. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  43959. attributes: attribs,
  43960. uniformsNames: uniforms,
  43961. uniformBuffersNames: uniformBuffers,
  43962. samplers: samplers,
  43963. defines: join,
  43964. fallbacks: fallbacks,
  43965. onCompiled: this.onCompiled,
  43966. onError: this.onError,
  43967. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
  43968. }, engine), defines);
  43969. this.buildUniformLayout();
  43970. }
  43971. if (!subMesh.effect || !subMesh.effect.isReady()) {
  43972. return false;
  43973. }
  43974. defines._renderId = scene.getRenderId();
  43975. this._wasPreviouslyReady = true;
  43976. return true;
  43977. };
  43978. StandardMaterial.prototype.buildUniformLayout = function () {
  43979. // Order is important !
  43980. this._uniformBuffer.addUniform("diffuseLeftColor", 4);
  43981. this._uniformBuffer.addUniform("diffuseRightColor", 4);
  43982. this._uniformBuffer.addUniform("opacityParts", 4);
  43983. this._uniformBuffer.addUniform("reflectionLeftColor", 4);
  43984. this._uniformBuffer.addUniform("reflectionRightColor", 4);
  43985. this._uniformBuffer.addUniform("refractionLeftColor", 4);
  43986. this._uniformBuffer.addUniform("refractionRightColor", 4);
  43987. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  43988. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  43989. this._uniformBuffer.addUniform("vDiffuseInfos", 2);
  43990. this._uniformBuffer.addUniform("vAmbientInfos", 2);
  43991. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  43992. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  43993. this._uniformBuffer.addUniform("vReflectionPosition", 3);
  43994. this._uniformBuffer.addUniform("vReflectionSize", 3);
  43995. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  43996. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  43997. this._uniformBuffer.addUniform("vSpecularInfos", 2);
  43998. this._uniformBuffer.addUniform("vBumpInfos", 3);
  43999. this._uniformBuffer.addUniform("diffuseMatrix", 16);
  44000. this._uniformBuffer.addUniform("ambientMatrix", 16);
  44001. this._uniformBuffer.addUniform("opacityMatrix", 16);
  44002. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  44003. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  44004. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  44005. this._uniformBuffer.addUniform("specularMatrix", 16);
  44006. this._uniformBuffer.addUniform("bumpMatrix", 16);
  44007. this._uniformBuffer.addUniform("vTangentSpaceParams", 2);
  44008. this._uniformBuffer.addUniform("refractionMatrix", 16);
  44009. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  44010. this._uniformBuffer.addUniform("vSpecularColor", 4);
  44011. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  44012. this._uniformBuffer.addUniform("vDiffuseColor", 4);
  44013. this._uniformBuffer.addUniform("pointSize", 1);
  44014. this._uniformBuffer.create();
  44015. };
  44016. StandardMaterial.prototype.unbind = function () {
  44017. if (this._activeEffect) {
  44018. var needFlag = false;
  44019. if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
  44020. this._activeEffect.setTexture("reflection2DSampler", null);
  44021. needFlag = true;
  44022. }
  44023. if (this._refractionTexture && this._refractionTexture.isRenderTarget) {
  44024. this._activeEffect.setTexture("refraction2DSampler", null);
  44025. needFlag = true;
  44026. }
  44027. if (needFlag) {
  44028. this._markAllSubMeshesAsTexturesDirty();
  44029. }
  44030. }
  44031. _super.prototype.unbind.call(this);
  44032. };
  44033. StandardMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  44034. var scene = this.getScene();
  44035. var defines = subMesh._materialDefines;
  44036. if (!defines) {
  44037. return;
  44038. }
  44039. var effect = subMesh.effect;
  44040. if (!effect) {
  44041. return;
  44042. }
  44043. this._activeEffect = effect;
  44044. // Matrices
  44045. this.bindOnlyWorldMatrix(world);
  44046. // Normal Matrix
  44047. if (defines.OBJECTSPACE_NORMALMAP) {
  44048. world.toNormalMatrix(this._normalMatrix);
  44049. this.bindOnlyNormalMatrix(this._normalMatrix);
  44050. }
  44051. var mustRebind = this._mustRebind(scene, effect, mesh.visibility);
  44052. // Bones
  44053. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  44054. if (mustRebind) {
  44055. this._uniformBuffer.bindToEffect(effect, "Material");
  44056. this.bindViewProjection(effect);
  44057. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  44058. if (StandardMaterial.FresnelEnabled && defines.FRESNEL) {
  44059. // Fresnel
  44060. if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
  44061. this._uniformBuffer.updateColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
  44062. this._uniformBuffer.updateColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
  44063. }
  44064. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  44065. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  44066. }
  44067. if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
  44068. this._uniformBuffer.updateColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
  44069. this._uniformBuffer.updateColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
  44070. }
  44071. if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {
  44072. this._uniformBuffer.updateColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
  44073. this._uniformBuffer.updateColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
  44074. }
  44075. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  44076. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  44077. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  44078. }
  44079. }
  44080. // Textures
  44081. if (scene.texturesEnabled) {
  44082. if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
  44083. this._uniformBuffer.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  44084. BABYLON.MaterialHelper.BindTextureMatrix(this._diffuseTexture, this._uniformBuffer, "diffuse");
  44085. if (this._diffuseTexture.hasAlpha) {
  44086. effect.setFloat("alphaCutOff", this.alphaCutOff);
  44087. }
  44088. }
  44089. if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {
  44090. this._uniformBuffer.updateFloat2("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);
  44091. BABYLON.MaterialHelper.BindTextureMatrix(this._ambientTexture, this._uniformBuffer, "ambient");
  44092. }
  44093. if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {
  44094. this._uniformBuffer.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  44095. BABYLON.MaterialHelper.BindTextureMatrix(this._opacityTexture, this._uniformBuffer, "opacity");
  44096. }
  44097. if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
  44098. this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, this.roughness);
  44099. this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
  44100. if (this._reflectionTexture.boundingBoxSize) {
  44101. var cubeTexture = this._reflectionTexture;
  44102. this._uniformBuffer.updateVector3("vReflectionPosition", cubeTexture.boundingBoxPosition);
  44103. this._uniformBuffer.updateVector3("vReflectionSize", cubeTexture.boundingBoxSize);
  44104. }
  44105. }
  44106. if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
  44107. this._uniformBuffer.updateFloat2("vEmissiveInfos", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);
  44108. BABYLON.MaterialHelper.BindTextureMatrix(this._emissiveTexture, this._uniformBuffer, "emissive");
  44109. }
  44110. if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
  44111. this._uniformBuffer.updateFloat2("vLightmapInfos", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);
  44112. BABYLON.MaterialHelper.BindTextureMatrix(this._lightmapTexture, this._uniformBuffer, "lightmap");
  44113. }
  44114. if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {
  44115. this._uniformBuffer.updateFloat2("vSpecularInfos", this._specularTexture.coordinatesIndex, this._specularTexture.level);
  44116. BABYLON.MaterialHelper.BindTextureMatrix(this._specularTexture, this._uniformBuffer, "specular");
  44117. }
  44118. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
  44119. this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
  44120. BABYLON.MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
  44121. if (scene._mirroredCameraPosition) {
  44122. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);
  44123. }
  44124. else {
  44125. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);
  44126. }
  44127. }
  44128. if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {
  44129. var depth = 1.0;
  44130. if (!this._refractionTexture.isCube) {
  44131. this._uniformBuffer.updateMatrix("refractionMatrix", this._refractionTexture.getReflectionTextureMatrix());
  44132. if (this._refractionTexture.depth) {
  44133. depth = this._refractionTexture.depth;
  44134. }
  44135. }
  44136. this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  44137. }
  44138. }
  44139. // Point size
  44140. if (this.pointsCloud) {
  44141. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  44142. }
  44143. if (defines.SPECULARTERM) {
  44144. this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
  44145. }
  44146. this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
  44147. // Diffuse
  44148. this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  44149. }
  44150. // Textures
  44151. if (scene.texturesEnabled) {
  44152. if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
  44153. effect.setTexture("diffuseSampler", this._diffuseTexture);
  44154. }
  44155. if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {
  44156. effect.setTexture("ambientSampler", this._ambientTexture);
  44157. }
  44158. if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {
  44159. effect.setTexture("opacitySampler", this._opacityTexture);
  44160. }
  44161. if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
  44162. if (this._reflectionTexture.isCube) {
  44163. effect.setTexture("reflectionCubeSampler", this._reflectionTexture);
  44164. }
  44165. else {
  44166. effect.setTexture("reflection2DSampler", this._reflectionTexture);
  44167. }
  44168. }
  44169. if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
  44170. effect.setTexture("emissiveSampler", this._emissiveTexture);
  44171. }
  44172. if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
  44173. effect.setTexture("lightmapSampler", this._lightmapTexture);
  44174. }
  44175. if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {
  44176. effect.setTexture("specularSampler", this._specularTexture);
  44177. }
  44178. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
  44179. effect.setTexture("bumpSampler", this._bumpTexture);
  44180. }
  44181. if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {
  44182. var depth = 1.0;
  44183. if (this._refractionTexture.isCube) {
  44184. effect.setTexture("refractionCubeSampler", this._refractionTexture);
  44185. }
  44186. else {
  44187. effect.setTexture("refraction2DSampler", this._refractionTexture);
  44188. }
  44189. }
  44190. }
  44191. // Clip plane
  44192. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  44193. // Colors
  44194. scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  44195. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  44196. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  44197. }
  44198. if (mustRebind || !this.isFrozen) {
  44199. // Lights
  44200. if (scene.lightsEnabled && !this._disableLighting) {
  44201. BABYLON.MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);
  44202. }
  44203. // View
  44204. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
  44205. this.bindView(effect);
  44206. }
  44207. // Fog
  44208. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, effect);
  44209. // Morph targets
  44210. if (defines.NUM_MORPH_INFLUENCERS) {
  44211. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
  44212. }
  44213. // Log. depth
  44214. BABYLON.MaterialHelper.BindLogDepth(defines, effect, scene);
  44215. // image processing
  44216. if (!this._imageProcessingConfiguration.applyByPostProcess) {
  44217. this._imageProcessingConfiguration.bind(this._activeEffect);
  44218. }
  44219. }
  44220. this._uniformBuffer.update();
  44221. this._afterBind(mesh, this._activeEffect);
  44222. };
  44223. StandardMaterial.prototype.getAnimatables = function () {
  44224. var results = [];
  44225. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  44226. results.push(this._diffuseTexture);
  44227. }
  44228. if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {
  44229. results.push(this._ambientTexture);
  44230. }
  44231. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  44232. results.push(this._opacityTexture);
  44233. }
  44234. if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {
  44235. results.push(this._reflectionTexture);
  44236. }
  44237. if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {
  44238. results.push(this._emissiveTexture);
  44239. }
  44240. if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {
  44241. results.push(this._specularTexture);
  44242. }
  44243. if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
  44244. results.push(this._bumpTexture);
  44245. }
  44246. if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {
  44247. results.push(this._lightmapTexture);
  44248. }
  44249. if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {
  44250. results.push(this._refractionTexture);
  44251. }
  44252. return results;
  44253. };
  44254. StandardMaterial.prototype.getActiveTextures = function () {
  44255. var activeTextures = _super.prototype.getActiveTextures.call(this);
  44256. if (this._diffuseTexture) {
  44257. activeTextures.push(this._diffuseTexture);
  44258. }
  44259. if (this._ambientTexture) {
  44260. activeTextures.push(this._ambientTexture);
  44261. }
  44262. if (this._opacityTexture) {
  44263. activeTextures.push(this._opacityTexture);
  44264. }
  44265. if (this._reflectionTexture) {
  44266. activeTextures.push(this._reflectionTexture);
  44267. }
  44268. if (this._emissiveTexture) {
  44269. activeTextures.push(this._emissiveTexture);
  44270. }
  44271. if (this._specularTexture) {
  44272. activeTextures.push(this._specularTexture);
  44273. }
  44274. if (this._bumpTexture) {
  44275. activeTextures.push(this._bumpTexture);
  44276. }
  44277. if (this._lightmapTexture) {
  44278. activeTextures.push(this._lightmapTexture);
  44279. }
  44280. if (this._refractionTexture) {
  44281. activeTextures.push(this._refractionTexture);
  44282. }
  44283. return activeTextures;
  44284. };
  44285. StandardMaterial.prototype.hasTexture = function (texture) {
  44286. if (_super.prototype.hasTexture.call(this, texture)) {
  44287. return true;
  44288. }
  44289. if (this._diffuseTexture === texture) {
  44290. return true;
  44291. }
  44292. if (this._ambientTexture === texture) {
  44293. return true;
  44294. }
  44295. if (this._opacityTexture === texture) {
  44296. return true;
  44297. }
  44298. if (this._reflectionTexture === texture) {
  44299. return true;
  44300. }
  44301. if (this._emissiveTexture === texture) {
  44302. return true;
  44303. }
  44304. if (this._specularTexture === texture) {
  44305. return true;
  44306. }
  44307. if (this._bumpTexture === texture) {
  44308. return true;
  44309. }
  44310. if (this._lightmapTexture === texture) {
  44311. return true;
  44312. }
  44313. if (this._refractionTexture === texture) {
  44314. return true;
  44315. }
  44316. return false;
  44317. };
  44318. StandardMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  44319. if (forceDisposeTextures) {
  44320. if (this._diffuseTexture) {
  44321. this._diffuseTexture.dispose();
  44322. }
  44323. if (this._ambientTexture) {
  44324. this._ambientTexture.dispose();
  44325. }
  44326. if (this._opacityTexture) {
  44327. this._opacityTexture.dispose();
  44328. }
  44329. if (this._reflectionTexture) {
  44330. this._reflectionTexture.dispose();
  44331. }
  44332. if (this._emissiveTexture) {
  44333. this._emissiveTexture.dispose();
  44334. }
  44335. if (this._specularTexture) {
  44336. this._specularTexture.dispose();
  44337. }
  44338. if (this._bumpTexture) {
  44339. this._bumpTexture.dispose();
  44340. }
  44341. if (this._lightmapTexture) {
  44342. this._lightmapTexture.dispose();
  44343. }
  44344. if (this._refractionTexture) {
  44345. this._refractionTexture.dispose();
  44346. }
  44347. }
  44348. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  44349. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  44350. }
  44351. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  44352. };
  44353. StandardMaterial.prototype.clone = function (name) {
  44354. var _this = this;
  44355. var result = BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial(name, _this.getScene()); }, this);
  44356. result.name = name;
  44357. result.id = name;
  44358. return result;
  44359. };
  44360. StandardMaterial.prototype.serialize = function () {
  44361. return BABYLON.SerializationHelper.Serialize(this);
  44362. };
  44363. // Statics
  44364. StandardMaterial.Parse = function (source, scene, rootUrl) {
  44365. return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial(source.name, scene); }, source, scene, rootUrl);
  44366. };
  44367. Object.defineProperty(StandardMaterial, "DiffuseTextureEnabled", {
  44368. get: function () {
  44369. return StandardMaterial._DiffuseTextureEnabled;
  44370. },
  44371. set: function (value) {
  44372. if (StandardMaterial._DiffuseTextureEnabled === value) {
  44373. return;
  44374. }
  44375. StandardMaterial._DiffuseTextureEnabled = value;
  44376. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44377. },
  44378. enumerable: true,
  44379. configurable: true
  44380. });
  44381. Object.defineProperty(StandardMaterial, "AmbientTextureEnabled", {
  44382. get: function () {
  44383. return StandardMaterial._AmbientTextureEnabled;
  44384. },
  44385. set: function (value) {
  44386. if (StandardMaterial._AmbientTextureEnabled === value) {
  44387. return;
  44388. }
  44389. StandardMaterial._AmbientTextureEnabled = value;
  44390. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44391. },
  44392. enumerable: true,
  44393. configurable: true
  44394. });
  44395. Object.defineProperty(StandardMaterial, "OpacityTextureEnabled", {
  44396. get: function () {
  44397. return StandardMaterial._OpacityTextureEnabled;
  44398. },
  44399. set: function (value) {
  44400. if (StandardMaterial._OpacityTextureEnabled === value) {
  44401. return;
  44402. }
  44403. StandardMaterial._OpacityTextureEnabled = value;
  44404. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44405. },
  44406. enumerable: true,
  44407. configurable: true
  44408. });
  44409. Object.defineProperty(StandardMaterial, "ReflectionTextureEnabled", {
  44410. get: function () {
  44411. return StandardMaterial._ReflectionTextureEnabled;
  44412. },
  44413. set: function (value) {
  44414. if (StandardMaterial._ReflectionTextureEnabled === value) {
  44415. return;
  44416. }
  44417. StandardMaterial._ReflectionTextureEnabled = value;
  44418. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44419. },
  44420. enumerable: true,
  44421. configurable: true
  44422. });
  44423. Object.defineProperty(StandardMaterial, "EmissiveTextureEnabled", {
  44424. get: function () {
  44425. return StandardMaterial._EmissiveTextureEnabled;
  44426. },
  44427. set: function (value) {
  44428. if (StandardMaterial._EmissiveTextureEnabled === value) {
  44429. return;
  44430. }
  44431. StandardMaterial._EmissiveTextureEnabled = value;
  44432. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44433. },
  44434. enumerable: true,
  44435. configurable: true
  44436. });
  44437. Object.defineProperty(StandardMaterial, "SpecularTextureEnabled", {
  44438. get: function () {
  44439. return StandardMaterial._SpecularTextureEnabled;
  44440. },
  44441. set: function (value) {
  44442. if (StandardMaterial._SpecularTextureEnabled === value) {
  44443. return;
  44444. }
  44445. StandardMaterial._SpecularTextureEnabled = value;
  44446. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44447. },
  44448. enumerable: true,
  44449. configurable: true
  44450. });
  44451. Object.defineProperty(StandardMaterial, "BumpTextureEnabled", {
  44452. get: function () {
  44453. return StandardMaterial._BumpTextureEnabled;
  44454. },
  44455. set: function (value) {
  44456. if (StandardMaterial._BumpTextureEnabled === value) {
  44457. return;
  44458. }
  44459. StandardMaterial._BumpTextureEnabled = value;
  44460. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44461. },
  44462. enumerable: true,
  44463. configurable: true
  44464. });
  44465. Object.defineProperty(StandardMaterial, "LightmapTextureEnabled", {
  44466. get: function () {
  44467. return StandardMaterial._LightmapTextureEnabled;
  44468. },
  44469. set: function (value) {
  44470. if (StandardMaterial._LightmapTextureEnabled === value) {
  44471. return;
  44472. }
  44473. StandardMaterial._LightmapTextureEnabled = value;
  44474. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44475. },
  44476. enumerable: true,
  44477. configurable: true
  44478. });
  44479. Object.defineProperty(StandardMaterial, "RefractionTextureEnabled", {
  44480. get: function () {
  44481. return StandardMaterial._RefractionTextureEnabled;
  44482. },
  44483. set: function (value) {
  44484. if (StandardMaterial._RefractionTextureEnabled === value) {
  44485. return;
  44486. }
  44487. StandardMaterial._RefractionTextureEnabled = value;
  44488. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44489. },
  44490. enumerable: true,
  44491. configurable: true
  44492. });
  44493. Object.defineProperty(StandardMaterial, "ColorGradingTextureEnabled", {
  44494. get: function () {
  44495. return StandardMaterial._ColorGradingTextureEnabled;
  44496. },
  44497. set: function (value) {
  44498. if (StandardMaterial._ColorGradingTextureEnabled === value) {
  44499. return;
  44500. }
  44501. StandardMaterial._ColorGradingTextureEnabled = value;
  44502. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  44503. },
  44504. enumerable: true,
  44505. configurable: true
  44506. });
  44507. Object.defineProperty(StandardMaterial, "FresnelEnabled", {
  44508. get: function () {
  44509. return StandardMaterial._FresnelEnabled;
  44510. },
  44511. set: function (value) {
  44512. if (StandardMaterial._FresnelEnabled === value) {
  44513. return;
  44514. }
  44515. StandardMaterial._FresnelEnabled = value;
  44516. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.FresnelDirtyFlag);
  44517. },
  44518. enumerable: true,
  44519. configurable: true
  44520. });
  44521. // Flags used to enable or disable a type of texture for all Standard Materials
  44522. StandardMaterial._DiffuseTextureEnabled = true;
  44523. StandardMaterial._AmbientTextureEnabled = true;
  44524. StandardMaterial._OpacityTextureEnabled = true;
  44525. StandardMaterial._ReflectionTextureEnabled = true;
  44526. StandardMaterial._EmissiveTextureEnabled = true;
  44527. StandardMaterial._SpecularTextureEnabled = true;
  44528. StandardMaterial._BumpTextureEnabled = true;
  44529. StandardMaterial._LightmapTextureEnabled = true;
  44530. StandardMaterial._RefractionTextureEnabled = true;
  44531. StandardMaterial._ColorGradingTextureEnabled = true;
  44532. StandardMaterial._FresnelEnabled = true;
  44533. __decorate([
  44534. BABYLON.serializeAsTexture("diffuseTexture")
  44535. ], StandardMaterial.prototype, "_diffuseTexture", void 0);
  44536. __decorate([
  44537. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
  44538. ], StandardMaterial.prototype, "diffuseTexture", void 0);
  44539. __decorate([
  44540. BABYLON.serializeAsTexture("ambientTexture")
  44541. ], StandardMaterial.prototype, "_ambientTexture", void 0);
  44542. __decorate([
  44543. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44544. ], StandardMaterial.prototype, "ambientTexture", void 0);
  44545. __decorate([
  44546. BABYLON.serializeAsTexture("opacityTexture")
  44547. ], StandardMaterial.prototype, "_opacityTexture", void 0);
  44548. __decorate([
  44549. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
  44550. ], StandardMaterial.prototype, "opacityTexture", void 0);
  44551. __decorate([
  44552. BABYLON.serializeAsTexture("reflectionTexture")
  44553. ], StandardMaterial.prototype, "_reflectionTexture", void 0);
  44554. __decorate([
  44555. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44556. ], StandardMaterial.prototype, "reflectionTexture", void 0);
  44557. __decorate([
  44558. BABYLON.serializeAsTexture("emissiveTexture")
  44559. ], StandardMaterial.prototype, "_emissiveTexture", void 0);
  44560. __decorate([
  44561. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44562. ], StandardMaterial.prototype, "emissiveTexture", void 0);
  44563. __decorate([
  44564. BABYLON.serializeAsTexture("specularTexture")
  44565. ], StandardMaterial.prototype, "_specularTexture", void 0);
  44566. __decorate([
  44567. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44568. ], StandardMaterial.prototype, "specularTexture", void 0);
  44569. __decorate([
  44570. BABYLON.serializeAsTexture("bumpTexture")
  44571. ], StandardMaterial.prototype, "_bumpTexture", void 0);
  44572. __decorate([
  44573. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44574. ], StandardMaterial.prototype, "bumpTexture", void 0);
  44575. __decorate([
  44576. BABYLON.serializeAsTexture("lightmapTexture")
  44577. ], StandardMaterial.prototype, "_lightmapTexture", void 0);
  44578. __decorate([
  44579. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44580. ], StandardMaterial.prototype, "lightmapTexture", void 0);
  44581. __decorate([
  44582. BABYLON.serializeAsTexture("refractionTexture")
  44583. ], StandardMaterial.prototype, "_refractionTexture", void 0);
  44584. __decorate([
  44585. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44586. ], StandardMaterial.prototype, "refractionTexture", void 0);
  44587. __decorate([
  44588. BABYLON.serializeAsColor3("ambient")
  44589. ], StandardMaterial.prototype, "ambientColor", void 0);
  44590. __decorate([
  44591. BABYLON.serializeAsColor3("diffuse")
  44592. ], StandardMaterial.prototype, "diffuseColor", void 0);
  44593. __decorate([
  44594. BABYLON.serializeAsColor3("specular")
  44595. ], StandardMaterial.prototype, "specularColor", void 0);
  44596. __decorate([
  44597. BABYLON.serializeAsColor3("emissive")
  44598. ], StandardMaterial.prototype, "emissiveColor", void 0);
  44599. __decorate([
  44600. BABYLON.serialize()
  44601. ], StandardMaterial.prototype, "specularPower", void 0);
  44602. __decorate([
  44603. BABYLON.serialize("useAlphaFromDiffuseTexture")
  44604. ], StandardMaterial.prototype, "_useAlphaFromDiffuseTexture", void 0);
  44605. __decorate([
  44606. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44607. ], StandardMaterial.prototype, "useAlphaFromDiffuseTexture", void 0);
  44608. __decorate([
  44609. BABYLON.serialize("useEmissiveAsIllumination")
  44610. ], StandardMaterial.prototype, "_useEmissiveAsIllumination", void 0);
  44611. __decorate([
  44612. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44613. ], StandardMaterial.prototype, "useEmissiveAsIllumination", void 0);
  44614. __decorate([
  44615. BABYLON.serialize("linkEmissiveWithDiffuse")
  44616. ], StandardMaterial.prototype, "_linkEmissiveWithDiffuse", void 0);
  44617. __decorate([
  44618. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44619. ], StandardMaterial.prototype, "linkEmissiveWithDiffuse", void 0);
  44620. __decorate([
  44621. BABYLON.serialize("useSpecularOverAlpha")
  44622. ], StandardMaterial.prototype, "_useSpecularOverAlpha", void 0);
  44623. __decorate([
  44624. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44625. ], StandardMaterial.prototype, "useSpecularOverAlpha", void 0);
  44626. __decorate([
  44627. BABYLON.serialize("useReflectionOverAlpha")
  44628. ], StandardMaterial.prototype, "_useReflectionOverAlpha", void 0);
  44629. __decorate([
  44630. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44631. ], StandardMaterial.prototype, "useReflectionOverAlpha", void 0);
  44632. __decorate([
  44633. BABYLON.serialize("disableLighting")
  44634. ], StandardMaterial.prototype, "_disableLighting", void 0);
  44635. __decorate([
  44636. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  44637. ], StandardMaterial.prototype, "disableLighting", void 0);
  44638. __decorate([
  44639. BABYLON.serialize("useObjectSpaceNormalMap")
  44640. ], StandardMaterial.prototype, "_useObjectSpaceNormalMap", void 0);
  44641. __decorate([
  44642. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44643. ], StandardMaterial.prototype, "useObjectSpaceNormalMap", void 0);
  44644. __decorate([
  44645. BABYLON.serialize("useParallax")
  44646. ], StandardMaterial.prototype, "_useParallax", void 0);
  44647. __decorate([
  44648. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44649. ], StandardMaterial.prototype, "useParallax", void 0);
  44650. __decorate([
  44651. BABYLON.serialize("useParallaxOcclusion")
  44652. ], StandardMaterial.prototype, "_useParallaxOcclusion", void 0);
  44653. __decorate([
  44654. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44655. ], StandardMaterial.prototype, "useParallaxOcclusion", void 0);
  44656. __decorate([
  44657. BABYLON.serialize()
  44658. ], StandardMaterial.prototype, "parallaxScaleBias", void 0);
  44659. __decorate([
  44660. BABYLON.serialize("roughness")
  44661. ], StandardMaterial.prototype, "_roughness", void 0);
  44662. __decorate([
  44663. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44664. ], StandardMaterial.prototype, "roughness", void 0);
  44665. __decorate([
  44666. BABYLON.serialize()
  44667. ], StandardMaterial.prototype, "indexOfRefraction", void 0);
  44668. __decorate([
  44669. BABYLON.serialize()
  44670. ], StandardMaterial.prototype, "invertRefractionY", void 0);
  44671. __decorate([
  44672. BABYLON.serialize()
  44673. ], StandardMaterial.prototype, "alphaCutOff", void 0);
  44674. __decorate([
  44675. BABYLON.serialize("useLightmapAsShadowmap")
  44676. ], StandardMaterial.prototype, "_useLightmapAsShadowmap", void 0);
  44677. __decorate([
  44678. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44679. ], StandardMaterial.prototype, "useLightmapAsShadowmap", void 0);
  44680. __decorate([
  44681. BABYLON.serializeAsFresnelParameters("diffuseFresnelParameters")
  44682. ], StandardMaterial.prototype, "_diffuseFresnelParameters", void 0);
  44683. __decorate([
  44684. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  44685. ], StandardMaterial.prototype, "diffuseFresnelParameters", void 0);
  44686. __decorate([
  44687. BABYLON.serializeAsFresnelParameters("opacityFresnelParameters")
  44688. ], StandardMaterial.prototype, "_opacityFresnelParameters", void 0);
  44689. __decorate([
  44690. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelAndMiscDirty")
  44691. ], StandardMaterial.prototype, "opacityFresnelParameters", void 0);
  44692. __decorate([
  44693. BABYLON.serializeAsFresnelParameters("reflectionFresnelParameters")
  44694. ], StandardMaterial.prototype, "_reflectionFresnelParameters", void 0);
  44695. __decorate([
  44696. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  44697. ], StandardMaterial.prototype, "reflectionFresnelParameters", void 0);
  44698. __decorate([
  44699. BABYLON.serializeAsFresnelParameters("refractionFresnelParameters")
  44700. ], StandardMaterial.prototype, "_refractionFresnelParameters", void 0);
  44701. __decorate([
  44702. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  44703. ], StandardMaterial.prototype, "refractionFresnelParameters", void 0);
  44704. __decorate([
  44705. BABYLON.serializeAsFresnelParameters("emissiveFresnelParameters")
  44706. ], StandardMaterial.prototype, "_emissiveFresnelParameters", void 0);
  44707. __decorate([
  44708. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  44709. ], StandardMaterial.prototype, "emissiveFresnelParameters", void 0);
  44710. __decorate([
  44711. BABYLON.serialize("useReflectionFresnelFromSpecular")
  44712. ], StandardMaterial.prototype, "_useReflectionFresnelFromSpecular", void 0);
  44713. __decorate([
  44714. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  44715. ], StandardMaterial.prototype, "useReflectionFresnelFromSpecular", void 0);
  44716. __decorate([
  44717. BABYLON.serialize("useGlossinessFromSpecularMapAlpha")
  44718. ], StandardMaterial.prototype, "_useGlossinessFromSpecularMapAlpha", void 0);
  44719. __decorate([
  44720. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44721. ], StandardMaterial.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
  44722. __decorate([
  44723. BABYLON.serialize("maxSimultaneousLights")
  44724. ], StandardMaterial.prototype, "_maxSimultaneousLights", void 0);
  44725. __decorate([
  44726. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  44727. ], StandardMaterial.prototype, "maxSimultaneousLights", void 0);
  44728. __decorate([
  44729. BABYLON.serialize("invertNormalMapX")
  44730. ], StandardMaterial.prototype, "_invertNormalMapX", void 0);
  44731. __decorate([
  44732. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44733. ], StandardMaterial.prototype, "invertNormalMapX", void 0);
  44734. __decorate([
  44735. BABYLON.serialize("invertNormalMapY")
  44736. ], StandardMaterial.prototype, "_invertNormalMapY", void 0);
  44737. __decorate([
  44738. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44739. ], StandardMaterial.prototype, "invertNormalMapY", void 0);
  44740. __decorate([
  44741. BABYLON.serialize("twoSidedLighting")
  44742. ], StandardMaterial.prototype, "_twoSidedLighting", void 0);
  44743. __decorate([
  44744. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  44745. ], StandardMaterial.prototype, "twoSidedLighting", void 0);
  44746. __decorate([
  44747. BABYLON.serialize()
  44748. ], StandardMaterial.prototype, "useLogarithmicDepth", null);
  44749. return StandardMaterial;
  44750. }(BABYLON.PushMaterial));
  44751. BABYLON.StandardMaterial = StandardMaterial;
  44752. })(BABYLON || (BABYLON = {}));
  44753. //# sourceMappingURL=babylon.standardMaterial.js.map
  44754. var BABYLON;
  44755. (function (BABYLON) {
  44756. BABYLON.CameraInputTypes = {};
  44757. var CameraInputsManager = /** @class */ (function () {
  44758. function CameraInputsManager(camera) {
  44759. this.attached = {};
  44760. this.camera = camera;
  44761. this.checkInputs = function () { };
  44762. }
  44763. /**
  44764. * Add an input method to a camera.
  44765. * builtin inputs example: camera.inputs.addGamepad();
  44766. * custom inputs example: camera.inputs.add(new BABYLON.FreeCameraGamepadInput());
  44767. * @param input camera input method
  44768. */
  44769. CameraInputsManager.prototype.add = function (input) {
  44770. var type = input.getSimpleName();
  44771. if (this.attached[type]) {
  44772. BABYLON.Tools.Warn("camera input of type " + type + " already exists on camera");
  44773. return;
  44774. }
  44775. this.attached[type] = input;
  44776. input.camera = this.camera;
  44777. //for checkInputs, we are dynamically creating a function
  44778. //the goal is to avoid the performance penalty of looping for inputs in the render loop
  44779. if (input.checkInputs) {
  44780. this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));
  44781. }
  44782. if (this.attachedElement) {
  44783. input.attachControl(this.attachedElement);
  44784. }
  44785. };
  44786. /**
  44787. * Remove a specific input method from a camera
  44788. * example: camera.inputs.remove(camera.inputs.attached.mouse);
  44789. * @param inputToRemove camera input method
  44790. */
  44791. CameraInputsManager.prototype.remove = function (inputToRemove) {
  44792. for (var cam in this.attached) {
  44793. var input = this.attached[cam];
  44794. if (input === inputToRemove) {
  44795. input.detachControl(this.attachedElement);
  44796. input.camera = null;
  44797. delete this.attached[cam];
  44798. this.rebuildInputCheck();
  44799. }
  44800. }
  44801. };
  44802. CameraInputsManager.prototype.removeByType = function (inputType) {
  44803. for (var cam in this.attached) {
  44804. var input = this.attached[cam];
  44805. if (input.getClassName() === inputType) {
  44806. input.detachControl(this.attachedElement);
  44807. input.camera = null;
  44808. delete this.attached[cam];
  44809. this.rebuildInputCheck();
  44810. }
  44811. }
  44812. };
  44813. CameraInputsManager.prototype._addCheckInputs = function (fn) {
  44814. var current = this.checkInputs;
  44815. return function () {
  44816. current();
  44817. fn();
  44818. };
  44819. };
  44820. CameraInputsManager.prototype.attachInput = function (input) {
  44821. if (this.attachedElement) {
  44822. input.attachControl(this.attachedElement, this.noPreventDefault);
  44823. }
  44824. };
  44825. CameraInputsManager.prototype.attachElement = function (element, noPreventDefault) {
  44826. if (noPreventDefault === void 0) { noPreventDefault = false; }
  44827. if (this.attachedElement) {
  44828. return;
  44829. }
  44830. noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
  44831. this.attachedElement = element;
  44832. this.noPreventDefault = noPreventDefault;
  44833. for (var cam in this.attached) {
  44834. this.attached[cam].attachControl(element, noPreventDefault);
  44835. }
  44836. };
  44837. CameraInputsManager.prototype.detachElement = function (element, disconnect) {
  44838. if (disconnect === void 0) { disconnect = false; }
  44839. if (this.attachedElement !== element) {
  44840. return;
  44841. }
  44842. for (var cam in this.attached) {
  44843. this.attached[cam].detachControl(element);
  44844. if (disconnect) {
  44845. this.attached[cam].camera = null;
  44846. }
  44847. }
  44848. this.attachedElement = null;
  44849. };
  44850. CameraInputsManager.prototype.rebuildInputCheck = function () {
  44851. this.checkInputs = function () { };
  44852. for (var cam in this.attached) {
  44853. var input = this.attached[cam];
  44854. if (input.checkInputs) {
  44855. this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));
  44856. }
  44857. }
  44858. };
  44859. /**
  44860. * Remove all attached input methods from a camera
  44861. */
  44862. CameraInputsManager.prototype.clear = function () {
  44863. if (this.attachedElement) {
  44864. this.detachElement(this.attachedElement, true);
  44865. }
  44866. this.attached = {};
  44867. this.attachedElement = null;
  44868. this.checkInputs = function () { };
  44869. };
  44870. CameraInputsManager.prototype.serialize = function (serializedCamera) {
  44871. var inputs = {};
  44872. for (var cam in this.attached) {
  44873. var input = this.attached[cam];
  44874. var res = BABYLON.SerializationHelper.Serialize(input);
  44875. inputs[input.getClassName()] = res;
  44876. }
  44877. serializedCamera.inputsmgr = inputs;
  44878. };
  44879. CameraInputsManager.prototype.parse = function (parsedCamera) {
  44880. var parsedInputs = parsedCamera.inputsmgr;
  44881. if (parsedInputs) {
  44882. this.clear();
  44883. for (var n in parsedInputs) {
  44884. var construct = BABYLON.CameraInputTypes[n];
  44885. if (construct) {
  44886. var parsedinput = parsedInputs[n];
  44887. var input = BABYLON.SerializationHelper.Parse(function () { return new construct(); }, parsedinput, null);
  44888. this.add(input);
  44889. }
  44890. }
  44891. }
  44892. else {
  44893. //2016-03-08 this part is for managing backward compatibility
  44894. for (var n in this.attached) {
  44895. var construct = BABYLON.CameraInputTypes[this.attached[n].getClassName()];
  44896. if (construct) {
  44897. var input = BABYLON.SerializationHelper.Parse(function () { return new construct(); }, parsedCamera, null);
  44898. this.remove(this.attached[n]);
  44899. this.add(input);
  44900. }
  44901. }
  44902. }
  44903. };
  44904. return CameraInputsManager;
  44905. }());
  44906. BABYLON.CameraInputsManager = CameraInputsManager;
  44907. })(BABYLON || (BABYLON = {}));
  44908. //# sourceMappingURL=babylon.cameraInputsManager.js.map
  44909. var BABYLON;
  44910. (function (BABYLON) {
  44911. var TargetCamera = /** @class */ (function (_super) {
  44912. __extends(TargetCamera, _super);
  44913. function TargetCamera(name, position, scene, setActiveOnSceneIfNoneActive) {
  44914. if (setActiveOnSceneIfNoneActive === void 0) { setActiveOnSceneIfNoneActive = true; }
  44915. var _this = _super.call(this, name, position, scene, setActiveOnSceneIfNoneActive) || this;
  44916. _this.cameraDirection = new BABYLON.Vector3(0, 0, 0);
  44917. _this.cameraRotation = new BABYLON.Vector2(0, 0);
  44918. _this.rotation = new BABYLON.Vector3(0, 0, 0);
  44919. _this.speed = 2.0;
  44920. _this.noRotationConstraint = false;
  44921. _this.lockedTarget = null;
  44922. _this._currentTarget = BABYLON.Vector3.Zero();
  44923. _this._viewMatrix = BABYLON.Matrix.Zero();
  44924. _this._camMatrix = BABYLON.Matrix.Zero();
  44925. _this._cameraTransformMatrix = BABYLON.Matrix.Zero();
  44926. _this._cameraRotationMatrix = BABYLON.Matrix.Zero();
  44927. _this._referencePoint = new BABYLON.Vector3(0, 0, 1);
  44928. _this._currentUpVector = new BABYLON.Vector3(0, 1, 0);
  44929. _this._transformedReferencePoint = BABYLON.Vector3.Zero();
  44930. _this._globalCurrentTarget = BABYLON.Vector3.Zero();
  44931. _this._globalCurrentUpVector = BABYLON.Vector3.Zero();
  44932. return _this;
  44933. }
  44934. TargetCamera.prototype.getFrontPosition = function (distance) {
  44935. this.getWorldMatrix();
  44936. var direction = this.getTarget().subtract(this.position);
  44937. direction.normalize();
  44938. direction.scaleInPlace(distance);
  44939. return this.globalPosition.add(direction);
  44940. };
  44941. TargetCamera.prototype._getLockedTargetPosition = function () {
  44942. if (!this.lockedTarget) {
  44943. return null;
  44944. }
  44945. if (this.lockedTarget.absolutePosition) {
  44946. this.lockedTarget.computeWorldMatrix();
  44947. }
  44948. return this.lockedTarget.absolutePosition || this.lockedTarget;
  44949. };
  44950. TargetCamera.prototype.storeState = function () {
  44951. this._storedPosition = this.position.clone();
  44952. this._storedRotation = this.rotation.clone();
  44953. if (this.rotationQuaternion) {
  44954. this._storedRotationQuaternion = this.rotationQuaternion.clone();
  44955. }
  44956. return _super.prototype.storeState.call(this);
  44957. };
  44958. /**
  44959. * Restored camera state. You must call storeState() first
  44960. */
  44961. TargetCamera.prototype._restoreStateValues = function () {
  44962. if (!_super.prototype._restoreStateValues.call(this)) {
  44963. return false;
  44964. }
  44965. this.position = this._storedPosition.clone();
  44966. this.rotation = this._storedRotation.clone();
  44967. if (this.rotationQuaternion) {
  44968. this.rotationQuaternion = this._storedRotationQuaternion.clone();
  44969. }
  44970. this.cameraDirection.copyFromFloats(0, 0, 0);
  44971. this.cameraRotation.copyFromFloats(0, 0);
  44972. return true;
  44973. };
  44974. // Cache
  44975. TargetCamera.prototype._initCache = function () {
  44976. _super.prototype._initCache.call(this);
  44977. this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  44978. this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  44979. this._cache.rotationQuaternion = new BABYLON.Quaternion(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  44980. };
  44981. TargetCamera.prototype._updateCache = function (ignoreParentClass) {
  44982. if (!ignoreParentClass) {
  44983. _super.prototype._updateCache.call(this);
  44984. }
  44985. var lockedTargetPosition = this._getLockedTargetPosition();
  44986. if (!lockedTargetPosition) {
  44987. this._cache.lockedTarget = null;
  44988. }
  44989. else {
  44990. if (!this._cache.lockedTarget) {
  44991. this._cache.lockedTarget = lockedTargetPosition.clone();
  44992. }
  44993. else {
  44994. this._cache.lockedTarget.copyFrom(lockedTargetPosition);
  44995. }
  44996. }
  44997. this._cache.rotation.copyFrom(this.rotation);
  44998. if (this.rotationQuaternion)
  44999. this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
  45000. };
  45001. // Synchronized
  45002. TargetCamera.prototype._isSynchronizedViewMatrix = function () {
  45003. if (!_super.prototype._isSynchronizedViewMatrix.call(this)) {
  45004. return false;
  45005. }
  45006. var lockedTargetPosition = this._getLockedTargetPosition();
  45007. return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
  45008. && (this.rotationQuaternion ? this.rotationQuaternion.equals(this._cache.rotationQuaternion) : this._cache.rotation.equals(this.rotation));
  45009. };
  45010. // Methods
  45011. TargetCamera.prototype._computeLocalCameraSpeed = function () {
  45012. var engine = this.getEngine();
  45013. return this.speed * Math.sqrt((engine.getDeltaTime() / (engine.getFps() * 100.0)));
  45014. };
  45015. // Target
  45016. TargetCamera.prototype.setTarget = function (target) {
  45017. this.upVector.normalize();
  45018. BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
  45019. this._camMatrix.invert();
  45020. this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
  45021. var vDir = target.subtract(this.position);
  45022. if (vDir.x >= 0.0) {
  45023. this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
  45024. }
  45025. else {
  45026. this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
  45027. }
  45028. this.rotation.z = 0;
  45029. if (isNaN(this.rotation.x)) {
  45030. this.rotation.x = 0;
  45031. }
  45032. if (isNaN(this.rotation.y)) {
  45033. this.rotation.y = 0;
  45034. }
  45035. if (isNaN(this.rotation.z)) {
  45036. this.rotation.z = 0;
  45037. }
  45038. if (this.rotationQuaternion) {
  45039. BABYLON.Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this.rotationQuaternion);
  45040. }
  45041. };
  45042. /**
  45043. * Return the current target position of the camera. This value is expressed in local space.
  45044. */
  45045. TargetCamera.prototype.getTarget = function () {
  45046. return this._currentTarget;
  45047. };
  45048. TargetCamera.prototype._decideIfNeedsToMove = function () {
  45049. return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
  45050. };
  45051. TargetCamera.prototype._updatePosition = function () {
  45052. if (this.parent) {
  45053. this.parent.getWorldMatrix().invertToRef(BABYLON.Tmp.Matrix[0]);
  45054. BABYLON.Vector3.TransformNormalToRef(this.cameraDirection, BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Vector3[0]);
  45055. this.position.addInPlace(BABYLON.Tmp.Vector3[0]);
  45056. return;
  45057. }
  45058. this.position.addInPlace(this.cameraDirection);
  45059. };
  45060. TargetCamera.prototype._checkInputs = function () {
  45061. var needToMove = this._decideIfNeedsToMove();
  45062. var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
  45063. // Move
  45064. if (needToMove) {
  45065. this._updatePosition();
  45066. }
  45067. // Rotate
  45068. if (needToRotate) {
  45069. this.rotation.x += this.cameraRotation.x;
  45070. this.rotation.y += this.cameraRotation.y;
  45071. //rotate, if quaternion is set and rotation was used
  45072. if (this.rotationQuaternion) {
  45073. var len = this.rotation.lengthSquared();
  45074. if (len) {
  45075. BABYLON.Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this.rotationQuaternion);
  45076. }
  45077. }
  45078. if (!this.noRotationConstraint) {
  45079. var limit = (Math.PI / 2) * 0.95;
  45080. if (this.rotation.x > limit)
  45081. this.rotation.x = limit;
  45082. if (this.rotation.x < -limit)
  45083. this.rotation.x = -limit;
  45084. }
  45085. }
  45086. // Inertia
  45087. if (needToMove) {
  45088. if (Math.abs(this.cameraDirection.x) < this.speed * BABYLON.Epsilon) {
  45089. this.cameraDirection.x = 0;
  45090. }
  45091. if (Math.abs(this.cameraDirection.y) < this.speed * BABYLON.Epsilon) {
  45092. this.cameraDirection.y = 0;
  45093. }
  45094. if (Math.abs(this.cameraDirection.z) < this.speed * BABYLON.Epsilon) {
  45095. this.cameraDirection.z = 0;
  45096. }
  45097. this.cameraDirection.scaleInPlace(this.inertia);
  45098. }
  45099. if (needToRotate) {
  45100. if (Math.abs(this.cameraRotation.x) < this.speed * BABYLON.Epsilon) {
  45101. this.cameraRotation.x = 0;
  45102. }
  45103. if (Math.abs(this.cameraRotation.y) < this.speed * BABYLON.Epsilon) {
  45104. this.cameraRotation.y = 0;
  45105. }
  45106. this.cameraRotation.scaleInPlace(this.inertia);
  45107. }
  45108. _super.prototype._checkInputs.call(this);
  45109. };
  45110. TargetCamera.prototype._updateCameraRotationMatrix = function () {
  45111. if (this.rotationQuaternion) {
  45112. this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix);
  45113. }
  45114. else {
  45115. BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
  45116. }
  45117. //update the up vector!
  45118. BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._currentUpVector);
  45119. };
  45120. TargetCamera.prototype._getViewMatrix = function () {
  45121. if (this.lockedTarget) {
  45122. this.setTarget(this._getLockedTargetPosition());
  45123. }
  45124. // Compute
  45125. this._updateCameraRotationMatrix();
  45126. BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
  45127. // Computing target and final matrix
  45128. this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
  45129. this._computeViewMatrix(this.position, this._currentTarget, this._currentUpVector);
  45130. return this._viewMatrix;
  45131. };
  45132. TargetCamera.prototype._computeViewMatrix = function (position, target, up) {
  45133. if (this.parent) {
  45134. var parentWorldMatrix = this.parent.getWorldMatrix();
  45135. BABYLON.Vector3.TransformCoordinatesToRef(this.position, parentWorldMatrix, this._globalPosition);
  45136. BABYLON.Vector3.TransformCoordinatesToRef(target, parentWorldMatrix, this._globalCurrentTarget);
  45137. BABYLON.Vector3.TransformNormalToRef(up, parentWorldMatrix, this._globalCurrentUpVector);
  45138. this._markSyncedWithParent();
  45139. }
  45140. else {
  45141. this._globalPosition.copyFrom(this.position);
  45142. this._globalCurrentTarget.copyFrom(target);
  45143. this._globalCurrentUpVector.copyFrom(up);
  45144. }
  45145. if (this.getScene().useRightHandedSystem) {
  45146. BABYLON.Matrix.LookAtRHToRef(this._globalPosition, this._globalCurrentTarget, this._globalCurrentUpVector, this._viewMatrix);
  45147. }
  45148. else {
  45149. BABYLON.Matrix.LookAtLHToRef(this._globalPosition, this._globalCurrentTarget, this._globalCurrentUpVector, this._viewMatrix);
  45150. }
  45151. };
  45152. /**
  45153. * @override
  45154. * Override Camera.createRigCamera
  45155. */
  45156. TargetCamera.prototype.createRigCamera = function (name, cameraIndex) {
  45157. if (this.cameraRigMode !== BABYLON.Camera.RIG_MODE_NONE) {
  45158. var rigCamera = new TargetCamera(name, this.position.clone(), this.getScene());
  45159. if (this.cameraRigMode === BABYLON.Camera.RIG_MODE_VR || this.cameraRigMode === BABYLON.Camera.RIG_MODE_WEBVR) {
  45160. if (!this.rotationQuaternion) {
  45161. this.rotationQuaternion = new BABYLON.Quaternion();
  45162. }
  45163. rigCamera._cameraRigParams = {};
  45164. rigCamera.rotationQuaternion = new BABYLON.Quaternion();
  45165. }
  45166. return rigCamera;
  45167. }
  45168. return null;
  45169. };
  45170. /**
  45171. * @override
  45172. * Override Camera._updateRigCameras
  45173. */
  45174. TargetCamera.prototype._updateRigCameras = function () {
  45175. var camLeft = this._rigCameras[0];
  45176. var camRight = this._rigCameras[1];
  45177. switch (this.cameraRigMode) {
  45178. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  45179. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  45180. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  45181. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  45182. //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
  45183. var leftSign = (this.cameraRigMode === BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? 1 : -1;
  45184. var rightSign = (this.cameraRigMode === BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? -1 : 1;
  45185. this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * leftSign, camLeft.position);
  45186. this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * rightSign, camRight.position);
  45187. camLeft.setTarget(this.getTarget());
  45188. camRight.setTarget(this.getTarget());
  45189. break;
  45190. case BABYLON.Camera.RIG_MODE_VR:
  45191. if (camLeft.rotationQuaternion) {
  45192. camLeft.rotationQuaternion.copyFrom(this.rotationQuaternion);
  45193. camRight.rotationQuaternion.copyFrom(this.rotationQuaternion);
  45194. }
  45195. else {
  45196. camLeft.rotation.copyFrom(this.rotation);
  45197. camRight.rotation.copyFrom(this.rotation);
  45198. }
  45199. camLeft.position.copyFrom(this.position);
  45200. camRight.position.copyFrom(this.position);
  45201. break;
  45202. }
  45203. _super.prototype._updateRigCameras.call(this);
  45204. };
  45205. TargetCamera.prototype._getRigCamPosition = function (halfSpace, result) {
  45206. if (!this._rigCamTransformMatrix) {
  45207. this._rigCamTransformMatrix = new BABYLON.Matrix();
  45208. }
  45209. var target = this.getTarget();
  45210. BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(halfSpace), this._rigCamTransformMatrix);
  45211. this._rigCamTransformMatrix = this._rigCamTransformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
  45212. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._rigCamTransformMatrix, result);
  45213. };
  45214. TargetCamera.prototype.getClassName = function () {
  45215. return "TargetCamera";
  45216. };
  45217. __decorate([
  45218. BABYLON.serializeAsVector3()
  45219. ], TargetCamera.prototype, "rotation", void 0);
  45220. __decorate([
  45221. BABYLON.serialize()
  45222. ], TargetCamera.prototype, "speed", void 0);
  45223. __decorate([
  45224. BABYLON.serializeAsMeshReference("lockedTargetId")
  45225. ], TargetCamera.prototype, "lockedTarget", void 0);
  45226. return TargetCamera;
  45227. }(BABYLON.Camera));
  45228. BABYLON.TargetCamera = TargetCamera;
  45229. })(BABYLON || (BABYLON = {}));
  45230. //# sourceMappingURL=babylon.targetCamera.js.map
  45231. var BABYLON;
  45232. (function (BABYLON) {
  45233. var FreeCameraMouseInput = /** @class */ (function () {
  45234. function FreeCameraMouseInput(touchEnabled) {
  45235. if (touchEnabled === void 0) { touchEnabled = true; }
  45236. this.touchEnabled = touchEnabled;
  45237. this.buttons = [0, 1, 2];
  45238. this.angularSensibility = 2000.0;
  45239. this.previousPosition = null;
  45240. }
  45241. FreeCameraMouseInput.prototype.attachControl = function (element, noPreventDefault) {
  45242. var _this = this;
  45243. var engine = this.camera.getEngine();
  45244. if (!this._pointerInput) {
  45245. this._pointerInput = function (p, s) {
  45246. var evt = p.event;
  45247. if (engine.isInVRExclusivePointerMode) {
  45248. return;
  45249. }
  45250. if (!_this.touchEnabled && evt.pointerType === "touch") {
  45251. return;
  45252. }
  45253. if (p.type !== BABYLON.PointerEventTypes.POINTERMOVE && _this.buttons.indexOf(evt.button) === -1) {
  45254. return;
  45255. }
  45256. var srcElement = (evt.srcElement || evt.target);
  45257. if (p.type === BABYLON.PointerEventTypes.POINTERDOWN && srcElement) {
  45258. try {
  45259. srcElement.setPointerCapture(evt.pointerId);
  45260. }
  45261. catch (e) {
  45262. //Nothing to do with the error. Execution will continue.
  45263. }
  45264. _this.previousPosition = {
  45265. x: evt.clientX,
  45266. y: evt.clientY
  45267. };
  45268. if (!noPreventDefault) {
  45269. evt.preventDefault();
  45270. element.focus();
  45271. }
  45272. }
  45273. else if (p.type === BABYLON.PointerEventTypes.POINTERUP && srcElement) {
  45274. try {
  45275. srcElement.releasePointerCapture(evt.pointerId);
  45276. }
  45277. catch (e) {
  45278. //Nothing to do with the error.
  45279. }
  45280. _this.previousPosition = null;
  45281. if (!noPreventDefault) {
  45282. evt.preventDefault();
  45283. }
  45284. }
  45285. else if (p.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  45286. if (!_this.previousPosition || engine.isPointerLock) {
  45287. return;
  45288. }
  45289. var offsetX = evt.clientX - _this.previousPosition.x;
  45290. if (_this.camera.getScene().useRightHandedSystem)
  45291. offsetX *= -1;
  45292. if (_this.camera.parent && _this.camera.parent._getWorldMatrixDeterminant() < 0)
  45293. offsetX *= -1;
  45294. _this.camera.cameraRotation.y += offsetX / _this.angularSensibility;
  45295. var offsetY = evt.clientY - _this.previousPosition.y;
  45296. _this.camera.cameraRotation.x += offsetY / _this.angularSensibility;
  45297. _this.previousPosition = {
  45298. x: evt.clientX,
  45299. y: evt.clientY
  45300. };
  45301. if (!noPreventDefault) {
  45302. evt.preventDefault();
  45303. }
  45304. }
  45305. };
  45306. }
  45307. this._onMouseMove = function (evt) {
  45308. if (!engine.isPointerLock) {
  45309. return;
  45310. }
  45311. if (engine.isInVRExclusivePointerMode) {
  45312. return;
  45313. }
  45314. var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
  45315. if (_this.camera.getScene().useRightHandedSystem)
  45316. offsetX *= -1;
  45317. if (_this.camera.parent && _this.camera.parent._getWorldMatrixDeterminant() < 0)
  45318. offsetX *= -1;
  45319. _this.camera.cameraRotation.y += offsetX / _this.angularSensibility;
  45320. var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
  45321. _this.camera.cameraRotation.x += offsetY / _this.angularSensibility;
  45322. _this.previousPosition = null;
  45323. if (!noPreventDefault) {
  45324. evt.preventDefault();
  45325. }
  45326. };
  45327. this._observer = this.camera.getScene().onPointerObservable.add(this._pointerInput, BABYLON.PointerEventTypes.POINTERDOWN | BABYLON.PointerEventTypes.POINTERUP | BABYLON.PointerEventTypes.POINTERMOVE);
  45328. element.addEventListener("mousemove", this._onMouseMove, false);
  45329. };
  45330. FreeCameraMouseInput.prototype.detachControl = function (element) {
  45331. if (this._observer && element) {
  45332. this.camera.getScene().onPointerObservable.remove(this._observer);
  45333. if (this._onMouseMove) {
  45334. element.removeEventListener("mousemove", this._onMouseMove);
  45335. }
  45336. this._observer = null;
  45337. this._onMouseMove = null;
  45338. this.previousPosition = null;
  45339. }
  45340. };
  45341. FreeCameraMouseInput.prototype.getClassName = function () {
  45342. return "FreeCameraMouseInput";
  45343. };
  45344. FreeCameraMouseInput.prototype.getSimpleName = function () {
  45345. return "mouse";
  45346. };
  45347. __decorate([
  45348. BABYLON.serialize()
  45349. ], FreeCameraMouseInput.prototype, "buttons", void 0);
  45350. __decorate([
  45351. BABYLON.serialize()
  45352. ], FreeCameraMouseInput.prototype, "angularSensibility", void 0);
  45353. return FreeCameraMouseInput;
  45354. }());
  45355. BABYLON.FreeCameraMouseInput = FreeCameraMouseInput;
  45356. BABYLON.CameraInputTypes["FreeCameraMouseInput"] = FreeCameraMouseInput;
  45357. })(BABYLON || (BABYLON = {}));
  45358. //# sourceMappingURL=babylon.freeCameraMouseInput.js.map
  45359. var BABYLON;
  45360. (function (BABYLON) {
  45361. var FreeCameraKeyboardMoveInput = /** @class */ (function () {
  45362. function FreeCameraKeyboardMoveInput() {
  45363. this._keys = new Array();
  45364. this.keysUp = [38];
  45365. this.keysDown = [40];
  45366. this.keysLeft = [37];
  45367. this.keysRight = [39];
  45368. }
  45369. FreeCameraKeyboardMoveInput.prototype.attachControl = function (element, noPreventDefault) {
  45370. var _this = this;
  45371. if (this._onCanvasBlurObserver) {
  45372. return;
  45373. }
  45374. this._scene = this.camera.getScene();
  45375. this._engine = this._scene.getEngine();
  45376. this._onCanvasBlurObserver = this._engine.onCanvasBlurObservable.add(function () {
  45377. _this._keys = [];
  45378. });
  45379. this._onKeyboardObserver = this._scene.onKeyboardObservable.add(function (info) {
  45380. var evt = info.event;
  45381. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  45382. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  45383. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  45384. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  45385. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  45386. var index = _this._keys.indexOf(evt.keyCode);
  45387. if (index === -1) {
  45388. _this._keys.push(evt.keyCode);
  45389. }
  45390. if (!noPreventDefault) {
  45391. evt.preventDefault();
  45392. }
  45393. }
  45394. }
  45395. else {
  45396. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  45397. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  45398. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  45399. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  45400. var index = _this._keys.indexOf(evt.keyCode);
  45401. if (index >= 0) {
  45402. _this._keys.splice(index, 1);
  45403. }
  45404. if (!noPreventDefault) {
  45405. evt.preventDefault();
  45406. }
  45407. }
  45408. }
  45409. });
  45410. };
  45411. FreeCameraKeyboardMoveInput.prototype.detachControl = function (element) {
  45412. if (this._scene) {
  45413. if (this._onKeyboardObserver) {
  45414. this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);
  45415. }
  45416. if (this._onCanvasBlurObserver) {
  45417. this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);
  45418. }
  45419. this._onKeyboardObserver = null;
  45420. this._onCanvasBlurObserver = null;
  45421. }
  45422. this._keys = [];
  45423. };
  45424. FreeCameraKeyboardMoveInput.prototype.checkInputs = function () {
  45425. if (this._onKeyboardObserver) {
  45426. var camera = this.camera;
  45427. // Keyboard
  45428. for (var index = 0; index < this._keys.length; index++) {
  45429. var keyCode = this._keys[index];
  45430. var speed = camera._computeLocalCameraSpeed();
  45431. if (this.keysLeft.indexOf(keyCode) !== -1) {
  45432. camera._localDirection.copyFromFloats(-speed, 0, 0);
  45433. }
  45434. else if (this.keysUp.indexOf(keyCode) !== -1) {
  45435. camera._localDirection.copyFromFloats(0, 0, speed);
  45436. }
  45437. else if (this.keysRight.indexOf(keyCode) !== -1) {
  45438. camera._localDirection.copyFromFloats(speed, 0, 0);
  45439. }
  45440. else if (this.keysDown.indexOf(keyCode) !== -1) {
  45441. camera._localDirection.copyFromFloats(0, 0, -speed);
  45442. }
  45443. if (camera.getScene().useRightHandedSystem) {
  45444. camera._localDirection.z *= -1;
  45445. }
  45446. camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
  45447. BABYLON.Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
  45448. camera.cameraDirection.addInPlace(camera._transformedDirection);
  45449. }
  45450. }
  45451. };
  45452. FreeCameraKeyboardMoveInput.prototype.getClassName = function () {
  45453. return "FreeCameraKeyboardMoveInput";
  45454. };
  45455. FreeCameraKeyboardMoveInput.prototype._onLostFocus = function (e) {
  45456. this._keys = [];
  45457. };
  45458. FreeCameraKeyboardMoveInput.prototype.getSimpleName = function () {
  45459. return "keyboard";
  45460. };
  45461. __decorate([
  45462. BABYLON.serialize()
  45463. ], FreeCameraKeyboardMoveInput.prototype, "keysUp", void 0);
  45464. __decorate([
  45465. BABYLON.serialize()
  45466. ], FreeCameraKeyboardMoveInput.prototype, "keysDown", void 0);
  45467. __decorate([
  45468. BABYLON.serialize()
  45469. ], FreeCameraKeyboardMoveInput.prototype, "keysLeft", void 0);
  45470. __decorate([
  45471. BABYLON.serialize()
  45472. ], FreeCameraKeyboardMoveInput.prototype, "keysRight", void 0);
  45473. return FreeCameraKeyboardMoveInput;
  45474. }());
  45475. BABYLON.FreeCameraKeyboardMoveInput = FreeCameraKeyboardMoveInput;
  45476. BABYLON.CameraInputTypes["FreeCameraKeyboardMoveInput"] = FreeCameraKeyboardMoveInput;
  45477. })(BABYLON || (BABYLON = {}));
  45478. //# sourceMappingURL=babylon.freeCameraKeyboardMoveInput.js.map
  45479. var BABYLON;
  45480. (function (BABYLON) {
  45481. var FreeCameraInputsManager = /** @class */ (function (_super) {
  45482. __extends(FreeCameraInputsManager, _super);
  45483. function FreeCameraInputsManager(camera) {
  45484. return _super.call(this, camera) || this;
  45485. }
  45486. FreeCameraInputsManager.prototype.addKeyboard = function () {
  45487. this.add(new BABYLON.FreeCameraKeyboardMoveInput());
  45488. return this;
  45489. };
  45490. FreeCameraInputsManager.prototype.addMouse = function (touchEnabled) {
  45491. if (touchEnabled === void 0) { touchEnabled = true; }
  45492. this.add(new BABYLON.FreeCameraMouseInput(touchEnabled));
  45493. return this;
  45494. };
  45495. FreeCameraInputsManager.prototype.addGamepad = function () {
  45496. this.add(new BABYLON.FreeCameraGamepadInput());
  45497. return this;
  45498. };
  45499. FreeCameraInputsManager.prototype.addDeviceOrientation = function () {
  45500. this.add(new BABYLON.FreeCameraDeviceOrientationInput());
  45501. return this;
  45502. };
  45503. FreeCameraInputsManager.prototype.addTouch = function () {
  45504. this.add(new BABYLON.FreeCameraTouchInput());
  45505. return this;
  45506. };
  45507. FreeCameraInputsManager.prototype.addVirtualJoystick = function () {
  45508. this.add(new BABYLON.FreeCameraVirtualJoystickInput());
  45509. return this;
  45510. };
  45511. return FreeCameraInputsManager;
  45512. }(BABYLON.CameraInputsManager));
  45513. BABYLON.FreeCameraInputsManager = FreeCameraInputsManager;
  45514. })(BABYLON || (BABYLON = {}));
  45515. //# sourceMappingURL=babylon.freeCameraInputsManager.js.map
  45516. var BABYLON;
  45517. (function (BABYLON) {
  45518. var FreeCamera = /** @class */ (function (_super) {
  45519. __extends(FreeCamera, _super);
  45520. function FreeCamera(name, position, scene, setActiveOnSceneIfNoneActive) {
  45521. if (setActiveOnSceneIfNoneActive === void 0) { setActiveOnSceneIfNoneActive = true; }
  45522. var _this = _super.call(this, name, position, scene, setActiveOnSceneIfNoneActive) || this;
  45523. _this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
  45524. _this.ellipsoidOffset = new BABYLON.Vector3(0, 0, 0);
  45525. _this.checkCollisions = false;
  45526. _this.applyGravity = false;
  45527. _this._needMoveForGravity = false;
  45528. _this._oldPosition = BABYLON.Vector3.Zero();
  45529. _this._diffPosition = BABYLON.Vector3.Zero();
  45530. _this._newPosition = BABYLON.Vector3.Zero();
  45531. // Collisions
  45532. _this._collisionMask = -1;
  45533. _this._onCollisionPositionChange = function (collisionId, newPosition, collidedMesh) {
  45534. if (collidedMesh === void 0) { collidedMesh = null; }
  45535. //TODO move this to the collision coordinator!
  45536. if (_this.getScene().workerCollisions)
  45537. newPosition.multiplyInPlace(_this._collider._radius);
  45538. var updatePosition = function (newPos) {
  45539. _this._newPosition.copyFrom(newPos);
  45540. _this._newPosition.subtractToRef(_this._oldPosition, _this._diffPosition);
  45541. if (_this._diffPosition.length() > BABYLON.Engine.CollisionsEpsilon) {
  45542. _this.position.addInPlace(_this._diffPosition);
  45543. if (_this.onCollide && collidedMesh) {
  45544. _this.onCollide(collidedMesh);
  45545. }
  45546. }
  45547. };
  45548. updatePosition(newPosition);
  45549. };
  45550. _this.inputs = new BABYLON.FreeCameraInputsManager(_this);
  45551. _this.inputs.addKeyboard().addMouse();
  45552. return _this;
  45553. }
  45554. Object.defineProperty(FreeCamera.prototype, "angularSensibility", {
  45555. //-- begin properties for backward compatibility for inputs
  45556. /**
  45557. * Gets the input sensibility for a mouse input. (default is 2000.0)
  45558. * Higher values reduce sensitivity.
  45559. */
  45560. get: function () {
  45561. var mouse = this.inputs.attached["mouse"];
  45562. if (mouse)
  45563. return mouse.angularSensibility;
  45564. return 0;
  45565. },
  45566. /**
  45567. * Sets the input sensibility for a mouse input. (default is 2000.0)
  45568. * Higher values reduce sensitivity.
  45569. */
  45570. set: function (value) {
  45571. var mouse = this.inputs.attached["mouse"];
  45572. if (mouse)
  45573. mouse.angularSensibility = value;
  45574. },
  45575. enumerable: true,
  45576. configurable: true
  45577. });
  45578. Object.defineProperty(FreeCamera.prototype, "keysUp", {
  45579. get: function () {
  45580. var keyboard = this.inputs.attached["keyboard"];
  45581. if (keyboard)
  45582. return keyboard.keysUp;
  45583. return [];
  45584. },
  45585. set: function (value) {
  45586. var keyboard = this.inputs.attached["keyboard"];
  45587. if (keyboard)
  45588. keyboard.keysUp = value;
  45589. },
  45590. enumerable: true,
  45591. configurable: true
  45592. });
  45593. Object.defineProperty(FreeCamera.prototype, "keysDown", {
  45594. get: function () {
  45595. var keyboard = this.inputs.attached["keyboard"];
  45596. if (keyboard)
  45597. return keyboard.keysDown;
  45598. return [];
  45599. },
  45600. set: function (value) {
  45601. var keyboard = this.inputs.attached["keyboard"];
  45602. if (keyboard)
  45603. keyboard.keysDown = value;
  45604. },
  45605. enumerable: true,
  45606. configurable: true
  45607. });
  45608. Object.defineProperty(FreeCamera.prototype, "keysLeft", {
  45609. get: function () {
  45610. var keyboard = this.inputs.attached["keyboard"];
  45611. if (keyboard)
  45612. return keyboard.keysLeft;
  45613. return [];
  45614. },
  45615. set: function (value) {
  45616. var keyboard = this.inputs.attached["keyboard"];
  45617. if (keyboard)
  45618. keyboard.keysLeft = value;
  45619. },
  45620. enumerable: true,
  45621. configurable: true
  45622. });
  45623. Object.defineProperty(FreeCamera.prototype, "keysRight", {
  45624. get: function () {
  45625. var keyboard = this.inputs.attached["keyboard"];
  45626. if (keyboard)
  45627. return keyboard.keysRight;
  45628. return [];
  45629. },
  45630. set: function (value) {
  45631. var keyboard = this.inputs.attached["keyboard"];
  45632. if (keyboard)
  45633. keyboard.keysRight = value;
  45634. },
  45635. enumerable: true,
  45636. configurable: true
  45637. });
  45638. // Controls
  45639. FreeCamera.prototype.attachControl = function (element, noPreventDefault) {
  45640. this.inputs.attachElement(element, noPreventDefault);
  45641. };
  45642. FreeCamera.prototype.detachControl = function (element) {
  45643. this.inputs.detachElement(element);
  45644. this.cameraDirection = new BABYLON.Vector3(0, 0, 0);
  45645. this.cameraRotation = new BABYLON.Vector2(0, 0);
  45646. };
  45647. Object.defineProperty(FreeCamera.prototype, "collisionMask", {
  45648. get: function () {
  45649. return this._collisionMask;
  45650. },
  45651. set: function (mask) {
  45652. this._collisionMask = !isNaN(mask) ? mask : -1;
  45653. },
  45654. enumerable: true,
  45655. configurable: true
  45656. });
  45657. FreeCamera.prototype._collideWithWorld = function (displacement) {
  45658. var globalPosition;
  45659. if (this.parent) {
  45660. globalPosition = BABYLON.Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());
  45661. }
  45662. else {
  45663. globalPosition = this.position;
  45664. }
  45665. globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);
  45666. this._oldPosition.addInPlace(this.ellipsoidOffset);
  45667. if (!this._collider) {
  45668. this._collider = new BABYLON.Collider();
  45669. }
  45670. this._collider._radius = this.ellipsoid;
  45671. this._collider.collisionMask = this._collisionMask;
  45672. //no need for clone, as long as gravity is not on.
  45673. var actualDisplacement = displacement;
  45674. //add gravity to the direction to prevent the dual-collision checking
  45675. if (this.applyGravity) {
  45676. //this prevents mending with cameraDirection, a global variable of the free camera class.
  45677. actualDisplacement = displacement.add(this.getScene().gravity);
  45678. }
  45679. this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, actualDisplacement, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
  45680. };
  45681. FreeCamera.prototype._checkInputs = function () {
  45682. if (!this._localDirection) {
  45683. this._localDirection = BABYLON.Vector3.Zero();
  45684. this._transformedDirection = BABYLON.Vector3.Zero();
  45685. }
  45686. this.inputs.checkInputs();
  45687. _super.prototype._checkInputs.call(this);
  45688. };
  45689. FreeCamera.prototype._decideIfNeedsToMove = function () {
  45690. return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
  45691. };
  45692. FreeCamera.prototype._updatePosition = function () {
  45693. if (this.checkCollisions && this.getScene().collisionsEnabled) {
  45694. this._collideWithWorld(this.cameraDirection);
  45695. }
  45696. else {
  45697. _super.prototype._updatePosition.call(this);
  45698. }
  45699. };
  45700. FreeCamera.prototype.dispose = function () {
  45701. this.inputs.clear();
  45702. _super.prototype.dispose.call(this);
  45703. };
  45704. FreeCamera.prototype.getClassName = function () {
  45705. return "FreeCamera";
  45706. };
  45707. __decorate([
  45708. BABYLON.serializeAsVector3()
  45709. ], FreeCamera.prototype, "ellipsoid", void 0);
  45710. __decorate([
  45711. BABYLON.serializeAsVector3()
  45712. ], FreeCamera.prototype, "ellipsoidOffset", void 0);
  45713. __decorate([
  45714. BABYLON.serialize()
  45715. ], FreeCamera.prototype, "checkCollisions", void 0);
  45716. __decorate([
  45717. BABYLON.serialize()
  45718. ], FreeCamera.prototype, "applyGravity", void 0);
  45719. return FreeCamera;
  45720. }(BABYLON.TargetCamera));
  45721. BABYLON.FreeCamera = FreeCamera;
  45722. })(BABYLON || (BABYLON = {}));
  45723. //# sourceMappingURL=babylon.freeCamera.js.map
  45724. var BABYLON;
  45725. (function (BABYLON) {
  45726. /**
  45727. * The HemisphericLight simulates the ambient environment light,
  45728. * so the passed direction is the light reflection direction, not the incoming direction.
  45729. */
  45730. var HemisphericLight = /** @class */ (function (_super) {
  45731. __extends(HemisphericLight, _super);
  45732. /**
  45733. * Creates a HemisphericLight object in the scene according to the passed direction (Vector3).
  45734. * The HemisphericLight simulates the ambient environment light, so the passed direction is the light reflection direction, not the incoming direction.
  45735. * The HemisphericLight can't cast shadows.
  45736. * Documentation : http://doc.babylonjs.com/tutorials/lights
  45737. * @param name The friendly name of the light
  45738. * @param direction The direction of the light reflection
  45739. * @param scene The scene the light belongs to
  45740. */
  45741. function HemisphericLight(name, direction, scene) {
  45742. var _this = _super.call(this, name, scene) || this;
  45743. /**
  45744. * The groundColor is the light in the opposite direction to the one specified during creation.
  45745. * You can think of the diffuse and specular light as coming from the centre of the object in the given direction and the groundColor light in the opposite direction.
  45746. */
  45747. _this.groundColor = new BABYLON.Color3(0.0, 0.0, 0.0);
  45748. _this.direction = direction || BABYLON.Vector3.Up();
  45749. return _this;
  45750. }
  45751. HemisphericLight.prototype._buildUniformLayout = function () {
  45752. this._uniformBuffer.addUniform("vLightData", 4);
  45753. this._uniformBuffer.addUniform("vLightDiffuse", 4);
  45754. this._uniformBuffer.addUniform("vLightSpecular", 3);
  45755. this._uniformBuffer.addUniform("vLightGround", 3);
  45756. this._uniformBuffer.addUniform("shadowsInfo", 3);
  45757. this._uniformBuffer.addUniform("depthValues", 2);
  45758. this._uniformBuffer.create();
  45759. };
  45760. /**
  45761. * Returns the string "HemisphericLight".
  45762. * @return The class name
  45763. */
  45764. HemisphericLight.prototype.getClassName = function () {
  45765. return "HemisphericLight";
  45766. };
  45767. /**
  45768. * Sets the HemisphericLight direction towards the passed target (Vector3).
  45769. * Returns the updated direction.
  45770. * @param target The target the direction should point to
  45771. * @return The computed direction
  45772. */
  45773. HemisphericLight.prototype.setDirectionToTarget = function (target) {
  45774. this.direction = BABYLON.Vector3.Normalize(target.subtract(BABYLON.Vector3.Zero()));
  45775. return this.direction;
  45776. };
  45777. /**
  45778. * Returns the shadow generator associated to the light.
  45779. * @returns Always null for hemispheric lights because it does not support shadows.
  45780. */
  45781. HemisphericLight.prototype.getShadowGenerator = function () {
  45782. return null;
  45783. };
  45784. /**
  45785. * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).
  45786. * @param effect The effect to update
  45787. * @param lightIndex The index of the light in the effect to update
  45788. * @returns The hemispheric light
  45789. */
  45790. HemisphericLight.prototype.transferToEffect = function (effect, lightIndex) {
  45791. var normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
  45792. this._uniformBuffer.updateFloat4("vLightData", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0.0, lightIndex);
  45793. this._uniformBuffer.updateColor3("vLightGround", this.groundColor.scale(this.intensity), lightIndex);
  45794. return this;
  45795. };
  45796. /**
  45797. * @hidden internal use only.
  45798. */
  45799. HemisphericLight.prototype._getWorldMatrix = function () {
  45800. if (!this._worldMatrix) {
  45801. this._worldMatrix = BABYLON.Matrix.Identity();
  45802. }
  45803. return this._worldMatrix;
  45804. };
  45805. /**
  45806. * Returns the integer 3.
  45807. * @return The light Type id as a constant defines in Light.LIGHTTYPEID_x
  45808. */
  45809. HemisphericLight.prototype.getTypeID = function () {
  45810. return BABYLON.Light.LIGHTTYPEID_HEMISPHERICLIGHT;
  45811. };
  45812. __decorate([
  45813. BABYLON.serializeAsColor3()
  45814. ], HemisphericLight.prototype, "groundColor", void 0);
  45815. __decorate([
  45816. BABYLON.serializeAsVector3()
  45817. ], HemisphericLight.prototype, "direction", void 0);
  45818. return HemisphericLight;
  45819. }(BABYLON.Light));
  45820. BABYLON.HemisphericLight = HemisphericLight;
  45821. })(BABYLON || (BABYLON = {}));
  45822. //# sourceMappingURL=babylon.hemisphericLight.js.map
  45823. var BABYLON;
  45824. (function (BABYLON) {
  45825. var ShaderMaterial = /** @class */ (function (_super) {
  45826. __extends(ShaderMaterial, _super);
  45827. function ShaderMaterial(name, scene, shaderPath, options) {
  45828. var _this = _super.call(this, name, scene) || this;
  45829. _this._textures = {};
  45830. _this._textureArrays = {};
  45831. _this._floats = {};
  45832. _this._ints = {};
  45833. _this._floatsArrays = {};
  45834. _this._colors3 = {};
  45835. _this._colors3Arrays = {};
  45836. _this._colors4 = {};
  45837. _this._vectors2 = {};
  45838. _this._vectors3 = {};
  45839. _this._vectors4 = {};
  45840. _this._matrices = {};
  45841. _this._matrices3x3 = {};
  45842. _this._matrices2x2 = {};
  45843. _this._vectors2Arrays = {};
  45844. _this._vectors3Arrays = {};
  45845. _this._cachedWorldViewMatrix = new BABYLON.Matrix();
  45846. _this._shaderPath = shaderPath;
  45847. options.needAlphaBlending = options.needAlphaBlending || false;
  45848. options.needAlphaTesting = options.needAlphaTesting || false;
  45849. options.attributes = options.attributes || ["position", "normal", "uv"];
  45850. options.uniforms = options.uniforms || ["worldViewProjection"];
  45851. options.uniformBuffers = options.uniformBuffers || [];
  45852. options.samplers = options.samplers || [];
  45853. options.defines = options.defines || [];
  45854. _this._options = options;
  45855. return _this;
  45856. }
  45857. ShaderMaterial.prototype.getClassName = function () {
  45858. return "ShaderMaterial";
  45859. };
  45860. ShaderMaterial.prototype.needAlphaBlending = function () {
  45861. return this._options.needAlphaBlending;
  45862. };
  45863. ShaderMaterial.prototype.needAlphaTesting = function () {
  45864. return this._options.needAlphaTesting;
  45865. };
  45866. ShaderMaterial.prototype._checkUniform = function (uniformName) {
  45867. if (this._options.uniforms.indexOf(uniformName) === -1) {
  45868. this._options.uniforms.push(uniformName);
  45869. }
  45870. };
  45871. ShaderMaterial.prototype.setTexture = function (name, texture) {
  45872. if (this._options.samplers.indexOf(name) === -1) {
  45873. this._options.samplers.push(name);
  45874. }
  45875. this._textures[name] = texture;
  45876. return this;
  45877. };
  45878. ShaderMaterial.prototype.setTextureArray = function (name, textures) {
  45879. if (this._options.samplers.indexOf(name) === -1) {
  45880. this._options.samplers.push(name);
  45881. }
  45882. this._checkUniform(name);
  45883. this._textureArrays[name] = textures;
  45884. return this;
  45885. };
  45886. ShaderMaterial.prototype.setFloat = function (name, value) {
  45887. this._checkUniform(name);
  45888. this._floats[name] = value;
  45889. return this;
  45890. };
  45891. ShaderMaterial.prototype.setInt = function (name, value) {
  45892. this._checkUniform(name);
  45893. this._ints[name] = value;
  45894. return this;
  45895. };
  45896. ShaderMaterial.prototype.setFloats = function (name, value) {
  45897. this._checkUniform(name);
  45898. this._floatsArrays[name] = value;
  45899. return this;
  45900. };
  45901. ShaderMaterial.prototype.setColor3 = function (name, value) {
  45902. this._checkUniform(name);
  45903. this._colors3[name] = value;
  45904. return this;
  45905. };
  45906. ShaderMaterial.prototype.setColor3Array = function (name, value) {
  45907. this._checkUniform(name);
  45908. this._colors3Arrays[name] = value.reduce(function (arr, color) {
  45909. color.toArray(arr, arr.length);
  45910. return arr;
  45911. }, []);
  45912. return this;
  45913. };
  45914. ShaderMaterial.prototype.setColor4 = function (name, value) {
  45915. this._checkUniform(name);
  45916. this._colors4[name] = value;
  45917. return this;
  45918. };
  45919. ShaderMaterial.prototype.setVector2 = function (name, value) {
  45920. this._checkUniform(name);
  45921. this._vectors2[name] = value;
  45922. return this;
  45923. };
  45924. ShaderMaterial.prototype.setVector3 = function (name, value) {
  45925. this._checkUniform(name);
  45926. this._vectors3[name] = value;
  45927. return this;
  45928. };
  45929. ShaderMaterial.prototype.setVector4 = function (name, value) {
  45930. this._checkUniform(name);
  45931. this._vectors4[name] = value;
  45932. return this;
  45933. };
  45934. ShaderMaterial.prototype.setMatrix = function (name, value) {
  45935. this._checkUniform(name);
  45936. this._matrices[name] = value;
  45937. return this;
  45938. };
  45939. ShaderMaterial.prototype.setMatrix3x3 = function (name, value) {
  45940. this._checkUniform(name);
  45941. this._matrices3x3[name] = value;
  45942. return this;
  45943. };
  45944. ShaderMaterial.prototype.setMatrix2x2 = function (name, value) {
  45945. this._checkUniform(name);
  45946. this._matrices2x2[name] = value;
  45947. return this;
  45948. };
  45949. ShaderMaterial.prototype.setArray2 = function (name, value) {
  45950. this._checkUniform(name);
  45951. this._vectors2Arrays[name] = value;
  45952. return this;
  45953. };
  45954. ShaderMaterial.prototype.setArray3 = function (name, value) {
  45955. this._checkUniform(name);
  45956. this._vectors3Arrays[name] = value;
  45957. return this;
  45958. };
  45959. ShaderMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  45960. if (!mesh) {
  45961. return true;
  45962. }
  45963. if (this._effect && (this._effect.defines.indexOf("#define INSTANCES") !== -1) !== useInstances) {
  45964. return false;
  45965. }
  45966. return false;
  45967. };
  45968. ShaderMaterial.prototype.isReady = function (mesh, useInstances) {
  45969. var scene = this.getScene();
  45970. var engine = scene.getEngine();
  45971. if (!this.checkReadyOnEveryCall) {
  45972. if (this._renderId === scene.getRenderId()) {
  45973. if (this._checkCache(scene, mesh, useInstances)) {
  45974. return true;
  45975. }
  45976. }
  45977. }
  45978. // Instances
  45979. var defines = [];
  45980. var attribs = [];
  45981. var fallbacks = new BABYLON.EffectFallbacks();
  45982. if (useInstances) {
  45983. defines.push("#define INSTANCES");
  45984. }
  45985. for (var index = 0; index < this._options.defines.length; index++) {
  45986. defines.push(this._options.defines[index]);
  45987. }
  45988. for (var index = 0; index < this._options.attributes.length; index++) {
  45989. attribs.push(this._options.attributes[index]);
  45990. }
  45991. if (mesh && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  45992. attribs.push(BABYLON.VertexBuffer.ColorKind);
  45993. defines.push("#define VERTEXCOLOR");
  45994. }
  45995. // Bones
  45996. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
  45997. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  45998. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  45999. if (mesh.numBoneInfluencers > 4) {
  46000. attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  46001. attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
  46002. }
  46003. defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
  46004. defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
  46005. fallbacks.addCPUSkinningFallback(0, mesh);
  46006. if (this._options.uniforms.indexOf("mBones") === -1) {
  46007. this._options.uniforms.push("mBones");
  46008. }
  46009. }
  46010. else {
  46011. defines.push("#define NUM_BONE_INFLUENCERS 0");
  46012. }
  46013. // Textures
  46014. for (var name in this._textures) {
  46015. if (!this._textures[name].isReady()) {
  46016. return false;
  46017. }
  46018. }
  46019. // Alpha test
  46020. if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
  46021. defines.push("#define ALPHATEST");
  46022. }
  46023. var previousEffect = this._effect;
  46024. var join = defines.join("\n");
  46025. this._effect = engine.createEffect(this._shaderPath, {
  46026. attributes: attribs,
  46027. uniformsNames: this._options.uniforms,
  46028. uniformBuffersNames: this._options.uniformBuffers,
  46029. samplers: this._options.samplers,
  46030. defines: join,
  46031. fallbacks: fallbacks,
  46032. onCompiled: this.onCompiled,
  46033. onError: this.onError
  46034. }, engine);
  46035. if (!this._effect.isReady()) {
  46036. return false;
  46037. }
  46038. if (previousEffect !== this._effect) {
  46039. scene.resetCachedMaterial();
  46040. }
  46041. this._renderId = scene.getRenderId();
  46042. return true;
  46043. };
  46044. ShaderMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  46045. var scene = this.getScene();
  46046. if (!this._effect) {
  46047. return;
  46048. }
  46049. if (this._options.uniforms.indexOf("world") !== -1) {
  46050. this._effect.setMatrix("world", world);
  46051. }
  46052. if (this._options.uniforms.indexOf("worldView") !== -1) {
  46053. world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);
  46054. this._effect.setMatrix("worldView", this._cachedWorldViewMatrix);
  46055. }
  46056. if (this._options.uniforms.indexOf("worldViewProjection") !== -1) {
  46057. this._effect.setMatrix("worldViewProjection", world.multiply(scene.getTransformMatrix()));
  46058. }
  46059. };
  46060. ShaderMaterial.prototype.bind = function (world, mesh) {
  46061. // Std values
  46062. this.bindOnlyWorldMatrix(world);
  46063. if (this._effect && this.getScene().getCachedMaterial() !== this) {
  46064. if (this._options.uniforms.indexOf("view") !== -1) {
  46065. this._effect.setMatrix("view", this.getScene().getViewMatrix());
  46066. }
  46067. if (this._options.uniforms.indexOf("projection") !== -1) {
  46068. this._effect.setMatrix("projection", this.getScene().getProjectionMatrix());
  46069. }
  46070. if (this._options.uniforms.indexOf("viewProjection") !== -1) {
  46071. this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
  46072. }
  46073. // Bones
  46074. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  46075. var name;
  46076. // Texture
  46077. for (name in this._textures) {
  46078. this._effect.setTexture(name, this._textures[name]);
  46079. }
  46080. // Texture arrays
  46081. for (name in this._textureArrays) {
  46082. this._effect.setTextureArray(name, this._textureArrays[name]);
  46083. }
  46084. // Int
  46085. for (name in this._ints) {
  46086. this._effect.setInt(name, this._ints[name]);
  46087. }
  46088. // Float
  46089. for (name in this._floats) {
  46090. this._effect.setFloat(name, this._floats[name]);
  46091. }
  46092. // Floats
  46093. for (name in this._floatsArrays) {
  46094. this._effect.setArray(name, this._floatsArrays[name]);
  46095. }
  46096. // Color3
  46097. for (name in this._colors3) {
  46098. this._effect.setColor3(name, this._colors3[name]);
  46099. }
  46100. for (name in this._colors3Arrays) {
  46101. this._effect.setArray3(name, this._colors3Arrays[name]);
  46102. }
  46103. // Color4
  46104. for (name in this._colors4) {
  46105. var color = this._colors4[name];
  46106. this._effect.setFloat4(name, color.r, color.g, color.b, color.a);
  46107. }
  46108. // Vector2
  46109. for (name in this._vectors2) {
  46110. this._effect.setVector2(name, this._vectors2[name]);
  46111. }
  46112. // Vector3
  46113. for (name in this._vectors3) {
  46114. this._effect.setVector3(name, this._vectors3[name]);
  46115. }
  46116. // Vector4
  46117. for (name in this._vectors4) {
  46118. this._effect.setVector4(name, this._vectors4[name]);
  46119. }
  46120. // Matrix
  46121. for (name in this._matrices) {
  46122. this._effect.setMatrix(name, this._matrices[name]);
  46123. }
  46124. // Matrix 3x3
  46125. for (name in this._matrices3x3) {
  46126. this._effect.setMatrix3x3(name, this._matrices3x3[name]);
  46127. }
  46128. // Matrix 2x2
  46129. for (name in this._matrices2x2) {
  46130. this._effect.setMatrix2x2(name, this._matrices2x2[name]);
  46131. }
  46132. // Vector2Array
  46133. for (name in this._vectors2Arrays) {
  46134. this._effect.setArray2(name, this._vectors2Arrays[name]);
  46135. }
  46136. // Vector3Array
  46137. for (name in this._vectors3Arrays) {
  46138. this._effect.setArray3(name, this._vectors3Arrays[name]);
  46139. }
  46140. }
  46141. this._afterBind(mesh);
  46142. };
  46143. ShaderMaterial.prototype.getActiveTextures = function () {
  46144. var activeTextures = _super.prototype.getActiveTextures.call(this);
  46145. for (var name in this._textures) {
  46146. activeTextures.push(this._textures[name]);
  46147. }
  46148. for (var name in this._textureArrays) {
  46149. var array = this._textureArrays[name];
  46150. for (var index = 0; index < array.length; index++) {
  46151. activeTextures.push(array[index]);
  46152. }
  46153. }
  46154. return activeTextures;
  46155. };
  46156. ShaderMaterial.prototype.hasTexture = function (texture) {
  46157. if (_super.prototype.hasTexture.call(this, texture)) {
  46158. return true;
  46159. }
  46160. for (var name in this._textures) {
  46161. if (this._textures[name] === texture) {
  46162. return true;
  46163. }
  46164. }
  46165. for (var name in this._textureArrays) {
  46166. var array = this._textureArrays[name];
  46167. for (var index = 0; index < array.length; index++) {
  46168. if (array[index] === texture) {
  46169. return true;
  46170. }
  46171. }
  46172. }
  46173. return false;
  46174. };
  46175. ShaderMaterial.prototype.clone = function (name) {
  46176. var newShaderMaterial = new ShaderMaterial(name, this.getScene(), this._shaderPath, this._options);
  46177. return newShaderMaterial;
  46178. };
  46179. ShaderMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  46180. if (forceDisposeTextures) {
  46181. var name;
  46182. for (name in this._textures) {
  46183. this._textures[name].dispose();
  46184. }
  46185. for (name in this._textureArrays) {
  46186. var array = this._textureArrays[name];
  46187. for (var index = 0; index < array.length; index++) {
  46188. array[index].dispose();
  46189. }
  46190. }
  46191. }
  46192. this._textures = {};
  46193. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  46194. };
  46195. ShaderMaterial.prototype.serialize = function () {
  46196. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  46197. serializationObject.customType = "BABYLON.ShaderMaterial";
  46198. serializationObject.options = this._options;
  46199. serializationObject.shaderPath = this._shaderPath;
  46200. var name;
  46201. // Texture
  46202. serializationObject.textures = {};
  46203. for (name in this._textures) {
  46204. serializationObject.textures[name] = this._textures[name].serialize();
  46205. }
  46206. // Texture arrays
  46207. serializationObject.textureArrays = {};
  46208. for (name in this._textureArrays) {
  46209. serializationObject.textureArrays[name] = [];
  46210. var array = this._textureArrays[name];
  46211. for (var index = 0; index < array.length; index++) {
  46212. serializationObject.textureArrays[name].push(array[index].serialize());
  46213. }
  46214. }
  46215. // Float
  46216. serializationObject.floats = {};
  46217. for (name in this._floats) {
  46218. serializationObject.floats[name] = this._floats[name];
  46219. }
  46220. // Float s
  46221. serializationObject.FloatArrays = {};
  46222. for (name in this._floatsArrays) {
  46223. serializationObject.FloatArrays[name] = this._floatsArrays[name];
  46224. }
  46225. // Color3
  46226. serializationObject.colors3 = {};
  46227. for (name in this._colors3) {
  46228. serializationObject.colors3[name] = this._colors3[name].asArray();
  46229. }
  46230. // Color3 array
  46231. serializationObject.colors3Arrays = {};
  46232. for (name in this._colors3Arrays) {
  46233. serializationObject.colors3Arrays[name] = this._colors3Arrays[name];
  46234. }
  46235. // Color4
  46236. serializationObject.colors4 = {};
  46237. for (name in this._colors4) {
  46238. serializationObject.colors4[name] = this._colors4[name].asArray();
  46239. }
  46240. // Vector2
  46241. serializationObject.vectors2 = {};
  46242. for (name in this._vectors2) {
  46243. serializationObject.vectors2[name] = this._vectors2[name].asArray();
  46244. }
  46245. // Vector3
  46246. serializationObject.vectors3 = {};
  46247. for (name in this._vectors3) {
  46248. serializationObject.vectors3[name] = this._vectors3[name].asArray();
  46249. }
  46250. // Vector4
  46251. serializationObject.vectors4 = {};
  46252. for (name in this._vectors4) {
  46253. serializationObject.vectors4[name] = this._vectors4[name].asArray();
  46254. }
  46255. // Matrix
  46256. serializationObject.matrices = {};
  46257. for (name in this._matrices) {
  46258. serializationObject.matrices[name] = this._matrices[name].asArray();
  46259. }
  46260. // Matrix 3x3
  46261. serializationObject.matrices3x3 = {};
  46262. for (name in this._matrices3x3) {
  46263. serializationObject.matrices3x3[name] = this._matrices3x3[name];
  46264. }
  46265. // Matrix 2x2
  46266. serializationObject.matrices2x2 = {};
  46267. for (name in this._matrices2x2) {
  46268. serializationObject.matrices2x2[name] = this._matrices2x2[name];
  46269. }
  46270. // Vector2Array
  46271. serializationObject.vectors2Arrays = {};
  46272. for (name in this._vectors2Arrays) {
  46273. serializationObject.vectors2Arrays[name] = this._vectors2Arrays[name];
  46274. }
  46275. // Vector3Array
  46276. serializationObject.vectors3Arrays = {};
  46277. for (name in this._vectors3Arrays) {
  46278. serializationObject.vectors3Arrays[name] = this._vectors3Arrays[name];
  46279. }
  46280. return serializationObject;
  46281. };
  46282. ShaderMaterial.Parse = function (source, scene, rootUrl) {
  46283. var material = BABYLON.SerializationHelper.Parse(function () { return new ShaderMaterial(source.name, scene, source.shaderPath, source.options); }, source, scene, rootUrl);
  46284. var name;
  46285. // Texture
  46286. for (name in source.textures) {
  46287. material.setTexture(name, BABYLON.Texture.Parse(source.textures[name], scene, rootUrl));
  46288. }
  46289. // Texture arrays
  46290. for (name in source.textureArrays) {
  46291. var array = source.textureArrays[name];
  46292. var textureArray = new Array();
  46293. for (var index = 0; index < array.length; index++) {
  46294. textureArray.push(BABYLON.Texture.Parse(array[index], scene, rootUrl));
  46295. }
  46296. material.setTextureArray(name, textureArray);
  46297. }
  46298. // Float
  46299. for (name in source.floats) {
  46300. material.setFloat(name, source.floats[name]);
  46301. }
  46302. // Float s
  46303. for (name in source.floatsArrays) {
  46304. material.setFloats(name, source.floatsArrays[name]);
  46305. }
  46306. // Color3
  46307. for (name in source.colors3) {
  46308. material.setColor3(name, BABYLON.Color3.FromArray(source.colors3[name]));
  46309. }
  46310. // Color3 arrays
  46311. for (name in source.colors3Arrays) {
  46312. var colors = source.colors3Arrays[name].reduce(function (arr, num, i) {
  46313. if (i % 3 === 0) {
  46314. arr.push([num]);
  46315. }
  46316. else {
  46317. arr[arr.length - 1].push(num);
  46318. }
  46319. return arr;
  46320. }, []).map(function (color) { return BABYLON.Color3.FromArray(color); });
  46321. material.setColor3Array(name, colors);
  46322. }
  46323. // Color4
  46324. for (name in source.colors4) {
  46325. material.setColor4(name, BABYLON.Color4.FromArray(source.colors4[name]));
  46326. }
  46327. // Vector2
  46328. for (name in source.vectors2) {
  46329. material.setVector2(name, BABYLON.Vector2.FromArray(source.vectors2[name]));
  46330. }
  46331. // Vector3
  46332. for (name in source.vectors3) {
  46333. material.setVector3(name, BABYLON.Vector3.FromArray(source.vectors3[name]));
  46334. }
  46335. // Vector4
  46336. for (name in source.vectors4) {
  46337. material.setVector4(name, BABYLON.Vector4.FromArray(source.vectors4[name]));
  46338. }
  46339. // Matrix
  46340. for (name in source.matrices) {
  46341. material.setMatrix(name, BABYLON.Matrix.FromArray(source.matrices[name]));
  46342. }
  46343. // Matrix 3x3
  46344. for (name in source.matrices3x3) {
  46345. material.setMatrix3x3(name, source.matrices3x3[name]);
  46346. }
  46347. // Matrix 2x2
  46348. for (name in source.matrices2x2) {
  46349. material.setMatrix2x2(name, source.matrices2x2[name]);
  46350. }
  46351. // Vector2Array
  46352. for (name in source.vectors2Arrays) {
  46353. material.setArray2(name, source.vectors2Arrays[name]);
  46354. }
  46355. // Vector3Array
  46356. for (name in source.vectors3Arrays) {
  46357. material.setArray3(name, source.vectors3Arrays[name]);
  46358. }
  46359. return material;
  46360. };
  46361. return ShaderMaterial;
  46362. }(BABYLON.Material));
  46363. BABYLON.ShaderMaterial = ShaderMaterial;
  46364. })(BABYLON || (BABYLON = {}));
  46365. //# sourceMappingURL=babylon.shaderMaterial.js.map
  46366. var BABYLON;
  46367. (function (BABYLON) {
  46368. var GroundMesh = /** @class */ (function (_super) {
  46369. __extends(GroundMesh, _super);
  46370. function GroundMesh(name, scene) {
  46371. var _this = _super.call(this, name, scene) || this;
  46372. _this.generateOctree = false;
  46373. return _this;
  46374. }
  46375. GroundMesh.prototype.getClassName = function () {
  46376. return "GroundMesh";
  46377. };
  46378. Object.defineProperty(GroundMesh.prototype, "subdivisions", {
  46379. get: function () {
  46380. return Math.min(this._subdivisionsX, this._subdivisionsY);
  46381. },
  46382. enumerable: true,
  46383. configurable: true
  46384. });
  46385. Object.defineProperty(GroundMesh.prototype, "subdivisionsX", {
  46386. get: function () {
  46387. return this._subdivisionsX;
  46388. },
  46389. enumerable: true,
  46390. configurable: true
  46391. });
  46392. Object.defineProperty(GroundMesh.prototype, "subdivisionsY", {
  46393. get: function () {
  46394. return this._subdivisionsY;
  46395. },
  46396. enumerable: true,
  46397. configurable: true
  46398. });
  46399. GroundMesh.prototype.optimize = function (chunksCount, octreeBlocksSize) {
  46400. if (octreeBlocksSize === void 0) { octreeBlocksSize = 32; }
  46401. this._subdivisionsX = chunksCount;
  46402. this._subdivisionsY = chunksCount;
  46403. this.subdivide(chunksCount);
  46404. this.createOrUpdateSubmeshesOctree(octreeBlocksSize);
  46405. };
  46406. /**
  46407. * Returns a height (y) value in the Worl system :
  46408. * the ground altitude at the coordinates (x, z) expressed in the World system.
  46409. * Returns the ground y position if (x, z) are outside the ground surface.
  46410. */
  46411. GroundMesh.prototype.getHeightAtCoordinates = function (x, z) {
  46412. var world = this.getWorldMatrix();
  46413. var invMat = BABYLON.Tmp.Matrix[5];
  46414. world.invertToRef(invMat);
  46415. var tmpVect = BABYLON.Tmp.Vector3[8];
  46416. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, invMat, tmpVect); // transform x,z in the mesh local space
  46417. x = tmpVect.x;
  46418. z = tmpVect.z;
  46419. if (x < this._minX || x > this._maxX || z < this._minZ || z > this._maxZ) {
  46420. return this.position.y;
  46421. }
  46422. if (!this._heightQuads || this._heightQuads.length == 0) {
  46423. this._initHeightQuads();
  46424. this._computeHeightQuads();
  46425. }
  46426. var facet = this._getFacetAt(x, z);
  46427. var y = -(facet.x * x + facet.z * z + facet.w) / facet.y;
  46428. // return y in the World system
  46429. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(0.0, y, 0.0, world, tmpVect);
  46430. return tmpVect.y;
  46431. };
  46432. /**
  46433. * Returns a normalized vector (Vector3) orthogonal to the ground
  46434. * at the ground coordinates (x, z) expressed in the World system.
  46435. * Returns Vector3(0.0, 1.0, 0.0) if (x, z) are outside the ground surface.
  46436. */
  46437. GroundMesh.prototype.getNormalAtCoordinates = function (x, z) {
  46438. var normal = new BABYLON.Vector3(0.0, 1.0, 0.0);
  46439. this.getNormalAtCoordinatesToRef(x, z, normal);
  46440. return normal;
  46441. };
  46442. /**
  46443. * Updates the Vector3 passed a reference with a normalized vector orthogonal to the ground
  46444. * at the ground coordinates (x, z) expressed in the World system.
  46445. * Doesn't uptade the reference Vector3 if (x, z) are outside the ground surface.
  46446. * Returns the GroundMesh.
  46447. */
  46448. GroundMesh.prototype.getNormalAtCoordinatesToRef = function (x, z, ref) {
  46449. var world = this.getWorldMatrix();
  46450. var tmpMat = BABYLON.Tmp.Matrix[5];
  46451. world.invertToRef(tmpMat);
  46452. var tmpVect = BABYLON.Tmp.Vector3[8];
  46453. BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, tmpMat, tmpVect); // transform x,z in the mesh local space
  46454. x = tmpVect.x;
  46455. z = tmpVect.z;
  46456. if (x < this._minX || x > this._maxX || z < this._minZ || z > this._maxZ) {
  46457. return this;
  46458. }
  46459. if (!this._heightQuads || this._heightQuads.length == 0) {
  46460. this._initHeightQuads();
  46461. this._computeHeightQuads();
  46462. }
  46463. var facet = this._getFacetAt(x, z);
  46464. BABYLON.Vector3.TransformNormalFromFloatsToRef(facet.x, facet.y, facet.z, world, ref);
  46465. return this;
  46466. };
  46467. /**
  46468. * Force the heights to be recomputed for getHeightAtCoordinates() or getNormalAtCoordinates()
  46469. * if the ground has been updated.
  46470. * This can be used in the render loop.
  46471. * Returns the GroundMesh.
  46472. */
  46473. GroundMesh.prototype.updateCoordinateHeights = function () {
  46474. if (!this._heightQuads || this._heightQuads.length == 0) {
  46475. this._initHeightQuads();
  46476. }
  46477. this._computeHeightQuads();
  46478. return this;
  46479. };
  46480. // Returns the element "facet" from the heightQuads array relative to (x, z) local coordinates
  46481. GroundMesh.prototype._getFacetAt = function (x, z) {
  46482. // retrieve col and row from x, z coordinates in the ground local system
  46483. var col = Math.floor((x + this._maxX) * this._subdivisionsX / this._width);
  46484. var row = Math.floor(-(z + this._maxZ) * this._subdivisionsY / this._height + this._subdivisionsY);
  46485. var quad = this._heightQuads[row * this._subdivisionsX + col];
  46486. var facet;
  46487. if (z < quad.slope.x * x + quad.slope.y) {
  46488. facet = quad.facet1;
  46489. }
  46490. else {
  46491. facet = quad.facet2;
  46492. }
  46493. return facet;
  46494. };
  46495. // Creates and populates the heightMap array with "facet" elements :
  46496. // a quad is two triangular facets separated by a slope, so a "facet" element is 1 slope + 2 facets
  46497. // slope : Vector2(c, h) = 2D diagonal line equation setting appart two triangular facets in a quad : z = cx + h
  46498. // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0
  46499. // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0
  46500. // Returns the GroundMesh.
  46501. GroundMesh.prototype._initHeightQuads = function () {
  46502. var subdivisionsX = this._subdivisionsX;
  46503. var subdivisionsY = this._subdivisionsY;
  46504. this._heightQuads = new Array();
  46505. for (var row = 0; row < subdivisionsY; row++) {
  46506. for (var col = 0; col < subdivisionsX; col++) {
  46507. var quad = { slope: BABYLON.Vector2.Zero(), facet1: new BABYLON.Vector4(0.0, 0.0, 0.0, 0.0), facet2: new BABYLON.Vector4(0.0, 0.0, 0.0, 0.0) };
  46508. this._heightQuads[row * subdivisionsX + col] = quad;
  46509. }
  46510. }
  46511. return this;
  46512. };
  46513. // Compute each quad element values and update the the heightMap array :
  46514. // slope : Vector2(c, h) = 2D diagonal line equation setting appart two triangular facets in a quad : z = cx + h
  46515. // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0
  46516. // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0
  46517. // Returns the GroundMesh.
  46518. GroundMesh.prototype._computeHeightQuads = function () {
  46519. var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  46520. if (!positions) {
  46521. return this;
  46522. }
  46523. var v1 = BABYLON.Tmp.Vector3[3];
  46524. var v2 = BABYLON.Tmp.Vector3[2];
  46525. var v3 = BABYLON.Tmp.Vector3[1];
  46526. var v4 = BABYLON.Tmp.Vector3[0];
  46527. var v1v2 = BABYLON.Tmp.Vector3[4];
  46528. var v1v3 = BABYLON.Tmp.Vector3[5];
  46529. var v1v4 = BABYLON.Tmp.Vector3[6];
  46530. var norm1 = BABYLON.Tmp.Vector3[7];
  46531. var norm2 = BABYLON.Tmp.Vector3[8];
  46532. var i = 0;
  46533. var j = 0;
  46534. var k = 0;
  46535. var cd = 0; // 2D slope coefficient : z = cd * x + h
  46536. var h = 0;
  46537. var d1 = 0; // facet plane equation : ax + by + cz + d = 0
  46538. var d2 = 0;
  46539. var subdivisionsX = this._subdivisionsX;
  46540. var subdivisionsY = this._subdivisionsY;
  46541. for (var row = 0; row < subdivisionsY; row++) {
  46542. for (var col = 0; col < subdivisionsX; col++) {
  46543. i = col * 3;
  46544. j = row * (subdivisionsX + 1) * 3;
  46545. k = (row + 1) * (subdivisionsX + 1) * 3;
  46546. v1.x = positions[j + i];
  46547. v1.y = positions[j + i + 1];
  46548. v1.z = positions[j + i + 2];
  46549. v2.x = positions[j + i + 3];
  46550. v2.y = positions[j + i + 4];
  46551. v2.z = positions[j + i + 5];
  46552. v3.x = positions[k + i];
  46553. v3.y = positions[k + i + 1];
  46554. v3.z = positions[k + i + 2];
  46555. v4.x = positions[k + i + 3];
  46556. v4.y = positions[k + i + 4];
  46557. v4.z = positions[k + i + 5];
  46558. // 2D slope V1V4
  46559. cd = (v4.z - v1.z) / (v4.x - v1.x);
  46560. h = v1.z - cd * v1.x; // v1 belongs to the slope
  46561. // facet equations :
  46562. // we compute each facet normal vector
  46563. // the equation of the facet plane is : norm.x * x + norm.y * y + norm.z * z + d = 0
  46564. // we compute the value d by applying the equation to v1 which belongs to the plane
  46565. // then we store the facet equation in a Vector4
  46566. v2.subtractToRef(v1, v1v2);
  46567. v3.subtractToRef(v1, v1v3);
  46568. v4.subtractToRef(v1, v1v4);
  46569. BABYLON.Vector3.CrossToRef(v1v4, v1v3, norm1); // caution : CrossToRef uses the Tmp class
  46570. BABYLON.Vector3.CrossToRef(v1v2, v1v4, norm2);
  46571. norm1.normalize();
  46572. norm2.normalize();
  46573. d1 = -(norm1.x * v1.x + norm1.y * v1.y + norm1.z * v1.z);
  46574. d2 = -(norm2.x * v2.x + norm2.y * v2.y + norm2.z * v2.z);
  46575. var quad = this._heightQuads[row * subdivisionsX + col];
  46576. quad.slope.copyFromFloats(cd, h);
  46577. quad.facet1.copyFromFloats(norm1.x, norm1.y, norm1.z, d1);
  46578. quad.facet2.copyFromFloats(norm2.x, norm2.y, norm2.z, d2);
  46579. }
  46580. }
  46581. return this;
  46582. };
  46583. GroundMesh.prototype.serialize = function (serializationObject) {
  46584. _super.prototype.serialize.call(this, serializationObject);
  46585. serializationObject.subdivisionsX = this._subdivisionsX;
  46586. serializationObject.subdivisionsY = this._subdivisionsY;
  46587. serializationObject.minX = this._minX;
  46588. serializationObject.maxX = this._maxX;
  46589. serializationObject.minZ = this._minZ;
  46590. serializationObject.maxZ = this._maxZ;
  46591. serializationObject.width = this._width;
  46592. serializationObject.height = this._height;
  46593. };
  46594. GroundMesh.Parse = function (parsedMesh, scene) {
  46595. var result = new GroundMesh(parsedMesh.name, scene);
  46596. result._subdivisionsX = parsedMesh.subdivisionsX || 1;
  46597. result._subdivisionsY = parsedMesh.subdivisionsY || 1;
  46598. result._minX = parsedMesh.minX;
  46599. result._maxX = parsedMesh.maxX;
  46600. result._minZ = parsedMesh.minZ;
  46601. result._maxZ = parsedMesh.maxZ;
  46602. result._width = parsedMesh.width;
  46603. result._height = parsedMesh.height;
  46604. return result;
  46605. };
  46606. return GroundMesh;
  46607. }(BABYLON.Mesh));
  46608. BABYLON.GroundMesh = GroundMesh;
  46609. })(BABYLON || (BABYLON = {}));
  46610. //# sourceMappingURL=babylon.groundMesh.js.map
  46611. var BABYLON;
  46612. (function (BABYLON) {
  46613. /**
  46614. * Creates an instance based on a source mesh.
  46615. */
  46616. var InstancedMesh = /** @class */ (function (_super) {
  46617. __extends(InstancedMesh, _super);
  46618. function InstancedMesh(name, source) {
  46619. var _this = _super.call(this, name, source.getScene()) || this;
  46620. source.instances.push(_this);
  46621. _this._sourceMesh = source;
  46622. _this.position.copyFrom(source.position);
  46623. _this.rotation.copyFrom(source.rotation);
  46624. _this.scaling.copyFrom(source.scaling);
  46625. if (source.rotationQuaternion) {
  46626. _this.rotationQuaternion = source.rotationQuaternion.clone();
  46627. }
  46628. _this.infiniteDistance = source.infiniteDistance;
  46629. _this.setPivotMatrix(source.getPivotMatrix());
  46630. _this.refreshBoundingInfo();
  46631. _this._syncSubMeshes();
  46632. return _this;
  46633. }
  46634. /**
  46635. * Returns the string "InstancedMesh".
  46636. */
  46637. InstancedMesh.prototype.getClassName = function () {
  46638. return "InstancedMesh";
  46639. };
  46640. Object.defineProperty(InstancedMesh.prototype, "receiveShadows", {
  46641. // Methods
  46642. get: function () {
  46643. return this._sourceMesh.receiveShadows;
  46644. },
  46645. enumerable: true,
  46646. configurable: true
  46647. });
  46648. Object.defineProperty(InstancedMesh.prototype, "material", {
  46649. get: function () {
  46650. return this._sourceMesh.material;
  46651. },
  46652. enumerable: true,
  46653. configurable: true
  46654. });
  46655. Object.defineProperty(InstancedMesh.prototype, "visibility", {
  46656. get: function () {
  46657. return this._sourceMesh.visibility;
  46658. },
  46659. enumerable: true,
  46660. configurable: true
  46661. });
  46662. Object.defineProperty(InstancedMesh.prototype, "skeleton", {
  46663. get: function () {
  46664. return this._sourceMesh.skeleton;
  46665. },
  46666. enumerable: true,
  46667. configurable: true
  46668. });
  46669. Object.defineProperty(InstancedMesh.prototype, "renderingGroupId", {
  46670. get: function () {
  46671. return this._sourceMesh.renderingGroupId;
  46672. },
  46673. set: function (value) {
  46674. if (!this._sourceMesh || value === this._sourceMesh.renderingGroupId) {
  46675. return;
  46676. }
  46677. //no-op with warning
  46678. BABYLON.Tools.Warn("Note - setting renderingGroupId of an instanced mesh has no effect on the scene");
  46679. },
  46680. enumerable: true,
  46681. configurable: true
  46682. });
  46683. /**
  46684. * Returns the total number of vertices (integer).
  46685. */
  46686. InstancedMesh.prototype.getTotalVertices = function () {
  46687. return this._sourceMesh.getTotalVertices();
  46688. };
  46689. Object.defineProperty(InstancedMesh.prototype, "sourceMesh", {
  46690. get: function () {
  46691. return this._sourceMesh;
  46692. },
  46693. enumerable: true,
  46694. configurable: true
  46695. });
  46696. /**
  46697. * Is this node ready to be used/rendered
  46698. * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
  46699. * @return {boolean} is it ready
  46700. */
  46701. InstancedMesh.prototype.isReady = function (completeCheck) {
  46702. if (completeCheck === void 0) { completeCheck = false; }
  46703. return this._sourceMesh.isReady(completeCheck, true);
  46704. };
  46705. /**
  46706. * Returns a float array or a Float32Array of the requested kind of data : positons, normals, uvs, etc.
  46707. */
  46708. InstancedMesh.prototype.getVerticesData = function (kind, copyWhenShared) {
  46709. return this._sourceMesh.getVerticesData(kind, copyWhenShared);
  46710. };
  46711. /**
  46712. * Sets the vertex data of the mesh geometry for the requested `kind`.
  46713. * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.
  46714. * The `data` are either a numeric array either a Float32Array.
  46715. * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initianilly none) or updater.
  46716. * The parameter `stride` is an optional positive integer, it is usually automatically deducted from the `kind` (3 for positions or normals, 2 for UV, etc).
  46717. * Note that a new underlying VertexBuffer object is created each call.
  46718. * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
  46719. *
  46720. * Possible `kind` values :
  46721. * - BABYLON.VertexBuffer.PositionKind
  46722. * - BABYLON.VertexBuffer.UVKind
  46723. * - BABYLON.VertexBuffer.UV2Kind
  46724. * - BABYLON.VertexBuffer.UV3Kind
  46725. * - BABYLON.VertexBuffer.UV4Kind
  46726. * - BABYLON.VertexBuffer.UV5Kind
  46727. * - BABYLON.VertexBuffer.UV6Kind
  46728. * - BABYLON.VertexBuffer.ColorKind
  46729. * - BABYLON.VertexBuffer.MatricesIndicesKind
  46730. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  46731. * - BABYLON.VertexBuffer.MatricesWeightsKind
  46732. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  46733. *
  46734. * Returns the Mesh.
  46735. */
  46736. InstancedMesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
  46737. if (this.sourceMesh) {
  46738. this.sourceMesh.setVerticesData(kind, data, updatable, stride);
  46739. }
  46740. return this.sourceMesh;
  46741. };
  46742. /**
  46743. * Updates the existing vertex data of the mesh geometry for the requested `kind`.
  46744. * If the mesh has no geometry, it is simply returned as it is.
  46745. * The `data` are either a numeric array either a Float32Array.
  46746. * No new underlying VertexBuffer object is created.
  46747. * If the `kind` is the `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
  46748. * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.
  46749. *
  46750. * Possible `kind` values :
  46751. * - BABYLON.VertexBuffer.PositionKind
  46752. * - BABYLON.VertexBuffer.UVKind
  46753. * - BABYLON.VertexBuffer.UV2Kind
  46754. * - BABYLON.VertexBuffer.UV3Kind
  46755. * - BABYLON.VertexBuffer.UV4Kind
  46756. * - BABYLON.VertexBuffer.UV5Kind
  46757. * - BABYLON.VertexBuffer.UV6Kind
  46758. * - BABYLON.VertexBuffer.ColorKind
  46759. * - BABYLON.VertexBuffer.MatricesIndicesKind
  46760. * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
  46761. * - BABYLON.VertexBuffer.MatricesWeightsKind
  46762. * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
  46763. *
  46764. * Returns the Mesh.
  46765. */
  46766. InstancedMesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
  46767. if (this.sourceMesh) {
  46768. this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);
  46769. }
  46770. return this.sourceMesh;
  46771. };
  46772. /**
  46773. * Sets the mesh indices.
  46774. * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).
  46775. * If the mesh has no geometry, a new Geometry object is created and set to the mesh.
  46776. * This method creates a new index buffer each call.
  46777. * Returns the Mesh.
  46778. */
  46779. InstancedMesh.prototype.setIndices = function (indices, totalVertices) {
  46780. if (totalVertices === void 0) { totalVertices = null; }
  46781. if (this.sourceMesh) {
  46782. this.sourceMesh.setIndices(indices, totalVertices);
  46783. }
  46784. return this.sourceMesh;
  46785. };
  46786. /**
  46787. * Boolean : True if the mesh owns the requested kind of data.
  46788. */
  46789. InstancedMesh.prototype.isVerticesDataPresent = function (kind) {
  46790. return this._sourceMesh.isVerticesDataPresent(kind);
  46791. };
  46792. /**
  46793. * Returns an array of indices (IndicesArray).
  46794. */
  46795. InstancedMesh.prototype.getIndices = function () {
  46796. return this._sourceMesh.getIndices();
  46797. };
  46798. Object.defineProperty(InstancedMesh.prototype, "_positions", {
  46799. get: function () {
  46800. return this._sourceMesh._positions;
  46801. },
  46802. enumerable: true,
  46803. configurable: true
  46804. });
  46805. /**
  46806. * Sets a new updated BoundingInfo to the mesh.
  46807. * Returns the mesh.
  46808. */
  46809. InstancedMesh.prototype.refreshBoundingInfo = function () {
  46810. var meshBB = this._sourceMesh.getBoundingInfo();
  46811. this._boundingInfo = new BABYLON.BoundingInfo(meshBB.minimum.clone(), meshBB.maximum.clone());
  46812. this._updateBoundingInfo();
  46813. return this;
  46814. };
  46815. InstancedMesh.prototype._preActivate = function () {
  46816. if (this._currentLOD) {
  46817. this._currentLOD._preActivate();
  46818. }
  46819. return this;
  46820. };
  46821. InstancedMesh.prototype._activate = function (renderId) {
  46822. if (this._currentLOD) {
  46823. this._currentLOD._registerInstanceForRenderId(this, renderId);
  46824. }
  46825. return this;
  46826. };
  46827. /**
  46828. * Returns the current associated LOD AbstractMesh.
  46829. */
  46830. InstancedMesh.prototype.getLOD = function (camera) {
  46831. if (!camera) {
  46832. return this;
  46833. }
  46834. var boundingInfo = this.getBoundingInfo();
  46835. this._currentLOD = this.sourceMesh.getLOD(camera, boundingInfo.boundingSphere);
  46836. if (this._currentLOD === this.sourceMesh) {
  46837. return this;
  46838. }
  46839. return this._currentLOD;
  46840. };
  46841. InstancedMesh.prototype._syncSubMeshes = function () {
  46842. this.releaseSubMeshes();
  46843. if (this._sourceMesh.subMeshes) {
  46844. for (var index = 0; index < this._sourceMesh.subMeshes.length; index++) {
  46845. this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);
  46846. }
  46847. }
  46848. return this;
  46849. };
  46850. InstancedMesh.prototype._generatePointsArray = function () {
  46851. return this._sourceMesh._generatePointsArray();
  46852. };
  46853. /**
  46854. * Creates a new InstancedMesh from the current mesh.
  46855. * - name (string) : the cloned mesh name
  46856. * - newParent (optional Node) : the optional Node to parent the clone to.
  46857. * - doNotCloneChildren (optional boolean, default `false`) : if `true` the model children aren't cloned.
  46858. *
  46859. * Returns the clone.
  46860. */
  46861. InstancedMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  46862. var result = this._sourceMesh.createInstance(name);
  46863. // Deep copy
  46864. BABYLON.Tools.DeepCopy(this, result, ["name", "subMeshes", "uniqueId"], []);
  46865. // Bounding info
  46866. this.refreshBoundingInfo();
  46867. // Parent
  46868. if (newParent) {
  46869. result.parent = newParent;
  46870. }
  46871. if (!doNotCloneChildren) {
  46872. // Children
  46873. for (var index = 0; index < this.getScene().meshes.length; index++) {
  46874. var mesh = this.getScene().meshes[index];
  46875. if (mesh.parent === this) {
  46876. mesh.clone(mesh.name, result);
  46877. }
  46878. }
  46879. }
  46880. result.computeWorldMatrix(true);
  46881. return result;
  46882. };
  46883. /**
  46884. * Disposes the InstancedMesh.
  46885. * Returns nothing.
  46886. */
  46887. InstancedMesh.prototype.dispose = function (doNotRecurse, disposeMaterialAndTextures) {
  46888. if (disposeMaterialAndTextures === void 0) { disposeMaterialAndTextures = false; }
  46889. // Remove from mesh
  46890. var index = this._sourceMesh.instances.indexOf(this);
  46891. this._sourceMesh.instances.splice(index, 1);
  46892. _super.prototype.dispose.call(this, doNotRecurse, disposeMaterialAndTextures);
  46893. };
  46894. return InstancedMesh;
  46895. }(BABYLON.AbstractMesh));
  46896. BABYLON.InstancedMesh = InstancedMesh;
  46897. })(BABYLON || (BABYLON = {}));
  46898. //# sourceMappingURL=babylon.instancedMesh.js.map
  46899. var BABYLON;
  46900. (function (BABYLON) {
  46901. var LinesMesh = /** @class */ (function (_super) {
  46902. __extends(LinesMesh, _super);
  46903. function LinesMesh(name, scene, parent, source, doNotCloneChildren, useVertexColor, useVertexAlpha) {
  46904. if (scene === void 0) { scene = null; }
  46905. if (parent === void 0) { parent = null; }
  46906. var _this = _super.call(this, name, scene, parent, source, doNotCloneChildren) || this;
  46907. _this.useVertexColor = useVertexColor;
  46908. _this.useVertexAlpha = useVertexAlpha;
  46909. _this.color = new BABYLON.Color3(1, 1, 1);
  46910. _this.alpha = 1;
  46911. if (source) {
  46912. _this.color = source.color.clone();
  46913. _this.alpha = source.alpha;
  46914. _this.useVertexColor = source.useVertexColor;
  46915. _this.useVertexAlpha = source.useVertexAlpha;
  46916. }
  46917. _this._intersectionThreshold = 0.1;
  46918. var defines = [];
  46919. var options = {
  46920. attributes: [BABYLON.VertexBuffer.PositionKind],
  46921. uniforms: ["world", "viewProjection"],
  46922. needAlphaBlending: true,
  46923. defines: defines
  46924. };
  46925. if (useVertexAlpha === false) {
  46926. options.needAlphaBlending = false;
  46927. }
  46928. if (!useVertexColor) {
  46929. options.uniforms.push("color");
  46930. }
  46931. else {
  46932. options.defines.push("#define VERTEXCOLOR");
  46933. options.attributes.push(BABYLON.VertexBuffer.ColorKind);
  46934. }
  46935. _this._colorShader = new BABYLON.ShaderMaterial("colorShader", _this.getScene(), "color", options);
  46936. return _this;
  46937. }
  46938. Object.defineProperty(LinesMesh.prototype, "intersectionThreshold", {
  46939. /**
  46940. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  46941. * This margin is expressed in world space coordinates, so its value may vary.
  46942. * Default value is 0.1
  46943. * @returns the intersection Threshold value.
  46944. */
  46945. get: function () {
  46946. return this._intersectionThreshold;
  46947. },
  46948. /**
  46949. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  46950. * This margin is expressed in world space coordinates, so its value may vary.
  46951. * @param value the new threshold to apply
  46952. */
  46953. set: function (value) {
  46954. if (this._intersectionThreshold === value) {
  46955. return;
  46956. }
  46957. this._intersectionThreshold = value;
  46958. if (this.geometry) {
  46959. this.geometry.boundingBias = new BABYLON.Vector2(0, value);
  46960. }
  46961. },
  46962. enumerable: true,
  46963. configurable: true
  46964. });
  46965. /**
  46966. * Returns the string "LineMesh"
  46967. */
  46968. LinesMesh.prototype.getClassName = function () {
  46969. return "LinesMesh";
  46970. };
  46971. Object.defineProperty(LinesMesh.prototype, "material", {
  46972. get: function () {
  46973. return this._colorShader;
  46974. },
  46975. set: function (value) {
  46976. // Do nothing
  46977. },
  46978. enumerable: true,
  46979. configurable: true
  46980. });
  46981. Object.defineProperty(LinesMesh.prototype, "checkCollisions", {
  46982. get: function () {
  46983. return false;
  46984. },
  46985. enumerable: true,
  46986. configurable: true
  46987. });
  46988. LinesMesh.prototype.createInstance = function (name) {
  46989. throw new Error("LinesMeshes do not support createInstance.");
  46990. };
  46991. LinesMesh.prototype._bind = function (subMesh, effect, fillMode) {
  46992. if (!this._geometry) {
  46993. return this;
  46994. }
  46995. // VBOs
  46996. this._geometry._bind(this._colorShader.getEffect());
  46997. // Color
  46998. if (!this.useVertexColor) {
  46999. this._colorShader.setColor4("color", this.color.toColor4(this.alpha));
  47000. }
  47001. return this;
  47002. };
  47003. LinesMesh.prototype._draw = function (subMesh, fillMode, instancesCount) {
  47004. if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
  47005. return this;
  47006. }
  47007. var engine = this.getScene().getEngine();
  47008. // Draw order
  47009. engine.drawElementsType(BABYLON.Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount);
  47010. return this;
  47011. };
  47012. LinesMesh.prototype.dispose = function (doNotRecurse) {
  47013. this._colorShader.dispose();
  47014. _super.prototype.dispose.call(this, doNotRecurse);
  47015. };
  47016. /**
  47017. * Returns a new LineMesh object cloned from the current one.
  47018. */
  47019. LinesMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  47020. return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
  47021. };
  47022. return LinesMesh;
  47023. }(BABYLON.Mesh));
  47024. BABYLON.LinesMesh = LinesMesh;
  47025. })(BABYLON || (BABYLON = {}));
  47026. //# sourceMappingURL=babylon.linesMesh.js.map
  47027. var BABYLON;
  47028. (function (BABYLON) {
  47029. /**
  47030. * Class containing static functions to help procedurally build meshes
  47031. */
  47032. var MeshBuilder = /** @class */ (function () {
  47033. function MeshBuilder() {
  47034. }
  47035. MeshBuilder.updateSideOrientation = function (orientation) {
  47036. if (orientation == BABYLON.Mesh.DOUBLESIDE) {
  47037. return BABYLON.Mesh.DOUBLESIDE;
  47038. }
  47039. if (orientation === undefined || orientation === null) {
  47040. return BABYLON.Mesh.FRONTSIDE;
  47041. }
  47042. return orientation;
  47043. };
  47044. /**
  47045. * Creates a box mesh
  47046. * * The parameter `size` sets the size (float) of each box side (default 1)
  47047. * * You can set some different box dimensions by using the parameters `width`, `height` and `depth` (all by default have the same value than `size`)
  47048. * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of 6 Color3 elements) and `faceUV` (an array of 6 Vector4 elements)
  47049. * * Please read this tutorial : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  47050. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47051. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47052. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47053. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box
  47054. * @param name defines the name of the mesh
  47055. * @param options defines the options used to create the mesh
  47056. * @param scene defines the hosting scene
  47057. * @returns the box mesh
  47058. */
  47059. MeshBuilder.CreateBox = function (name, options, scene) {
  47060. if (scene === void 0) { scene = null; }
  47061. var box = new BABYLON.Mesh(name, scene);
  47062. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47063. box._originalBuilderSideOrientation = options.sideOrientation;
  47064. var vertexData = BABYLON.VertexData.CreateBox(options);
  47065. vertexData.applyToMesh(box, options.updatable);
  47066. return box;
  47067. };
  47068. /**
  47069. * Creates a sphere mesh
  47070. * * The parameter `diameter` sets the diameter size (float) of the sphere (default 1)
  47071. * * You can set some different sphere dimensions, for instance to build an ellipsoid, by using the parameters `diameterX`, `diameterY` and `diameterZ` (all by default have the same value than `diameter`)
  47072. * * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32)
  47073. * * You can create an unclosed sphere with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference (latitude) : 2 x PI x ratio
  47074. * * You can create an unclosed sphere on its height with the parameter `slice` (positive float, default1), valued between 0 and 1, what is the height ratio (longitude)
  47075. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47076. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47077. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47078. * @param name defines the name of the mesh
  47079. * @param options defines the options used to create the mesh
  47080. * @param scene defines the hosting scene
  47081. * @returns the sphere mesh
  47082. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#sphere
  47083. */
  47084. MeshBuilder.CreateSphere = function (name, options, scene) {
  47085. var sphere = new BABYLON.Mesh(name, scene);
  47086. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47087. sphere._originalBuilderSideOrientation = options.sideOrientation;
  47088. var vertexData = BABYLON.VertexData.CreateSphere(options);
  47089. vertexData.applyToMesh(sphere, options.updatable);
  47090. return sphere;
  47091. };
  47092. /**
  47093. * Creates a plane polygonal mesh. By default, this is a disc
  47094. * * The parameter `radius` sets the radius size (float) of the polygon (default 0.5)
  47095. * * The parameter `tessellation` sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc
  47096. * * You can create an unclosed polygon with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference : 2 x PI x ratio
  47097. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47098. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47099. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47100. * @param name defines the name of the mesh
  47101. * @param options defines the options used to create the mesh
  47102. * @param scene defines the hosting scene
  47103. * @returns the plane polygonal mesh
  47104. * @see http://doc.babylonjs.com/how_to/set_shapes#disc-or-regular-polygon
  47105. */
  47106. MeshBuilder.CreateDisc = function (name, options, scene) {
  47107. if (scene === void 0) { scene = null; }
  47108. var disc = new BABYLON.Mesh(name, scene);
  47109. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47110. disc._originalBuilderSideOrientation = options.sideOrientation;
  47111. var vertexData = BABYLON.VertexData.CreateDisc(options);
  47112. vertexData.applyToMesh(disc, options.updatable);
  47113. return disc;
  47114. };
  47115. /**
  47116. * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided
  47117. * * The parameter `radius` sets the radius size (float) of the icosphere (default 1)
  47118. * * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value than `radius`)
  47119. * * The parameter `subdivisions` sets the number of subdivisions (postive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size
  47120. * * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface
  47121. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47122. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47123. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47124. * @param name defines the name of the mesh
  47125. * @param options defines the options used to create the mesh
  47126. * @param scene defines the hosting scene
  47127. * @returns the icosahedron mesh
  47128. * @see http://doc.babylonjs.com/how_to/polyhedra_shapes#icosphere
  47129. */
  47130. MeshBuilder.CreateIcoSphere = function (name, options, scene) {
  47131. var sphere = new BABYLON.Mesh(name, scene);
  47132. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47133. sphere._originalBuilderSideOrientation = options.sideOrientation;
  47134. var vertexData = BABYLON.VertexData.CreateIcoSphere(options);
  47135. vertexData.applyToMesh(sphere, options.updatable);
  47136. return sphere;
  47137. };
  47138. ;
  47139. /**
  47140. * Creates a ribbon mesh. The ribbon is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters
  47141. * * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry
  47142. * * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array
  47143. * * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array
  47144. * * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path
  47145. * * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11
  47146. * * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#ribbon
  47147. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47148. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47149. * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture
  47150. * * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones
  47151. * * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values
  47152. * * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that if you set `closePath` to `true`, there's one extra vertex per path in the geometry
  47153. * * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time
  47154. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47155. * @param name defines the name of the mesh
  47156. * @param options defines the options used to create the mesh
  47157. * @param scene defines the hosting scene
  47158. * @returns the ribbon mesh
  47159. * @see http://doc.babylonjs.com/tutorials/Ribbon_Tutorial
  47160. * @see http://doc.babylonjs.com/tutorials/Parametric_Shapes
  47161. */
  47162. MeshBuilder.CreateRibbon = function (name, options, scene) {
  47163. if (scene === void 0) { scene = null; }
  47164. var pathArray = options.pathArray;
  47165. var closeArray = options.closeArray;
  47166. var closePath = options.closePath;
  47167. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47168. var instance = options.instance;
  47169. var updatable = options.updatable;
  47170. if (instance) { // existing ribbon instance update
  47171. // positionFunction : ribbon case
  47172. // only pathArray and sideOrientation parameters are taken into account for positions update
  47173. BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, BABYLON.Tmp.Vector3[0]); // minimum
  47174. BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, BABYLON.Tmp.Vector3[1]);
  47175. var positionFunction = function (positions) {
  47176. var minlg = pathArray[0].length;
  47177. var i = 0;
  47178. var ns = (instance._originalBuilderSideOrientation === BABYLON.Mesh.DOUBLESIDE) ? 2 : 1;
  47179. for (var si = 1; si <= ns; si++) {
  47180. for (var p = 0; p < pathArray.length; p++) {
  47181. var path = pathArray[p];
  47182. var l = path.length;
  47183. minlg = (minlg < l) ? minlg : l;
  47184. var j = 0;
  47185. while (j < minlg) {
  47186. positions[i] = path[j].x;
  47187. positions[i + 1] = path[j].y;
  47188. positions[i + 2] = path[j].z;
  47189. if (path[j].x < BABYLON.Tmp.Vector3[0].x) {
  47190. BABYLON.Tmp.Vector3[0].x = path[j].x;
  47191. }
  47192. if (path[j].x > BABYLON.Tmp.Vector3[1].x) {
  47193. BABYLON.Tmp.Vector3[1].x = path[j].x;
  47194. }
  47195. if (path[j].y < BABYLON.Tmp.Vector3[0].y) {
  47196. BABYLON.Tmp.Vector3[0].y = path[j].y;
  47197. }
  47198. if (path[j].y > BABYLON.Tmp.Vector3[1].y) {
  47199. BABYLON.Tmp.Vector3[1].y = path[j].y;
  47200. }
  47201. if (path[j].z < BABYLON.Tmp.Vector3[0].z) {
  47202. BABYLON.Tmp.Vector3[0].z = path[j].z;
  47203. }
  47204. if (path[j].z > BABYLON.Tmp.Vector3[1].z) {
  47205. BABYLON.Tmp.Vector3[1].z = path[j].z;
  47206. }
  47207. j++;
  47208. i += 3;
  47209. }
  47210. if (instance._closePath) {
  47211. positions[i] = path[0].x;
  47212. positions[i + 1] = path[0].y;
  47213. positions[i + 2] = path[0].z;
  47214. i += 3;
  47215. }
  47216. }
  47217. }
  47218. };
  47219. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  47220. positionFunction(positions);
  47221. instance._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Tmp.Vector3[0], BABYLON.Tmp.Vector3[1]);
  47222. instance._boundingInfo.update(instance._worldMatrix);
  47223. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  47224. if (options.colors) {
  47225. var colors = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  47226. for (var c = 0; c < options.colors.length; c++) {
  47227. colors[c * 4] = options.colors[c].r;
  47228. colors[c * 4 + 1] = options.colors[c].g;
  47229. colors[c * 4 + 2] = options.colors[c].b;
  47230. colors[c * 4 + 3] = options.colors[c].a;
  47231. }
  47232. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, colors, false, false);
  47233. }
  47234. if (options.uvs) {
  47235. var uvs = instance.getVerticesData(BABYLON.VertexBuffer.UVKind);
  47236. for (var i = 0; i < options.uvs.length; i++) {
  47237. uvs[i * 2] = options.uvs[i].x;
  47238. uvs[i * 2 + 1] = options.uvs[i].y;
  47239. }
  47240. instance.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs, false, false);
  47241. }
  47242. if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {
  47243. var indices = instance.getIndices();
  47244. var normals = instance.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  47245. var params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;
  47246. BABYLON.VertexData.ComputeNormals(positions, indices, normals, params);
  47247. if (instance._closePath) {
  47248. var indexFirst = 0;
  47249. var indexLast = 0;
  47250. for (var p = 0; p < pathArray.length; p++) {
  47251. indexFirst = instance._idx[p] * 3;
  47252. if (p + 1 < pathArray.length) {
  47253. indexLast = (instance._idx[p + 1] - 1) * 3;
  47254. }
  47255. else {
  47256. indexLast = normals.length - 3;
  47257. }
  47258. normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;
  47259. normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;
  47260. normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;
  47261. normals[indexLast] = normals[indexFirst];
  47262. normals[indexLast + 1] = normals[indexFirst + 1];
  47263. normals[indexLast + 2] = normals[indexFirst + 2];
  47264. }
  47265. }
  47266. if (!(instance.areNormalsFrozen)) {
  47267. instance.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
  47268. }
  47269. }
  47270. return instance;
  47271. }
  47272. else { // new ribbon creation
  47273. var ribbon = new BABYLON.Mesh(name, scene);
  47274. ribbon._originalBuilderSideOrientation = sideOrientation;
  47275. var vertexData = BABYLON.VertexData.CreateRibbon(options);
  47276. if (closePath) {
  47277. ribbon._idx = vertexData._idx;
  47278. }
  47279. ribbon._closePath = closePath;
  47280. ribbon._closeArray = closeArray;
  47281. vertexData.applyToMesh(ribbon, updatable);
  47282. return ribbon;
  47283. }
  47284. };
  47285. /**
  47286. * Creates a cylinder or a cone mesh
  47287. * * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).
  47288. * * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).
  47289. * * The parameters `diameterTop` and `diameterBottom` overwrite the parameter `diameter` and set respectively the top cap and bottom cap diameter (floats, default 1). The parameter "diameterBottom" can't be zero.
  47290. * * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.
  47291. * * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).
  47292. * * The parameter `hasRings` (boolean, default false) makes the subdivisions independent from each other, so they become different faces.
  47293. * * The parameter `enclose` (boolean, default false) adds two extra faces per subdivision to a sliced cylinder to close it around its height axis.
  47294. * * The parameter `arc` (float, default 1) is the ratio (max 1) to apply to the circumference to slice the cylinder.
  47295. * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of n Color3 elements) and `faceUV` (an array of n Vector4 elements).
  47296. * * The value of n is the number of cylinder faces. If the cylinder has only 1 subdivisions, n equals : top face + cylinder surface + bottom face = 3
  47297. * * Now, if the cylinder has 5 independent subdivisions (hasRings = true), n equals : top face + 5 stripe surfaces + bottom face = 2 + 5 = 7
  47298. * * Finally, if the cylinder has 5 independent subdivisions and is enclose, n equals : top face + 5 x (stripe surface + 2 closing faces) + bottom face = 2 + 5 * 3 = 17
  47299. * * Each array (color or UVs) is always ordered the same way : the first element is the bottom cap, the last element is the top cap. The other elements are each a ring surface.
  47300. * * If `enclose` is false, a ring surface is one element.
  47301. * * If `enclose` is true, a ring surface is 3 successive elements in the array : the tubular surface, then the two closing faces.
  47302. * * Example how to set colors and textures on a sliced cylinder : http://www.html5gamedevs.com/topic/17945-creating-a-closed-slice-of-a-cylinder/#comment-106379
  47303. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47304. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47305. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47306. * @param name defines the name of the mesh
  47307. * @param options defines the options used to create the mesh
  47308. * @param scene defines the hosting scene
  47309. * @returns the cylinder mesh
  47310. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#cylinder-or-cone
  47311. */
  47312. MeshBuilder.CreateCylinder = function (name, options, scene) {
  47313. var cylinder = new BABYLON.Mesh(name, scene);
  47314. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47315. cylinder._originalBuilderSideOrientation = options.sideOrientation;
  47316. var vertexData = BABYLON.VertexData.CreateCylinder(options);
  47317. vertexData.applyToMesh(cylinder, options.updatable);
  47318. return cylinder;
  47319. };
  47320. /**
  47321. * Creates a torus mesh
  47322. * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)
  47323. * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)
  47324. * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)
  47325. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47326. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47327. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47328. * @param name defines the name of the mesh
  47329. * @param options defines the options used to create the mesh
  47330. * @param scene defines the hosting scene
  47331. * @returns the torus mesh
  47332. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus
  47333. */
  47334. MeshBuilder.CreateTorus = function (name, options, scene) {
  47335. var torus = new BABYLON.Mesh(name, scene);
  47336. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47337. torus._originalBuilderSideOrientation = options.sideOrientation;
  47338. var vertexData = BABYLON.VertexData.CreateTorus(options);
  47339. vertexData.applyToMesh(torus, options.updatable);
  47340. return torus;
  47341. };
  47342. /**
  47343. * Creates a torus knot mesh
  47344. * * The parameter `radius` sets the global radius size (float) of the torus knot (default 2)
  47345. * * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32)
  47346. * * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32)
  47347. * * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3)
  47348. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47349. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47350. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47351. * @param name defines the name of the mesh
  47352. * @param options defines the options used to create the mesh
  47353. * @param scene defines the hosting scene
  47354. * @returns the torus knot mesh
  47355. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus-knot
  47356. */
  47357. MeshBuilder.CreateTorusKnot = function (name, options, scene) {
  47358. var torusKnot = new BABYLON.Mesh(name, scene);
  47359. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47360. torusKnot._originalBuilderSideOrientation = options.sideOrientation;
  47361. var vertexData = BABYLON.VertexData.CreateTorusKnot(options);
  47362. vertexData.applyToMesh(torusKnot, options.updatable);
  47363. return torusKnot;
  47364. };
  47365. /**
  47366. * Creates a line system mesh. A line system is a pool of many lines gathered in a single mesh
  47367. * * A line system mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of lines as an input parameter
  47368. * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineSystem to this static function
  47369. * * The parameter `lines` is an array of lines, each line being an array of successive Vector3
  47370. * * The optional parameter `instance` is an instance of an existing LineSystem object to be updated with the passed `lines` parameter
  47371. * * The optional parameter `colors` is an array of line colors, each line colors being an array of successive Color4, one per line point
  47372. * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need the alpha blending (faster)
  47373. * * Updating a simple Line mesh, you just need to update every line in the `lines` array : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  47374. * * When updating an instance, remember that only line point positions can change, not the number of points, neither the number of lines
  47375. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47376. * @see http://doc.babylonjs.com/how_to/parametric_shapes#line-system
  47377. * @param name defines the name of the new line system
  47378. * @param options defines the options used to create the line system
  47379. * @param scene defines the hosting scene
  47380. * @returns a new line system mesh
  47381. */
  47382. MeshBuilder.CreateLineSystem = function (name, options, scene) {
  47383. var instance = options.instance;
  47384. var lines = options.lines;
  47385. var colors = options.colors;
  47386. if (instance) { // lines update
  47387. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  47388. var vertexColor;
  47389. var lineColors;
  47390. if (colors) {
  47391. vertexColor = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  47392. }
  47393. var i = 0;
  47394. var c = 0;
  47395. for (var l = 0; l < lines.length; l++) {
  47396. var points = lines[l];
  47397. for (var p = 0; p < points.length; p++) {
  47398. positions[i] = points[p].x;
  47399. positions[i + 1] = points[p].y;
  47400. positions[i + 2] = points[p].z;
  47401. if (colors && vertexColor) {
  47402. lineColors = colors[l];
  47403. vertexColor[c] = lineColors[p].r;
  47404. vertexColor[c + 1] = lineColors[p].g;
  47405. vertexColor[c + 2] = lineColors[p].b;
  47406. vertexColor[c + 3] = lineColors[p].a;
  47407. c += 4;
  47408. }
  47409. i += 3;
  47410. }
  47411. }
  47412. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  47413. if (colors && vertexColor) {
  47414. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, vertexColor, false, false);
  47415. }
  47416. return instance;
  47417. }
  47418. // line system creation
  47419. var useVertexColor = (colors) ? true : false;
  47420. var lineSystem = new BABYLON.LinesMesh(name, scene, null, undefined, undefined, useVertexColor, options.useVertexAlpha);
  47421. var vertexData = BABYLON.VertexData.CreateLineSystem(options);
  47422. vertexData.applyToMesh(lineSystem, options.updatable);
  47423. return lineSystem;
  47424. };
  47425. /**
  47426. * Creates a line mesh
  47427. * A line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter
  47428. * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function
  47429. * * The parameter `points` is an array successive Vector3
  47430. * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  47431. * * The optional parameter `colors` is an array of successive Color4, one per line point
  47432. * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need alpha blending (faster)
  47433. * * When updating an instance, remember that only point positions can change, not the number of points
  47434. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47435. * @see http://doc.babylonjs.com/how_to/parametric_shapes#lines
  47436. * @param name defines the name of the new line system
  47437. * @param options defines the options used to create the line system
  47438. * @param scene defines the hosting scene
  47439. * @returns a new line mesh
  47440. */
  47441. MeshBuilder.CreateLines = function (name, options, scene) {
  47442. if (scene === void 0) { scene = null; }
  47443. var colors = (options.colors) ? [options.colors] : null;
  47444. var lines = MeshBuilder.CreateLineSystem(name, { lines: [options.points], updatable: options.updatable, instance: options.instance, colors: colors, useVertexAlpha: options.useVertexAlpha }, scene);
  47445. return lines;
  47446. };
  47447. /**
  47448. * Creates a dashed line mesh
  47449. * * A dashed line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter
  47450. * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function
  47451. * * The parameter `points` is an array successive Vector3
  47452. * * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200)
  47453. * * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3)
  47454. * * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1)
  47455. * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  47456. * * When updating an instance, remember that only point positions can change, not the number of points
  47457. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47458. * @param name defines the name of the mesh
  47459. * @param options defines the options used to create the mesh
  47460. * @param scene defines the hosting scene
  47461. * @returns the dashed line mesh
  47462. * @see http://doc.babylonjs.com/how_to/parametric_shapes#dashed-lines
  47463. */
  47464. MeshBuilder.CreateDashedLines = function (name, options, scene) {
  47465. if (scene === void 0) { scene = null; }
  47466. var points = options.points;
  47467. var instance = options.instance;
  47468. var gapSize = options.gapSize || 1;
  47469. var dashSize = options.dashSize || 3;
  47470. if (instance) { // dashed lines update
  47471. var positionFunction = function (positions) {
  47472. var curvect = BABYLON.Vector3.Zero();
  47473. var nbSeg = positions.length / 6;
  47474. var lg = 0;
  47475. var nb = 0;
  47476. var shft = 0;
  47477. var dashshft = 0;
  47478. var curshft = 0;
  47479. var p = 0;
  47480. var i = 0;
  47481. var j = 0;
  47482. for (i = 0; i < points.length - 1; i++) {
  47483. points[i + 1].subtractToRef(points[i], curvect);
  47484. lg += curvect.length();
  47485. }
  47486. shft = lg / nbSeg;
  47487. dashshft = instance.dashSize * shft / (instance.dashSize + instance.gapSize);
  47488. for (i = 0; i < points.length - 1; i++) {
  47489. points[i + 1].subtractToRef(points[i], curvect);
  47490. nb = Math.floor(curvect.length() / shft);
  47491. curvect.normalize();
  47492. j = 0;
  47493. while (j < nb && p < positions.length) {
  47494. curshft = shft * j;
  47495. positions[p] = points[i].x + curshft * curvect.x;
  47496. positions[p + 1] = points[i].y + curshft * curvect.y;
  47497. positions[p + 2] = points[i].z + curshft * curvect.z;
  47498. positions[p + 3] = points[i].x + (curshft + dashshft) * curvect.x;
  47499. positions[p + 4] = points[i].y + (curshft + dashshft) * curvect.y;
  47500. positions[p + 5] = points[i].z + (curshft + dashshft) * curvect.z;
  47501. p += 6;
  47502. j++;
  47503. }
  47504. }
  47505. while (p < positions.length) {
  47506. positions[p] = points[i].x;
  47507. positions[p + 1] = points[i].y;
  47508. positions[p + 2] = points[i].z;
  47509. p += 3;
  47510. }
  47511. };
  47512. instance.updateMeshPositions(positionFunction, false);
  47513. return instance;
  47514. }
  47515. // dashed lines creation
  47516. var dashedLines = new BABYLON.LinesMesh(name, scene);
  47517. var vertexData = BABYLON.VertexData.CreateDashedLines(options);
  47518. vertexData.applyToMesh(dashedLines, options.updatable);
  47519. dashedLines.dashSize = dashSize;
  47520. dashedLines.gapSize = gapSize;
  47521. return dashedLines;
  47522. };
  47523. /**
  47524. * Creates an extruded shape mesh. The extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.
  47525. * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.
  47526. * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  47527. * * The parameter `rotation` (float, default 0 radians) is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve.
  47528. * * The parameter `scale` (float, default 1) is the value to scale the shape.
  47529. * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  47530. * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  47531. * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  47532. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47533. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47534. * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  47535. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47536. * @param name defines the name of the mesh
  47537. * @param options defines the options used to create the mesh
  47538. * @param scene defines the hosting scene
  47539. * @returns the extruded shape mesh
  47540. * @see http://doc.babylonjs.com/tutorials/Parametric_Shapes
  47541. * @see http://doc.babylonjs.com/how_to/parametric_shapes#extruded-shapes
  47542. * @see http://doc.babylonjs.com/how_to/parametric_shapes#extruded-shapes
  47543. */
  47544. MeshBuilder.ExtrudeShape = function (name, options, scene) {
  47545. if (scene === void 0) { scene = null; }
  47546. var path = options.path;
  47547. var shape = options.shape;
  47548. var scale = options.scale || 1;
  47549. var rotation = options.rotation || 0;
  47550. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  47551. var updatable = options.updatable;
  47552. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47553. var instance = options.instance || null;
  47554. var invertUV = options.invertUV || false;
  47555. return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, cap, false, scene, updatable ? true : false, sideOrientation, instance, invertUV, options.frontUVs || null, options.backUVs || null);
  47556. };
  47557. /**
  47558. * Creates an custom extruded shape mesh.
  47559. * The custom extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.
  47560. * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.
  47561. * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  47562. * * The parameter `rotationFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the begining of the path
  47563. * * It must returns a float value that will be the rotation in radians applied to the shape on each path point.
  47564. * * The parameter `scaleFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the begining of the path
  47565. * * It must returns a float value that will be the scale value applied to the shape on each path point
  47566. * * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray`
  47567. * * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray`
  47568. * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  47569. * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  47570. * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape
  47571. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47572. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47573. * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture
  47574. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47575. * @param name defines the name of the mesh
  47576. * @param options defines the options used to create the mesh
  47577. * @param scene defines the hosting scene
  47578. * @returns the custom extruded shape mesh
  47579. * @see http://doc.babylonjs.com/how_to/parametric_shapes#custom-extruded-shapes
  47580. * @see http://doc.babylonjs.com/tutorials/Parametric_Shapes
  47581. * @see http://doc.babylonjs.com/how_to/parametric_shapes#extruded-shapes
  47582. */
  47583. MeshBuilder.ExtrudeShapeCustom = function (name, options, scene) {
  47584. var path = options.path;
  47585. var shape = options.shape;
  47586. var scaleFunction = options.scaleFunction || (function () { return 1; });
  47587. var rotationFunction = options.rotationFunction || (function () { return 0; });
  47588. var ribbonCloseArray = options.ribbonCloseArray || false;
  47589. var ribbonClosePath = options.ribbonClosePath || false;
  47590. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  47591. var updatable = options.updatable;
  47592. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47593. var instance = options.instance;
  47594. var invertUV = options.invertUV || false;
  47595. return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable ? true : false, sideOrientation, instance || null, invertUV, options.frontUVs || null, options.backUVs || null);
  47596. };
  47597. /**
  47598. * Creates lathe mesh.
  47599. * The lathe is a shape with a symetry axis : a 2D model shape is rotated around this axis to design the lathe
  47600. * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero
  47601. * * The parameter `radius` (positive float, default 1) is the radius value of the lathe
  47602. * * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe
  47603. * * The parameter `arc` (positive float, default 1) is the ratio of the lathe. 0.5 builds for instance half a lathe, so an opened shape
  47604. * * The parameter `closed` (boolean, default true) opens/closes the lathe circumference. This should be set to false when used with the parameter "arc"
  47605. * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  47606. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47607. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47608. * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture
  47609. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47610. * @param name defines the name of the mesh
  47611. * @param options defines the options used to create the mesh
  47612. * @param scene defines the hosting scene
  47613. * @returns the lathe mesh
  47614. * @see http://doc.babylonjs.com/how_to/parametric_shapes#lathe
  47615. */
  47616. MeshBuilder.CreateLathe = function (name, options, scene) {
  47617. var arc = options.arc ? ((options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc) : 1.0;
  47618. var closed = (options.closed === undefined) ? true : options.closed;
  47619. var shape = options.shape;
  47620. var radius = options.radius || 1;
  47621. var tessellation = options.tessellation || 64;
  47622. var updatable = options.updatable;
  47623. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47624. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  47625. var pi2 = Math.PI * 2;
  47626. var paths = new Array();
  47627. var invertUV = options.invertUV || false;
  47628. var i = 0;
  47629. var p = 0;
  47630. var step = pi2 / tessellation * arc;
  47631. var rotated;
  47632. var path = new Array();
  47633. for (i = 0; i <= tessellation; i++) {
  47634. var path = [];
  47635. if (cap == BABYLON.Mesh.CAP_START || cap == BABYLON.Mesh.CAP_ALL) {
  47636. path.push(new BABYLON.Vector3(0, shape[0].y, 0));
  47637. path.push(new BABYLON.Vector3(Math.cos(i * step) * shape[0].x * radius, shape[0].y, Math.sin(i * step) * shape[0].x * radius));
  47638. }
  47639. for (p = 0; p < shape.length; p++) {
  47640. rotated = new BABYLON.Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y, Math.sin(i * step) * shape[p].x * radius);
  47641. path.push(rotated);
  47642. }
  47643. if (cap == BABYLON.Mesh.CAP_END || cap == BABYLON.Mesh.CAP_ALL) {
  47644. path.push(new BABYLON.Vector3(Math.cos(i * step) * shape[shape.length - 1].x * radius, shape[shape.length - 1].y, Math.sin(i * step) * shape[shape.length - 1].x * radius));
  47645. path.push(new BABYLON.Vector3(0, shape[shape.length - 1].y, 0));
  47646. }
  47647. paths.push(path);
  47648. }
  47649. // lathe ribbon
  47650. var lathe = MeshBuilder.CreateRibbon(name, { pathArray: paths, closeArray: closed, sideOrientation: sideOrientation, updatable: updatable, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  47651. return lathe;
  47652. };
  47653. /**
  47654. * Creates a plane mesh
  47655. * * The parameter `size` sets the size (float) of both sides of the plane at once (default 1)
  47656. * * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value than `size`)
  47657. * * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane
  47658. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47659. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47660. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47661. * @param name defines the name of the mesh
  47662. * @param options defines the options used to create the mesh
  47663. * @param scene defines the hosting scene
  47664. * @returns the plane mesh
  47665. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  47666. */
  47667. MeshBuilder.CreatePlane = function (name, options, scene) {
  47668. var plane = new BABYLON.Mesh(name, scene);
  47669. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47670. plane._originalBuilderSideOrientation = options.sideOrientation;
  47671. var vertexData = BABYLON.VertexData.CreatePlane(options);
  47672. vertexData.applyToMesh(plane, options.updatable);
  47673. if (options.sourcePlane) {
  47674. plane.translate(options.sourcePlane.normal, options.sourcePlane.d);
  47675. var product = Math.acos(BABYLON.Vector3.Dot(options.sourcePlane.normal, BABYLON.Axis.Z));
  47676. var vectorProduct = BABYLON.Vector3.Cross(BABYLON.Axis.Z, options.sourcePlane.normal);
  47677. plane.rotate(vectorProduct, product);
  47678. }
  47679. return plane;
  47680. };
  47681. /**
  47682. * Creates a ground mesh
  47683. * * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground
  47684. * * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side
  47685. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47686. * @param name defines the name of the mesh
  47687. * @param options defines the options used to create the mesh
  47688. * @param scene defines the hosting scene
  47689. * @returns the ground mesh
  47690. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  47691. */
  47692. MeshBuilder.CreateGround = function (name, options, scene) {
  47693. var ground = new BABYLON.GroundMesh(name, scene);
  47694. ground._setReady(false);
  47695. ground._subdivisionsX = options.subdivisionsX || options.subdivisions || 1;
  47696. ground._subdivisionsY = options.subdivisionsY || options.subdivisions || 1;
  47697. ground._width = options.width || 1;
  47698. ground._height = options.height || 1;
  47699. ground._maxX = ground._width / 2;
  47700. ground._maxZ = ground._height / 2;
  47701. ground._minX = -ground._maxX;
  47702. ground._minZ = -ground._maxZ;
  47703. var vertexData = BABYLON.VertexData.CreateGround(options);
  47704. vertexData.applyToMesh(ground, options.updatable);
  47705. ground._setReady(true);
  47706. return ground;
  47707. };
  47708. /**
  47709. * Creates a tiled ground mesh
  47710. * * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates
  47711. * * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates
  47712. * * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile
  47713. * * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile
  47714. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47715. * @param name defines the name of the mesh
  47716. * @param options defines the options used to create the mesh
  47717. * @param scene defines the hosting scene
  47718. * @returns the tiled ground mesh
  47719. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tiled-ground
  47720. */
  47721. MeshBuilder.CreateTiledGround = function (name, options, scene) {
  47722. var tiledGround = new BABYLON.Mesh(name, scene);
  47723. var vertexData = BABYLON.VertexData.CreateTiledGround(options);
  47724. vertexData.applyToMesh(tiledGround, options.updatable);
  47725. return tiledGround;
  47726. };
  47727. /**
  47728. * Creates a ground mesh from a height map
  47729. * * The parameter `url` sets the URL of the height map image resource.
  47730. * * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.
  47731. * * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.
  47732. * * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.
  47733. * * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.
  47734. * * The parameter `colorFilter` (optional Color3, default (0.3, 0.59, 0.11) ) is the filter to apply to the image pixel colors to compute the height.
  47735. * * The parameter `onReady` is a javascript callback function that will be called once the mesh is just built (the height map download can last some time).
  47736. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  47737. * @param name defines the name of the mesh
  47738. * @param url defines the url to the height map
  47739. * @param options defines the options used to create the mesh
  47740. * @param scene defines the hosting scene
  47741. * @returns the ground mesh
  47742. * @see http://doc.babylonjs.com/babylon101/height_map
  47743. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#ground-from-a-height-map
  47744. */
  47745. MeshBuilder.CreateGroundFromHeightMap = function (name, url, options, scene) {
  47746. var width = options.width || 10.0;
  47747. var height = options.height || 10.0;
  47748. var subdivisions = options.subdivisions || 1 | 0;
  47749. var minHeight = options.minHeight || 0.0;
  47750. var maxHeight = options.maxHeight || 1.0;
  47751. var filter = options.colorFilter || new BABYLON.Color3(0.3, 0.59, 0.11);
  47752. var updatable = options.updatable;
  47753. var onReady = options.onReady;
  47754. var ground = new BABYLON.GroundMesh(name, scene);
  47755. ground._subdivisionsX = subdivisions;
  47756. ground._subdivisionsY = subdivisions;
  47757. ground._width = width;
  47758. ground._height = height;
  47759. ground._maxX = ground._width / 2.0;
  47760. ground._maxZ = ground._height / 2.0;
  47761. ground._minX = -ground._maxX;
  47762. ground._minZ = -ground._maxZ;
  47763. ground._setReady(false);
  47764. var onload = function (img) {
  47765. // Getting height map data
  47766. var canvas = document.createElement("canvas");
  47767. var context = canvas.getContext("2d");
  47768. if (!context) {
  47769. throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");
  47770. }
  47771. if (scene.isDisposed) {
  47772. return;
  47773. }
  47774. var bufferWidth = img.width;
  47775. var bufferHeight = img.height;
  47776. canvas.width = bufferWidth;
  47777. canvas.height = bufferHeight;
  47778. context.drawImage(img, 0, 0);
  47779. // Create VertexData from map data
  47780. // Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949
  47781. var buffer = context.getImageData(0, 0, bufferWidth, bufferHeight).data;
  47782. var vertexData = BABYLON.VertexData.CreateGroundFromHeightMap({
  47783. width: width, height: height,
  47784. subdivisions: subdivisions,
  47785. minHeight: minHeight, maxHeight: maxHeight, colorFilter: filter,
  47786. buffer: buffer, bufferWidth: bufferWidth, bufferHeight: bufferHeight
  47787. });
  47788. vertexData.applyToMesh(ground, updatable);
  47789. //execute ready callback, if set
  47790. if (onReady) {
  47791. onReady(ground);
  47792. }
  47793. ground._setReady(true);
  47794. };
  47795. BABYLON.Tools.LoadImage(url, onload, function () { }, scene.database);
  47796. return ground;
  47797. };
  47798. /**
  47799. * Creates a polygon mesh
  47800. * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh
  47801. * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors
  47802. * * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47803. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47804. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)
  47805. * * Remember you can only change the shape positions, not their number when updating a polygon
  47806. * @param name defines the name of the mesh
  47807. * @param options defines the options used to create the mesh
  47808. * @param scene defines the hosting scene
  47809. * @returns the polygon mesh
  47810. */
  47811. MeshBuilder.CreatePolygon = function (name, options, scene) {
  47812. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47813. var shape = options.shape;
  47814. var holes = options.holes || [];
  47815. var depth = options.depth || 0;
  47816. var contours = [];
  47817. var hole = [];
  47818. for (var i = 0; i < shape.length; i++) {
  47819. contours[i] = new BABYLON.Vector2(shape[i].x, shape[i].z);
  47820. }
  47821. var epsilon = 0.00000001;
  47822. if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
  47823. contours.pop();
  47824. }
  47825. var polygonTriangulation = new BABYLON.PolygonMeshBuilder(name, contours, scene);
  47826. for (var hNb = 0; hNb < holes.length; hNb++) {
  47827. hole = [];
  47828. for (var hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
  47829. hole.push(new BABYLON.Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
  47830. }
  47831. polygonTriangulation.addHole(hole);
  47832. }
  47833. var polygon = polygonTriangulation.build(options.updatable, depth);
  47834. polygon._originalBuilderSideOrientation = options.sideOrientation;
  47835. var vertexData = BABYLON.VertexData.CreatePolygon(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs);
  47836. vertexData.applyToMesh(polygon, options.updatable);
  47837. return polygon;
  47838. };
  47839. ;
  47840. /**
  47841. * Creates an extruded polygon mesh, with depth in the Y direction.
  47842. * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)
  47843. * @see http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  47844. * @param name defines the name of the mesh
  47845. * @param options defines the options used to create the mesh
  47846. * @param scene defines the hosting scene
  47847. * @returns the polygon mesh
  47848. */
  47849. MeshBuilder.ExtrudePolygon = function (name, options, scene) {
  47850. return MeshBuilder.CreatePolygon(name, options, scene);
  47851. };
  47852. ;
  47853. /**
  47854. * Creates a tube mesh.
  47855. * The tube is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters
  47856. * * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube
  47857. * * The parameter `radius` (positive float, default 1) sets the tube radius size
  47858. * * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface
  47859. * * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overwrittes the parameter `radius`
  47860. * * This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path. It must return a radius value (positive float)
  47861. * * The parameter `arc` (positive float, maximum 1, default 1) is the ratio to apply to the tube circumference : 2 x PI x arc
  47862. * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  47863. * * The optional parameter `instance` is an instance of an existing Tube object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#tube
  47864. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47865. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47866. * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture
  47867. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47868. * @param name defines the name of the mesh
  47869. * @param options defines the options used to create the mesh
  47870. * @param scene defines the hosting scene
  47871. * @returns the tube mesh
  47872. * @see http://doc.babylonjs.com/tutorials/Parametric_Shapes
  47873. * @see http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tube
  47874. */
  47875. MeshBuilder.CreateTube = function (name, options, scene) {
  47876. var path = options.path;
  47877. var instance = options.instance;
  47878. var radius = 1.0;
  47879. if (instance) {
  47880. radius = instance.radius;
  47881. }
  47882. if (options.radius !== undefined) {
  47883. radius = options.radius;
  47884. }
  47885. ;
  47886. var tessellation = options.tessellation || 64 | 0;
  47887. var radiusFunction = options.radiusFunction || null;
  47888. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  47889. var invertUV = options.invertUV || false;
  47890. var updatable = options.updatable;
  47891. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  47892. options.arc = options.arc && (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
  47893. // tube geometry
  47894. var tubePathArray = function (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) {
  47895. var tangents = path3D.getTangents();
  47896. var normals = path3D.getNormals();
  47897. var distances = path3D.getDistances();
  47898. var pi2 = Math.PI * 2;
  47899. var step = pi2 / tessellation * arc;
  47900. var returnRadius = function () { return radius; };
  47901. var radiusFunctionFinal = radiusFunction || returnRadius;
  47902. var circlePath;
  47903. var rad;
  47904. var normal;
  47905. var rotated;
  47906. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  47907. var index = (cap === BABYLON.Mesh._NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  47908. for (var i = 0; i < path.length; i++) {
  47909. rad = radiusFunctionFinal(i, distances[i]); // current radius
  47910. circlePath = Array(); // current circle array
  47911. normal = normals[i]; // current normal
  47912. for (var t = 0; t < tessellation; t++) {
  47913. BABYLON.Matrix.RotationAxisToRef(tangents[i], step * t, rotationMatrix);
  47914. rotated = circlePath[t] ? circlePath[t] : BABYLON.Vector3.Zero();
  47915. BABYLON.Vector3.TransformCoordinatesToRef(normal, rotationMatrix, rotated);
  47916. rotated.scaleInPlace(rad).addInPlace(path[i]);
  47917. circlePath[t] = rotated;
  47918. }
  47919. circlePaths[index] = circlePath;
  47920. index++;
  47921. }
  47922. // cap
  47923. var capPath = function (nbPoints, pathIndex) {
  47924. var pointCap = Array();
  47925. for (var i = 0; i < nbPoints; i++) {
  47926. pointCap.push(path[pathIndex]);
  47927. }
  47928. return pointCap;
  47929. };
  47930. switch (cap) {
  47931. case BABYLON.Mesh.NO_CAP:
  47932. break;
  47933. case BABYLON.Mesh.CAP_START:
  47934. circlePaths[0] = capPath(tessellation, 0);
  47935. circlePaths[1] = circlePaths[2].slice(0);
  47936. break;
  47937. case BABYLON.Mesh.CAP_END:
  47938. circlePaths[index] = circlePaths[index - 1].slice(0);
  47939. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  47940. break;
  47941. case BABYLON.Mesh.CAP_ALL:
  47942. circlePaths[0] = capPath(tessellation, 0);
  47943. circlePaths[1] = circlePaths[2].slice(0);
  47944. circlePaths[index] = circlePaths[index - 1].slice(0);
  47945. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  47946. break;
  47947. default:
  47948. break;
  47949. }
  47950. return circlePaths;
  47951. };
  47952. var path3D;
  47953. var pathArray;
  47954. if (instance) { // tube update
  47955. var arc = options.arc || instance.arc;
  47956. path3D = (instance.path3D).update(path);
  47957. pathArray = tubePathArray(path, path3D, instance.pathArray, radius, instance.tessellation, radiusFunction, instance.cap, arc);
  47958. instance = MeshBuilder.CreateRibbon("", { pathArray: pathArray, instance: instance });
  47959. instance.path3D = path3D;
  47960. instance.pathArray = pathArray;
  47961. instance.arc = arc;
  47962. instance.radius = radius;
  47963. return instance;
  47964. }
  47965. // tube creation
  47966. path3D = new BABYLON.Path3D(path);
  47967. var newPathArray = new Array();
  47968. cap = (cap < 0 || cap > 3) ? 0 : cap;
  47969. pathArray = tubePathArray(path, path3D, newPathArray, radius, tessellation, radiusFunction, cap, options.arc);
  47970. var tube = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closePath: true, closeArray: false, updatable: updatable, sideOrientation: sideOrientation, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  47971. tube.pathArray = pathArray;
  47972. tube.path3D = path3D;
  47973. tube.tessellation = tessellation;
  47974. tube.cap = cap;
  47975. tube.arc = options.arc;
  47976. tube.radius = radius;
  47977. return tube;
  47978. };
  47979. /**
  47980. * Creates a polyhedron mesh
  47981. * * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embbeded types. Please refer to the type sheet in the tutorial to choose the wanted type
  47982. * * The parameter `size` (positive float, default 1) sets the polygon size
  47983. * * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value)
  47984. * * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overwrittes the parameter `type`
  47985. * * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron
  47986. * * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`)
  47987. * * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  47988. * * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored
  47989. * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  47990. * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation
  47991. * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created
  47992. * @param name defines the name of the mesh
  47993. * @param options defines the options used to create the mesh
  47994. * @param scene defines the hosting scene
  47995. * @returns the polyhedron mesh
  47996. * @see http://doc.babylonjs.com/how_to/polyhedra_shapes
  47997. */
  47998. MeshBuilder.CreatePolyhedron = function (name, options, scene) {
  47999. var polyhedron = new BABYLON.Mesh(name, scene);
  48000. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  48001. polyhedron._originalBuilderSideOrientation = options.sideOrientation;
  48002. var vertexData = BABYLON.VertexData.CreatePolyhedron(options);
  48003. vertexData.applyToMesh(polyhedron, options.updatable);
  48004. return polyhedron;
  48005. };
  48006. /**
  48007. * Creates a decal mesh.
  48008. * A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal
  48009. * * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates
  48010. * * The parameter `normal` (Vector3, default `Vector3.Up`) sets the normal of the mesh where the decal is applied onto in World coordinates
  48011. * * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling
  48012. * * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal
  48013. * @param name defines the name of the mesh
  48014. * @param sourceMesh defines the mesh where the decal must be applied
  48015. * @param options defines the options used to create the mesh
  48016. * @param scene defines the hosting scene
  48017. * @returns the decal mesh
  48018. * @see http://doc.babylonjs.com/how_to/decals
  48019. */
  48020. MeshBuilder.CreateDecal = function (name, sourceMesh, options) {
  48021. var indices = sourceMesh.getIndices();
  48022. var positions = sourceMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  48023. var normals = sourceMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  48024. var position = options.position || BABYLON.Vector3.Zero();
  48025. var normal = options.normal || BABYLON.Vector3.Up();
  48026. var size = options.size || BABYLON.Vector3.One();
  48027. var angle = options.angle || 0;
  48028. // Getting correct rotation
  48029. if (!normal) {
  48030. var target = new BABYLON.Vector3(0, 0, 1);
  48031. var camera = sourceMesh.getScene().activeCamera;
  48032. var cameraWorldTarget = BABYLON.Vector3.TransformCoordinates(target, camera.getWorldMatrix());
  48033. normal = camera.globalPosition.subtract(cameraWorldTarget);
  48034. }
  48035. var yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;
  48036. var len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);
  48037. var pitch = Math.atan2(normal.y, len);
  48038. // Matrix
  48039. var decalWorldMatrix = BABYLON.Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(BABYLON.Matrix.Translation(position.x, position.y, position.z));
  48040. var inverseDecalWorldMatrix = BABYLON.Matrix.Invert(decalWorldMatrix);
  48041. var meshWorldMatrix = sourceMesh.getWorldMatrix();
  48042. var transformMatrix = meshWorldMatrix.multiply(inverseDecalWorldMatrix);
  48043. var vertexData = new BABYLON.VertexData();
  48044. vertexData.indices = [];
  48045. vertexData.positions = [];
  48046. vertexData.normals = [];
  48047. vertexData.uvs = [];
  48048. var currentVertexDataIndex = 0;
  48049. var extractDecalVector3 = function (indexId) {
  48050. var result = new BABYLON.PositionNormalVertex();
  48051. if (!indices || !positions || !normals) {
  48052. return result;
  48053. }
  48054. var vertexId = indices[indexId];
  48055. result.position = new BABYLON.Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);
  48056. // Send vector to decal local world
  48057. result.position = BABYLON.Vector3.TransformCoordinates(result.position, transformMatrix);
  48058. // Get normal
  48059. result.normal = new BABYLON.Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
  48060. result.normal = BABYLON.Vector3.TransformNormal(result.normal, transformMatrix);
  48061. return result;
  48062. }; // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
  48063. var clip = function (vertices, axis) {
  48064. if (vertices.length === 0) {
  48065. return vertices;
  48066. }
  48067. var clipSize = 0.5 * Math.abs(BABYLON.Vector3.Dot(size, axis));
  48068. var clipVertices = function (v0, v1) {
  48069. var clipFactor = BABYLON.Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);
  48070. return new BABYLON.PositionNormalVertex(BABYLON.Vector3.Lerp(v0.position, v1.position, clipFactor), BABYLON.Vector3.Lerp(v0.normal, v1.normal, clipFactor));
  48071. };
  48072. var result = new Array();
  48073. for (var index = 0; index < vertices.length; index += 3) {
  48074. var v1Out;
  48075. var v2Out;
  48076. var v3Out;
  48077. var total = 0;
  48078. var nV1 = null;
  48079. var nV2 = null;
  48080. var nV3 = null;
  48081. var nV4 = null;
  48082. var d1 = BABYLON.Vector3.Dot(vertices[index].position, axis) - clipSize;
  48083. var d2 = BABYLON.Vector3.Dot(vertices[index + 1].position, axis) - clipSize;
  48084. var d3 = BABYLON.Vector3.Dot(vertices[index + 2].position, axis) - clipSize;
  48085. v1Out = d1 > 0;
  48086. v2Out = d2 > 0;
  48087. v3Out = d3 > 0;
  48088. total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);
  48089. switch (total) {
  48090. case 0:
  48091. result.push(vertices[index]);
  48092. result.push(vertices[index + 1]);
  48093. result.push(vertices[index + 2]);
  48094. break;
  48095. case 1:
  48096. if (v1Out) {
  48097. nV1 = vertices[index + 1];
  48098. nV2 = vertices[index + 2];
  48099. nV3 = clipVertices(vertices[index], nV1);
  48100. nV4 = clipVertices(vertices[index], nV2);
  48101. }
  48102. if (v2Out) {
  48103. nV1 = vertices[index];
  48104. nV2 = vertices[index + 2];
  48105. nV3 = clipVertices(vertices[index + 1], nV1);
  48106. nV4 = clipVertices(vertices[index + 1], nV2);
  48107. result.push(nV3);
  48108. result.push(nV2.clone());
  48109. result.push(nV1.clone());
  48110. result.push(nV2.clone());
  48111. result.push(nV3.clone());
  48112. result.push(nV4);
  48113. break;
  48114. }
  48115. if (v3Out) {
  48116. nV1 = vertices[index];
  48117. nV2 = vertices[index + 1];
  48118. nV3 = clipVertices(vertices[index + 2], nV1);
  48119. nV4 = clipVertices(vertices[index + 2], nV2);
  48120. }
  48121. if (nV1 && nV2 && nV3 && nV4) {
  48122. result.push(nV1.clone());
  48123. result.push(nV2.clone());
  48124. result.push(nV3);
  48125. result.push(nV4);
  48126. result.push(nV3.clone());
  48127. result.push(nV2.clone());
  48128. }
  48129. break;
  48130. case 2:
  48131. if (!v1Out) {
  48132. nV1 = vertices[index].clone();
  48133. nV2 = clipVertices(nV1, vertices[index + 1]);
  48134. nV3 = clipVertices(nV1, vertices[index + 2]);
  48135. result.push(nV1);
  48136. result.push(nV2);
  48137. result.push(nV3);
  48138. }
  48139. if (!v2Out) {
  48140. nV1 = vertices[index + 1].clone();
  48141. nV2 = clipVertices(nV1, vertices[index + 2]);
  48142. nV3 = clipVertices(nV1, vertices[index]);
  48143. result.push(nV1);
  48144. result.push(nV2);
  48145. result.push(nV3);
  48146. }
  48147. if (!v3Out) {
  48148. nV1 = vertices[index + 2].clone();
  48149. nV2 = clipVertices(nV1, vertices[index]);
  48150. nV3 = clipVertices(nV1, vertices[index + 1]);
  48151. result.push(nV1);
  48152. result.push(nV2);
  48153. result.push(nV3);
  48154. }
  48155. break;
  48156. case 3:
  48157. break;
  48158. }
  48159. }
  48160. return result;
  48161. };
  48162. for (var index = 0; index < indices.length; index += 3) {
  48163. var faceVertices = new Array();
  48164. faceVertices.push(extractDecalVector3(index));
  48165. faceVertices.push(extractDecalVector3(index + 1));
  48166. faceVertices.push(extractDecalVector3(index + 2));
  48167. // Clip
  48168. faceVertices = clip(faceVertices, new BABYLON.Vector3(1, 0, 0));
  48169. faceVertices = clip(faceVertices, new BABYLON.Vector3(-1, 0, 0));
  48170. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 1, 0));
  48171. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, -1, 0));
  48172. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, 1));
  48173. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, -1));
  48174. if (faceVertices.length === 0) {
  48175. continue;
  48176. }
  48177. // Add UVs and get back to world
  48178. for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
  48179. var vertex = faceVertices[vIndex];
  48180. //TODO check for Int32Array | Uint32Array | Uint16Array
  48181. vertexData.indices.push(currentVertexDataIndex);
  48182. vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
  48183. vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
  48184. vertexData.uvs.push(0.5 + vertex.position.x / size.x);
  48185. vertexData.uvs.push(0.5 + vertex.position.y / size.y);
  48186. currentVertexDataIndex++;
  48187. }
  48188. }
  48189. // Return mesh
  48190. var decal = new BABYLON.Mesh(name, sourceMesh.getScene());
  48191. vertexData.applyToMesh(decal);
  48192. decal.position = position.clone();
  48193. decal.rotation = new BABYLON.Vector3(pitch, yaw, angle);
  48194. return decal;
  48195. };
  48196. // Privates
  48197. MeshBuilder._ExtrudeShapeGeneric = function (name, shape, curve, scale, rotation, scaleFunction, rotateFunction, rbCA, rbCP, cap, custom, scene, updtbl, side, instance, invertUV, frontUVs, backUVs) {
  48198. // extrusion geometry
  48199. var extrusionPathArray = function (shape, curve, path3D, shapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom) {
  48200. var tangents = path3D.getTangents();
  48201. var normals = path3D.getNormals();
  48202. var binormals = path3D.getBinormals();
  48203. var distances = path3D.getDistances();
  48204. var angle = 0;
  48205. var returnScale = function () { return scale !== null ? scale : 1; };
  48206. var returnRotation = function () { return rotation !== null ? rotation : 0; };
  48207. var rotate = custom && rotateFunction ? rotateFunction : returnRotation;
  48208. var scl = custom && scaleFunction ? scaleFunction : returnScale;
  48209. var index = (cap === BABYLON.Mesh.NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  48210. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  48211. for (var i = 0; i < curve.length; i++) {
  48212. var shapePath = new Array();
  48213. var angleStep = rotate(i, distances[i]);
  48214. var scaleRatio = scl(i, distances[i]);
  48215. for (var p = 0; p < shape.length; p++) {
  48216. BABYLON.Matrix.RotationAxisToRef(tangents[i], angle, rotationMatrix);
  48217. var planed = ((tangents[i].scale(shape[p].z)).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y)));
  48218. var rotated = shapePath[p] ? shapePath[p] : BABYLON.Vector3.Zero();
  48219. BABYLON.Vector3.TransformCoordinatesToRef(planed, rotationMatrix, rotated);
  48220. rotated.scaleInPlace(scaleRatio).addInPlace(curve[i]);
  48221. shapePath[p] = rotated;
  48222. }
  48223. shapePaths[index] = shapePath;
  48224. angle += angleStep;
  48225. index++;
  48226. }
  48227. // cap
  48228. var capPath = function (shapePath) {
  48229. var pointCap = Array();
  48230. var barycenter = BABYLON.Vector3.Zero();
  48231. var i;
  48232. for (i = 0; i < shapePath.length; i++) {
  48233. barycenter.addInPlace(shapePath[i]);
  48234. }
  48235. barycenter.scaleInPlace(1.0 / shapePath.length);
  48236. for (i = 0; i < shapePath.length; i++) {
  48237. pointCap.push(barycenter);
  48238. }
  48239. return pointCap;
  48240. };
  48241. switch (cap) {
  48242. case BABYLON.Mesh.NO_CAP:
  48243. break;
  48244. case BABYLON.Mesh.CAP_START:
  48245. shapePaths[0] = capPath(shapePaths[2]);
  48246. shapePaths[1] = shapePaths[2];
  48247. break;
  48248. case BABYLON.Mesh.CAP_END:
  48249. shapePaths[index] = shapePaths[index - 1];
  48250. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  48251. break;
  48252. case BABYLON.Mesh.CAP_ALL:
  48253. shapePaths[0] = capPath(shapePaths[2]);
  48254. shapePaths[1] = shapePaths[2];
  48255. shapePaths[index] = shapePaths[index - 1];
  48256. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  48257. break;
  48258. default:
  48259. break;
  48260. }
  48261. return shapePaths;
  48262. };
  48263. var path3D;
  48264. var pathArray;
  48265. if (instance) { // instance update
  48266. path3D = (instance.path3D).update(curve);
  48267. pathArray = extrusionPathArray(shape, curve, instance.path3D, instance.pathArray, scale, rotation, scaleFunction, rotateFunction, instance.cap, custom);
  48268. instance = BABYLON.Mesh.CreateRibbon("", pathArray, false, false, 0, scene || undefined, false, 0, instance);
  48269. return instance;
  48270. }
  48271. // extruded shape creation
  48272. path3D = new BABYLON.Path3D(curve);
  48273. var newShapePaths = new Array();
  48274. cap = (cap < 0 || cap > 3) ? 0 : cap;
  48275. pathArray = extrusionPathArray(shape, curve, path3D, newShapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom);
  48276. var extrudedGeneric = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closeArray: rbCA, closePath: rbCP, updatable: updtbl, sideOrientation: side, invertUV: invertUV, frontUVs: frontUVs || undefined, backUVs: backUVs || undefined }, scene);
  48277. extrudedGeneric.pathArray = pathArray;
  48278. extrudedGeneric.path3D = path3D;
  48279. extrudedGeneric.cap = cap;
  48280. return extrudedGeneric;
  48281. };
  48282. return MeshBuilder;
  48283. }());
  48284. BABYLON.MeshBuilder = MeshBuilder;
  48285. })(BABYLON || (BABYLON = {}));
  48286. //# sourceMappingURL=babylon.meshBuilder.js.map
  48287. BABYLON.Effect.ShadersStore={"defaultVertexShader":"#include<__decl__defaultVertex>\n\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n#define CUSTOM_VERTEX_MAIN_END\n}\n","defaultPixelShader":"#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n#ifdef ALPHATEST\nuniform float alphaCutOff;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<alphaCutOff)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0) {\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb;\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor=toGammaSpace(refractionColor);\n#endif\nrefractionColor*=vRefractionInfos.x;\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb;\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor=toGammaSpace(reflectionColor);\n#endif\nreflectionColor*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FOG\ncolor.rgb=max(color.rgb,0.);\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\ngl_FragColor=color;\n}\n","colorVertexShader":"\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}","colorPixelShader":"#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}"};
  48288. BABYLON.Effect.IncludesShadersStore={"depthPrePass":"#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif","bonesDeclaration":"#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif","instancesDeclaration":"#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif","pointCloudVertexDeclaration":"#ifdef POINTSIZE\nuniform float pointSize;\n#endif","bumpVertexDeclaration":"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n","clipPlaneVertexDeclaration":"#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif","fogVertexDeclaration":"#ifdef FOG\nvarying vec3 vFogDistance;\n#endif","morphTargetsVertexGlobalDeclaration":"#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif","morphTargetsVertexDeclaration":"#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif","logDepthDeclaration":"#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif","morphTargetsVertex":"#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif","instancesVertex":"#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif","bonesVertex":"#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif","bumpVertex":"#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif","clipPlaneVertex":"#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif","fogVertex":"#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif","shadowsVertex":"#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif","pointCloudVertex":"#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif","logDepthVertex":"#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif","helperFunctions":"const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nfloat dither(vec2 seed,float varianceAmount) {\nfloat rand=getRand(seed);\nfloat dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);\nreturn dither;\n}\n\nconst float rgbdMaxRange=255.0;\nvec4 toRGBD(vec3 color) {\nfloat maxRGB=max(0.0000001,max(color.r,max(color.g,color.b)));\nfloat D=max(rgbdMaxRange/maxRGB,1.);\nD=clamp(floor(D)/255.0,0.,1.);\n\nvec3 rgb=color.rgb*D;\n\nrgb=toGammaSpace(rgb);\nreturn vec4(rgb,D); \n}\nvec3 fromRGBD(vec4 rgbd) {\n\nrgbd.rgb=toLinearSpace(rgbd.rgb);\n\nreturn rgbd.rgb/rgbd.a;\n}","lightFragmentDeclaration":"#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};\nuniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{X};\n#endif\n#endif","lightsFragmentFunctions":"\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){\nvec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);\nstrq/=strq.w;\nvec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;\nreturn textureColor;\n}","lightUboDeclaration":"#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};\nuniform sampler2D projectionLightSampler{X};\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X}; \n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};\nuniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif","defaultVertexDeclaration":"\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n","defaultFragmentDeclaration":"uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;\nuniform vec3 vReflectionSize; \n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif","defaultUboDeclaration":"layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec3 vReflectionPosition;\nvec3 vReflectionSize;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};","shadowsFragmentFunctions":"#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#ifdef WEBGL2\n\nfloat computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nfloat shadow=texture2D(shadowSampler,uvDepth);\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\n\n\n\nfloat computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nvec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \n\n\n\n\nvec2 uvw0=3.-2.*st;\nvec2 uvw1=1.+2.*st;\nvec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;\nvec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;\nfloat shadow=0.;\nshadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));\nshadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));\nshadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));\nshadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));\nshadow=shadow/16.;\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\n\n\n\nfloat computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nvec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \n\n\nvec2 uvw0=4.-3.*st;\nvec2 uvw1=vec2(7.);\nvec2 uvw2=1.+3.*st;\nvec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;\nvec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;\nfloat shadow=0.;\nshadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));\nshadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));\nshadow+=uvw2.x*uvw0.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z));\nshadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));\nshadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));\nshadow+=uvw2.x*uvw1.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z));\nshadow+=uvw0.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z));\nshadow+=uvw1.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z));\nshadow+=uvw2.x*uvw2.y*texture2D(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z));\nshadow=shadow/144.;\nshadow=mix(darkness,1.,shadow);\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\nconst vec3 PoissonSamplers32[64]=vec3[64](\nvec3(0.06407013,0.05409927,0.),\nvec3(0.7366577,0.5789394,0.),\nvec3(-0.6270542,-0.5320278,0.),\nvec3(-0.4096107,0.8411095,0.),\nvec3(0.6849564,-0.4990818,0.),\nvec3(-0.874181,-0.04579735,0.),\nvec3(0.9989998,0.0009880066,0.),\nvec3(-0.004920578,-0.9151649,0.),\nvec3(0.1805763,0.9747483,0.),\nvec3(-0.2138451,0.2635818,0.),\nvec3(0.109845,0.3884785,0.),\nvec3(0.06876755,-0.3581074,0.),\nvec3(0.374073,-0.7661266,0.),\nvec3(0.3079132,-0.1216763,0.),\nvec3(-0.3794335,-0.8271583,0.),\nvec3(-0.203878,-0.07715034,0.),\nvec3(0.5912697,0.1469799,0.),\nvec3(-0.88069,0.3031784,0.),\nvec3(0.5040108,0.8283722,0.),\nvec3(-0.5844124,0.5494877,0.),\nvec3(0.6017799,-0.1726654,0.),\nvec3(-0.5554981,0.1559997,0.),\nvec3(-0.3016369,-0.3900928,0.),\nvec3(-0.5550632,-0.1723762,0.),\nvec3(0.925029,0.2995041,0.),\nvec3(-0.2473137,0.5538505,0.),\nvec3(0.9183037,-0.2862392,0.),\nvec3(0.2469421,0.6718712,0.),\nvec3(0.3916397,-0.4328209,0.),\nvec3(-0.03576927,-0.6220032,0.),\nvec3(-0.04661255,0.7995201,0.),\nvec3(0.4402924,0.3640312,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.)\n);\nconst vec3 PoissonSamplers64[64]=vec3[64](\nvec3(-0.613392,0.617481,0.),\nvec3(0.170019,-0.040254,0.),\nvec3(-0.299417,0.791925,0.),\nvec3(0.645680,0.493210,0.),\nvec3(-0.651784,0.717887,0.),\nvec3(0.421003,0.027070,0.),\nvec3(-0.817194,-0.271096,0.),\nvec3(-0.705374,-0.668203,0.),\nvec3(0.977050,-0.108615,0.),\nvec3(0.063326,0.142369,0.),\nvec3(0.203528,0.214331,0.),\nvec3(-0.667531,0.326090,0.),\nvec3(-0.098422,-0.295755,0.),\nvec3(-0.885922,0.215369,0.),\nvec3(0.566637,0.605213,0.),\nvec3(0.039766,-0.396100,0.),\nvec3(0.751946,0.453352,0.),\nvec3(0.078707,-0.715323,0.),\nvec3(-0.075838,-0.529344,0.),\nvec3(0.724479,-0.580798,0.),\nvec3(0.222999,-0.215125,0.),\nvec3(-0.467574,-0.405438,0.),\nvec3(-0.248268,-0.814753,0.),\nvec3(0.354411,-0.887570,0.),\nvec3(0.175817,0.382366,0.),\nvec3(0.487472,-0.063082,0.),\nvec3(-0.084078,0.898312,0.),\nvec3(0.488876,-0.783441,0.),\nvec3(0.470016,0.217933,0.),\nvec3(-0.696890,-0.549791,0.),\nvec3(-0.149693,0.605762,0.),\nvec3(0.034211,0.979980,0.),\nvec3(0.503098,-0.308878,0.),\nvec3(-0.016205,-0.872921,0.),\nvec3(0.385784,-0.393902,0.),\nvec3(-0.146886,-0.859249,0.),\nvec3(0.643361,0.164098,0.),\nvec3(0.634388,-0.049471,0.),\nvec3(-0.688894,0.007843,0.),\nvec3(0.464034,-0.188818,0.),\nvec3(-0.440840,0.137486,0.),\nvec3(0.364483,0.511704,0.),\nvec3(0.034028,0.325968,0.),\nvec3(0.099094,-0.308023,0.),\nvec3(0.693960,-0.366253,0.),\nvec3(0.678884,-0.204688,0.),\nvec3(0.001801,0.780328,0.),\nvec3(0.145177,-0.898984,0.),\nvec3(0.062655,-0.611866,0.),\nvec3(0.315226,-0.604297,0.),\nvec3(-0.780145,0.486251,0.),\nvec3(-0.371868,0.882138,0.),\nvec3(0.200476,0.494430,0.),\nvec3(-0.494552,-0.711051,0.),\nvec3(0.612476,0.705252,0.),\nvec3(-0.578845,-0.768792,0.),\nvec3(-0.772454,-0.090976,0.),\nvec3(0.504440,0.372295,0.),\nvec3(0.155736,0.065157,0.),\nvec3(0.391522,0.849605,0.),\nvec3(-0.620106,-0.328104,0.),\nvec3(0.789239,-0.419965,0.),\nvec3(-0.545396,0.538133,0.),\nvec3(-0.178564,-0.596057,0.)\n);\n\n\n\n\n\nfloat computeShadowWithPCSS(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers)\n{\nif (depthMetric>1.0 || depthMetric<0.0) {\nreturn 1.0;\n}\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));\nfloat blockerDepth=0.0;\nfloat sumBlockerDepth=0.0;\nfloat numBlocker=0.0;\nfor (int i=0; i<searchTapCount; i ++) {\nblockerDepth=texture(depthSampler,uvDepth.xy+(lightSizeUV*shadowMapSizeInverse*PoissonSamplers32[i].xy)).r;\nif (blockerDepth<depthMetric) {\nsumBlockerDepth+=blockerDepth;\nnumBlocker++;\n}\n}\nif (numBlocker<1.0) {\nreturn 1.0;\n}\nfloat avgBlockerDepth=sumBlockerDepth/numBlocker;\n\nfloat AAOffset=shadowMapSizeInverse*10.;\n\n\nfloat penumbraRatio=((depthMetric-avgBlockerDepth)+AAOffset);\nfloat filterRadius=penumbraRatio*lightSizeUV*shadowMapSizeInverse;\nfloat random=getRand(vPositionFromLight.xy);\nfloat rotationAngle=random*3.1415926;\nvec2 rotationVector=vec2(cos(rotationAngle),sin(rotationAngle));\nfloat shadow=0.;\nfor (int i=0; i<pcfTapCount; i++) {\nvec3 offset=poissonSamplers[i];\n\noffset=vec3(offset.x*rotationVector.x-offset.y*rotationVector.y,offset.y*rotationVector.x+offset.x*rotationVector.y,0.);\nshadow+=texture2D(shadowSampler,uvDepth+offset*filterRadius);\n}\nshadow/=float(pcfTapCount);\n\nshadow=mix(shadow,1.,depthMetric-avgBlockerDepth);\n\nshadow=mix(darkness,1.,shadow);\n\nreturn computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithPCSS16(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)\n{\nreturn computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);\n}\nfloat computeShadowWithPCSS32(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)\n{\nreturn computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);\n}\nfloat computeShadowWithPCSS64(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)\n{\nreturn computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);\n}\n#endif\n#endif\n","fresnelFunction":"#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif","reflectionFunction":"#ifdef USE_LOCAL_REFLECTIONMAP_CUBIC\nvec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {\n\nvec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;\nvec3 halfSize=cubeSize*0.5;\nvec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;\nvec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;\n\nvec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);\n\nfloat distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);\n\nvec3 intersectPositionWS=vertexPos+origVec*distance;\n\nreturn intersectPositionWS-cubePos;\n}\n#endif\nvec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=vDirectionW;\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=normalize(worldPos.xyz-vEyePosition.xyz);\n\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef USE_LOCAL_REFLECTIONMAP_CUBIC\ncoords=parallaxCorrectNormal(worldPos.xyz,coords,vReflectionSize,vReflectionPosition);\n#endif\ncoords=vec3(reflectionMatrix*vec4(coords,0));\n#ifdef INVERTCUBICMAP\ncoords.y*=-1.0;\n#endif\nreturn coords;\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}","imageProcessingDeclaration":"#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif","imageProcessingFunctions":"#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}","bumpFragmentFunctions":"#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nuniform mat4 normalMatrix;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif","clipPlaneFragmentDeclaration":"#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif","fogFragmentDeclaration":"#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif","clipPlaneFragment":"#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif","bumpFragment":"vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz*2.0-1.0);\nnormalW=normalize(mat3(normalMatrix)*normalW); \n#else\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif\n#endif","lightFragment":"#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\ninfo.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler{X},textureProjectionMatrix{X});\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPOISSON{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPoissonSamplingCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPoissonSampling(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCF1(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCF3(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCF5(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCSS16(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCSS32(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCSS64(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif","logDepthFragment":"#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif","fogFragment":"#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif"};
  48289. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  48290. globalObject["BABYLON"] = BABYLON;
  48291. //backwards compatibility
  48292. if(typeof earcut !== 'undefined') {
  48293. globalObject["Earcut"] = {
  48294. earcut: earcut
  48295. };
  48296. }
  48297. return BABYLON;
  48298. });
  48299. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(17)))
  48300. /***/ }),
  48301. /* 1 */
  48302. /***/ (function(module, exports, __webpack_require__) {
  48303. "use strict";
  48304. Object.defineProperty(exports, "__esModule", { value: true });
  48305. var deepmerge = __webpack_require__(21);
  48306. var expDm = deepmerge['default'];
  48307. exports.deepmerge = expDm;
  48308. /**
  48309. * Is the provided string a URL?
  48310. *
  48311. * @param urlToCheck the url to inspect
  48312. */
  48313. function isUrl(urlToCheck) {
  48314. if (urlToCheck.indexOf('http') === 0 || urlToCheck.indexOf('/') === 0 || urlToCheck.indexOf('./') === 0 || urlToCheck.indexOf('../') === 0) {
  48315. return true;
  48316. }
  48317. return false;
  48318. }
  48319. exports.isUrl = isUrl;
  48320. /**
  48321. * Convert a string from kebab-case to camelCase
  48322. * @param s string to convert
  48323. */
  48324. function kebabToCamel(s) {
  48325. return s.replace(/(\-\w)/g, function (m) { return m[1].toUpperCase(); });
  48326. }
  48327. exports.kebabToCamel = kebabToCamel;
  48328. //https://gist.github.com/youssman/745578062609e8acac9f
  48329. /**
  48330. * Convert a string from camelCase to kebab-case
  48331. * @param str string to convert
  48332. */
  48333. function camelToKebab(str) {
  48334. return !str ? null : str.replace(/([A-Z])/g, function (g) { return '-' + g[0].toLowerCase(); });
  48335. }
  48336. exports.camelToKebab = camelToKebab;
  48337. /**
  48338. * This will extend an object with configuration values.
  48339. * What it practically does it take the keys from the configuration and set them on the object.
  48340. * I the configuration is a tree, it will traverse into the tree.
  48341. * @param object the object to extend
  48342. * @param config the configuration object that will extend the object
  48343. */
  48344. function extendClassWithConfig(object, config) {
  48345. if (!config)
  48346. return;
  48347. Object.keys(config).forEach(function (key) {
  48348. if (key in object && typeof object[key] !== 'function') {
  48349. // if (typeof object[key] === 'function') return;
  48350. // if it is an object, iterate internally until reaching basic types
  48351. if (typeof object[key] === 'object') {
  48352. extendClassWithConfig(object[key], config[key]);
  48353. }
  48354. else {
  48355. if (config[key] !== undefined) {
  48356. object[key] = config[key];
  48357. }
  48358. }
  48359. }
  48360. });
  48361. }
  48362. exports.extendClassWithConfig = extendClassWithConfig;
  48363. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvaGVscGVyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEscUNBQXVDO0FBRXZDLElBQUksS0FBSyxHQUFHLFNBQVMsQ0FBQyxTQUFTLENBQUMsQ0FBQztBQUNmLDBCQUFTO0FBRTNCOzs7O0dBSUc7QUFDSCxlQUFzQixVQUFrQjtJQUNwQyxJQUFJLFVBQVUsQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxJQUFJLFVBQVUsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxJ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RUFBRTtZQUNwRCxpREFBaUQ7WUFDakQsb0VBQW9FO1lBQ3BFLElBQUksT0FBTyxNQUFNLENBQUMsR0FBRyxDQUFDLEtBQUssUUFBUSxFQUFFO2dCQUNqQyxxQkFBcUIsQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLEVBQUUsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7YUFDbkQ7aUJBQU07Z0JBQ0gsSUFBSSxNQUFNLENBQUMsR0FBRyxDQUFDLEtBQUssU0FBUyxFQUFFO29CQUMzQixNQUFNLENBQUMsR0FBRyxDQUFDLEdBQUcsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO2lCQUM3QjthQUNKO1NBQ0o7SUFDTCxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUM7QUFmRCxzREFlQyJ9
  48364. /***/ }),
  48365. /* 2 */
  48366. /***/ (function(module, exports, __webpack_require__) {
  48367. "use strict";
  48368. function __export(m) {
  48369. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  48370. }
  48371. Object.defineProperty(exports, "__esModule", { value: true });
  48372. __export(__webpack_require__(31));
  48373. __export(__webpack_require__(33));
  48374. __export(__webpack_require__(39));
  48375. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXNzZXRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsNEJBQXVCO0FBQ3ZCLDJCQUFzQjtBQUN0QixpQ0FBNEIifQ==
  48376. /***/ }),
  48377. /* 3 */
  48378. /***/ (function(module, exports, __webpack_require__) {
  48379. "use strict";
  48380. Object.defineProperty(exports, "__esModule", { value: true });
  48381. var babylonjs_1 = __webpack_require__(0);
  48382. var _1 = __webpack_require__(1);
  48383. /**
  48384. * This is a simple HTML mapper.
  48385. * This mapper parses a single HTML element and returns the configuration from its attributes.
  48386. * it parses numbers and boolean values to the corresponding variable types.
  48387. * The following HTML element:
  48388. * <div test="1" random-flag="true" a.string.object="test"> will result in the following configuration:
  48389. *
  48390. * {
  48391. * test: 1, //a number!
  48392. * randomFlag: boolean, //camelCase and boolean
  48393. * a: {
  48394. * string: {
  48395. * object: "test" //dot-separated object levels
  48396. * }
  48397. * }
  48398. * }
  48399. */
  48400. var HTMLMapper = /** @class */ (function () {
  48401. function HTMLMapper() {
  48402. }
  48403. /**
  48404. * Map a specific element and get configuration from it
  48405. * @param element the HTML element to analyze.
  48406. */
  48407. HTMLMapper.prototype.map = function (element) {
  48408. var config = {};
  48409. var _loop_1 = function (attrIdx) {
  48410. var attr = element.attributes.item(attrIdx);
  48411. if (!attr) {
  48412. return "continue";
  48413. }
  48414. // map "object.property" to the right configuration place.
  48415. var split = attr.nodeName.split('.');
  48416. split.reduce(function (currentConfig, key, idx) {
  48417. //convert html-style to json-style
  48418. var camelKey = _1.kebabToCamel(key);
  48419. if (idx === split.length - 1) {
  48420. var val = attr.nodeValue; // firefox warns nodeValue is deprecated, but I found no sign of it anywhere.
  48421. if (val === "true") {
  48422. val = true;
  48423. }
  48424. else if (val === "false") {
  48425. val = false;
  48426. }
  48427. else {
  48428. var isnum = !isNaN(parseFloat(val)) && isFinite(val); ///^\d+$/.test(val);
  48429. if (isnum) {
  48430. var number = parseFloat(val);
  48431. if (!isNaN(number)) {
  48432. val = number;
  48433. }
  48434. }
  48435. }
  48436. currentConfig[camelKey] = val;
  48437. }
  48438. else {
  48439. currentConfig[camelKey] = currentConfig[camelKey] || {};
  48440. }
  48441. return currentConfig[camelKey];
  48442. }, config);
  48443. };
  48444. for (var attrIdx = 0; attrIdx < element.attributes.length; ++attrIdx) {
  48445. _loop_1(attrIdx);
  48446. }
  48447. return config;
  48448. };
  48449. return HTMLMapper;
  48450. }());
  48451. /**
  48452. * A simple string-to-JSON mapper.
  48453. * This is the main mapper, used to analyze downloaded JSON-Configuration or JSON payload
  48454. */
  48455. var JSONMapper = /** @class */ (function () {
  48456. function JSONMapper() {
  48457. }
  48458. JSONMapper.prototype.map = function (rawSource) {
  48459. return JSON.parse(rawSource);
  48460. };
  48461. return JSONMapper;
  48462. }());
  48463. /**
  48464. * The DOM Mapper will traverse an entire DOM Tree and will load the configuration from the
  48465. * DOM elements and attributes.
  48466. */
  48467. var DOMMapper = /** @class */ (function () {
  48468. function DOMMapper() {
  48469. }
  48470. /**
  48471. * The mapping function that will convert HTML data to a viewer configuration object
  48472. * @param baseElement the baseElement from which to start traversing
  48473. * @returns a ViewerCOnfiguration object from the provided HTML Element
  48474. */
  48475. DOMMapper.prototype.map = function (baseElement) {
  48476. var htmlMapper = new HTMLMapper();
  48477. var config = htmlMapper.map(baseElement);
  48478. var traverseChildren = function (element, partConfig) {
  48479. var children = element.children;
  48480. if (children.length) {
  48481. for (var i = 0; i < children.length; ++i) {
  48482. var item = children.item(i);
  48483. // use the HTML Mapper to read configuration from a single element
  48484. var configMapped = htmlMapper.map(item);
  48485. var key = _1.kebabToCamel(item.nodeName.toLowerCase());
  48486. if (item.attributes.getNamedItem('array') && item.attributes.getNamedItem('array').nodeValue === 'true') {
  48487. partConfig[key] = [];
  48488. }
  48489. else {
  48490. if (element.attributes.getNamedItem('array') && element.attributes.getNamedItem('array').nodeValue === 'true') {
  48491. partConfig.push(configMapped);
  48492. }
  48493. else if (partConfig[key]) {
  48494. //exists already! probably an array
  48495. element.setAttribute('array', 'true');
  48496. var oldItem = partConfig[key];
  48497. partConfig = [oldItem, configMapped];
  48498. }
  48499. else {
  48500. partConfig[key] = configMapped;
  48501. }
  48502. }
  48503. traverseChildren(item, partConfig[key] || configMapped);
  48504. }
  48505. }
  48506. return partConfig;
  48507. };
  48508. traverseChildren(baseElement, config);
  48509. return config;
  48510. };
  48511. return DOMMapper;
  48512. }());
  48513. /**
  48514. * The MapperManager manages the different implemented mappers.
  48515. * It allows the user to register new mappers as well and use them to parse their own configuration data
  48516. */
  48517. var MapperManager = /** @class */ (function () {
  48518. function MapperManager() {
  48519. this._mappers = {
  48520. "html": new HTMLMapper(),
  48521. "json": new JSONMapper(),
  48522. "dom": new DOMMapper()
  48523. };
  48524. }
  48525. /**
  48526. * Get a specific configuration mapper.
  48527. *
  48528. * @param type the name of the mapper to load
  48529. */
  48530. MapperManager.prototype.getMapper = function (type) {
  48531. if (!this._mappers[type]) {
  48532. babylonjs_1.Tools.Error("No mapper defined for " + type);
  48533. }
  48534. return this._mappers[type];
  48535. };
  48536. /**
  48537. * Use this functio to register your own configuration mapper.
  48538. * After a mapper is registered, it can be used to parse the specific type fo configuration to the standard ViewerConfiguration.
  48539. * @param type the name of the mapper. This will be used to define the configuration type and/or to get the mapper
  48540. * @param mapper The implemented mapper
  48541. */
  48542. MapperManager.prototype.registerMapper = function (type, mapper) {
  48543. this._mappers[type] = mapper;
  48544. };
  48545. /**
  48546. * Dispose the mapper manager and all of its mappers.
  48547. */
  48548. MapperManager.prototype.dispose = function () {
  48549. this._mappers = {};
  48550. };
  48551. /**
  48552. * The default mapper is the JSON mapper.
  48553. */
  48554. MapperManager.DefaultMapper = 'json';
  48555. return MapperManager;
  48556. }());
  48557. exports.MapperManager = MapperManager;
  48558. /**
  48559. * mapperManager is a singleton of the type MapperManager.
  48560. * The mapperManager can be disposed directly with calling mapperManager.dispose()
  48561. * or indirectly with using BabylonViewer.disposeAll()
  48562. */
  48563. exports.mapperManager = new MapperManager();
  48564. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFwcGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL21hcHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBa0M7QUFHbEMsK0JBQTBDO0FBUzFDOzs7Ozs7Ozs7Ozs7Ozs7O0dBZ0JHO0FBQ0g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0FBQyxDQUFDO1NBQ2hEO1FBQ0QsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQy9CLENBQUM7SUFFRDs7Ozs7T0FLRztJQUNJLHNDQUFjLEdBQXJCLFVBQXNCLElBQVksRUFBRSxNQUFlO1FBQy9DLElBQUksQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLEdBQUcsTUFBTSxDQUFDO0lBQ2pDLENBQUM7SUFFRDs7T0FFRztJQUNJLCtCQUFPLEdBQWQ7UUFDSSxJQUFJLENBQUMsUUFBUSxHQUFHLEVBQUUsQ0FBQztJQUN2QixDQUFDO0lBeENEOztPQUVHO0lBQ1csMkJBQWEsR0FBRyxNQUFNLENBQUM7SUF1Q3pDLG9CQUFDO0NBQUEsQUE3Q0QsSUE2Q0M7QUE3Q1ksc0NBQWE7QUErQzFCOzs7O0dBSUc7QUFDUSxRQUFBLGFBQWEsR0FBRyxJQUFJLGFBQWEsRUFBRSxDQUFDIn0=
  48565. /***/ }),
  48566. /* 4 */
  48567. /***/ (function(module, exports, __webpack_require__) {
  48568. "use strict";
  48569. Object.defineProperty(exports, "__esModule", { value: true });
  48570. var babylonjs_1 = __webpack_require__(0);
  48571. var ViewerGlobals = /** @class */ (function () {
  48572. function ViewerGlobals() {
  48573. this.disableInit = false;
  48574. this.disableWebGL2Support = false;
  48575. }
  48576. Object.defineProperty(ViewerGlobals.prototype, "version", {
  48577. get: function () {
  48578. return babylonjs_1.Engine.Version;
  48579. },
  48580. enumerable: true,
  48581. configurable: true
  48582. });
  48583. return ViewerGlobals;
  48584. }());
  48585. exports.ViewerGlobals = ViewerGlobals;
  48586. exports.viewerGlobals = new ViewerGlobals();
  48587. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2xvYmFscy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL2dsb2JhbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBbUM7QUFFbkM7SUFBQTtRQUVXLGdCQUFXLEdBQVksS0FBSyxDQUFDO1FBQzdCLHlCQUFvQixHQUFZLEtBQUssQ0FBQztJQU1qRCxDQUFDO0lBSkcsc0JBQVcsa0NBQU87YUFBbEI7WUFDSSxPQUFPLGtCQUFNLENBQUMsT0FBTyxDQUFDO1FBQzFCLENBQUM7OztPQUFBO0lBRUwsb0JBQUM7QUFBRCxDQUFDLEFBVEQsSUFTQztBQVRZLHNDQUFhO0FBV2YsUUFBQSxhQUFhLEdBQWtCLElBQUksYUFBYSxFQUFFLENBQUMifQ==
  48588. /***/ }),
  48589. /* 5 */
  48590. /***/ (function(module, exports, __webpack_require__) {
  48591. "use strict";
  48592. Object.defineProperty(exports, "__esModule", { value: true });
  48593. var babylonjs_1 = __webpack_require__(0);
  48594. var modelAnimation_1 = __webpack_require__(23);
  48595. var _1 = __webpack_require__(1);
  48596. /**
  48597. * The current state of the model
  48598. */
  48599. var ModelState;
  48600. (function (ModelState) {
  48601. ModelState[ModelState["INIT"] = 0] = "INIT";
  48602. ModelState[ModelState["LOADING"] = 1] = "LOADING";
  48603. ModelState[ModelState["LOADED"] = 2] = "LOADED";
  48604. ModelState[ModelState["ENTRY"] = 3] = "ENTRY";
  48605. ModelState[ModelState["ENTRYDONE"] = 4] = "ENTRYDONE";
  48606. ModelState[ModelState["COMPLETE"] = 5] = "COMPLETE";
  48607. ModelState[ModelState["CANCELED"] = 6] = "CANCELED";
  48608. ModelState[ModelState["ERROR"] = 7] = "ERROR";
  48609. })(ModelState = exports.ModelState || (exports.ModelState = {}));
  48610. /**
  48611. * The viewer model is a container for all assets representing a sngle loaded model.
  48612. */
  48613. var ViewerModel = /** @class */ (function () {
  48614. function ViewerModel(_observablesManager, modelConfiguration, _configurationContainer) {
  48615. var _this = this;
  48616. this._observablesManager = _observablesManager;
  48617. this._configurationContainer = _configurationContainer;
  48618. /**
  48619. * the list of meshes that are a part of this model
  48620. */
  48621. this._meshes = [];
  48622. /**
  48623. * ParticleSystems connected to this model
  48624. */
  48625. this.particleSystems = [];
  48626. /**
  48627. * Skeletons defined in this model
  48628. */
  48629. this.skeletons = [];
  48630. this._loaderDone = false;
  48631. this._animatables = [];
  48632. this._frameRate = 60;
  48633. this._shadowsRenderedAfterLoad = false;
  48634. this.onLoadedObservable = new babylonjs_1.Observable();
  48635. this.onLoadErrorObservable = new babylonjs_1.Observable();
  48636. this.onLoadProgressObservable = new babylonjs_1.Observable();
  48637. this.onCompleteObservable = new babylonjs_1.Observable();
  48638. this.onAfterConfigure = new babylonjs_1.Observable();
  48639. this.state = ModelState.INIT;
  48640. this.rootMesh = new babylonjs_1.AbstractMesh("modelRootMesh");
  48641. this._pivotMesh = new babylonjs_1.AbstractMesh("pivotMesh");
  48642. this._pivotMesh.parent = this.rootMesh;
  48643. // rotate 180, gltf fun
  48644. this._pivotMesh.rotation.y += Math.PI;
  48645. this._scaleTransition = new babylonjs_1.Animation("scaleAnimation", "scaling", this._frameRate, babylonjs_1.Animation.ANIMATIONTYPE_VECTOR3, babylonjs_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
  48646. this._animations = [];
  48647. //create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
  48648. this._modelConfiguration = _1.deepmerge((this._configurationContainer && this._configurationContainer.configuration.model) || {}, modelConfiguration);
  48649. if (this._observablesManager) {
  48650. this._observablesManager.onModelAddedObservable.notifyObservers(this);
  48651. }
  48652. if (this._modelConfiguration.entryAnimation) {
  48653. this.rootMesh.setEnabled(false);
  48654. }
  48655. this.onLoadedObservable.add(function () {
  48656. _this.updateConfiguration(_this._modelConfiguration);
  48657. if (_this._observablesManager) {
  48658. _this._observablesManager.onModelLoadedObservable.notifyObservers(_this);
  48659. }
  48660. _this._initAnimations();
  48661. });
  48662. this.onCompleteObservable.add(function () {
  48663. _this.state = ModelState.COMPLETE;
  48664. });
  48665. }
  48666. Object.defineProperty(ViewerModel.prototype, "shadowsRenderedAfterLoad", {
  48667. get: function () {
  48668. return this._shadowsRenderedAfterLoad;
  48669. },
  48670. set: function (rendered) {
  48671. if (!rendered) {
  48672. throw new Error("can only be enabled");
  48673. }
  48674. else {
  48675. this._shadowsRenderedAfterLoad = rendered;
  48676. }
  48677. },
  48678. enumerable: true,
  48679. configurable: true
  48680. });
  48681. ViewerModel.prototype.getViewerId = function () {
  48682. return this._configurationContainer && this._configurationContainer.viewerId;
  48683. };
  48684. Object.defineProperty(ViewerModel.prototype, "enabled", {
  48685. /**
  48686. * Is this model enabled?
  48687. */
  48688. get: function () {
  48689. return this.rootMesh.isEnabled();
  48690. },
  48691. /**
  48692. * Set whether this model is enabled or not.
  48693. */
  48694. set: function (enable) {
  48695. this.rootMesh.setEnabled(enable);
  48696. },
  48697. enumerable: true,
  48698. configurable: true
  48699. });
  48700. Object.defineProperty(ViewerModel.prototype, "loaderDone", {
  48701. set: function (done) {
  48702. this._loaderDone = done;
  48703. this._checkCompleteState();
  48704. },
  48705. enumerable: true,
  48706. configurable: true
  48707. });
  48708. ViewerModel.prototype._checkCompleteState = function () {
  48709. if (this._loaderDone && (this.state === ModelState.ENTRYDONE)) {
  48710. this._modelComplete();
  48711. }
  48712. };
  48713. /**
  48714. * Add a mesh to this model.
  48715. * Any mesh that has no parent will be provided with the root mesh as its new parent.
  48716. *
  48717. * @param mesh the new mesh to add
  48718. * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
  48719. */
  48720. ViewerModel.prototype.addMesh = function (mesh, triggerLoaded) {
  48721. if (!mesh.parent) {
  48722. mesh.parent = this._pivotMesh;
  48723. }
  48724. mesh.receiveShadows = !!this.configuration.receiveShadows;
  48725. this._meshes.push(mesh);
  48726. if (triggerLoaded) {
  48727. return this.onLoadedObservable.notifyObserversWithPromise(this);
  48728. }
  48729. };
  48730. Object.defineProperty(ViewerModel.prototype, "meshes", {
  48731. /**
  48732. * get the list of meshes (excluding the root mesh)
  48733. */
  48734. get: function () {
  48735. return this._meshes;
  48736. },
  48737. enumerable: true,
  48738. configurable: true
  48739. });
  48740. Object.defineProperty(ViewerModel.prototype, "configuration", {
  48741. /**
  48742. * Get the model's configuration
  48743. */
  48744. get: function () {
  48745. return this._modelConfiguration;
  48746. },
  48747. /**
  48748. * (Re-)set the model's entire configuration
  48749. * @param newConfiguration the new configuration to replace the new one
  48750. */
  48751. set: function (newConfiguration) {
  48752. this._modelConfiguration = newConfiguration;
  48753. this._configureModel();
  48754. },
  48755. enumerable: true,
  48756. configurable: true
  48757. });
  48758. /**
  48759. * Update the current configuration with new values.
  48760. * Configuration will not be overwritten, but merged with the new configuration.
  48761. * Priority is to the new configuration
  48762. * @param newConfiguration the configuration to be merged into the current configuration;
  48763. */
  48764. ViewerModel.prototype.updateConfiguration = function (newConfiguration) {
  48765. this._modelConfiguration = _1.deepmerge(this._modelConfiguration, newConfiguration);
  48766. this._configureModel();
  48767. };
  48768. ViewerModel.prototype._initAnimations = function () {
  48769. var _this = this;
  48770. // check if this is not a gltf loader and init the animations
  48771. if (this.skeletons.length) {
  48772. this.skeletons.forEach(function (skeleton, idx) {
  48773. var ag = new babylonjs_1.AnimationGroup("animation-" + idx);
  48774. skeleton.getAnimatables().forEach(function (a) {
  48775. if (a.animations[0]) {
  48776. ag.addTargetedAnimation(a.animations[0], a);
  48777. }
  48778. });
  48779. _this.addAnimationGroup(ag);
  48780. });
  48781. }
  48782. var completeCallback = function () {
  48783. };
  48784. if (this._modelConfiguration.animation) {
  48785. if (this._modelConfiguration.animation.playOnce) {
  48786. this._animations.forEach(function (a) {
  48787. a.playMode = 0 /* ONCE */;
  48788. });
  48789. }
  48790. if (this._modelConfiguration.animation.autoStart && this._animations.length) {
  48791. var animationName_1 = this._modelConfiguration.animation.autoStart === true ?
  48792. this._animations[0].name : this._modelConfiguration.animation.autoStart;
  48793. completeCallback = function () {
  48794. _this.playAnimation(animationName_1);
  48795. };
  48796. }
  48797. }
  48798. this._enterScene(completeCallback);
  48799. };
  48800. /**
  48801. * Animates the model from the current position to the default position
  48802. * @param completeCallback A function to call when the animation has completed
  48803. */
  48804. ViewerModel.prototype._enterScene = function (completeCallback) {
  48805. var _this = this;
  48806. var scene = this.rootMesh.getScene();
  48807. var previousValue = scene.animationPropertiesOverride.enableBlending;
  48808. var callback = function () {
  48809. _this.state = ModelState.ENTRYDONE;
  48810. scene.animationPropertiesOverride.enableBlending = previousValue;
  48811. _this._checkCompleteState();
  48812. if (completeCallback)
  48813. completeCallback();
  48814. };
  48815. if (!this._entryAnimation) {
  48816. callback();
  48817. return;
  48818. }
  48819. this.rootMesh.setEnabled(true);
  48820. // disable blending for the sake of the entry animation;
  48821. scene.animationPropertiesOverride.enableBlending = false;
  48822. this._applyAnimation(this._entryAnimation, true, callback);
  48823. };
  48824. /**
  48825. * Animates the model from the current position to the exit-screen position
  48826. * @param completeCallback A function to call when the animation has completed
  48827. */
  48828. ViewerModel.prototype._exitScene = function (completeCallback) {
  48829. if (!this._exitAnimation) {
  48830. completeCallback();
  48831. return;
  48832. }
  48833. this._applyAnimation(this._exitAnimation, false, completeCallback);
  48834. };
  48835. ViewerModel.prototype._modelComplete = function () {
  48836. var _this = this;
  48837. //reapply material defines to be sure:
  48838. var meshes = this._pivotMesh.getChildMeshes(false);
  48839. meshes.filter(function (m) { return m.material; }).forEach(function (mesh) {
  48840. _this._applyModelMaterialConfiguration(mesh.material);
  48841. });
  48842. this.state = ModelState.COMPLETE;
  48843. this.onCompleteObservable.notifyObservers(this);
  48844. };
  48845. /**
  48846. * Add a new animation group to this model.
  48847. * @param animationGroup the new animation group to be added
  48848. */
  48849. ViewerModel.prototype.addAnimationGroup = function (animationGroup) {
  48850. this._animations.push(new modelAnimation_1.GroupModelAnimation(animationGroup));
  48851. };
  48852. /**
  48853. * Get the ModelAnimation array
  48854. */
  48855. ViewerModel.prototype.getAnimations = function () {
  48856. return this._animations;
  48857. };
  48858. /**
  48859. * Get the animations' names. Using the names you can play a specific animation.
  48860. */
  48861. ViewerModel.prototype.getAnimationNames = function () {
  48862. return this._animations.map(function (a) { return a.name; });
  48863. };
  48864. /**
  48865. * Get an animation by the provided name. Used mainly when playing n animation.
  48866. * @param name the name of the animation to find
  48867. */
  48868. ViewerModel.prototype._getAnimationByName = function (name) {
  48869. // can't use .find, noe available on IE
  48870. var filtered = this._animations.filter(function (a) { return a.name === name; });
  48871. // what the next line means - if two animations have the same name, they will not be returned!
  48872. if (filtered.length === 1) {
  48873. return filtered[0];
  48874. }
  48875. else {
  48876. return null;
  48877. }
  48878. };
  48879. /**
  48880. * Choose an initialized animation using its name and start playing it
  48881. * @param name the name of the animation to play
  48882. * @returns The model aniamtion to be played.
  48883. */
  48884. ViewerModel.prototype.playAnimation = function (name) {
  48885. var animation = this.setCurrentAnimationByName(name);
  48886. if (animation) {
  48887. animation.start();
  48888. }
  48889. return animation;
  48890. };
  48891. ViewerModel.prototype.setCurrentAnimationByName = function (name) {
  48892. var animation = this._getAnimationByName(name);
  48893. if (animation) {
  48894. if (this.currentAnimation && this.currentAnimation.state !== 3 /* STOPPED */) {
  48895. this.currentAnimation.stop();
  48896. }
  48897. this.currentAnimation = animation;
  48898. return animation;
  48899. }
  48900. else {
  48901. throw new Error("animation not found - " + name);
  48902. }
  48903. };
  48904. ViewerModel.prototype._configureModel = function () {
  48905. var _this = this;
  48906. // this can be changed to the meshes that have rootMesh a parent without breaking anything.
  48907. var meshesWithNoParent = [this.rootMesh]; //this._meshes.filter(m => m.parent === this.rootMesh);
  48908. var updateMeshesWithNoParent = function (variable, value, param) {
  48909. meshesWithNoParent.forEach(function (mesh) {
  48910. if (param) {
  48911. mesh[variable][param] = value;
  48912. }
  48913. else {
  48914. mesh[variable] = value;
  48915. }
  48916. });
  48917. };
  48918. var updateXYZ = function (variable, configValues) {
  48919. if (configValues.x !== undefined) {
  48920. updateMeshesWithNoParent(variable, configValues.x, 'x');
  48921. }
  48922. if (configValues.y !== undefined) {
  48923. updateMeshesWithNoParent(variable, configValues.y, 'y');
  48924. }
  48925. if (configValues.z !== undefined) {
  48926. updateMeshesWithNoParent(variable, configValues.z, 'z');
  48927. }
  48928. if (configValues.w !== undefined) {
  48929. updateMeshesWithNoParent(variable, configValues.w, 'w');
  48930. }
  48931. };
  48932. if (this._modelConfiguration.normalize) {
  48933. var center = false;
  48934. var unitSize = false;
  48935. var parentIndex = void 0;
  48936. if (this._modelConfiguration.normalize === true) {
  48937. center = true;
  48938. unitSize = true;
  48939. }
  48940. else {
  48941. center = !!this._modelConfiguration.normalize.center;
  48942. unitSize = !!this._modelConfiguration.normalize.unitSize;
  48943. parentIndex = this._modelConfiguration.normalize.parentIndex;
  48944. }
  48945. var meshesToNormalize = [];
  48946. if (parentIndex !== undefined) {
  48947. meshesToNormalize.push(this._meshes[parentIndex]);
  48948. }
  48949. else {
  48950. meshesToNormalize = this._pivotMesh.getChildMeshes(true).length === 1 ? [this._pivotMesh] : meshesWithNoParent;
  48951. }
  48952. if (unitSize) {
  48953. meshesToNormalize.forEach(function (mesh) {
  48954. mesh.normalizeToUnitCube(true);
  48955. mesh.computeWorldMatrix(true);
  48956. });
  48957. }
  48958. if (center) {
  48959. meshesToNormalize.forEach(function (mesh) {
  48960. var boundingInfo = mesh.getHierarchyBoundingVectors(true);
  48961. var sizeVec = boundingInfo.max.subtract(boundingInfo.min);
  48962. var halfSizeVec = sizeVec.scale(0.5);
  48963. var center = boundingInfo.min.add(halfSizeVec);
  48964. mesh.position = center.scale(-1);
  48965. mesh.position.y += halfSizeVec.y;
  48966. // Recompute Info.
  48967. mesh.computeWorldMatrix(true);
  48968. });
  48969. }
  48970. }
  48971. else {
  48972. // if centered, should be done here
  48973. }
  48974. // position?
  48975. if (this._modelConfiguration.position) {
  48976. updateXYZ('position', this._modelConfiguration.position);
  48977. }
  48978. if (this._modelConfiguration.rotation) {
  48979. //quaternion?
  48980. if (this._modelConfiguration.rotation.w) {
  48981. meshesWithNoParent.forEach(function (mesh) {
  48982. if (!mesh.rotationQuaternion) {
  48983. mesh.rotationQuaternion = new babylonjs_1.Quaternion();
  48984. }
  48985. });
  48986. updateXYZ('rotationQuaternion', this._modelConfiguration.rotation);
  48987. }
  48988. else {
  48989. updateXYZ('rotation', this._modelConfiguration.rotation);
  48990. }
  48991. }
  48992. if (this._modelConfiguration.rotationOffsetAxis) {
  48993. var rotationAxis_1 = new babylonjs_1.Vector3(0, 0, 0).copyFrom(this._modelConfiguration.rotationOffsetAxis);
  48994. meshesWithNoParent.forEach(function (m) {
  48995. if (_this._modelConfiguration.rotationOffsetAngle) {
  48996. m.rotate(rotationAxis_1, _this._modelConfiguration.rotationOffsetAngle);
  48997. }
  48998. });
  48999. }
  49000. if (this._modelConfiguration.scaling) {
  49001. updateXYZ('scaling', this._modelConfiguration.scaling);
  49002. }
  49003. if (this._modelConfiguration.castShadow) {
  49004. this._meshes.forEach(function (mesh) {
  49005. babylonjs_1.Tags.AddTagsTo(mesh, 'castShadow');
  49006. });
  49007. }
  49008. var meshes = this._pivotMesh.getChildMeshes(false);
  49009. meshes.filter(function (m) { return m.material; }).forEach(function (mesh) {
  49010. _this._applyModelMaterialConfiguration(mesh.material);
  49011. });
  49012. if (this._modelConfiguration.entryAnimation) {
  49013. this._entryAnimation = this._modelAnimationConfigurationToObject(this._modelConfiguration.entryAnimation);
  49014. }
  49015. if (this._modelConfiguration.exitAnimation) {
  49016. this._exitAnimation = this._modelAnimationConfigurationToObject(this._modelConfiguration.exitAnimation);
  49017. }
  49018. this.onAfterConfigure.notifyObservers(this);
  49019. };
  49020. ViewerModel.prototype._modelAnimationConfigurationToObject = function (animConfig) {
  49021. var anim = {
  49022. time: 0.5
  49023. };
  49024. if (animConfig.scaling) {
  49025. anim.scaling = babylonjs_1.Vector3.Zero();
  49026. }
  49027. if (animConfig.easingFunction !== undefined) {
  49028. anim.easingFunction = animConfig.easingFunction;
  49029. }
  49030. if (animConfig.easingMode !== undefined) {
  49031. anim.easingMode = animConfig.easingMode;
  49032. }
  49033. _1.extendClassWithConfig(anim, animConfig);
  49034. return anim;
  49035. };
  49036. /**
  49037. * Apply a material configuration to a material
  49038. * @param material Material to apply configuration to
  49039. */
  49040. ViewerModel.prototype._applyModelMaterialConfiguration = function (material) {
  49041. if (!this._modelConfiguration.material)
  49042. return;
  49043. _1.extendClassWithConfig(material, this._modelConfiguration.material);
  49044. if (material instanceof babylonjs_1.PBRMaterial) {
  49045. if (this._modelConfiguration.material.directIntensity !== undefined) {
  49046. material.directIntensity = this._modelConfiguration.material.directIntensity;
  49047. }
  49048. if (this._modelConfiguration.material.emissiveIntensity !== undefined) {
  49049. material.emissiveIntensity = this._modelConfiguration.material.emissiveIntensity;
  49050. }
  49051. if (this._modelConfiguration.material.environmentIntensity !== undefined) {
  49052. material.environmentIntensity = this._modelConfiguration.material.environmentIntensity;
  49053. }
  49054. if (this._modelConfiguration.material.directEnabled !== undefined) {
  49055. material.disableLighting = !this._modelConfiguration.material.directEnabled;
  49056. }
  49057. if (this._configurationContainer && this._configurationContainer.reflectionColor) {
  49058. material.reflectionColor = this._configurationContainer.reflectionColor;
  49059. }
  49060. }
  49061. else if (material instanceof babylonjs_1.MultiMaterial) {
  49062. for (var i = 0; i < material.subMaterials.length; i++) {
  49063. var subMaterial = material.subMaterials[i];
  49064. if (subMaterial) {
  49065. this._applyModelMaterialConfiguration(subMaterial);
  49066. }
  49067. }
  49068. }
  49069. };
  49070. /**
  49071. * Start entry/exit animation given an animation configuration
  49072. * @param animationConfiguration Entry/Exit animation configuration
  49073. * @param isEntry Pass true if the animation is an entry animation
  49074. * @param completeCallback Callback to execute when the animation completes
  49075. */
  49076. ViewerModel.prototype._applyAnimation = function (animationConfiguration, isEntry, completeCallback) {
  49077. var animations = [];
  49078. //scale
  49079. if (animationConfiguration.scaling) {
  49080. var scaleStart = isEntry ? animationConfiguration.scaling : new babylonjs_1.Vector3(1, 1, 1);
  49081. var scaleEnd = isEntry ? new babylonjs_1.Vector3(1, 1, 1) : animationConfiguration.scaling;
  49082. if (!scaleStart.equals(scaleEnd)) {
  49083. this.rootMesh.scaling = scaleStart;
  49084. this._setLinearKeys(this._scaleTransition, this.rootMesh.scaling, scaleEnd, animationConfiguration.time);
  49085. animations.push(this._scaleTransition);
  49086. }
  49087. }
  49088. //Start the animation(s)
  49089. this.transitionTo(animations, animationConfiguration.time, this._createEasingFunction(animationConfiguration.easingFunction), animationConfiguration.easingMode, function () { if (completeCallback)
  49090. completeCallback(); });
  49091. };
  49092. /**
  49093. * Begin @animations with the specified @easingFunction
  49094. * @param animations The BABYLON Animations to begin
  49095. * @param duration of transition, in seconds
  49096. * @param easingFunction An easing function to apply
  49097. * @param easingMode A easing mode to apply to the easingFunction
  49098. * @param onAnimationEnd Call back trigger at the end of the animation.
  49099. */
  49100. ViewerModel.prototype.transitionTo = function (animations, duration, easingFunction, easingMode, onAnimationEnd) {
  49101. if (easingMode === void 0) { easingMode = BABYLON.EasingFunction.EASINGMODE_EASEINOUT; }
  49102. if (easingFunction) {
  49103. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  49104. var animation = animations_1[_i];
  49105. easingFunction.setEasingMode(easingMode);
  49106. animation.setEasingFunction(easingFunction);
  49107. }
  49108. }
  49109. //Stop any current animations before starting the new one - merging not yet supported.
  49110. this.stopAllAnimations();
  49111. this.rootMesh.animations = animations;
  49112. if (this.rootMesh.getScene().beginAnimation) {
  49113. var animatable = this.rootMesh.getScene().beginAnimation(this.rootMesh, 0, this._frameRate * duration, false, 1, function () {
  49114. if (onAnimationEnd) {
  49115. onAnimationEnd();
  49116. }
  49117. });
  49118. this._animatables.push(animatable);
  49119. }
  49120. };
  49121. /**
  49122. * Sets key values on an Animation from first to last frame.
  49123. * @param animation The Babylon animation object to set keys on
  49124. * @param startValue The value of the first key
  49125. * @param endValue The value of the last key
  49126. * @param duration The duration of the animation, used to determine the end frame
  49127. */
  49128. ViewerModel.prototype._setLinearKeys = function (animation, startValue, endValue, duration) {
  49129. animation.setKeys([
  49130. {
  49131. frame: 0,
  49132. value: startValue
  49133. },
  49134. {
  49135. frame: this._frameRate * duration,
  49136. value: endValue
  49137. }
  49138. ]);
  49139. };
  49140. /**
  49141. * Creates and returns a Babylon easing funtion object based on a string representing the Easing function
  49142. * @param easingFunctionID The enum of the easing funtion to create
  49143. * @return The newly created Babylon easing function object
  49144. */
  49145. ViewerModel.prototype._createEasingFunction = function (easingFunctionID) {
  49146. var easingFunction;
  49147. switch (easingFunctionID) {
  49148. case 1 /* CircleEase */:
  49149. easingFunction = new babylonjs_1.CircleEase();
  49150. break;
  49151. case 2 /* BackEase */:
  49152. easingFunction = new babylonjs_1.BackEase(0.3);
  49153. break;
  49154. case 3 /* BounceEase */:
  49155. easingFunction = new babylonjs_1.BounceEase();
  49156. break;
  49157. case 4 /* CubicEase */:
  49158. easingFunction = new babylonjs_1.CubicEase();
  49159. break;
  49160. case 5 /* ElasticEase */:
  49161. easingFunction = new babylonjs_1.ElasticEase();
  49162. break;
  49163. case 6 /* ExponentialEase */:
  49164. easingFunction = new babylonjs_1.ExponentialEase();
  49165. break;
  49166. case 7 /* PowerEase */:
  49167. easingFunction = new babylonjs_1.PowerEase();
  49168. break;
  49169. case 8 /* QuadraticEase */:
  49170. easingFunction = new babylonjs_1.QuadraticEase();
  49171. break;
  49172. case 9 /* QuarticEase */:
  49173. easingFunction = new babylonjs_1.QuarticEase();
  49174. break;
  49175. case 10 /* QuinticEase */:
  49176. easingFunction = new babylonjs_1.QuinticEase();
  49177. break;
  49178. case 11 /* SineEase */:
  49179. easingFunction = new babylonjs_1.SineEase();
  49180. break;
  49181. default:
  49182. babylonjs_1.Tools.Log("No ease function found");
  49183. break;
  49184. }
  49185. return easingFunction;
  49186. };
  49187. /**
  49188. * Stops and removes all animations that have been applied to the model
  49189. */
  49190. ViewerModel.prototype.stopAllAnimations = function () {
  49191. if (this.rootMesh) {
  49192. this.rootMesh.animations = [];
  49193. }
  49194. if (this.currentAnimation) {
  49195. this.currentAnimation.stop();
  49196. }
  49197. while (this._animatables.length) {
  49198. this._animatables[0].onAnimationEnd = null;
  49199. this._animatables[0].stop();
  49200. this._animatables.shift();
  49201. }
  49202. };
  49203. /**
  49204. * Will remove this model from the viewer (but NOT dispose it).
  49205. */
  49206. ViewerModel.prototype.remove = function () {
  49207. this.stopAllAnimations();
  49208. // hide it
  49209. this.rootMesh.isVisible = false;
  49210. if (this._observablesManager) {
  49211. this._observablesManager.onModelRemovedObservable.notifyObservers(this);
  49212. }
  49213. };
  49214. /**
  49215. * Dispose this model, including all of its associated assets.
  49216. */
  49217. ViewerModel.prototype.dispose = function () {
  49218. this.remove();
  49219. this.onAfterConfigure.clear();
  49220. this.onLoadedObservable.clear();
  49221. this.onLoadErrorObservable.clear();
  49222. this.onLoadProgressObservable.clear();
  49223. if (this.loader && this.loader.name === "gltf") {
  49224. this.loader.dispose();
  49225. }
  49226. this.particleSystems.forEach(function (ps) { return ps.dispose(); });
  49227. this.particleSystems.length = 0;
  49228. this.skeletons.forEach(function (s) { return s.dispose(); });
  49229. this.skeletons.length = 0;
  49230. this._animations.forEach(function (ag) { return ag.dispose(); });
  49231. this._animations.length = 0;
  49232. this.rootMesh.dispose(false, true);
  49233. };
  49234. return ViewerModel;
  49235. }());
  49236. exports.ViewerModel = ViewerModel;
  49237. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlld2VyTW9kZWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbW9kZWwvdmlld2VyTW9kZWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBc2Q7QUFJdGQsbURBQXdKO0FBRXhKLCtCQUE4RDtBQUs5RDs7R0FFRztBQUNILElBQVksVUFTWDtBQVRELFdBQVksVUFBVTtJQUNsQiwyQ0FBSSxDQUFBO0lBQ0osaURBQU8sQ0FBQTtJQUNQLCtDQUFNLENBQUE7SUFDTiw2Q0FBSyxDQUFBO0lBQ0wsc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T0FBTyxFQUFFLEVBQVosQ0FBWSxDQUFDLENBQUM7UUFDakQsSUFBSSxDQUFDLGVBQWUsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDO1FBQ2hDLElBQUksQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLFVBQUEsQ0FBQyxJQUFJLE9BQUEsQ0FBQyxDQUFDLE9BQU8sRUFBRSxFQUFYLENBQVcsQ0FBQyxDQUFDO1FBQ3pDLElBQUksQ0FBQyxTQUFTLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQztRQUMxQixJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxVQUFBLEVBQUUsSUFBSSxPQUFBLEVBQUUsQ0FBQyxPQUFPLEVBQUUsRUFBWixDQUFZLENBQUMsQ0FBQztRQUM3QyxJQUFJLENBQUMsV0FBVyxDQUFDLE1BQU0sR0FBRyxDQUFDLENBQUM7UUFDNUIsSUFBSSxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUMsS0FBSyxFQUFFLElBQUksQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7SUFDTCxrQkFBQztBQUFELENBQUMsQUE1dEJELElBNHRCQztBQTV0Qlksa0NBQVcifQ==
  49238. /***/ }),
  49239. /* 6 */
  49240. /***/ (function(module, exports, __webpack_require__) {
  49241. "use strict";
  49242. Object.defineProperty(exports, "__esModule", { value: true });
  49243. var babylonjs_1 = __webpack_require__(0);
  49244. /**
  49245. * Receives Telemetry events and raises events to the API
  49246. */
  49247. var TelemetryManager = /** @class */ (function () {
  49248. function TelemetryManager() {
  49249. this.onEventBroadcastedObservable = new babylonjs_1.Observable();
  49250. this._event = this._eventEnabled;
  49251. }
  49252. Object.defineProperty(TelemetryManager.prototype, "broadcast", {
  49253. /**
  49254. * Receives a telemetry event
  49255. * @param event The name of the Telemetry event
  49256. * @param details An additional value, or an object containing a list of property/value pairs
  49257. */
  49258. get: function () {
  49259. return this._event;
  49260. },
  49261. enumerable: true,
  49262. configurable: true
  49263. });
  49264. /**
  49265. * Log a Telemetry event for errors raised on the WebGL context.
  49266. * @param engine The Babylon engine with the WebGL context.
  49267. */
  49268. TelemetryManager.prototype.flushWebGLErrors = function (engine, viewerId) {
  49269. if (!engine) {
  49270. return;
  49271. }
  49272. var logErrors = true;
  49273. while (logErrors) {
  49274. var gl = engine._gl;
  49275. if (gl && gl.getError) {
  49276. var error = gl.getError();
  49277. if (error === gl.NO_ERROR) {
  49278. logErrors = false;
  49279. }
  49280. else {
  49281. this.broadcast("WebGL Error", viewerId, { error: error });
  49282. }
  49283. }
  49284. else {
  49285. logErrors = false;
  49286. }
  49287. }
  49288. };
  49289. Object.defineProperty(TelemetryManager.prototype, "enable", {
  49290. /**
  49291. * Enable or disable telemetry events
  49292. * @param enabled Boolan, true if events are enabled
  49293. */
  49294. set: function (enabled) {
  49295. if (enabled) {
  49296. this._event = this._eventEnabled;
  49297. }
  49298. else {
  49299. this._event = this._eventDisabled;
  49300. }
  49301. },
  49302. enumerable: true,
  49303. configurable: true
  49304. });
  49305. /**
  49306. * Called on event when disabled, typically do nothing here
  49307. */
  49308. TelemetryManager.prototype._eventDisabled = function () {
  49309. // nothing to do
  49310. };
  49311. /**
  49312. * Called on event when enabled
  49313. * @param event - The name of the Telemetry event
  49314. * @param details An additional value, or an object containing a list of property/value pairs
  49315. */
  49316. TelemetryManager.prototype._eventEnabled = function (event, viewerId, details) {
  49317. var telemetryData = {
  49318. viewerId: viewerId,
  49319. event: event,
  49320. session: this.session,
  49321. date: new Date(),
  49322. now: window.performance ? window.performance.now() : Date.now(),
  49323. detail: null
  49324. };
  49325. if (typeof details === "object") {
  49326. for (var attr in details) {
  49327. if (details.hasOwnProperty(attr)) {
  49328. telemetryData[attr] = details[attr];
  49329. }
  49330. }
  49331. }
  49332. else if (details) {
  49333. telemetryData.detail = details;
  49334. }
  49335. this.onEventBroadcastedObservable.notifyObservers(telemetryData);
  49336. };
  49337. Object.defineProperty(TelemetryManager.prototype, "session", {
  49338. /**
  49339. * Returns the current session ID or creates one if it doesn't exixt
  49340. * @return The current session ID
  49341. */
  49342. get: function () {
  49343. if (!this._currentSessionId) {
  49344. //String + Timestamp + Random Integer
  49345. this._currentSessionId = "SESSION_" + Date.now() + Math.floor(Math.random() * 0x10000);
  49346. }
  49347. return this._currentSessionId;
  49348. },
  49349. enumerable: true,
  49350. configurable: true
  49351. });
  49352. /**
  49353. * Disposes the telemetry manager
  49354. */
  49355. TelemetryManager.prototype.dispose = function () {
  49356. this.onEventBroadcastedObservable.clear();
  49357. delete this.onEventBroadcastedObservable;
  49358. };
  49359. return TelemetryManager;
  49360. }());
  49361. exports.TelemetryManager = TelemetryManager;
  49362. exports.telemetryManager = new TelemetryManager();
  49363. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVsZW1ldHJ5TWFuYWdlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tYW5hZ2Vycy90ZWxlbWV0cnlNYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsdUNBQStDO0FBYy9DOztHQUVHO0FBQ0g7SUFBQTtRQUVXLGlDQUE0QixHQUE4QixJQUFJLHNCQUFVLEVBQUUsQ0FBQztRQUkxRSxXQUFNLEdBQThELElBQUksQ0FBQyxhQUFhLENBQUM7SUFzR25HLENBQUM7SUEvRkcsc0JBQVcsdUNBQVM7UUFMcEI7Ozs7V0FJRzthQUNIO1lBQ0ksT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDO1FBQ3ZCLENBQUM7OztPQUFBO0lBRUQ7OztPQUdHO0lBQ0ksMkNBQWdCLEdBQXZCLFVBQXdCLE1BQWMsRUFBRSxRQUFpQjtRQUNyRCxJQUFJLENBQUMsTUFBTSxFQUFFO1lBQ1QsT0FBTztTQUNWO1FBQ0QsSUFBSSxTQUFTLEdBQUcsSUFBSSxDQUFDO1FBRXJ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FJLENBQUMsNEJBQTRCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDMUMsT0FBTyxJQUFJLENBQUMsNEJBQTRCLENBQUM7SUFDN0MsQ0FBQztJQUNMLHVCQUFDO0FBQUQsQ0FBQyxBQTVHRCxJQTRHQztBQTVHWSw0Q0FBZ0I7QUE4R2hCLFFBQUEsZ0JBQWdCLEdBQUcsSUFBSSxnQkFBZ0IsRUFBRSxDQUFDIn0=
  49364. /***/ }),
  49365. /* 7 */
  49366. /***/ (function(module, exports, __webpack_require__) {
  49367. "use strict";
  49368. Object.defineProperty(exports, "__esModule", { value: true });
  49369. var babylonjs_1 = __webpack_require__(0);
  49370. /**
  49371. * The viewer manager is the container for all viewers currently registered on this page.
  49372. * It is possible to have more than one viewer on a single page.
  49373. */
  49374. var ViewerManager = /** @class */ (function () {
  49375. function ViewerManager() {
  49376. this._viewers = {};
  49377. this.onViewerAddedObservable = new babylonjs_1.Observable();
  49378. this.onViewerRemovedObservable = new babylonjs_1.Observable();
  49379. }
  49380. /**
  49381. * Adding a new viewer to the viewer manager and start tracking it.
  49382. * @param viewer the viewer to add
  49383. */
  49384. ViewerManager.prototype.addViewer = function (viewer) {
  49385. this._viewers[viewer.getBaseId()] = viewer;
  49386. this._onViewerAdded(viewer);
  49387. };
  49388. /**
  49389. * remove a viewer from the viewer manager
  49390. * @param viewer the viewer to remove
  49391. */
  49392. ViewerManager.prototype.removeViewer = function (viewer) {
  49393. var id = viewer.getBaseId();
  49394. delete this._viewers[id];
  49395. this.onViewerRemovedObservable.notifyObservers(id);
  49396. };
  49397. /**
  49398. * Get a viewer by its baseId (if the container element has an ID, it is the this is. if not, a random id was assigned)
  49399. * @param id the id of the HTMl element (or the viewer's, if none provided)
  49400. */
  49401. ViewerManager.prototype.getViewerById = function (id) {
  49402. return this._viewers[id];
  49403. };
  49404. /**
  49405. * Get a viewer using a container element
  49406. * @param element the HTML element to search viewers associated with
  49407. */
  49408. ViewerManager.prototype.getViewerByHTMLElement = function (element) {
  49409. for (var id in this._viewers) {
  49410. if (this._viewers[id].containerElement === element) {
  49411. return this.getViewerById(id);
  49412. }
  49413. }
  49414. };
  49415. /**
  49416. * Get a promise that will fullfil when this viewer was initialized.
  49417. * Since viewer initialization and template injection is asynchronous, using the promise will guaranty that
  49418. * you will get the viewer after everything was already configured.
  49419. * @param id the viewer id to find
  49420. */
  49421. ViewerManager.prototype.getViewerPromiseById = function (id) {
  49422. var _this = this;
  49423. return new Promise(function (resolve, reject) {
  49424. var localViewer = _this.getViewerById(id);
  49425. if (localViewer) {
  49426. return resolve(localViewer);
  49427. }
  49428. var viewerFunction = function (viewer) {
  49429. if (viewer.getBaseId() === id) {
  49430. resolve(viewer);
  49431. _this.onViewerAddedObservable.removeCallback(viewerFunction);
  49432. }
  49433. };
  49434. _this.onViewerAddedObservable.add(viewerFunction);
  49435. });
  49436. };
  49437. ViewerManager.prototype._onViewerAdded = function (viewer) {
  49438. this.onViewerAdded && this.onViewerAdded(viewer);
  49439. this.onViewerAddedObservable.notifyObservers(viewer);
  49440. };
  49441. /**
  49442. * dispose the manager and all of its associated viewers
  49443. */
  49444. ViewerManager.prototype.dispose = function () {
  49445. delete this._onViewerAdded;
  49446. for (var id in this._viewers) {
  49447. this._viewers[id].dispose();
  49448. }
  49449. this.onViewerAddedObservable.clear();
  49450. this.onViewerRemovedObservable.clear();
  49451. };
  49452. return ViewerManager;
  49453. }());
  49454. exports.ViewerManager = ViewerManager;
  49455. exports.viewerManager = new ViewerManager();
  49456. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlld2VyTWFuYWdlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy92aWV3ZXIvdmlld2VyTWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVDQUF1QztBQUd2Qzs7O0dBR0c7QUFDSDtJQWlCSTtRQUNJLElBQUksQ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MsUUFBUSxDQUFDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sRUFBRSxDQUFDO1NBQy9CO1FBRUQsSUFBSSxDQUFDLHVCQUF1QixDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3JDLElBQUksQ0FBQyx5QkFBeUIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUMzQyxDQUFDO0lBQ0wsb0JBQUM7QUFBRCxDQUFDLEFBdEdELElBc0dDO0FBdEdZLHNDQUFhO0FBd0dmLFFBQUEsYUFBYSxHQUFHLElBQUksYUFBYSxFQUFFLENBQUMifQ==
  49457. /***/ }),
  49458. /* 8 */
  49459. /***/ (function(module, exports, __webpack_require__) {
  49460. "use strict";
  49461. var __extends = (this && this.__extends) || (function () {
  49462. var extendStatics = Object.setPrototypeOf ||
  49463. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  49464. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  49465. return function (d, b) {
  49466. extendStatics(d, b);
  49467. function __() { this.constructor = d; }
  49468. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  49469. };
  49470. })();
  49471. Object.defineProperty(exports, "__esModule", { value: true });
  49472. var viewer_1 = __webpack_require__(9);
  49473. var babylonjs_1 = __webpack_require__(0);
  49474. /**
  49475. * The Default viewer is the default implementation of the AbstractViewer.
  49476. * It uses the templating system to render a new canvas and controls.
  49477. */
  49478. var DefaultViewer = /** @class */ (function (_super) {
  49479. __extends(DefaultViewer, _super);
  49480. /**
  49481. * Create a new default viewer
  49482. * @param containerElement the element in which the templates will be rendered
  49483. * @param initialConfiguration the initial configuration. Defaults to extending the default configuration
  49484. */
  49485. function DefaultViewer(containerElement, initialConfiguration) {
  49486. if (initialConfiguration === void 0) { initialConfiguration = { extends: 'default' }; }
  49487. var _this = _super.call(this, containerElement, initialConfiguration) || this;
  49488. _this.containerElement = containerElement;
  49489. _this._handlePointerDown = function (event) {
  49490. var pointerDown = event.event;
  49491. if (pointerDown.button !== 0)
  49492. return;
  49493. var element = event.event.target;
  49494. if (!element) {
  49495. return;
  49496. }
  49497. var parentClasses = element.parentElement.classList;
  49498. switch (element.id) {
  49499. case "speed-button":
  49500. case "types-button":
  49501. if (parentClasses.contains("open")) {
  49502. parentClasses.remove("open");
  49503. }
  49504. else {
  49505. parentClasses.add("open");
  49506. }
  49507. break;
  49508. case "play-pause-button":
  49509. _this._togglePlayPause();
  49510. break;
  49511. case "label-option-button":
  49512. var label = element.dataset["value"];
  49513. if (label) {
  49514. _this._updateAnimationType(label);
  49515. }
  49516. break;
  49517. case "speed-option-button":
  49518. if (!_this._currentAnimation) {
  49519. return;
  49520. }
  49521. var speed = element.dataset["value"];
  49522. if (speed)
  49523. _this._updateAnimationSpeed(speed);
  49524. break;
  49525. case "progress-wrapper":
  49526. _this._resumePlay = !_this._isAnimationPaused;
  49527. if (_this._resumePlay) {
  49528. _this._togglePlayPause(true);
  49529. }
  49530. break;
  49531. case "fullscreen-button":
  49532. _this.toggleFullscreen();
  49533. break;
  49534. default:
  49535. return;
  49536. }
  49537. };
  49538. /**
  49539. * Plays or Pauses animation
  49540. */
  49541. _this._togglePlayPause = function (noUiUpdate) {
  49542. if (!_this._currentAnimation) {
  49543. return;
  49544. }
  49545. if (_this._isAnimationPaused) {
  49546. _this._currentAnimation.restart();
  49547. }
  49548. else {
  49549. _this._currentAnimation.pause();
  49550. }
  49551. _this._isAnimationPaused = !_this._isAnimationPaused;
  49552. if (noUiUpdate)
  49553. return;
  49554. var navbar = _this.templateManager.getTemplate('navBar');
  49555. if (!navbar)
  49556. return;
  49557. navbar.updateParams({
  49558. paused: _this._isAnimationPaused,
  49559. });
  49560. };
  49561. /**
  49562. * Control progress bar position based on animation current frame
  49563. */
  49564. _this._updateProgressBar = function () {
  49565. var navbar = _this.templateManager.getTemplate('navBar');
  49566. if (!navbar)
  49567. return;
  49568. var progressSlider = navbar.parent.querySelector("input#progress-wrapper");
  49569. if (progressSlider && _this._currentAnimation) {
  49570. var progress = _this._currentAnimation.currentFrame / _this._currentAnimation.frames * 100;
  49571. var currentValue = progressSlider.valueAsNumber;
  49572. if (Math.abs(currentValue - progress) > 0.5) { // Only move if greater than a 1% change
  49573. progressSlider.value = '' + progress;
  49574. }
  49575. if (_this._currentAnimation.state === 1 /* PLAYING */) {
  49576. if (_this.sceneManager.camera.autoRotationBehavior && !_this._oldIdleRotationValue) {
  49577. _this._oldIdleRotationValue = _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed;
  49578. _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = 0;
  49579. }
  49580. }
  49581. else {
  49582. if (_this.sceneManager.camera.autoRotationBehavior && _this._oldIdleRotationValue) {
  49583. _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = _this._oldIdleRotationValue;
  49584. _this._oldIdleRotationValue = 0;
  49585. }
  49586. }
  49587. }
  49588. };
  49589. /**
  49590. * Update Current Animation Speed
  49591. */
  49592. _this._updateAnimationSpeed = function (speed, paramsObject) {
  49593. var navbar = _this.templateManager.getTemplate('navBar');
  49594. if (!navbar)
  49595. return;
  49596. if (speed && _this._currentAnimation) {
  49597. _this._currentAnimation.speedRatio = parseFloat(speed);
  49598. if (!_this._isAnimationPaused) {
  49599. _this._currentAnimation.restart();
  49600. }
  49601. if (paramsObject) {
  49602. paramsObject.selectedSpeed = speed + "x";
  49603. }
  49604. else {
  49605. navbar.updateParams({
  49606. selectedSpeed: speed + "x",
  49607. });
  49608. }
  49609. }
  49610. };
  49611. /**
  49612. * Update Current Animation Type
  49613. */
  49614. _this._updateAnimationType = function (label, paramsObject) {
  49615. var navbar = _this.templateManager.getTemplate('navBar');
  49616. if (!navbar)
  49617. return;
  49618. if (label) {
  49619. _this._currentAnimation = _this.sceneManager.models[0].setCurrentAnimationByName(label);
  49620. }
  49621. if (paramsObject) {
  49622. paramsObject.selectedAnimation = (_this._animationList.indexOf(label) + 1);
  49623. paramsObject.selectedAnimationName = label;
  49624. }
  49625. else {
  49626. navbar.updateParams({
  49627. selectedAnimation: (_this._animationList.indexOf(label) + 1),
  49628. selectedAnimationName: label
  49629. });
  49630. }
  49631. _this._updateAnimationSpeed("1.0", paramsObject);
  49632. };
  49633. /**
  49634. * Toggle fullscreen of the entire viewer
  49635. */
  49636. _this.toggleFullscreen = function () {
  49637. var viewerTemplate = _this.templateManager.getTemplate('viewer');
  49638. var viewerElement = viewerTemplate && viewerTemplate.parent;
  49639. if (viewerElement) {
  49640. var fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
  49641. if (!fullscreenElement) {
  49642. var requestFullScreen = viewerElement.requestFullscreen || viewerElement.webkitRequestFullscreen || viewerElement.msRequestFullscreen || viewerElement.mozRequestFullScreen;
  49643. requestFullScreen.call(viewerElement);
  49644. }
  49645. else {
  49646. var exitFullscreen = document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen;
  49647. exitFullscreen.call(document);
  49648. }
  49649. }
  49650. };
  49651. _this._onModelLoaded = function (model) {
  49652. _this._configureTemplate(model);
  49653. // with a short timeout, making sure everything is there already.
  49654. var hideLoadingDelay = 20;
  49655. if (_this.configuration.lab && _this.configuration.lab.hideLoadingDelay !== undefined) {
  49656. hideLoadingDelay = _this.configuration.lab.hideLoadingDelay;
  49657. }
  49658. setTimeout(function () {
  49659. _this.sceneManager.scene.executeWhenReady(function () {
  49660. _this.hideLoadingScreen();
  49661. });
  49662. }, hideLoadingDelay);
  49663. return;
  49664. };
  49665. _this.onModelLoadedObservable.add(_this._onModelLoaded);
  49666. _this.onModelRemovedObservable.add(function () {
  49667. _this._configureTemplate();
  49668. });
  49669. _this.onEngineInitObservable.add(function () {
  49670. _this.sceneManager.onLightsConfiguredObservable.add(function (data) {
  49671. _this._configureLights(data.newConfiguration, data.model);
  49672. });
  49673. });
  49674. return _this;
  49675. }
  49676. /**
  49677. * This will be executed when the templates initialize.
  49678. */
  49679. DefaultViewer.prototype._onTemplatesLoaded = function () {
  49680. var _this = this;
  49681. this.showLoadingScreen();
  49682. // navbar
  49683. this._initNavbar();
  49684. // close overlay button
  49685. var closeButton = document.getElementById('close-button');
  49686. if (closeButton) {
  49687. closeButton.addEventListener('pointerdown', function () {
  49688. _this.hideOverlayScreen();
  49689. });
  49690. }
  49691. if (this.configuration.templates && this.configuration.templates.viewer) {
  49692. if (this.configuration.templates.viewer.params && this.configuration.templates.viewer.params.enableDragAndDrop) {
  49693. var filesInput = new babylonjs_1.FilesInput(this.engine, this.sceneManager.scene, function () {
  49694. }, function () {
  49695. }, function () {
  49696. }, function () {
  49697. }, function () {
  49698. }, function (file) {
  49699. _this.loadModel(file);
  49700. }, function () {
  49701. });
  49702. filesInput.monitorElementForDragNDrop(this.templateManager.getCanvas());
  49703. }
  49704. }
  49705. return _super.prototype._onTemplatesLoaded.call(this);
  49706. };
  49707. DefaultViewer.prototype._dropped = function (evt) {
  49708. };
  49709. DefaultViewer.prototype._initNavbar = function () {
  49710. var _this = this;
  49711. var navbar = this.templateManager.getTemplate('navBar');
  49712. if (navbar) {
  49713. this.onFrameRenderedObservable.add(this._updateProgressBar);
  49714. this.templateManager.eventManager.registerCallback('navBar', this._handlePointerDown, 'pointerdown');
  49715. // an example how to trigger the help button. publiclly available
  49716. this.templateManager.eventManager.registerCallback("navBar", function () {
  49717. // do your thing
  49718. }, "pointerdown", "#help-button");
  49719. this.templateManager.eventManager.registerCallback("navBar", function (event) {
  49720. var evt = event.event;
  49721. var element = (evt.target);
  49722. if (!_this._currentAnimation)
  49723. return;
  49724. var gotoFrame = +element.value / 100 * _this._currentAnimation.frames;
  49725. if (isNaN(gotoFrame))
  49726. return;
  49727. _this._currentAnimation.goToFrame(gotoFrame);
  49728. }, "input");
  49729. this.templateManager.eventManager.registerCallback("navBar", function (e) {
  49730. if (_this._resumePlay) {
  49731. _this._togglePlayPause(true);
  49732. }
  49733. _this._resumePlay = false;
  49734. }, "pointerup", "#progress-wrapper");
  49735. }
  49736. };
  49737. /**
  49738. * Preparing the container element to present the viewer
  49739. */
  49740. DefaultViewer.prototype._prepareContainerElement = function () {
  49741. this.containerElement.style.position = 'relative';
  49742. this.containerElement.style.height = '100%';
  49743. this.containerElement.style.display = 'flex';
  49744. };
  49745. /**
  49746. * This function will configure the templates and update them after a model was loaded
  49747. * It is mainly responsible to changing the title and subtitle etc'.
  49748. * @param model the model to be used to configure the templates by
  49749. */
  49750. DefaultViewer.prototype._configureTemplate = function (model) {
  49751. var navbar = this.templateManager.getTemplate('navBar');
  49752. if (!navbar)
  49753. return;
  49754. var newParams = navbar.configuration.params || {};
  49755. if (!model) {
  49756. newParams.animations = null;
  49757. }
  49758. else {
  49759. var animationNames = model.getAnimationNames();
  49760. newParams.animations = animationNames;
  49761. if (animationNames.length) {
  49762. this._isAnimationPaused = (model.configuration.animation && !model.configuration.animation.autoStart) || !model.configuration.animation;
  49763. this._animationList = animationNames;
  49764. newParams.paused = this._isAnimationPaused;
  49765. var animationIndex = 0;
  49766. if (model.configuration.animation && typeof model.configuration.animation.autoStart === 'string') {
  49767. animationIndex = animationNames.indexOf(model.configuration.animation.autoStart);
  49768. if (animationIndex === -1) {
  49769. animationIndex = 0;
  49770. }
  49771. }
  49772. this._updateAnimationType(animationNames[animationIndex], newParams);
  49773. }
  49774. else {
  49775. newParams.animations = null;
  49776. }
  49777. if (model.configuration.thumbnail) {
  49778. newParams.logoImage = model.configuration.thumbnail;
  49779. }
  49780. }
  49781. navbar.updateParams(newParams, false);
  49782. };
  49783. /**
  49784. * This will load a new model to the default viewer
  49785. * overriding the AbstractViewer's loadModel.
  49786. * The scene will automatically be cleared of the old models, if exist.
  49787. * @param model the configuration object (or URL) to load.
  49788. */
  49789. DefaultViewer.prototype.loadModel = function (model) {
  49790. var _this = this;
  49791. if (!model) {
  49792. model = this.configuration.model;
  49793. }
  49794. this.showLoadingScreen();
  49795. return _super.prototype.loadModel.call(this, model, true).catch(function (error) {
  49796. console.log(error);
  49797. _this.hideLoadingScreen();
  49798. _this.showOverlayScreen('error');
  49799. return Promise.reject(error);
  49800. });
  49801. };
  49802. /**
  49803. * Show the overlay and the defined sub-screen.
  49804. * Mainly used for help and errors
  49805. * @param subScreen the name of the subScreen. Those can be defined in the configuration object
  49806. */
  49807. DefaultViewer.prototype.showOverlayScreen = function (subScreen) {
  49808. var _this = this;
  49809. var template = this.templateManager.getTemplate('overlay');
  49810. if (!template)
  49811. return Promise.resolve('Overlay template not found');
  49812. return template.show((function (template) {
  49813. var canvasRect = _this.containerElement.getBoundingClientRect();
  49814. template.parent.style.display = 'flex';
  49815. template.parent.style.width = canvasRect.width + "px";
  49816. template.parent.style.height = canvasRect.height + "px";
  49817. template.parent.style.opacity = "1";
  49818. var subTemplate = _this.templateManager.getTemplate(subScreen);
  49819. if (!subTemplate) {
  49820. return Promise.reject(subScreen + ' template not found');
  49821. }
  49822. return subTemplate.show((function (template) {
  49823. template.parent.style.display = 'flex';
  49824. return Promise.resolve(template);
  49825. }));
  49826. }));
  49827. };
  49828. /**
  49829. * Hide the overlay screen.
  49830. */
  49831. DefaultViewer.prototype.hideOverlayScreen = function () {
  49832. var template = this.templateManager.getTemplate('overlay');
  49833. if (!template)
  49834. return Promise.resolve('Overlay template not found');
  49835. return template.hide((function (template) {
  49836. template.parent.style.opacity = "0";
  49837. var onTransitionEnd = function () {
  49838. template.parent.removeEventListener("transitionend", onTransitionEnd);
  49839. template.parent.style.display = 'none';
  49840. };
  49841. template.parent.addEventListener("transitionend", onTransitionEnd);
  49842. var overlays = template.parent.querySelectorAll('.overlay');
  49843. if (overlays) {
  49844. for (var i = 0; i < overlays.length; ++i) {
  49845. var htmlElement = overlays.item(i);
  49846. htmlElement.style.display = 'none';
  49847. }
  49848. }
  49849. return Promise.resolve(template);
  49850. }));
  49851. };
  49852. /**
  49853. * show the viewer (in case it was hidden)
  49854. *
  49855. * @param visibilityFunction an optional function to execute in order to show the container
  49856. */
  49857. DefaultViewer.prototype.show = function (visibilityFunction) {
  49858. var template = this.templateManager.getTemplate('main');
  49859. //not possible, but yet:
  49860. if (!template)
  49861. return Promise.reject('Main template not found');
  49862. return template.show(visibilityFunction);
  49863. };
  49864. /**
  49865. * hide the viewer (in case it is visible)
  49866. *
  49867. * @param visibilityFunction an optional function to execute in order to hide the container
  49868. */
  49869. DefaultViewer.prototype.hide = function (visibilityFunction) {
  49870. var template = this.templateManager.getTemplate('main');
  49871. //not possible, but yet:
  49872. if (!template)
  49873. return Promise.reject('Main template not found');
  49874. return template.hide(visibilityFunction);
  49875. };
  49876. /**
  49877. * Show the loading screen.
  49878. * The loading screen can be configured using the configuration object
  49879. */
  49880. DefaultViewer.prototype.showLoadingScreen = function () {
  49881. var _this = this;
  49882. var template = this.templateManager.getTemplate('loadingScreen');
  49883. if (!template)
  49884. return Promise.resolve('Loading Screen template not found');
  49885. return template.show((function (template) {
  49886. var canvasRect = _this.containerElement.getBoundingClientRect();
  49887. // var canvasPositioning = window.getComputedStyle(this.containerElement).position;
  49888. template.parent.style.display = 'flex';
  49889. template.parent.style.width = canvasRect.width + "px";
  49890. template.parent.style.height = canvasRect.height + "px";
  49891. template.parent.style.opacity = "1";
  49892. // from the configuration!!!
  49893. var color = "black";
  49894. if (_this.configuration.templates && _this.configuration.templates.loadingScreen) {
  49895. color = (_this.configuration.templates.loadingScreen.params &&
  49896. _this.configuration.templates.loadingScreen.params.backgroundColor) || color;
  49897. }
  49898. template.parent.style.backgroundColor = color;
  49899. return Promise.resolve(template);
  49900. }));
  49901. };
  49902. /**
  49903. * Hide the loading screen
  49904. */
  49905. DefaultViewer.prototype.hideLoadingScreen = function () {
  49906. var template = this.templateManager.getTemplate('loadingScreen');
  49907. if (!template)
  49908. return Promise.resolve('Loading Screen template not found');
  49909. return template.hide((function (template) {
  49910. template.parent.style.opacity = "0";
  49911. var onTransitionEnd = function () {
  49912. template.parent.removeEventListener("transitionend", onTransitionEnd);
  49913. template.parent.style.display = 'none';
  49914. };
  49915. template.parent.addEventListener("transitionend", onTransitionEnd);
  49916. return Promise.resolve(template);
  49917. }));
  49918. };
  49919. DefaultViewer.prototype.dispose = function () {
  49920. this.templateManager.dispose();
  49921. _super.prototype.dispose.call(this);
  49922. };
  49923. DefaultViewer.prototype._onConfigurationLoaded = function (configuration) {
  49924. var _this = this;
  49925. _super.prototype._onConfigurationLoaded.call(this, configuration);
  49926. // initialize the templates
  49927. var templateConfiguration = this.configuration.templates || {};
  49928. this.templateManager.initTemplate(templateConfiguration);
  49929. // when done, execute onTemplatesLoaded()
  49930. this.templateManager.onAllLoaded.add(function () {
  49931. var canvas = _this.templateManager.getCanvas();
  49932. if (canvas) {
  49933. _this._canvas = canvas;
  49934. }
  49935. _this._onTemplateLoaded();
  49936. });
  49937. };
  49938. /**
  49939. * An extension of the light configuration of the abstract viewer.
  49940. * @param lightsConfiguration the light configuration to use
  49941. * @param model the model that will be used to configure the lights (if the lights are model-dependant)
  49942. */
  49943. DefaultViewer.prototype._configureLights = function (lightsConfiguration, model) {
  49944. var _this = this;
  49945. if (lightsConfiguration === void 0) { lightsConfiguration = {}; }
  49946. // labs feature - flashlight
  49947. if (this.configuration.lab && this.configuration.lab.flashlight) {
  49948. var pointerPosition = babylonjs_1.Vector3.Zero();
  49949. var lightTarget_1;
  49950. var angle = 0.5;
  49951. var exponent = Math.PI / 2;
  49952. if (typeof this.configuration.lab.flashlight === "object") {
  49953. exponent = this.configuration.lab.flashlight.exponent || exponent;
  49954. angle = this.configuration.lab.flashlight.angle || angle;
  49955. }
  49956. var flashlight = new babylonjs_1.SpotLight("flashlight", babylonjs_1.Vector3.Zero(), babylonjs_1.Vector3.Zero(), exponent, angle, this.sceneManager.scene);
  49957. if (typeof this.configuration.lab.flashlight === "object") {
  49958. flashlight.intensity = this.configuration.lab.flashlight.intensity || flashlight.intensity;
  49959. if (this.configuration.lab.flashlight.diffuse) {
  49960. flashlight.diffuse.r = this.configuration.lab.flashlight.diffuse.r;
  49961. flashlight.diffuse.g = this.configuration.lab.flashlight.diffuse.g;
  49962. flashlight.diffuse.b = this.configuration.lab.flashlight.diffuse.b;
  49963. }
  49964. if (this.configuration.lab.flashlight.specular) {
  49965. flashlight.specular.r = this.configuration.lab.flashlight.specular.r;
  49966. flashlight.specular.g = this.configuration.lab.flashlight.specular.g;
  49967. flashlight.specular.b = this.configuration.lab.flashlight.specular.b;
  49968. }
  49969. }
  49970. this.sceneManager.scene.constantlyUpdateMeshUnderPointer = true;
  49971. this.sceneManager.scene.onPointerObservable.add(function (eventData, eventState) {
  49972. if (eventData.type === 4 && eventData.pickInfo) {
  49973. lightTarget_1 = (eventData.pickInfo.pickedPoint);
  49974. }
  49975. else {
  49976. lightTarget_1 = undefined;
  49977. }
  49978. });
  49979. var updateFlashlightFunction = function () {
  49980. if (_this.sceneManager.camera && flashlight) {
  49981. flashlight.position.copyFrom(_this.sceneManager.camera.position);
  49982. if (lightTarget_1) {
  49983. lightTarget_1.subtractToRef(flashlight.position, flashlight.direction);
  49984. }
  49985. }
  49986. };
  49987. this.sceneManager.scene.registerBeforeRender(updateFlashlightFunction);
  49988. this._registeredOnBeforeRenderFunctions.push(updateFlashlightFunction);
  49989. }
  49990. };
  49991. return DefaultViewer;
  49992. }(viewer_1.AbstractViewer));
  49993. exports.DefaultViewer = DefaultViewer;
  49994. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdFZpZXdlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy92aWV3ZXIvZGVmYXVsdFZpZXdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFJQSxtQ0FBMEM7QUFDMUMsdUNBQXNZO0FBTXRZOzs7R0FHRztBQUNIO0lBQW1DLGlDQUFjO0lBSTdDOzs7O09BSUc7SUFDSCx1QkFBbUIsZ0JBQTZCLEVBQUUsb0JBQWtFO1FBQWxFLHFDQUFBLEVBQUEseUJBQThDLE9BQ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FBQyxDQUFDLENBQUM7WUFDSCxJQUFJLHdCQUF3QixHQUFHO2dCQUMzQixJQUFJLEtBQUksQ0FBQyxZQUFZLENBQUMsTUFBTSxJQUFJLFVBQVUsRUFBRTtvQkFDeEMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsS0FBSSxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUM7b0JBQ2hFLElBQUksYUFBVyxFQUFFO3dCQUNiLGFBQVcsQ0FBQyxhQUFhLENBQUMsVUFBVSxDQUFDLFFBQVEsRUFBRSxVQUFVLENBQUMsU0FBUyxDQUFDLENBQUM7cUJBQ3hFO2lCQUNKO1lBQ0wsQ0FBQyxDQUFBO1lBQ0QsSUFBSSxDQUFDLFlBQVksQ0FBQyxLQUFLLENBQUMsb0JBQW9CLENBQUMsd0JBQXdCLENBQUMsQ0FBQztZQUN2RSxJQUFJLENBQUMsa0NBQWtDLENBQUMsSUFBSSxDQUFDLHdCQUF3QixDQUFDLENBQUM7U0FDMUU7SUFDTCxDQUFDO0lBQ0wsb0JBQUM7QUFBRCxDQUFDLEFBemlCRCxDQUFtQyx1QkFBYyxHQXlpQmhEO0FBemlCWSxzQ0FBYSJ9
  49995. /***/ }),
  49996. /* 9 */
  49997. /***/ (function(module, exports, __webpack_require__) {
  49998. "use strict";
  49999. Object.defineProperty(exports, "__esModule", { value: true });
  50000. var viewerManager_1 = __webpack_require__(7);
  50001. var sceneManager_1 = __webpack_require__(22);
  50002. var loader_1 = __webpack_require__(28);
  50003. var babylonjs_1 = __webpack_require__(0);
  50004. var modelLoader_1 = __webpack_require__(13);
  50005. var globals_1 = __webpack_require__(4);
  50006. var telemetryManager_1 = __webpack_require__(6);
  50007. var _1 = __webpack_require__(1);
  50008. var observablesManager_1 = __webpack_require__(59);
  50009. var configurationContainer_1 = __webpack_require__(60);
  50010. var templateManager_1 = __webpack_require__(61);
  50011. /**
  50012. * The AbstractViewr is the center of Babylon's viewer.
  50013. * It is the basic implementation of the default viewer and is responsible of loading and showing the model and the templates
  50014. */
  50015. var AbstractViewer = /** @class */ (function () {
  50016. function AbstractViewer(containerElement, initialConfiguration) {
  50017. if (initialConfiguration === void 0) { initialConfiguration = {}; }
  50018. var _this = this;
  50019. this.containerElement = containerElement;
  50020. /**
  50021. * A flag that controls whether or not the render loop should be executed
  50022. */
  50023. this.runRenderLoop = true;
  50024. /**
  50025. * is this viewer disposed?
  50026. */
  50027. this._isDisposed = false;
  50028. /**
  50029. * The resize function that will be registered with the window object
  50030. */
  50031. this._resize = function () {
  50032. // Only resize if Canvas is in the DOM
  50033. if (!_this.isCanvasInDOM()) {
  50034. return;
  50035. }
  50036. if (_this.canvas.clientWidth <= 0 || _this.canvas.clientHeight <= 0) {
  50037. return;
  50038. }
  50039. if (_this.configuration.engine && _this.configuration.engine.disableResize) {
  50040. return;
  50041. }
  50042. _this.engine.resize();
  50043. };
  50044. /**
  50045. * render loop that will be executed by the engine
  50046. */
  50047. this._render = function (force) {
  50048. if (force === void 0) { force = false; }
  50049. if (force || (_this.sceneManager.scene && _this.sceneManager.scene.activeCamera)) {
  50050. if (_this.runRenderLoop || force) {
  50051. _this.engine.performanceMonitor.enable();
  50052. _this.sceneManager.scene.render();
  50053. _this.onFrameRenderedObservable.notifyObservers(_this);
  50054. }
  50055. else {
  50056. _this.engine.performanceMonitor.disable();
  50057. // update camera instead of rendering
  50058. _this.sceneManager.scene.activeCamera && _this.sceneManager.scene.activeCamera.update();
  50059. }
  50060. }
  50061. };
  50062. // if exists, use the container id. otherwise, generate a random string.
  50063. if (containerElement.id) {
  50064. this.baseId = containerElement.id;
  50065. }
  50066. else {
  50067. this.baseId = containerElement.id = 'bjs' + Math.random().toString(32).substr(2, 8);
  50068. }
  50069. this._registeredOnBeforeRenderFunctions = [];
  50070. this._configurationContainer = new configurationContainer_1.ConfigurationContainer();
  50071. // add this viewer to the viewer manager
  50072. viewerManager_1.viewerManager.addViewer(this);
  50073. this.observablesManager = new observablesManager_1.ObservablesManager();
  50074. this.modelLoader = new modelLoader_1.ModelLoader(this.observablesManager, this._configurationContainer);
  50075. babylonjs_1.RenderingManager.AUTOCLEAR = false;
  50076. // extend the configuration
  50077. this._configurationLoader = new loader_1.ConfigurationLoader();
  50078. this._configurationLoader.loadConfiguration(initialConfiguration, function (configuration) {
  50079. _this._onConfigurationLoaded(configuration);
  50080. });
  50081. this.onSceneInitObservable.add(function () {
  50082. _this.updateConfiguration();
  50083. });
  50084. this.onInitDoneObservable.add(function () {
  50085. _this._isInit = true;
  50086. _this.engine.runRenderLoop(_this._render);
  50087. });
  50088. this._prepareContainerElement();
  50089. }
  50090. Object.defineProperty(AbstractViewer.prototype, "onSceneInitObservable", {
  50091. // observables
  50092. /**
  50093. * Will notify when the scene was initialized
  50094. */
  50095. get: function () {
  50096. return this.observablesManager.onSceneInitObservable;
  50097. },
  50098. enumerable: true,
  50099. configurable: true
  50100. });
  50101. Object.defineProperty(AbstractViewer.prototype, "onEngineInitObservable", {
  50102. /**
  50103. * will notify when the engine was initialized
  50104. */
  50105. get: function () {
  50106. return this.observablesManager.onEngineInitObservable;
  50107. },
  50108. enumerable: true,
  50109. configurable: true
  50110. });
  50111. Object.defineProperty(AbstractViewer.prototype, "onModelAddedObservable", {
  50112. /**
  50113. * Will notify when a new model was added to the scene.
  50114. * Note that added does not neccessarily mean loaded!
  50115. */
  50116. get: function () {
  50117. return this.observablesManager.onModelAddedObservable;
  50118. },
  50119. enumerable: true,
  50120. configurable: true
  50121. });
  50122. Object.defineProperty(AbstractViewer.prototype, "onModelLoadedObservable", {
  50123. /**
  50124. * will notify after every model load
  50125. */
  50126. get: function () {
  50127. return this.observablesManager.onModelLoadedObservable;
  50128. },
  50129. enumerable: true,
  50130. configurable: true
  50131. });
  50132. Object.defineProperty(AbstractViewer.prototype, "onModelLoadProgressObservable", {
  50133. /**
  50134. * will notify when any model notify of progress
  50135. */
  50136. get: function () {
  50137. return this.observablesManager.onModelLoadProgressObservable;
  50138. },
  50139. enumerable: true,
  50140. configurable: true
  50141. });
  50142. Object.defineProperty(AbstractViewer.prototype, "onModelLoadErrorObservable", {
  50143. /**
  50144. * will notify when any model load failed.
  50145. */
  50146. get: function () {
  50147. return this.observablesManager.onModelLoadErrorObservable;
  50148. },
  50149. enumerable: true,
  50150. configurable: true
  50151. });
  50152. Object.defineProperty(AbstractViewer.prototype, "onModelRemovedObservable", {
  50153. /**
  50154. * Will notify when a model was removed from the scene;
  50155. */
  50156. get: function () {
  50157. return this.observablesManager.onModelRemovedObservable;
  50158. },
  50159. enumerable: true,
  50160. configurable: true
  50161. });
  50162. Object.defineProperty(AbstractViewer.prototype, "onLoaderInitObservable", {
  50163. /**
  50164. * will notify when a new loader was initialized.
  50165. * Used mainly to know when a model starts loading.
  50166. */
  50167. get: function () {
  50168. return this.observablesManager.onLoaderInitObservable;
  50169. },
  50170. enumerable: true,
  50171. configurable: true
  50172. });
  50173. Object.defineProperty(AbstractViewer.prototype, "onInitDoneObservable", {
  50174. /**
  50175. * Observers registered here will be executed when the entire load process has finished.
  50176. */
  50177. get: function () {
  50178. return this.observablesManager.onViewerInitDoneObservable;
  50179. },
  50180. enumerable: true,
  50181. configurable: true
  50182. });
  50183. Object.defineProperty(AbstractViewer.prototype, "onFrameRenderedObservable", {
  50184. /**
  50185. * Functions added to this observable will be executed on each frame rendered.
  50186. */
  50187. get: function () {
  50188. return this.observablesManager.onFrameRenderedObservable;
  50189. },
  50190. enumerable: true,
  50191. configurable: true
  50192. });
  50193. Object.defineProperty(AbstractViewer.prototype, "canvas", {
  50194. /**
  50195. * The (single) canvas of this viewer
  50196. */
  50197. get: function () {
  50198. return this._canvas;
  50199. },
  50200. enumerable: true,
  50201. configurable: true
  50202. });
  50203. Object.defineProperty(AbstractViewer.prototype, "configurationContainer", {
  50204. get: function () {
  50205. return this._configurationContainer;
  50206. },
  50207. enumerable: true,
  50208. configurable: true
  50209. });
  50210. /**
  50211. * get the baseId of this viewer
  50212. */
  50213. AbstractViewer.prototype.getBaseId = function () {
  50214. return this.baseId;
  50215. };
  50216. /**
  50217. * Do we have a canvas to render on, and is it a part of the scene
  50218. */
  50219. AbstractViewer.prototype.isCanvasInDOM = function () {
  50220. return !!this._canvas && !!this._canvas.parentElement;
  50221. };
  50222. Object.defineProperty(AbstractViewer.prototype, "renderInBackground", {
  50223. /**
  50224. * Is the engine currently set to rende even when the page is in background
  50225. */
  50226. get: function () {
  50227. return this.engine && this.engine.renderEvenInBackground;
  50228. },
  50229. /**
  50230. * Set the viewer's background rendering flag.
  50231. */
  50232. set: function (value) {
  50233. if (this.engine) {
  50234. this.engine.renderEvenInBackground = value;
  50235. }
  50236. },
  50237. enumerable: true,
  50238. configurable: true
  50239. });
  50240. Object.defineProperty(AbstractViewer.prototype, "configuration", {
  50241. /**
  50242. * Get the configuration object. This is a reference only.
  50243. * The configuration can ONLY be updated using the updateConfiguration function.
  50244. * changing this object will have no direct effect on the scene.
  50245. */
  50246. get: function () {
  50247. return this._configurationContainer.configuration;
  50248. },
  50249. enumerable: true,
  50250. configurable: true
  50251. });
  50252. /**
  50253. * force resizing the engine.
  50254. */
  50255. AbstractViewer.prototype.forceResize = function () {
  50256. this._resize();
  50257. };
  50258. AbstractViewer.prototype._onConfigurationLoaded = function (configuration) {
  50259. var _this = this;
  50260. this._configurationContainer.configuration = _1.deepmerge(this.configuration || {}, configuration);
  50261. if (this.configuration.observers) {
  50262. this._configureObservers(this.configuration.observers);
  50263. }
  50264. // TODO remove this after testing, as this is done in the updateCOnfiguration as well.
  50265. if (this.configuration.loaderPlugins) {
  50266. Object.keys(this.configuration.loaderPlugins).forEach((function (name) {
  50267. if (_this.configuration.loaderPlugins && _this.configuration.loaderPlugins[name]) {
  50268. _this.modelLoader.addPlugin(name);
  50269. }
  50270. }));
  50271. }
  50272. this.templateManager = new templateManager_1.TemplateManager(this.containerElement);
  50273. };
  50274. /**
  50275. * Force a single render loop execution.
  50276. */
  50277. AbstractViewer.prototype.forceRender = function () {
  50278. this._render(true);
  50279. };
  50280. /**
  50281. * Takes a screenshot of the scene and returns it as a base64 encoded png.
  50282. * @param callback optional callback that will be triggered when screenshot is done.
  50283. * @param width Optional screenshot width (default to 512).
  50284. * @param height Optional screenshot height (default to 512).
  50285. * @returns a promise with the screenshot data
  50286. */
  50287. AbstractViewer.prototype.takeScreenshot = function (callback, width, height) {
  50288. var _this = this;
  50289. if (width === void 0) { width = 0; }
  50290. if (height === void 0) { height = 0; }
  50291. width = width || this.canvas.clientWidth;
  50292. height = height || this.canvas.clientHeight;
  50293. // Create the screenshot
  50294. return new Promise(function (resolve, reject) {
  50295. try {
  50296. BABYLON.Tools.CreateScreenshot(_this.engine, _this.sceneManager.camera, { width: width, height: height }, function (data) {
  50297. if (callback) {
  50298. callback(data);
  50299. }
  50300. resolve(data);
  50301. });
  50302. }
  50303. catch (e) {
  50304. reject(e);
  50305. }
  50306. });
  50307. };
  50308. /**
  50309. * Update the current viewer configuration with new values.
  50310. * Only provided information will be updated, old configuration values will be kept.
  50311. * If this.configuration was manually changed, you can trigger this function with no parameters,
  50312. * and the entire configuration will be updated.
  50313. * @param newConfiguration the partial configuration to update
  50314. *
  50315. */
  50316. AbstractViewer.prototype.updateConfiguration = function (newConfiguration) {
  50317. var _this = this;
  50318. if (newConfiguration === void 0) { newConfiguration = this.configuration; }
  50319. // update this.configuration with the new data
  50320. this._configurationContainer.configuration = _1.deepmerge(this.configuration || {}, newConfiguration);
  50321. this.sceneManager.updateConfiguration(newConfiguration);
  50322. // observers in configuration
  50323. if (newConfiguration.observers) {
  50324. this._configureObservers(newConfiguration.observers);
  50325. }
  50326. if (newConfiguration.loaderPlugins) {
  50327. Object.keys(newConfiguration.loaderPlugins).forEach((function (name) {
  50328. if (newConfiguration.loaderPlugins && newConfiguration.loaderPlugins[name]) {
  50329. _this.modelLoader.addPlugin(name);
  50330. }
  50331. }));
  50332. }
  50333. };
  50334. /**
  50335. * this is used to register native functions using the configuration object.
  50336. * This will configure the observers.
  50337. * @param observersConfiguration observers configuration
  50338. */
  50339. AbstractViewer.prototype._configureObservers = function (observersConfiguration) {
  50340. if (observersConfiguration.onEngineInit) {
  50341. this.onEngineInitObservable.add(window[observersConfiguration.onEngineInit]);
  50342. }
  50343. else {
  50344. if (observersConfiguration.onEngineInit === '' && this.configuration.observers && this.configuration.observers.onEngineInit) {
  50345. this.onEngineInitObservable.removeCallback(window[this.configuration.observers.onEngineInit]);
  50346. }
  50347. }
  50348. if (observersConfiguration.onSceneInit) {
  50349. this.onSceneInitObservable.add(window[observersConfiguration.onSceneInit]);
  50350. }
  50351. else {
  50352. if (observersConfiguration.onSceneInit === '' && this.configuration.observers && this.configuration.observers.onSceneInit) {
  50353. this.onSceneInitObservable.removeCallback(window[this.configuration.observers.onSceneInit]);
  50354. }
  50355. }
  50356. if (observersConfiguration.onModelLoaded) {
  50357. this.onModelLoadedObservable.add(window[observersConfiguration.onModelLoaded]);
  50358. }
  50359. else {
  50360. if (observersConfiguration.onModelLoaded === '' && this.configuration.observers && this.configuration.observers.onModelLoaded) {
  50361. this.onModelLoadedObservable.removeCallback(window[this.configuration.observers.onModelLoaded]);
  50362. }
  50363. }
  50364. };
  50365. /**
  50366. * Dispoe the entire viewer including the scene and the engine
  50367. */
  50368. AbstractViewer.prototype.dispose = function () {
  50369. if (this._isDisposed) {
  50370. return;
  50371. }
  50372. window.removeEventListener('resize', this._resize);
  50373. if (this.sceneManager) {
  50374. if (this.sceneManager.scene && this.sceneManager.scene.activeCamera) {
  50375. this.sceneManager.scene.activeCamera.detachControl(this.canvas);
  50376. }
  50377. this.sceneManager.dispose();
  50378. }
  50379. this._fpsTimeoutInterval && clearInterval(this._fpsTimeoutInterval);
  50380. this.observablesManager.dispose();
  50381. this.modelLoader.dispose();
  50382. if (this.engine) {
  50383. this.engine.dispose();
  50384. }
  50385. viewerManager_1.viewerManager.removeViewer(this);
  50386. this._isDisposed = true;
  50387. };
  50388. /**
  50389. * This function will execute when the HTML templates finished initializing.
  50390. * It should initialize the engine and continue execution.
  50391. *
  50392. * @returns {Promise<AbstractViewer>} The viewer object will be returned after the object was loaded.
  50393. */
  50394. AbstractViewer.prototype._onTemplatesLoaded = function () {
  50395. return Promise.resolve(this);
  50396. };
  50397. /**
  50398. * This will force the creation of an engine and a scene.
  50399. * It will also load a model if preconfigured.
  50400. * But first - it will load the extendible onTemplateLoaded()!
  50401. */
  50402. AbstractViewer.prototype._onTemplateLoaded = function () {
  50403. var _this = this;
  50404. // check if viewer was disposed right after created
  50405. if (this._isDisposed) {
  50406. return Promise.reject("viewer was disposed");
  50407. }
  50408. return this._onTemplatesLoaded().then(function () {
  50409. var autoLoad = typeof _this.configuration.model === 'string' || (_this.configuration.model && _this.configuration.model.url);
  50410. return _this._initEngine().then(function (engine) {
  50411. return _this.onEngineInitObservable.notifyObserversWithPromise(engine);
  50412. }).then(function () {
  50413. _this._initTelemetryEvents();
  50414. if (autoLoad) {
  50415. return _this.loadModel(_this.configuration.model).catch(function (e) { }).then(function () { return _this.sceneManager.scene; });
  50416. }
  50417. else {
  50418. return _this.sceneManager.scene || _this.sceneManager.initScene(_this.configuration.scene);
  50419. }
  50420. }).then(function () {
  50421. return _this.onInitDoneObservable.notifyObserversWithPromise(_this);
  50422. }).catch(function (e) {
  50423. babylonjs_1.Tools.Warn(e.toString());
  50424. return _this;
  50425. });
  50426. });
  50427. };
  50428. /**
  50429. * Initialize the engine. Retruns a promise in case async calls are needed.
  50430. *
  50431. * @protected
  50432. * @returns {Promise<Engine>}
  50433. * @memberof Viewer
  50434. */
  50435. AbstractViewer.prototype._initEngine = function () {
  50436. // init custom shaders
  50437. this._injectCustomShaders();
  50438. //let canvasElement = this.templateManager.getCanvas();
  50439. if (!this.canvas) {
  50440. return Promise.reject('Canvas element not found!');
  50441. }
  50442. var config = this.configuration.engine || {};
  50443. // TDO enable further configuration
  50444. // check for webgl2 support, force-disable if needed.
  50445. if (globals_1.viewerGlobals.disableWebGL2Support) {
  50446. config.engineOptions = config.engineOptions || {};
  50447. config.engineOptions.disableWebGL2Support = true;
  50448. }
  50449. this.engine = new babylonjs_1.Engine(this.canvas, !!config.antialiasing, config.engineOptions);
  50450. // Disable manifest checking
  50451. babylonjs_1.Database.IDBStorageEnabled = false;
  50452. if (!config.disableResize) {
  50453. window.addEventListener('resize', this._resize);
  50454. }
  50455. if (this.configuration.engine && this.configuration.engine.adaptiveQuality) {
  50456. var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
  50457. this.engine.setHardwareScalingLevel(scale);
  50458. }
  50459. // create a new template manager for this viewer
  50460. this.sceneManager = new sceneManager_1.SceneManager(this.engine, this._configurationContainer, this.observablesManager);
  50461. return Promise.resolve(this.engine);
  50462. };
  50463. /**
  50464. * Initialize a model loading. The returned object (a ViewerModel object) will be loaded in the background.
  50465. * The difference between this and loadModel is that loadModel will fulfill the promise when the model finished loading.
  50466. *
  50467. * @param modelConfig model configuration to use when loading the model.
  50468. * @param clearScene should the scene be cleared before loading this model
  50469. * @returns a ViewerModel object that is not yet fully loaded.
  50470. */
  50471. AbstractViewer.prototype.initModel = function (modelConfig, clearScene) {
  50472. var _this = this;
  50473. if (clearScene === void 0) { clearScene = true; }
  50474. var configuration;
  50475. if (typeof modelConfig === 'string') {
  50476. configuration = {
  50477. url: modelConfig
  50478. };
  50479. }
  50480. else if (modelConfig instanceof File) {
  50481. configuration = {
  50482. file: modelConfig,
  50483. root: "file:"
  50484. };
  50485. }
  50486. else {
  50487. configuration = modelConfig;
  50488. }
  50489. if (!configuration.url && !configuration.file) {
  50490. throw new Error("no model provided");
  50491. }
  50492. if (clearScene) {
  50493. this.sceneManager.clearScene(true, false);
  50494. }
  50495. //merge the configuration for future models:
  50496. if (this.configuration.model && typeof this.configuration.model === 'object') {
  50497. var globalConfig = _1.deepmerge({}, this.configuration.model);
  50498. configuration = _1.deepmerge(globalConfig, configuration);
  50499. if (modelConfig instanceof File) {
  50500. configuration.file = modelConfig;
  50501. }
  50502. }
  50503. else {
  50504. this.configuration.model = configuration;
  50505. }
  50506. this._isLoading = true;
  50507. var model = this.modelLoader.load(configuration);
  50508. this.lastUsedLoader = model.loader;
  50509. model.onLoadErrorObservable.add(function (errorObject) {
  50510. _this.onModelLoadErrorObservable.notifyObserversWithPromise(errorObject);
  50511. });
  50512. model.onLoadProgressObservable.add(function (progressEvent) {
  50513. _this.onModelLoadProgressObservable.notifyObserversWithPromise(progressEvent);
  50514. });
  50515. this.onLoaderInitObservable.notifyObserversWithPromise(this.lastUsedLoader);
  50516. model.onLoadedObservable.add(function () {
  50517. _this._isLoading = false;
  50518. });
  50519. return model;
  50520. };
  50521. /**
  50522. * load a model using the provided configuration.
  50523. * This function, as opposed to initModel, will return a promise that resolves when the model is loaded, and rejects with error.
  50524. * If you want to attach to the observables of the model, use initModle instead.
  50525. *
  50526. * @param modelConfig the model configuration or URL to load.
  50527. * @param clearScene Should the scene be cleared before loading the model
  50528. * @returns a Promise the fulfills when the model finished loading successfully.
  50529. */
  50530. AbstractViewer.prototype.loadModel = function (modelConfig, clearScene) {
  50531. var _this = this;
  50532. if (clearScene === void 0) { clearScene = true; }
  50533. if (this._isLoading) {
  50534. // We can decide here whether or not to cancel the lst load, but the developer can do that.
  50535. return Promise.reject("another model is curently being loaded.");
  50536. }
  50537. return Promise.resolve(this.sceneManager.scene).then(function (scene) {
  50538. if (!scene)
  50539. return _this.sceneManager.initScene(_this.configuration.scene, _this.configuration.optimizer);
  50540. return scene;
  50541. }).then(function () {
  50542. var model = _this.initModel(modelConfig, clearScene);
  50543. return new Promise(function (resolve, reject) {
  50544. // at this point, configuration.model is an object, not a string
  50545. model.onLoadedObservable.add(function () {
  50546. resolve(model);
  50547. });
  50548. model.onLoadErrorObservable.add(function (error) {
  50549. reject(error);
  50550. });
  50551. });
  50552. });
  50553. };
  50554. AbstractViewer.prototype._initTelemetryEvents = function () {
  50555. var _this = this;
  50556. telemetryManager_1.telemetryManager.broadcast("Engine Capabilities", this.baseId, this.engine.getCaps());
  50557. telemetryManager_1.telemetryManager.broadcast("Platform Details", this.baseId, {
  50558. userAgent: navigator.userAgent,
  50559. platform: navigator.platform
  50560. });
  50561. telemetryManager_1.telemetryManager.flushWebGLErrors(this.engine, this.baseId);
  50562. var trackFPS = function () {
  50563. telemetryManager_1.telemetryManager.broadcast("Current FPS", _this.baseId, { fps: _this.engine.getFps() });
  50564. };
  50565. trackFPS();
  50566. // Track the FPS again after 60 seconds
  50567. this._fpsTimeoutInterval = window.setInterval(trackFPS, 60 * 1000);
  50568. };
  50569. /**
  50570. * Injects all the spectre shader in the babylon shader store
  50571. */
  50572. AbstractViewer.prototype._injectCustomShaders = function () {
  50573. var customShaders = this.configuration.customShaders;
  50574. // Inject all the spectre shader in the babylon shader store.
  50575. if (!customShaders) {
  50576. return;
  50577. }
  50578. if (customShaders.shaders) {
  50579. Object.keys(customShaders.shaders).forEach(function (key) {
  50580. // typescript considers a callback "unsafe", so... '!'
  50581. babylonjs_1.Effect.ShadersStore[key] = customShaders.shaders[key];
  50582. });
  50583. }
  50584. if (customShaders.includes) {
  50585. Object.keys(customShaders.includes).forEach(function (key) {
  50586. // typescript considers a callback "unsafe", so... '!'
  50587. babylonjs_1.Effect.IncludesShadersStore[key] = customShaders.includes[key];
  50588. });
  50589. }
  50590. };
  50591. return AbstractViewer;
  50592. }());
  50593. exports.AbstractViewer = AbstractViewer;
  50594. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlld2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3ZpZXdlci92aWV3ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpREFBZ0Q7QUFDaEQseURBQXdEO0FBQ3hELGtEQUE4RDtBQUM5RCx1Q0FBbWdCO0FBS25nQixxREFBb0Q7QUFFcEQsb0RBQXlEO0FBRXpELGlFQUFnRTtBQUNoRSwrQkFBdUM7QUFDdkMscUVBQW9FO0FBQ3BFLGtGQUFpRjtB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FDeEIsTUFBTSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsUUFBUSxDQUFDLENBQUMsT0FBTyxDQUFDLFVBQUEsR0FBRztnQkFDM0Msc0RBQXNEO2dCQUN0RCxrQkFBTSxDQUFDLG9CQUFvQixDQUFDLEdBQUcsQ0FBQyxHQUFHLGFBQWMsQ0FBQyxRQUFTLENBQUMsR0FBRyxDQUFDLENBQUM7WUFDckUsQ0FBQyxDQUFDLENBQUM7U0FDTjtJQUNMLENBQUM7SUFDTCxxQkFBQztBQUFELENBQUMsQUE5bkJELElBOG5CQztBQTluQnFCLHdDQUFjIn0=
  50595. /***/ }),
  50596. /* 10 */
  50597. /***/ (function(module, exports, __webpack_require__) {
  50598. "use strict";
  50599. function __export(m) {
  50600. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  50601. }
  50602. Object.defineProperty(exports, "__esModule", { value: true });
  50603. __export(__webpack_require__(11));
  50604. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29uZmlndXJhdGlvbi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHFDQUFnQyJ9
  50605. /***/ }),
  50606. /* 11 */
  50607. /***/ (function(module, exports, __webpack_require__) {
  50608. "use strict";
  50609. Object.defineProperty(exports, "__esModule", { value: true });
  50610. function getConfigurationKey(key, configObject) {
  50611. var splits = key.split('.');
  50612. if (splits.length === 0 || !configObject)
  50613. return;
  50614. else if (splits.length === 1) {
  50615. if (configObject[key] !== undefined) {
  50616. return configObject[key];
  50617. }
  50618. }
  50619. else {
  50620. var firstKey = splits.shift();
  50621. return getConfigurationKey(splits.join("."), configObject[firstKey]);
  50622. }
  50623. }
  50624. exports.getConfigurationKey = getConfigurationKey;
  50625. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlndXJhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL2NvbmZpZ3VyYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFHQSw2QkFBb0MsR0FBVyxFQUFFLFlBQWlCO0lBQzlELElBQUksTUFBTSxHQUFHLEdBQUcsQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7SUFFNUIsSUFBSSxNQUFNLENBQUMsTUFBTSxLQUFLLENBQUMsSUFBSSxDQUFDLFlBQVk7UUFBRSxPQUFPO1NBQzVDLElBQUksTUFBTSxDQUFDLE1BQU0sS0FBSyxDQUFDLEVBQUU7UUFDMUIsSUFBSSxZQUFZLENBQUMsR0FBRyxDQUFDLEtBQUssU0FBUyxFQUFFO1lBQ2pDLE9BQU8sWUFBWSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1NBQzVCO0tBQ0o7U0FBTTtRQUNILElBQUksUUFBUSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM5QixPQUFPLG1CQUFtQixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsWUFBWSxDQUFDLFFBQVMsQ0FBQyxDQUFDLENBQUE7S0FDeEU7QUFDTCxDQUFDO0FBWkQsa0RBWUMifQ==
  50626. /***/ }),
  50627. /* 12 */
  50628. /***/ (function(module, exports, __webpack_require__) {
  50629. "use strict";
  50630. Object.defineProperty(exports, "__esModule", { value: true });
  50631. var babylonjs_1 = __webpack_require__(0);
  50632. /**
  50633. * A minimal WebGL cubemap descriptor
  50634. */
  50635. var TextureCube = /** @class */ (function () {
  50636. /**
  50637. * constructor
  50638. * @param internalFormat WebGL pixel format for the texture on the GPU
  50639. * @param type WebGL pixel type of the supplied data and texture on the GPU
  50640. * @param source An array containing mipmap levels of faces, where each mipmap level is an array of faces and each face is a TextureSource object
  50641. */
  50642. function TextureCube(internalFormat, type, source) {
  50643. if (source === void 0) { source = []; }
  50644. this.internalFormat = internalFormat;
  50645. this.type = type;
  50646. this.source = source;
  50647. }
  50648. Object.defineProperty(TextureCube.prototype, "Width", {
  50649. /**
  50650. * Returns the width of a face of the texture or 0 if not available
  50651. */
  50652. get: function () {
  50653. return (this.source && this.source[0] && this.source[0][0]) ? this.source[0][0].width : 0;
  50654. },
  50655. enumerable: true,
  50656. configurable: true
  50657. });
  50658. Object.defineProperty(TextureCube.prototype, "Height", {
  50659. /**
  50660. * Returns the height of a face of the texture or 0 if not available
  50661. */
  50662. get: function () {
  50663. return (this.source && this.source[0] && this.source[0][0]) ? this.source[0][0].height : 0;
  50664. },
  50665. enumerable: true,
  50666. configurable: true
  50667. });
  50668. return TextureCube;
  50669. }());
  50670. exports.TextureCube = TextureCube;
  50671. /**
  50672. * A static class providing methods to aid working with Bablyon textures.
  50673. */
  50674. var TextureUtils = /** @class */ (function () {
  50675. function TextureUtils() {
  50676. }
  50677. /**
  50678. * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
  50679. * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
  50680. * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
  50681. * @param scene A Babylon Scene instance
  50682. * @param textureCube A Spectre TextureCube object
  50683. * @param parameters WebGL texture sampling parameters
  50684. * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
  50685. * @param environment Specifies that the texture will be used as an environment
  50686. * @param singleLod Specifies that the texture will be a singleLod (for environment)
  50687. * @return Babylon cube texture
  50688. */
  50689. TextureUtils.GetBabylonCubeTexture = function (scene, textureCube, automaticMipmaps, environment, singleLod) {
  50690. if (environment === void 0) { environment = false; }
  50691. if (singleLod === void 0) { singleLod = false; }
  50692. if (!textureCube)
  50693. throw new Error("no texture cube provided");
  50694. var parameters;
  50695. if (environment) {
  50696. parameters = singleLod ? TextureUtils._EnvironmentSingleMipSampling : TextureUtils._EnvironmentSampling;
  50697. }
  50698. else {
  50699. parameters = {
  50700. magFilter: 9728 /* NEAREST */,
  50701. minFilter: 9728 /* NEAREST */,
  50702. wrapS: 33071 /* CLAMP_TO_EDGE */,
  50703. wrapT: 33071 /* CLAMP_TO_EDGE */
  50704. };
  50705. }
  50706. var key = TextureUtils.BabylonTextureKeyPrefix + parameters.magFilter + '' + parameters.minFilter + '' + parameters.wrapS + '' + parameters.wrapT;
  50707. var babylonTexture = textureCube[key];
  50708. if (!babylonTexture) {
  50709. //initialize babylon texture
  50710. babylonTexture = new babylonjs_1.CubeTexture('', scene);
  50711. if (environment) {
  50712. babylonTexture.lodGenerationOffset = TextureUtils.EnvironmentLODOffset;
  50713. babylonTexture.lodGenerationScale = TextureUtils.EnvironmentLODScale;
  50714. }
  50715. babylonTexture.gammaSpace = false;
  50716. var internalTexture_1 = new babylonjs_1.InternalTexture(scene.getEngine(), babylonjs_1.InternalTexture.DATASOURCE_CUBERAW);
  50717. var glTexture_1 = internalTexture_1._webGLTexture;
  50718. //babylon properties
  50719. internalTexture_1.isCube = true;
  50720. internalTexture_1.generateMipMaps = false;
  50721. babylonTexture._texture = internalTexture_1;
  50722. TextureUtils.ApplySamplingParameters(babylonTexture, parameters);
  50723. var maxMipLevel_1 = automaticMipmaps ? 0 : textureCube.source.length - 1;
  50724. var texturesUploaded_1 = 0;
  50725. var textureComplete = function () {
  50726. return texturesUploaded_1 === ((maxMipLevel_1 + 1) * 6);
  50727. };
  50728. var uploadFace = function (i, level, face) {
  50729. if (!glTexture_1)
  50730. return;
  50731. if (i === 0 && level === 0) {
  50732. internalTexture_1.width = face.width;
  50733. internalTexture_1.height = face.height;
  50734. }
  50735. var gl = (scene.getEngine())._gl;
  50736. gl.bindTexture(gl.TEXTURE_CUBE_MAP, glTexture_1);
  50737. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
  50738. if (face instanceof HTMLElement || face instanceof ImageData) {
  50739. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureCube.internalFormat, textureCube.type, face);
  50740. }
  50741. else {
  50742. var textureData = face;
  50743. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureData.width, textureData.height, 0, textureData.format, textureCube.type, textureData.data);
  50744. }
  50745. texturesUploaded_1++;
  50746. if (textureComplete()) {
  50747. //generate mipmaps
  50748. if (automaticMipmaps) {
  50749. var w = face.width;
  50750. var h = face.height;
  50751. var isPot = (((w !== 0) && (w & (w - 1))) === 0) && (((h !== 0) && (h & (h - 1))) === 0);
  50752. if (isPot) {
  50753. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  50754. }
  50755. }
  50756. // Upload Separate lods in case there is no support for texture lod.
  50757. if (environment && !scene.getEngine().getCaps().textureLOD && !singleLod) {
  50758. var mipSlices = 3;
  50759. for (var i_1 = 0; i_1 < mipSlices; i_1++) {
  50760. var lodKey = TextureUtils.BabylonTextureKeyPrefix + 'lod' + i_1;
  50761. var lod = textureCube[lodKey];
  50762. //initialize lod texture if it doesn't already exist
  50763. if (lod == null && textureCube.Width) {
  50764. //compute LOD from even spacing in smoothness (matching shader calculation)
  50765. var smoothness = i_1 / (mipSlices - 1);
  50766. var roughness = 1 - smoothness;
  50767. var kMinimumVariance = 0.0005;
  50768. var alphaG = roughness * roughness + kMinimumVariance;
  50769. var microsurfaceAverageSlopeTexels = alphaG * textureCube.Width;
  50770. var environmentSpecularLOD = TextureUtils.EnvironmentLODScale * (babylonjs_1.Scalar.Log2(microsurfaceAverageSlopeTexels)) + TextureUtils.EnvironmentLODOffset;
  50771. var maxLODIndex = textureCube.source.length - 1;
  50772. var mipmapIndex = Math.min(Math.max(Math.round(environmentSpecularLOD), 0), maxLODIndex);
  50773. lod = TextureUtils.GetBabylonCubeTexture(scene, new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */, [textureCube.source[mipmapIndex]]), false, true, true);
  50774. if (i_1 === 0) {
  50775. internalTexture_1._lodTextureLow = lod;
  50776. }
  50777. else if (i_1 === 1) {
  50778. internalTexture_1._lodTextureMid = lod;
  50779. }
  50780. else {
  50781. internalTexture_1._lodTextureHigh = lod;
  50782. }
  50783. textureCube[lodKey] = lod;
  50784. }
  50785. }
  50786. }
  50787. internalTexture_1.isReady = true;
  50788. }
  50789. gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
  50790. scene.getEngine().resetTextureCache();
  50791. };
  50792. var _loop_1 = function (i) {
  50793. var faces = textureCube.source[i];
  50794. var _loop_2 = function (j) {
  50795. var face = faces[j];
  50796. if (face instanceof HTMLImageElement && !face.complete) {
  50797. face.addEventListener('load', function () {
  50798. uploadFace(j, i, face);
  50799. }, false);
  50800. }
  50801. else {
  50802. uploadFace(j, i, face);
  50803. }
  50804. };
  50805. for (var j = 0; j < faces.length; j++) {
  50806. _loop_2(j);
  50807. }
  50808. };
  50809. for (var i = 0; i <= maxMipLevel_1; i++) {
  50810. _loop_1(i);
  50811. }
  50812. scene.getEngine().resetTextureCache();
  50813. babylonTexture.isReady = function () {
  50814. return textureComplete();
  50815. };
  50816. textureCube[key] = babylonTexture;
  50817. }
  50818. return babylonTexture;
  50819. };
  50820. /**
  50821. * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
  50822. * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
  50823. * @param parameters Spectre SamplingParameters to apply
  50824. */
  50825. TextureUtils.ApplySamplingParameters = function (babylonTexture, parameters) {
  50826. var scene = babylonTexture.getScene();
  50827. if (!scene)
  50828. return;
  50829. var gl = (scene.getEngine())._gl;
  50830. var target = babylonTexture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
  50831. var internalTexture = babylonTexture._texture;
  50832. if (!internalTexture)
  50833. return;
  50834. var glTexture = internalTexture._webGLTexture;
  50835. gl.bindTexture(target, glTexture);
  50836. if (parameters.magFilter != null)
  50837. gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, parameters.magFilter);
  50838. if (parameters.minFilter != null)
  50839. gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, parameters.minFilter);
  50840. if (parameters.wrapS != null)
  50841. gl.texParameteri(target, gl.TEXTURE_WRAP_S, parameters.wrapS);
  50842. if (parameters.wrapT != null)
  50843. gl.texParameteri(target, gl.TEXTURE_WRAP_T, parameters.wrapT);
  50844. //set babylon wrap modes from sampling parameter
  50845. switch (parameters.wrapS) {
  50846. case 10497 /* REPEAT */:
  50847. babylonTexture.wrapU = babylonjs_1.Texture.WRAP_ADDRESSMODE;
  50848. break;
  50849. case 33071 /* CLAMP_TO_EDGE */:
  50850. babylonTexture.wrapU = babylonjs_1.Texture.CLAMP_ADDRESSMODE;
  50851. break;
  50852. case 33648 /* MIRRORED_REPEAT */:
  50853. babylonTexture.wrapU = babylonjs_1.Texture.MIRROR_ADDRESSMODE;
  50854. break;
  50855. default: babylonTexture.wrapU = babylonjs_1.Texture.CLAMP_ADDRESSMODE;
  50856. }
  50857. switch (parameters.wrapT) {
  50858. case 10497 /* REPEAT */:
  50859. babylonTexture.wrapV = babylonjs_1.Texture.WRAP_ADDRESSMODE;
  50860. break;
  50861. case 33071 /* CLAMP_TO_EDGE */:
  50862. babylonTexture.wrapV = babylonjs_1.Texture.CLAMP_ADDRESSMODE;
  50863. break;
  50864. case 33648 /* MIRRORED_REPEAT */:
  50865. babylonTexture.wrapV = babylonjs_1.Texture.MIRROR_ADDRESSMODE;
  50866. break;
  50867. default: babylonTexture.wrapV = babylonjs_1.Texture.CLAMP_ADDRESSMODE;
  50868. }
  50869. if (parameters.maxAnisotropy != null && parameters.maxAnisotropy > 1) {
  50870. var anisotropicExt = gl.getExtension('EXT_texture_filter_anisotropic');
  50871. if (anisotropicExt) {
  50872. var maxAnisotropicSamples = gl.getParameter(anisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  50873. var maxAnisotropy = Math.min(parameters.maxAnisotropy, maxAnisotropicSamples);
  50874. gl.texParameterf(target, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
  50875. babylonTexture.anisotropicFilteringLevel = maxAnisotropy;
  50876. }
  50877. }
  50878. gl.bindTexture(target, null);
  50879. scene.getEngine().resetTextureCache();
  50880. };
  50881. /**
  50882. * A prefix used when storing a babylon texture object reference on a Spectre texture object
  50883. */
  50884. TextureUtils.BabylonTextureKeyPrefix = '__babylonTexture_';
  50885. /**
  50886. * Controls anisotropic filtering for deserialized textures.
  50887. */
  50888. TextureUtils.MaxAnisotropy = 4;
  50889. TextureUtils._EnvironmentSampling = {
  50890. magFilter: 9729 /* LINEAR */,
  50891. minFilter: 9987 /* LINEAR_MIPMAP_LINEAR */,
  50892. wrapS: 33071 /* CLAMP_TO_EDGE */,
  50893. wrapT: 33071 /* CLAMP_TO_EDGE */,
  50894. maxAnisotropy: 1
  50895. };
  50896. TextureUtils._EnvironmentSingleMipSampling = {
  50897. magFilter: 9729 /* LINEAR */,
  50898. minFilter: 9729 /* LINEAR */,
  50899. wrapS: 33071 /* CLAMP_TO_EDGE */,
  50900. wrapT: 33071 /* CLAMP_TO_EDGE */,
  50901. maxAnisotropy: 1
  50902. };
  50903. //from "/Internal/Lighting.EnvironmentFilterScale" in Engine/*/Configuration.cpp
  50904. /**
  50905. * Environment preprocessing dedicated value (Internal Use or Advanced only).
  50906. */
  50907. TextureUtils.EnvironmentLODScale = 0.8;
  50908. /**
  50909. * Environment preprocessing dedicated value (Internal Use or Advanced only)..
  50910. */
  50911. TextureUtils.EnvironmentLODOffset = 1.0;
  50912. return TextureUtils;
  50913. }());
  50914. exports.TextureUtils = TextureUtils;
  50915. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGV4dHVyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3N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* 13 */
  50918. /***/ (function(module, exports, __webpack_require__) {
  50919. "use strict";
  50920. Object.defineProperty(exports, "__esModule", { value: true });
  50921. var babylonjs_1 = __webpack_require__(0);
  50922. var babylonjs_loaders_1 = __webpack_require__(14);
  50923. var viewerModel_1 = __webpack_require__(5);
  50924. var _1 = __webpack_require__(54);
  50925. /**
  50926. * An instance of the class is in charge of loading the model correctly.
  50927. * This class will continously be expended with tasks required from the specific loaders Babylon has.
  50928. *
  50929. * A Model loader is unique per (Abstract)Viewer. It is being generated by the viewer
  50930. */
  50931. var ModelLoader = /** @class */ (function () {
  50932. /**
  50933. * Create a new Model loader
  50934. * @param _viewer the viewer using this model loader
  50935. */
  50936. function ModelLoader(_observablesManager, _configurationContainer) {
  50937. this._observablesManager = _observablesManager;
  50938. this._configurationContainer = _configurationContainer;
  50939. this._disposed = false;
  50940. this._loaders = [];
  50941. this._loadId = 0;
  50942. this._plugins = [];
  50943. }
  50944. /**
  50945. * Adds a new plugin to the loader process.
  50946. *
  50947. * @param plugin the plugin name or the plugin itself
  50948. */
  50949. ModelLoader.prototype.addPlugin = function (plugin) {
  50950. var actualPlugin = {};
  50951. if (typeof plugin === 'string') {
  50952. var loadedPlugin = _1.getLoaderPluginByName(plugin);
  50953. if (loadedPlugin) {
  50954. actualPlugin = loadedPlugin;
  50955. }
  50956. }
  50957. else {
  50958. actualPlugin = plugin;
  50959. }
  50960. if (actualPlugin && this._plugins.indexOf(actualPlugin) === -1) {
  50961. this._plugins.push(actualPlugin);
  50962. }
  50963. };
  50964. /**
  50965. * Load a model using predefined configuration
  50966. * @param modelConfiguration the modelConfiguration to use to load the model
  50967. */
  50968. ModelLoader.prototype.load = function (modelConfiguration) {
  50969. var _this = this;
  50970. var model = new viewerModel_1.ViewerModel(this._observablesManager, modelConfiguration);
  50971. model.loadId = this._loadId++;
  50972. if (!modelConfiguration.url) {
  50973. model.state = viewerModel_1.ModelState.ERROR;
  50974. babylonjs_1.Tools.Error("No URL provided");
  50975. return model;
  50976. }
  50977. var base;
  50978. var filename;
  50979. if (modelConfiguration.file) {
  50980. base = "file:";
  50981. filename = modelConfiguration.file;
  50982. }
  50983. else {
  50984. filename = babylonjs_1.Tools.GetFilename(modelConfiguration.url) || modelConfiguration.url;
  50985. base = modelConfiguration.root || babylonjs_1.Tools.GetFolderPath(modelConfiguration.url);
  50986. }
  50987. var plugin = modelConfiguration.loader;
  50988. var scene = model.rootMesh.getScene();
  50989. model.loader = babylonjs_1.SceneLoader.ImportMesh(undefined, base, filename, scene, function (meshes, particleSystems, skeletons, animationGroups) {
  50990. meshes.forEach(function (mesh) {
  50991. babylonjs_1.Tags.AddTagsTo(mesh, "viewerMesh");
  50992. model.addMesh(mesh);
  50993. });
  50994. model.particleSystems = particleSystems;
  50995. model.skeletons = skeletons;
  50996. for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
  50997. var animationGroup = animationGroups_1[_i];
  50998. model.addAnimationGroup(animationGroup);
  50999. }
  51000. _this._checkAndRun("onLoaded", model);
  51001. scene.executeWhenReady(function () {
  51002. model.onLoadedObservable.notifyObservers(model);
  51003. });
  51004. }, function (progressEvent) {
  51005. _this._checkAndRun("onProgress", progressEvent);
  51006. model.onLoadProgressObservable.notifyObserversWithPromise(progressEvent);
  51007. }, function (scene, m, exception) {
  51008. model.state = viewerModel_1.ModelState.ERROR;
  51009. babylonjs_1.Tools.Error("Load Error: There was an error loading the model. " + m);
  51010. _this._checkAndRun("onError", m, exception);
  51011. model.onLoadErrorObservable.notifyObserversWithPromise({ message: m, exception: exception });
  51012. }, plugin);
  51013. if (model.loader.name === "gltf") {
  51014. var gltfLoader_1 = model.loader;
  51015. gltfLoader_1.animationStartMode = babylonjs_loaders_1.GLTFLoaderAnimationStartMode.NONE;
  51016. gltfLoader_1.compileMaterials = true;
  51017. if (!modelConfiguration.file) {
  51018. gltfLoader_1.rewriteRootURL = function (rootURL, responseURL) {
  51019. return modelConfiguration.root || babylonjs_1.Tools.GetFolderPath(responseURL || modelConfiguration.url || '');
  51020. };
  51021. }
  51022. // if ground is set to "mirror":
  51023. if (this._configurationContainer
  51024. && this._configurationContainer.configuration
  51025. && this._configurationContainer.configuration.ground
  51026. && typeof this._configurationContainer.configuration.ground === 'object'
  51027. && this._configurationContainer.configuration.ground.mirror) {
  51028. gltfLoader_1.useClipPlane = true;
  51029. }
  51030. Object.keys(gltfLoader_1).filter(function (name) { return name.indexOf('on') === 0 && name.indexOf('Observable') !== -1; }).forEach(function (functionName) {
  51031. gltfLoader_1[functionName].add(function (payload) {
  51032. _this._checkAndRun(functionName.replace("Observable", ''), payload);
  51033. });
  51034. });
  51035. gltfLoader_1.onParsedObservable.add(function (data) {
  51036. if (data && data.json && data.json['asset']) {
  51037. model.loadInfo = data.json['asset'];
  51038. }
  51039. });
  51040. gltfLoader_1.onCompleteObservable.add(function () {
  51041. model.loaderDone = true;
  51042. });
  51043. }
  51044. else {
  51045. model.loaderDone = true;
  51046. }
  51047. this._checkAndRun("onInit", model.loader, model);
  51048. this._loaders.push(model.loader);
  51049. return model;
  51050. };
  51051. ModelLoader.prototype.cancelLoad = function (model) {
  51052. var loader = model.loader || this._loaders[model.loadId];
  51053. // ATM only available in the GLTF Loader
  51054. if (loader && loader.name === "gltf") {
  51055. var gltfLoader = loader;
  51056. gltfLoader.dispose();
  51057. model.state = viewerModel_1.ModelState.CANCELED;
  51058. }
  51059. else {
  51060. babylonjs_1.Tools.Warn("This type of loader cannot cancel the request");
  51061. }
  51062. };
  51063. /**
  51064. * dispose the model loader.
  51065. * If loaders are registered and are in the middle of loading, they will be disposed and the request(s) will be cancelled.
  51066. */
  51067. ModelLoader.prototype.dispose = function () {
  51068. this._loaders.forEach(function (loader) {
  51069. if (loader.name === "gltf") {
  51070. loader.dispose();
  51071. }
  51072. });
  51073. this._loaders.length = 0;
  51074. this._disposed = true;
  51075. };
  51076. ModelLoader.prototype._checkAndRun = function (functionName) {
  51077. var _this = this;
  51078. var payload = [];
  51079. for (var _i = 1; _i < arguments.length; _i++) {
  51080. payload[_i - 1] = arguments[_i];
  51081. }
  51082. if (this._disposed)
  51083. return;
  51084. this._plugins.filter(function (p) { return p[functionName]; }).forEach(function (plugin) {
  51085. try {
  51086. plugin[functionName].apply(_this, payload);
  51087. }
  51088. catch (e) { }
  51089. });
  51090. };
  51091. return ModelLoader;
  51092. }());
  51093. exports.ModelLoader = ModelLoader;
  51094. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kZWxMb2FkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbG9hZGVyL21vZGVsTG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsdUNBQWtHO0FBQ2xHLHVEQUFpRjtBQUdqRixvREFBK0Q7QUFDL0QsK0JBQXlGO0FBSXpGOzs7OztHQUtHO0FBQ0g7SUFTSTs7O09BR0c7SUFDSCxxQkFBb0IsbUJBQXVDLEVBQVUsdUJBQWdEO1FBQWpHLHdCQUFtQixHQUFuQixtQkFBbUIsQ0FBb0I7UUFBVSw0QkFBdUIsR0FBdkIsdUJBQXVCLENBQXlCO1FBVjdHLGNBQVMsR0FBRyxLQUFLLENBQUM7UUFXdEIsSUFBSSxDQUFDLFFBQVEsR0FBRyxFQUFFLENBQUM7UUFDbkIsSUFBSSxDQUFDLE9BQU8sR0FBRyxDQUFDLENBQUM7UUFDakIsSUFBSSxDQUFDLFFBQVEsR0FBRyxFQUFFLENBQUM7SUFDdkIsQ0FBQztJQUVEOzs7O09BSUc7SUFDSSwrQkFBUyxHQUFoQixVQUFpQixNQUE4QjtRQUMzQyxJQUFJLFlBQVksR0FBa0IsRUFBRSxDQUFDO1FBQ3JDLElBQUksT0FBTyxNQUFNLEtBQUssUUFBUSxFQUFFO1lBQzVCLElBQUksWUFBWSxHQUFHLHdCQUFxQixDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBQ2pELElBQU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FoTFksa0NBQVcifQ==
  51095. /***/ }),
  51096. /* 14 */
  51097. /***/ (function(module, exports, __webpack_require__) {
  51098. (function universalModuleDefinition(root, factory) {
  51099. var amdDependencies = [];
  51100. var BABYLON = root.BABYLON || this.BABYLON;
  51101. if(true) {
  51102. BABYLON = BABYLON || __webpack_require__(0);
  51103. module.exports = factory(BABYLON);
  51104. } else if(typeof define === 'function' && define.amd) {
  51105. amdDependencies.push("babylonjs");
  51106. define("babylonjs-loaders", amdDependencies, factory);
  51107. } else if(typeof exports === 'object') {
  51108. BABYLON = BABYLON || require("babylonjs");
  51109. exports["babylonjs-loaders"] = factory(BABYLON);
  51110. } else {
  51111. root["BABYLON"] = factory(BABYLON);
  51112. }
  51113. })(this, function(BABYLON) {
  51114. BABYLON = BABYLON || this.BABYLON;
  51115. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  51116. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  51117. var BABYLON;
  51118. (function (BABYLON) {
  51119. var STLFileLoader = /** @class */ (function () {
  51120. function STLFileLoader() {
  51121. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  51122. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  51123. this.normalPattern = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  51124. this.vertexPattern = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  51125. this.name = "stl";
  51126. // force data to come in as an ArrayBuffer
  51127. // we'll convert to string if it looks like it's an ASCII .stl
  51128. this.extensions = {
  51129. ".stl": { isBinary: true },
  51130. };
  51131. }
  51132. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  51133. var matches;
  51134. if (this.isBinary(data)) {
  51135. // binary .stl
  51136. var babylonMesh = new BABYLON.Mesh("stlmesh", scene);
  51137. this.parseBinary(babylonMesh, data);
  51138. if (meshes) {
  51139. meshes.push(babylonMesh);
  51140. }
  51141. return true;
  51142. }
  51143. // ASCII .stl
  51144. // convert to string
  51145. var array_buffer = new Uint8Array(data);
  51146. var str = '';
  51147. for (var i = 0; i < data.byteLength; i++) {
  51148. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  51149. }
  51150. data = str;
  51151. while (matches = this.solidPattern.exec(data)) {
  51152. var meshName = matches[1];
  51153. var meshNameFromEnd = matches[3];
  51154. if (meshName != meshNameFromEnd) {
  51155. BABYLON.Tools.Error("Error in STL, solid name != endsolid name");
  51156. return false;
  51157. }
  51158. // check meshesNames
  51159. if (meshesNames && meshName) {
  51160. if (meshesNames instanceof Array) {
  51161. if (!meshesNames.indexOf(meshName)) {
  51162. continue;
  51163. }
  51164. }
  51165. else {
  51166. if (meshName !== meshesNames) {
  51167. continue;
  51168. }
  51169. }
  51170. }
  51171. // stl mesh name can be empty as well
  51172. meshName = meshName || "stlmesh";
  51173. var babylonMesh = new BABYLON.Mesh(meshName, scene);
  51174. this.parseASCII(babylonMesh, matches[2]);
  51175. if (meshes) {
  51176. meshes.push(babylonMesh);
  51177. }
  51178. }
  51179. return true;
  51180. };
  51181. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  51182. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  51183. if (result) {
  51184. scene.createDefaultCameraOrLight();
  51185. }
  51186. return result;
  51187. };
  51188. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  51189. var container = new BABYLON.AssetContainer(scene);
  51190. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  51191. container.removeAllFromScene();
  51192. return container;
  51193. };
  51194. STLFileLoader.prototype.isBinary = function (data) {
  51195. // check if file size is correct for binary stl
  51196. var faceSize, nFaces, reader;
  51197. reader = new DataView(data);
  51198. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  51199. nFaces = reader.getUint32(80, true);
  51200. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  51201. return true;
  51202. }
  51203. // check characters higher than ASCII to confirm binary
  51204. var fileLength = reader.byteLength;
  51205. for (var index = 0; index < fileLength; index++) {
  51206. if (reader.getUint8(index) > 127) {
  51207. return true;
  51208. }
  51209. }
  51210. return false;
  51211. };
  51212. STLFileLoader.prototype.parseBinary = function (mesh, data) {
  51213. var reader = new DataView(data);
  51214. var faces = reader.getUint32(80, true);
  51215. var dataOffset = 84;
  51216. var faceLength = 12 * 4 + 2;
  51217. var offset = 0;
  51218. var positions = new Float32Array(faces * 3 * 3);
  51219. var normals = new Float32Array(faces * 3 * 3);
  51220. var indices = new Uint32Array(faces * 3);
  51221. var indicesCount = 0;
  51222. for (var face = 0; face < faces; face++) {
  51223. var start = dataOffset + face * faceLength;
  51224. var normalX = reader.getFloat32(start, true);
  51225. var normalY = reader.getFloat32(start + 4, true);
  51226. var normalZ = reader.getFloat32(start + 8, true);
  51227. for (var i = 1; i <= 3; i++) {
  51228. var vertexstart = start + i * 12;
  51229. // ordering is intentional to match ascii import
  51230. positions[offset] = reader.getFloat32(vertexstart, true);
  51231. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  51232. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  51233. normals[offset] = normalX;
  51234. normals[offset + 2] = normalY;
  51235. normals[offset + 1] = normalZ;
  51236. offset += 3;
  51237. }
  51238. indices[indicesCount] = indicesCount++;
  51239. indices[indicesCount] = indicesCount++;
  51240. indices[indicesCount] = indicesCount++;
  51241. }
  51242. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
  51243. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
  51244. mesh.setIndices(indices);
  51245. mesh.computeWorldMatrix(true);
  51246. };
  51247. STLFileLoader.prototype.parseASCII = function (mesh, solidData) {
  51248. var positions = [];
  51249. var normals = [];
  51250. var indices = [];
  51251. var indicesCount = 0;
  51252. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  51253. var matches;
  51254. while (matches = this.facetsPattern.exec(solidData)) {
  51255. var facet = matches[1];
  51256. //one normal per face
  51257. var normalMatches = this.normalPattern.exec(facet);
  51258. this.normalPattern.lastIndex = 0;
  51259. if (!normalMatches) {
  51260. continue;
  51261. }
  51262. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  51263. var vertexMatch;
  51264. while (vertexMatch = this.vertexPattern.exec(facet)) {
  51265. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  51266. normals.push(normal[0], normal[1], normal[2]);
  51267. }
  51268. indices.push(indicesCount++, indicesCount++, indicesCount++);
  51269. this.vertexPattern.lastIndex = 0;
  51270. }
  51271. this.facetsPattern.lastIndex = 0;
  51272. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
  51273. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
  51274. mesh.setIndices(indices);
  51275. mesh.computeWorldMatrix(true);
  51276. };
  51277. return STLFileLoader;
  51278. }());
  51279. BABYLON.STLFileLoader = STLFileLoader;
  51280. if (BABYLON.SceneLoader) {
  51281. BABYLON.SceneLoader.RegisterPlugin(new STLFileLoader());
  51282. }
  51283. })(BABYLON || (BABYLON = {}));
  51284. //# sourceMappingURL=babylon.stlFileLoader.js.map
  51285. var BABYLON;
  51286. (function (BABYLON) {
  51287. /**
  51288. * Class reading and parsing the MTL file bundled with the obj file.
  51289. */
  51290. var MTLFileLoader = /** @class */ (function () {
  51291. function MTLFileLoader() {
  51292. // All material loaded from the mtl will be set here
  51293. this.materials = [];
  51294. }
  51295. /**
  51296. * This function will read the mtl file and create each material described inside
  51297. * This function could be improve by adding :
  51298. * -some component missing (Ni, Tf...)
  51299. * -including the specific options available
  51300. *
  51301. * @param scene
  51302. * @param data
  51303. * @param rootUrl
  51304. */
  51305. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl) {
  51306. if (data instanceof ArrayBuffer) {
  51307. return;
  51308. }
  51309. //Split the lines from the file
  51310. var lines = data.split('\n');
  51311. //Space char
  51312. var delimiter_pattern = /\s+/;
  51313. //Array with RGB colors
  51314. var color;
  51315. //New material
  51316. var material = null;
  51317. //Look at each line
  51318. for (var i = 0; i < lines.length; i++) {
  51319. var line = lines[i].trim();
  51320. // Blank line or comment
  51321. if (line.length === 0 || line.charAt(0) === '#') {
  51322. continue;
  51323. }
  51324. //Get the first parameter (keyword)
  51325. var pos = line.indexOf(' ');
  51326. var key = (pos >= 0) ? line.substring(0, pos) : line;
  51327. key = key.toLowerCase();
  51328. //Get the data following the key
  51329. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  51330. //This mtl keyword will create the new material
  51331. if (key === "newmtl") {
  51332. //Check if it is the first material.
  51333. // Materials specifications are described after this keyword.
  51334. if (material) {
  51335. //Add the previous material in the material array.
  51336. this.materials.push(material);
  51337. }
  51338. //Create a new material.
  51339. // value is the name of the material read in the mtl file
  51340. material = new BABYLON.StandardMaterial(value, scene);
  51341. }
  51342. else if (key === "kd" && material) {
  51343. // Diffuse color (color under white light) using RGB values
  51344. //value = "r g b"
  51345. color = value.split(delimiter_pattern, 3).map(parseFloat);
  51346. //color = [r,g,b]
  51347. //Set tghe color into the material
  51348. material.diffuseColor = BABYLON.Color3.FromArray(color);
  51349. }
  51350. else if (key === "ka" && material) {
  51351. // Ambient color (color under shadow) using RGB values
  51352. //value = "r g b"
  51353. color = value.split(delimiter_pattern, 3).map(parseFloat);
  51354. //color = [r,g,b]
  51355. //Set tghe color into the material
  51356. material.ambientColor = BABYLON.Color3.FromArray(color);
  51357. }
  51358. else if (key === "ks" && material) {
  51359. // Specular color (color when light is reflected from shiny surface) using RGB values
  51360. //value = "r g b"
  51361. color = value.split(delimiter_pattern, 3).map(parseFloat);
  51362. //color = [r,g,b]
  51363. //Set the color into the material
  51364. material.specularColor = BABYLON.Color3.FromArray(color);
  51365. }
  51366. else if (key === "ke" && material) {
  51367. // Emissive color using RGB values
  51368. color = value.split(delimiter_pattern, 3).map(parseFloat);
  51369. material.emissiveColor = BABYLON.Color3.FromArray(color);
  51370. }
  51371. else if (key === "ns" && material) {
  51372. //value = "Integer"
  51373. material.specularPower = parseFloat(value);
  51374. }
  51375. else if (key === "d" && material) {
  51376. //d is dissolve for current material. It mean alpha for BABYLON
  51377. material.alpha = parseFloat(value);
  51378. //Texture
  51379. //This part can be improved by adding the possible options of texture
  51380. }
  51381. else if (key === "map_ka" && material) {
  51382. // ambient texture map with a loaded image
  51383. //We must first get the folder of the image
  51384. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  51385. }
  51386. else if (key === "map_kd" && material) {
  51387. // Diffuse texture map with a loaded image
  51388. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  51389. }
  51390. else if (key === "map_ks" && material) {
  51391. // Specular texture map with a loaded image
  51392. //We must first get the folder of the image
  51393. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  51394. }
  51395. else if (key === "map_ns") {
  51396. //Specular
  51397. //Specular highlight component
  51398. //We must first get the folder of the image
  51399. //
  51400. //Not supported by BABYLON
  51401. //
  51402. // continue;
  51403. }
  51404. else if (key === "map_bump" && material) {
  51405. //The bump texture
  51406. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  51407. }
  51408. else if (key === "map_d" && material) {
  51409. // The dissolve of the material
  51410. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  51411. //Options for illumination
  51412. }
  51413. else if (key === "illum") {
  51414. //Illumination
  51415. if (value === "0") {
  51416. //That mean Kd == Kd
  51417. }
  51418. else if (value === "1") {
  51419. //Color on and Ambient on
  51420. }
  51421. else if (value === "2") {
  51422. //Highlight on
  51423. }
  51424. else if (value === "3") {
  51425. //Reflection on and Ray trace on
  51426. }
  51427. else if (value === "4") {
  51428. //Transparency: Glass on, Reflection: Ray trace on
  51429. }
  51430. else if (value === "5") {
  51431. //Reflection: Fresnel on and Ray trace on
  51432. }
  51433. else if (value === "6") {
  51434. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  51435. }
  51436. else if (value === "7") {
  51437. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  51438. }
  51439. else if (value === "8") {
  51440. //Reflection on and Ray trace off
  51441. }
  51442. else if (value === "9") {
  51443. //Transparency: Glass on, Reflection: Ray trace off
  51444. }
  51445. else if (value === "10") {
  51446. //Casts shadows onto invisible surfaces
  51447. }
  51448. }
  51449. else {
  51450. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  51451. }
  51452. }
  51453. //At the end of the file, add the last material
  51454. if (material) {
  51455. this.materials.push(material);
  51456. }
  51457. };
  51458. /**
  51459. * Gets the texture for the material.
  51460. *
  51461. * If the material is imported from input file,
  51462. * We sanitize the url to ensure it takes the textre from aside the material.
  51463. *
  51464. * @param rootUrl The root url to load from
  51465. * @param value The value stored in the mtl
  51466. * @return The Texture
  51467. */
  51468. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  51469. if (!value) {
  51470. return null;
  51471. }
  51472. var url = rootUrl;
  51473. // Load from input file.
  51474. if (rootUrl === "file:") {
  51475. var lastDelimiter = value.lastIndexOf("\\");
  51476. if (lastDelimiter === -1) {
  51477. lastDelimiter = value.lastIndexOf("/");
  51478. }
  51479. if (lastDelimiter > -1) {
  51480. url += value.substr(lastDelimiter + 1);
  51481. }
  51482. else {
  51483. url += value;
  51484. }
  51485. }
  51486. // Not from input file.
  51487. else {
  51488. url += value;
  51489. }
  51490. return new BABYLON.Texture(url, scene);
  51491. };
  51492. return MTLFileLoader;
  51493. }());
  51494. BABYLON.MTLFileLoader = MTLFileLoader;
  51495. var OBJFileLoader = /** @class */ (function () {
  51496. function OBJFileLoader() {
  51497. this.name = "obj";
  51498. this.extensions = ".obj";
  51499. this.obj = /^o/;
  51500. this.group = /^g/;
  51501. this.mtllib = /^mtllib /;
  51502. this.usemtl = /^usemtl /;
  51503. this.smooth = /^s /;
  51504. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  51505. // vn float float float
  51506. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  51507. // vt float float
  51508. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  51509. // f vertex vertex vertex ...
  51510. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  51511. // f vertex/uvs vertex/uvs vertex/uvs ...
  51512. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  51513. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  51514. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  51515. // f vertex//normal vertex//normal vertex//normal ...
  51516. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  51517. }
  51518. /**
  51519. * Calls synchronously the MTL file attached to this obj.
  51520. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  51521. * Without this function materials are not displayed in the first frame (but displayed after).
  51522. * In consequence it is impossible to get material information in your HTML file
  51523. *
  51524. * @param url The URL of the MTL file
  51525. * @param rootUrl
  51526. * @param onSuccess Callback function to be called when the MTL file is loaded
  51527. * @private
  51528. */
  51529. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess) {
  51530. //The complete path to the mtl file
  51531. var pathOfFile = BABYLON.Tools.BaseUrl + rootUrl + url;
  51532. // Loads through the babylon tools to allow fileInput search.
  51533. BABYLON.Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function () { console.warn("Error - Unable to load " + pathOfFile); });
  51534. };
  51535. OBJFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  51536. //get the meshes from OBJ file
  51537. var loadedMeshes = this._parseSolid(meshesNames, scene, data, rootUrl);
  51538. //Push meshes from OBJ file into the variable mesh of this function
  51539. if (meshes) {
  51540. loadedMeshes.forEach(function (mesh) {
  51541. meshes.push(mesh);
  51542. });
  51543. }
  51544. return true;
  51545. };
  51546. OBJFileLoader.prototype.load = function (scene, data, rootUrl) {
  51547. //Get the 3D model
  51548. return this.importMesh(null, scene, data, rootUrl, null, null, null);
  51549. };
  51550. OBJFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  51551. var container = new BABYLON.AssetContainer(scene);
  51552. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  51553. container.removeAllFromScene();
  51554. return container;
  51555. };
  51556. /**
  51557. * Read the OBJ file and create an Array of meshes.
  51558. * Each mesh contains all information given by the OBJ and the MTL file.
  51559. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  51560. *
  51561. * @param meshesNames
  51562. * @param scene BABYLON.Scene The scene where are displayed the data
  51563. * @param data String The content of the obj file
  51564. * @param rootUrl String The path to the folder
  51565. * @returns Array<AbstractMesh>
  51566. * @private
  51567. */
  51568. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  51569. var positions = []; //values for the positions of vertices
  51570. var normals = []; //Values for the normals
  51571. var uvs = []; //Values for the textures
  51572. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  51573. var handledMesh; //The current mesh of meshes array
  51574. var indicesForBabylon = []; //The list of indices for VertexData
  51575. var wrappedPositionForBabylon = []; //The list of position in vectors
  51576. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  51577. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  51578. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  51579. var curPositionInIndices = 0;
  51580. var hasMeshes = false; //Meshes are defined in the file
  51581. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  51582. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  51583. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  51584. var triangles = []; //Indices from new triangles coming from polygons
  51585. var materialNameFromObj = ""; //The name of the current material
  51586. var fileToLoad = ""; //The name of the mtlFile to load
  51587. var materialsFromMTLFile = new MTLFileLoader();
  51588. var objMeshName = ""; //The name of the current obj mesh
  51589. var increment = 1; //Id for meshes created by the multimaterial
  51590. var isFirstMaterial = true;
  51591. /**
  51592. * Search for obj in the given array.
  51593. * This function is called to check if a couple of data already exists in an array.
  51594. *
  51595. * If found, returns the index of the founded tuple index. Returns -1 if not found
  51596. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  51597. * @param obj Array<number>
  51598. * @returns {boolean}
  51599. */
  51600. var isInArray = function (arr, obj) {
  51601. if (!arr[obj[0]])
  51602. arr[obj[0]] = { normals: [], idx: [] };
  51603. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  51604. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  51605. };
  51606. var isInArrayUV = function (arr, obj) {
  51607. if (!arr[obj[0]])
  51608. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  51609. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  51610. if (idx != 1 && (obj[2] == arr[obj[0]].uv[idx])) {
  51611. return arr[obj[0]].idx[idx];
  51612. }
  51613. return -1;
  51614. };
  51615. /**
  51616. * This function set the data for each triangle.
  51617. * Data are position, normals and uvs
  51618. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  51619. * If the tuple already exist, add only their indice
  51620. *
  51621. * @param indicePositionFromObj Integer The index in positions array
  51622. * @param indiceUvsFromObj Integer The index in uvs array
  51623. * @param indiceNormalFromObj Integer The index in normals array
  51624. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  51625. * @param textureVectorFromOBJ Vector3 The value of uvs
  51626. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  51627. */
  51628. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ) {
  51629. //Check if this tuple already exists in the list of tuples
  51630. var _index;
  51631. if (OBJFileLoader.OPTIMIZE_WITH_UV) {
  51632. _index = isInArrayUV(tuplePosNorm, [
  51633. indicePositionFromObj,
  51634. indiceNormalFromObj,
  51635. indiceUvsFromObj
  51636. ]);
  51637. }
  51638. else {
  51639. _index = isInArray(tuplePosNorm, [
  51640. indicePositionFromObj,
  51641. indiceNormalFromObj
  51642. ]);
  51643. }
  51644. //If it not exists
  51645. if (_index == -1) {
  51646. //Add an new indice.
  51647. //The array of indices is only an array with his length equal to the number of triangles - 1.
  51648. //We add vertices data in this order
  51649. indicesForBabylon.push(wrappedPositionForBabylon.length);
  51650. //Push the position of vertice for Babylon
  51651. //Each element is a BABYLON.Vector3(x,y,z)
  51652. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  51653. //Push the uvs for Babylon
  51654. //Each element is a BABYLON.Vector3(u,v)
  51655. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  51656. //Push the normals for Babylon
  51657. //Each element is a BABYLON.Vector3(x,y,z)
  51658. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  51659. //Add the tuple in the comparison list
  51660. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  51661. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  51662. if (OBJFileLoader.OPTIMIZE_WITH_UV)
  51663. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  51664. }
  51665. else {
  51666. //The tuple already exists
  51667. //Add the index of the already existing tuple
  51668. //At this index we can get the value of position, normal and uvs of vertex
  51669. indicesForBabylon.push(_index);
  51670. }
  51671. };
  51672. /**
  51673. * Transform BABYLON.Vector() object onto 3 digits in an array
  51674. */
  51675. var unwrapData = function () {
  51676. //Every array has the same length
  51677. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  51678. //Push the x, y, z values of each element in the unwrapped array
  51679. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  51680. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  51681. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  51682. }
  51683. // Reset arrays for the next new meshes
  51684. wrappedPositionForBabylon = [];
  51685. wrappedNormalsForBabylon = [];
  51686. wrappedUvsForBabylon = [];
  51687. tuplePosNorm = [];
  51688. curPositionInIndices = 0;
  51689. };
  51690. /**
  51691. * Create triangles from polygons by recursion
  51692. * The best to understand how it works is to draw it in the same time you get the recursion.
  51693. * It is important to notice that a triangle is a polygon
  51694. * We get 4 patterns of face defined in OBJ File :
  51695. * facePattern1 = ["1","2","3","4","5","6"]
  51696. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  51697. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  51698. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  51699. * Each pattern is divided by the same method
  51700. * @param face Array[String] The indices of elements
  51701. * @param v Integer The variable to increment
  51702. */
  51703. var getTriangles = function (face, v) {
  51704. //Work for each element of the array
  51705. if (v + 1 < face.length) {
  51706. //Add on the triangle variable the indexes to obtain triangles
  51707. triangles.push(face[0], face[v], face[v + 1]);
  51708. //Incrementation for recursion
  51709. v += 1;
  51710. //Recursion
  51711. getTriangles(face, v);
  51712. }
  51713. //Result obtained after 2 iterations:
  51714. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  51715. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  51716. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  51717. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  51718. };
  51719. /**
  51720. * Create triangles and push the data for each polygon for the pattern 1
  51721. * In this pattern we get vertice positions
  51722. * @param face
  51723. * @param v
  51724. */
  51725. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  51726. //Get the indices of triangles for each polygon
  51727. getTriangles(face, v);
  51728. //For each element in the triangles array.
  51729. //This var could contains 1 to an infinity of triangles
  51730. for (var k = 0; k < triangles.length; k++) {
  51731. // Set position indice
  51732. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  51733. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  51734. positions[indicePositionFromObj], //Get the vectors data
  51735. BABYLON.Vector2.Zero(), BABYLON.Vector3.Up() //Create default vectors
  51736. );
  51737. }
  51738. //Reset variable for the next line
  51739. triangles = [];
  51740. };
  51741. /**
  51742. * Create triangles and push the data for each polygon for the pattern 2
  51743. * In this pattern we get vertice positions and uvsu
  51744. * @param face
  51745. * @param v
  51746. */
  51747. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  51748. //Get the indices of triangles for each polygon
  51749. getTriangles(face, v);
  51750. for (var k = 0; k < triangles.length; k++) {
  51751. //triangle[k] = "1/1"
  51752. //Split the data for getting position and uv
  51753. var point = triangles[k].split("/"); // ["1", "1"]
  51754. //Set position indice
  51755. var indicePositionFromObj = parseInt(point[0]) - 1;
  51756. //Set uv indice
  51757. var indiceUvsFromObj = parseInt(point[1]) - 1;
  51758. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  51759. positions[indicePositionFromObj], //Get the values for each element
  51760. uvs[indiceUvsFromObj], BABYLON.Vector3.Up() //Default value for normals
  51761. );
  51762. }
  51763. //Reset variable for the next line
  51764. triangles = [];
  51765. };
  51766. /**
  51767. * Create triangles and push the data for each polygon for the pattern 3
  51768. * In this pattern we get vertice positions, uvs and normals
  51769. * @param face
  51770. * @param v
  51771. */
  51772. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  51773. //Get the indices of triangles for each polygon
  51774. getTriangles(face, v);
  51775. for (var k = 0; k < triangles.length; k++) {
  51776. //triangle[k] = "1/1/1"
  51777. //Split the data for getting position, uv, and normals
  51778. var point = triangles[k].split("/"); // ["1", "1", "1"]
  51779. // Set position indice
  51780. var indicePositionFromObj = parseInt(point[0]) - 1;
  51781. // Set uv indice
  51782. var indiceUvsFromObj = parseInt(point[1]) - 1;
  51783. // Set normal indice
  51784. var indiceNormalFromObj = parseInt(point[2]) - 1;
  51785. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  51786. );
  51787. }
  51788. //Reset variable for the next line
  51789. triangles = [];
  51790. };
  51791. /**
  51792. * Create triangles and push the data for each polygon for the pattern 4
  51793. * In this pattern we get vertice positions and normals
  51794. * @param face
  51795. * @param v
  51796. */
  51797. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  51798. getTriangles(face, v);
  51799. for (var k = 0; k < triangles.length; k++) {
  51800. //triangle[k] = "1//1"
  51801. //Split the data for getting position and normals
  51802. var point = triangles[k].split("//"); // ["1", "1"]
  51803. // We check indices, and normals
  51804. var indicePositionFromObj = parseInt(point[0]) - 1;
  51805. var indiceNormalFromObj = parseInt(point[1]) - 1;
  51806. setData(indicePositionFromObj, 1, //Default value for uv
  51807. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  51808. BABYLON.Vector2.Zero(), normals[indiceNormalFromObj]);
  51809. }
  51810. //Reset variable for the next line
  51811. triangles = [];
  51812. };
  51813. var addPreviousObjMesh = function () {
  51814. //Check if it is not the first mesh. Otherwise we don't have data.
  51815. if (meshesFromObj.length > 0) {
  51816. //Get the previous mesh for applying the data about the faces
  51817. //=> in obj file, faces definition append after the name of the mesh
  51818. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  51819. //Set the data into Array for the mesh
  51820. unwrapData();
  51821. // Reverse tab. Otherwise face are displayed in the wrong sens
  51822. indicesForBabylon.reverse();
  51823. //Set the information for the mesh
  51824. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  51825. handledMesh.indices = indicesForBabylon.slice();
  51826. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  51827. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  51828. handledMesh.uvs = unwrappedUVForBabylon.slice();
  51829. //Reset the array for the next mesh
  51830. indicesForBabylon = [];
  51831. unwrappedPositionsForBabylon = [];
  51832. unwrappedNormalsForBabylon = [];
  51833. unwrappedUVForBabylon = [];
  51834. }
  51835. };
  51836. //Main function
  51837. //Split the file into lines
  51838. var lines = data.split('\n');
  51839. //Look at each line
  51840. for (var i = 0; i < lines.length; i++) {
  51841. var line = lines[i].trim();
  51842. var result;
  51843. //Comment or newLine
  51844. if (line.length === 0 || line.charAt(0) === '#') {
  51845. continue;
  51846. //Get information about one position possible for the vertices
  51847. }
  51848. else if ((result = this.vertexPattern.exec(line)) !== null) {
  51849. //Create a Vector3 with the position x, y, z
  51850. //Value of result:
  51851. // ["v 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  51852. //Add the Vector in the list of positions
  51853. positions.push(new BABYLON.Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  51854. }
  51855. else if ((result = this.normalPattern.exec(line)) !== null) {
  51856. //Create a Vector3 with the normals x, y, z
  51857. //Value of result
  51858. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  51859. //Add the Vector in the list of normals
  51860. normals.push(new BABYLON.Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  51861. }
  51862. else if ((result = this.uvPattern.exec(line)) !== null) {
  51863. //Create a Vector2 with the normals u, v
  51864. //Value of result
  51865. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  51866. //Add the Vector in the list of uvs
  51867. uvs.push(new BABYLON.Vector2(parseFloat(result[1]), parseFloat(result[2])));
  51868. //Identify patterns of faces
  51869. //Face could be defined in different type of pattern
  51870. }
  51871. else if ((result = this.facePattern3.exec(line)) !== null) {
  51872. //Value of result:
  51873. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  51874. //Set the data for this face
  51875. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  51876. 1);
  51877. }
  51878. else if ((result = this.facePattern4.exec(line)) !== null) {
  51879. //Value of result:
  51880. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  51881. //Set the data for this face
  51882. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  51883. 1);
  51884. }
  51885. else if ((result = this.facePattern2.exec(line)) !== null) {
  51886. //Value of result:
  51887. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  51888. //Set the data for this face
  51889. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  51890. 1);
  51891. }
  51892. else if ((result = this.facePattern1.exec(line)) !== null) {
  51893. //Value of result
  51894. //["f 1 2 3", "1 2 3"...]
  51895. //Set the data for this face
  51896. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  51897. 1);
  51898. //Define a mesh or an object
  51899. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  51900. }
  51901. else if (this.group.test(line) || this.obj.test(line)) {
  51902. //Create a new mesh corresponding to the name of the group.
  51903. //Definition of the mesh
  51904. var objMesh =
  51905. //Set the name of the current obj mesh
  51906. {
  51907. name: line.substring(2).trim(),
  51908. indices: undefined,
  51909. positions: undefined,
  51910. normals: undefined,
  51911. uvs: undefined,
  51912. materialName: ""
  51913. };
  51914. addPreviousObjMesh();
  51915. //Push the last mesh created with only the name
  51916. meshesFromObj.push(objMesh);
  51917. //Set this variable to indicate that now meshesFromObj has objects defined inside
  51918. hasMeshes = true;
  51919. isFirstMaterial = true;
  51920. increment = 1;
  51921. //Keyword for applying a material
  51922. }
  51923. else if (this.usemtl.test(line)) {
  51924. //Get the name of the material
  51925. materialNameFromObj = line.substring(7).trim();
  51926. //If this new material is in the same mesh
  51927. if (!isFirstMaterial) {
  51928. //Set the data for the previous mesh
  51929. addPreviousObjMesh();
  51930. //Create a new mesh
  51931. var objMesh =
  51932. //Set the name of the current obj mesh
  51933. {
  51934. name: objMeshName + "_mm" + increment.toString(),
  51935. indices: undefined,
  51936. positions: undefined,
  51937. normals: undefined,
  51938. uvs: undefined,
  51939. materialName: materialNameFromObj
  51940. };
  51941. increment++;
  51942. //If meshes are already defined
  51943. meshesFromObj.push(objMesh);
  51944. }
  51945. //Set the material name if the previous line define a mesh
  51946. if (hasMeshes && isFirstMaterial) {
  51947. //Set the material name to the previous mesh (1 material per mesh)
  51948. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  51949. isFirstMaterial = false;
  51950. }
  51951. //Keyword for loading the mtl file
  51952. }
  51953. else if (this.mtllib.test(line)) {
  51954. //Get the name of mtl file
  51955. fileToLoad = line.substring(7).trim();
  51956. //Apply smoothing
  51957. }
  51958. else if (this.smooth.test(line)) {
  51959. // smooth shading => apply smoothing
  51960. //Toda y I don't know it work with babylon and with obj.
  51961. //With the obj file an integer is set
  51962. }
  51963. else {
  51964. //If there is another possibility
  51965. console.log("Unhandled expression at line : " + line);
  51966. }
  51967. }
  51968. //At the end of the file, add the last mesh into the meshesFromObj array
  51969. if (hasMeshes) {
  51970. //Set the data for the last mesh
  51971. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  51972. //Reverse indices for displaying faces in the good sens
  51973. indicesForBabylon.reverse();
  51974. //Get the good array
  51975. unwrapData();
  51976. //Set array
  51977. handledMesh.indices = indicesForBabylon;
  51978. handledMesh.positions = unwrappedPositionsForBabylon;
  51979. handledMesh.normals = unwrappedNormalsForBabylon;
  51980. handledMesh.uvs = unwrappedUVForBabylon;
  51981. }
  51982. //If any o or g keyword found, create a mesj with a random id
  51983. if (!hasMeshes) {
  51984. // reverse tab of indices
  51985. indicesForBabylon.reverse();
  51986. //Get positions normals uvs
  51987. unwrapData();
  51988. //Set data for one mesh
  51989. meshesFromObj.push({
  51990. name: BABYLON.Geometry.RandomId(),
  51991. indices: indicesForBabylon,
  51992. positions: unwrappedPositionsForBabylon,
  51993. normals: unwrappedNormalsForBabylon,
  51994. uvs: unwrappedUVForBabylon,
  51995. materialName: materialNameFromObj
  51996. });
  51997. }
  51998. //Create a BABYLON.Mesh list
  51999. var babylonMeshesArray = []; //The mesh for babylon
  52000. var materialToUse = new Array();
  52001. //Set data for each mesh
  52002. for (var j = 0; j < meshesFromObj.length; j++) {
  52003. //check meshesNames (stlFileLoader)
  52004. if (meshesNames && meshesFromObj[j].name) {
  52005. if (meshesNames instanceof Array) {
  52006. if (meshesNames.indexOf(meshesFromObj[j].name) == -1) {
  52007. continue;
  52008. }
  52009. }
  52010. else {
  52011. if (meshesFromObj[j].name !== meshesNames) {
  52012. continue;
  52013. }
  52014. }
  52015. }
  52016. //Get the current mesh
  52017. //Set the data with VertexBuffer for each mesh
  52018. handledMesh = meshesFromObj[j];
  52019. //Create a BABYLON.Mesh with the name of the obj mesh
  52020. var babylonMesh = new BABYLON.Mesh(meshesFromObj[j].name, scene);
  52021. //Push the name of the material to an array
  52022. //This is indispensable for the importMesh function
  52023. materialToUse.push(meshesFromObj[j].materialName);
  52024. var vertexData = new BABYLON.VertexData(); //The container for the values
  52025. //Set the data for the babylonMesh
  52026. vertexData.positions = handledMesh.positions;
  52027. vertexData.normals = handledMesh.normals;
  52028. vertexData.uvs = handledMesh.uvs;
  52029. vertexData.indices = handledMesh.indices;
  52030. //Set the data from the VertexBuffer to the current BABYLON.Mesh
  52031. vertexData.applyToMesh(babylonMesh);
  52032. if (OBJFileLoader.INVERT_Y) {
  52033. babylonMesh.scaling.y *= -1;
  52034. }
  52035. //Push the mesh into an array
  52036. babylonMeshesArray.push(babylonMesh);
  52037. }
  52038. //load the materials
  52039. //Check if we have a file to load
  52040. if (fileToLoad !== "") {
  52041. //Load the file synchronously
  52042. this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  52043. //Create materials thanks MTLLoader function
  52044. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl);
  52045. //Look at each material loaded in the mtl file
  52046. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  52047. //Three variables to get all meshes with the same material
  52048. var startIndex = 0;
  52049. var _indices = [];
  52050. var _index;
  52051. //The material from MTL file is used in the meshes loaded
  52052. //Push the indice in an array
  52053. //Check if the material is not used for another mesh
  52054. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  52055. _indices.push(_index);
  52056. startIndex = _index + 1;
  52057. }
  52058. //If the material is not used dispose it
  52059. if (_index == -1 && _indices.length == 0) {
  52060. //If the material is not needed, remove it
  52061. materialsFromMTLFile.materials[n].dispose();
  52062. }
  52063. else {
  52064. for (var o = 0; o < _indices.length; o++) {
  52065. //Apply the material to the BABYLON.Mesh for each mesh with the material
  52066. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  52067. }
  52068. }
  52069. }
  52070. });
  52071. }
  52072. //Return an array with all BABYLON.Mesh
  52073. return babylonMeshesArray;
  52074. };
  52075. OBJFileLoader.OPTIMIZE_WITH_UV = false;
  52076. OBJFileLoader.INVERT_Y = false;
  52077. return OBJFileLoader;
  52078. }());
  52079. BABYLON.OBJFileLoader = OBJFileLoader;
  52080. if (BABYLON.SceneLoader) {
  52081. //Add this loader into the register plugin
  52082. BABYLON.SceneLoader.RegisterPlugin(new OBJFileLoader());
  52083. }
  52084. })(BABYLON || (BABYLON = {}));
  52085. //# sourceMappingURL=babylon.objFileLoader.js.map
  52086. var BABYLON;
  52087. (function (BABYLON) {
  52088. /**
  52089. * Mode that determines the coordinate system to use.
  52090. */
  52091. var GLTFLoaderCoordinateSystemMode;
  52092. (function (GLTFLoaderCoordinateSystemMode) {
  52093. /**
  52094. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  52095. */
  52096. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  52097. /**
  52098. * Sets the useRightHandedSystem flag on the scene.
  52099. */
  52100. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  52101. })(GLTFLoaderCoordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode || (BABYLON.GLTFLoaderCoordinateSystemMode = {}));
  52102. /**
  52103. * Mode that determines what animations will start.
  52104. */
  52105. var GLTFLoaderAnimationStartMode;
  52106. (function (GLTFLoaderAnimationStartMode) {
  52107. /**
  52108. * No animation will start.
  52109. */
  52110. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  52111. /**
  52112. * The first animation will start.
  52113. */
  52114. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  52115. /**
  52116. * All animations will start.
  52117. */
  52118. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  52119. })(GLTFLoaderAnimationStartMode = BABYLON.GLTFLoaderAnimationStartMode || (BABYLON.GLTFLoaderAnimationStartMode = {}));
  52120. /**
  52121. * Loader state.
  52122. */
  52123. var GLTFLoaderState;
  52124. (function (GLTFLoaderState) {
  52125. /**
  52126. * The asset is loading.
  52127. */
  52128. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  52129. /**
  52130. * The asset is ready for rendering.
  52131. */
  52132. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  52133. /**
  52134. * The asset is completely loaded.
  52135. */
  52136. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  52137. })(GLTFLoaderState = BABYLON.GLTFLoaderState || (BABYLON.GLTFLoaderState = {}));
  52138. /**
  52139. * File loader for loading glTF files into a scene.
  52140. */
  52141. var GLTFFileLoader = /** @class */ (function () {
  52142. function GLTFFileLoader() {
  52143. // #region Common options
  52144. /**
  52145. * Raised when the asset has been parsed
  52146. */
  52147. this.onParsedObservable = new BABYLON.Observable();
  52148. // #endregion
  52149. // #region V2 options
  52150. /**
  52151. * The coordinate system mode. Defaults to AUTO.
  52152. */
  52153. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  52154. /**
  52155. * The animation start mode. Defaults to FIRST.
  52156. */
  52157. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  52158. /**
  52159. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  52160. */
  52161. this.compileMaterials = false;
  52162. /**
  52163. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  52164. */
  52165. this.useClipPlane = false;
  52166. /**
  52167. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  52168. */
  52169. this.compileShadowGenerators = false;
  52170. /**
  52171. * Defines if the Alpha blended materials are only applied as coverage.
  52172. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  52173. * If true, no extra effects are applied to transparent pixels.
  52174. */
  52175. this.transparencyAsCoverage = false;
  52176. /** @hidden */
  52177. this._normalizeAnimationGroupsToBeginAtZero = true;
  52178. /**
  52179. * Function called before loading a url referenced by the asset.
  52180. */
  52181. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  52182. /**
  52183. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  52184. */
  52185. this.onMeshLoadedObservable = new BABYLON.Observable();
  52186. /**
  52187. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  52188. */
  52189. this.onTextureLoadedObservable = new BABYLON.Observable();
  52190. /**
  52191. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  52192. */
  52193. this.onMaterialLoadedObservable = new BABYLON.Observable();
  52194. /**
  52195. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  52196. */
  52197. this.onCameraLoadedObservable = new BABYLON.Observable();
  52198. /**
  52199. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  52200. * For assets with LODs, raised when all of the LODs are complete.
  52201. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  52202. */
  52203. this.onCompleteObservable = new BABYLON.Observable();
  52204. /**
  52205. * Observable raised after the loader is disposed.
  52206. */
  52207. this.onDisposeObservable = new BABYLON.Observable();
  52208. /**
  52209. * Observable raised after a loader extension is created.
  52210. * Set additional options for a loader extension in this event.
  52211. */
  52212. this.onExtensionLoadedObservable = new BABYLON.Observable();
  52213. // #endregion
  52214. this._loader = null;
  52215. /**
  52216. * Name of the loader ("gltf")
  52217. */
  52218. this.name = "gltf";
  52219. /**
  52220. * Supported file extensions of the loader (.gltf, .glb)
  52221. */
  52222. this.extensions = {
  52223. ".gltf": { isBinary: false },
  52224. ".glb": { isBinary: true }
  52225. };
  52226. }
  52227. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  52228. /**
  52229. * Raised when the asset has been parsed
  52230. */
  52231. set: function (callback) {
  52232. if (this._onParsedObserver) {
  52233. this.onParsedObservable.remove(this._onParsedObserver);
  52234. }
  52235. this._onParsedObserver = this.onParsedObservable.add(callback);
  52236. },
  52237. enumerable: true,
  52238. configurable: true
  52239. });
  52240. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  52241. /**
  52242. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  52243. */
  52244. set: function (callback) {
  52245. if (this._onMeshLoadedObserver) {
  52246. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  52247. }
  52248. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  52249. },
  52250. enumerable: true,
  52251. configurable: true
  52252. });
  52253. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  52254. /**
  52255. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  52256. */
  52257. set: function (callback) {
  52258. if (this._onTextureLoadedObserver) {
  52259. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  52260. }
  52261. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  52262. },
  52263. enumerable: true,
  52264. configurable: true
  52265. });
  52266. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  52267. /**
  52268. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  52269. */
  52270. set: function (callback) {
  52271. if (this._onMaterialLoadedObserver) {
  52272. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  52273. }
  52274. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  52275. },
  52276. enumerable: true,
  52277. configurable: true
  52278. });
  52279. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  52280. /**
  52281. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  52282. */
  52283. set: function (callback) {
  52284. if (this._onCameraLoadedObserver) {
  52285. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  52286. }
  52287. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  52288. },
  52289. enumerable: true,
  52290. configurable: true
  52291. });
  52292. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  52293. /**
  52294. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  52295. */
  52296. set: function (callback) {
  52297. if (this._onCompleteObserver) {
  52298. this.onCompleteObservable.remove(this._onCompleteObserver);
  52299. }
  52300. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  52301. },
  52302. enumerable: true,
  52303. configurable: true
  52304. });
  52305. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  52306. /**
  52307. * Callback raised after the loader is disposed.
  52308. */
  52309. set: function (callback) {
  52310. if (this._onDisposeObserver) {
  52311. this.onDisposeObservable.remove(this._onDisposeObserver);
  52312. }
  52313. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  52314. },
  52315. enumerable: true,
  52316. configurable: true
  52317. });
  52318. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  52319. /**
  52320. * Callback raised after a loader extension is created.
  52321. */
  52322. set: function (callback) {
  52323. if (this._onExtensionLoadedObserver) {
  52324. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  52325. }
  52326. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  52327. },
  52328. enumerable: true,
  52329. configurable: true
  52330. });
  52331. /**
  52332. * Returns a promise that resolves when the asset is completely loaded.
  52333. * @returns a promise that resolves when the asset is completely loaded.
  52334. */
  52335. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  52336. var _this = this;
  52337. return new Promise(function (resolve) {
  52338. _this.onCompleteObservable.addOnce(function () {
  52339. resolve();
  52340. });
  52341. });
  52342. };
  52343. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  52344. /**
  52345. * The loader state or null if the loader is not active.
  52346. */
  52347. get: function () {
  52348. return this._loader ? this._loader.state : null;
  52349. },
  52350. enumerable: true,
  52351. configurable: true
  52352. });
  52353. /**
  52354. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  52355. */
  52356. GLTFFileLoader.prototype.dispose = function () {
  52357. if (this._loader) {
  52358. this._loader.dispose();
  52359. this._loader = null;
  52360. }
  52361. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  52362. this.onMeshLoadedObservable.clear();
  52363. this.onTextureLoadedObservable.clear();
  52364. this.onMaterialLoadedObservable.clear();
  52365. this.onCameraLoadedObservable.clear();
  52366. this.onCompleteObservable.clear();
  52367. this.onExtensionLoadedObservable.clear();
  52368. this.onDisposeObservable.notifyObservers(this);
  52369. this.onDisposeObservable.clear();
  52370. };
  52371. /**
  52372. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  52373. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  52374. * @param scene the scene the meshes should be added to
  52375. * @param data the glTF data to load
  52376. * @param rootUrl root url to load from
  52377. * @param onProgress event that fires when loading progress has occured
  52378. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  52379. */
  52380. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  52381. var _this = this;
  52382. return Promise.resolve().then(function () {
  52383. var loaderData = _this._parse(data);
  52384. _this._loader = _this._getLoader(loaderData);
  52385. return _this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onProgress);
  52386. });
  52387. };
  52388. /**
  52389. * Imports all objects from the loaded glTF data and adds them to the scene
  52390. * @param scene the scene the objects should be added to
  52391. * @param data the glTF data to load
  52392. * @param rootUrl root url to load from
  52393. * @param onProgress event that fires when loading progress has occured
  52394. * @returns a promise which completes when objects have been loaded to the scene
  52395. */
  52396. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  52397. var _this = this;
  52398. return Promise.resolve().then(function () {
  52399. var loaderData = _this._parse(data);
  52400. _this._loader = _this._getLoader(loaderData);
  52401. return _this._loader.loadAsync(scene, loaderData, rootUrl, onProgress);
  52402. });
  52403. };
  52404. /**
  52405. * Load into an asset container.
  52406. * @param scene The scene to load into
  52407. * @param data The data to import
  52408. * @param rootUrl The root url for scene and resources
  52409. * @param onProgress The callback when the load progresses
  52410. * @returns The loaded asset container
  52411. */
  52412. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress) {
  52413. var _this = this;
  52414. return Promise.resolve().then(function () {
  52415. var loaderData = _this._parse(data);
  52416. _this._loader = _this._getLoader(loaderData);
  52417. return _this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress).then(function (result) {
  52418. var container = new BABYLON.AssetContainer(scene);
  52419. Array.prototype.push.apply(container.meshes, result.meshes);
  52420. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  52421. Array.prototype.push.apply(container.skeletons, result.skeletons);
  52422. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  52423. container.removeAllFromScene();
  52424. return container;
  52425. });
  52426. });
  52427. };
  52428. /**
  52429. * If the data string can be loaded directly.
  52430. * @param data string contianing the file data
  52431. * @returns if the data can be loaded directly
  52432. */
  52433. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  52434. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  52435. };
  52436. /**
  52437. * Instantiates a glTF file loader plugin.
  52438. * @returns the created plugin
  52439. */
  52440. GLTFFileLoader.prototype.createPlugin = function () {
  52441. return new GLTFFileLoader();
  52442. };
  52443. GLTFFileLoader.prototype._parse = function (data) {
  52444. var parsedData;
  52445. if (data instanceof ArrayBuffer) {
  52446. parsedData = GLTFFileLoader._parseBinary(data);
  52447. }
  52448. else {
  52449. parsedData = {
  52450. json: JSON.parse(data),
  52451. bin: null
  52452. };
  52453. }
  52454. this.onParsedObservable.notifyObservers(parsedData);
  52455. this.onParsedObservable.clear();
  52456. return parsedData;
  52457. };
  52458. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  52459. var _this = this;
  52460. var loaderVersion = { major: 2, minor: 0 };
  52461. var asset = loaderData.json.asset || {};
  52462. var version = GLTFFileLoader._parseVersion(asset.version);
  52463. if (!version) {
  52464. throw new Error("Invalid version: " + asset.version);
  52465. }
  52466. if (asset.minVersion !== undefined) {
  52467. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  52468. if (!minVersion) {
  52469. throw new Error("Invalid minimum version: " + asset.minVersion);
  52470. }
  52471. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  52472. throw new Error("Incompatible minimum version: " + asset.minVersion);
  52473. }
  52474. }
  52475. var createLoaders = {
  52476. 1: GLTFFileLoader._CreateGLTFLoaderV1,
  52477. 2: GLTFFileLoader._CreateGLTFLoaderV2
  52478. };
  52479. var createLoader = createLoaders[version.major];
  52480. if (!createLoader) {
  52481. throw new Error("Unsupported version: " + asset.version);
  52482. }
  52483. var loader = createLoader();
  52484. loader.coordinateSystemMode = this.coordinateSystemMode;
  52485. loader.animationStartMode = this.animationStartMode;
  52486. loader.compileMaterials = this.compileMaterials;
  52487. loader.useClipPlane = this.useClipPlane;
  52488. loader.compileShadowGenerators = this.compileShadowGenerators;
  52489. loader.transparencyAsCoverage = this.transparencyAsCoverage;
  52490. loader._normalizeAnimationGroupsToBeginAtZero = this._normalizeAnimationGroupsToBeginAtZero;
  52491. loader.preprocessUrlAsync = this.preprocessUrlAsync;
  52492. loader.onMeshLoadedObservable.add(function (mesh) { return _this.onMeshLoadedObservable.notifyObservers(mesh); });
  52493. loader.onTextureLoadedObservable.add(function (texture) { return _this.onTextureLoadedObservable.notifyObservers(texture); });
  52494. loader.onMaterialLoadedObservable.add(function (material) { return _this.onMaterialLoadedObservable.notifyObservers(material); });
  52495. loader.onCameraLoadedObservable.add(function (camera) { return _this.onCameraLoadedObservable.notifyObservers(camera); });
  52496. loader.onExtensionLoadedObservable.add(function (extension) { return _this.onExtensionLoadedObservable.notifyObservers(extension); });
  52497. loader.onCompleteObservable.add(function () {
  52498. _this.onMeshLoadedObservable.clear();
  52499. _this.onTextureLoadedObservable.clear();
  52500. _this.onMaterialLoadedObservable.clear();
  52501. _this.onCameraLoadedObservable.clear();
  52502. _this.onExtensionLoadedObservable.clear();
  52503. _this.onCompleteObservable.notifyObservers(_this);
  52504. _this.onCompleteObservable.clear();
  52505. });
  52506. return loader;
  52507. };
  52508. GLTFFileLoader._parseBinary = function (data) {
  52509. var Binary = {
  52510. Magic: 0x46546C67
  52511. };
  52512. var binaryReader = new BinaryReader(data);
  52513. var magic = binaryReader.readUint32();
  52514. if (magic !== Binary.Magic) {
  52515. throw new Error("Unexpected magic: " + magic);
  52516. }
  52517. var version = binaryReader.readUint32();
  52518. switch (version) {
  52519. case 1: return GLTFFileLoader._parseV1(binaryReader);
  52520. case 2: return GLTFFileLoader._parseV2(binaryReader);
  52521. }
  52522. throw new Error("Unsupported version: " + version);
  52523. };
  52524. GLTFFileLoader._parseV1 = function (binaryReader) {
  52525. var ContentFormat = {
  52526. JSON: 0
  52527. };
  52528. var length = binaryReader.readUint32();
  52529. if (length != binaryReader.getLength()) {
  52530. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  52531. }
  52532. var contentLength = binaryReader.readUint32();
  52533. var contentFormat = binaryReader.readUint32();
  52534. var content;
  52535. switch (contentFormat) {
  52536. case ContentFormat.JSON: {
  52537. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  52538. break;
  52539. }
  52540. default: {
  52541. throw new Error("Unexpected content format: " + contentFormat);
  52542. }
  52543. }
  52544. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  52545. var body = binaryReader.readUint8Array(bytesRemaining);
  52546. return {
  52547. json: content,
  52548. bin: body
  52549. };
  52550. };
  52551. GLTFFileLoader._parseV2 = function (binaryReader) {
  52552. var ChunkFormat = {
  52553. JSON: 0x4E4F534A,
  52554. BIN: 0x004E4942
  52555. };
  52556. var length = binaryReader.readUint32();
  52557. if (length !== binaryReader.getLength()) {
  52558. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  52559. }
  52560. // JSON chunk
  52561. var chunkLength = binaryReader.readUint32();
  52562. var chunkFormat = binaryReader.readUint32();
  52563. if (chunkFormat !== ChunkFormat.JSON) {
  52564. throw new Error("First chunk format is not JSON");
  52565. }
  52566. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  52567. // Look for BIN chunk
  52568. var bin = null;
  52569. while (binaryReader.getPosition() < binaryReader.getLength()) {
  52570. var chunkLength_1 = binaryReader.readUint32();
  52571. var chunkFormat_1 = binaryReader.readUint32();
  52572. switch (chunkFormat_1) {
  52573. case ChunkFormat.JSON: {
  52574. throw new Error("Unexpected JSON chunk");
  52575. }
  52576. case ChunkFormat.BIN: {
  52577. bin = binaryReader.readUint8Array(chunkLength_1);
  52578. break;
  52579. }
  52580. default: {
  52581. // ignore unrecognized chunkFormat
  52582. binaryReader.skipBytes(chunkLength_1);
  52583. break;
  52584. }
  52585. }
  52586. }
  52587. return {
  52588. json: json,
  52589. bin: bin
  52590. };
  52591. };
  52592. GLTFFileLoader._parseVersion = function (version) {
  52593. if (version === "1.0" || version === "1.0.1") {
  52594. return {
  52595. major: 1,
  52596. minor: 0
  52597. };
  52598. }
  52599. var match = (version + "").match(/^(\d+)\.(\d+)/);
  52600. if (!match) {
  52601. return null;
  52602. }
  52603. return {
  52604. major: parseInt(match[1]),
  52605. minor: parseInt(match[2])
  52606. };
  52607. };
  52608. GLTFFileLoader._compareVersion = function (a, b) {
  52609. if (a.major > b.major)
  52610. return 1;
  52611. if (a.major < b.major)
  52612. return -1;
  52613. if (a.minor > b.minor)
  52614. return 1;
  52615. if (a.minor < b.minor)
  52616. return -1;
  52617. return 0;
  52618. };
  52619. GLTFFileLoader._decodeBufferToText = function (buffer) {
  52620. var result = "";
  52621. var length = buffer.byteLength;
  52622. for (var i = 0; i < length; i++) {
  52623. result += String.fromCharCode(buffer[i]);
  52624. }
  52625. return result;
  52626. };
  52627. // #endregion
  52628. // #region V1 options
  52629. /**
  52630. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  52631. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  52632. * Defaults to true.
  52633. * @hidden
  52634. */
  52635. GLTFFileLoader.IncrementalLoading = true;
  52636. /**
  52637. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  52638. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  52639. * @hidden
  52640. */
  52641. GLTFFileLoader.HomogeneousCoordinates = false;
  52642. return GLTFFileLoader;
  52643. }());
  52644. BABYLON.GLTFFileLoader = GLTFFileLoader;
  52645. var BinaryReader = /** @class */ (function () {
  52646. function BinaryReader(arrayBuffer) {
  52647. this._arrayBuffer = arrayBuffer;
  52648. this._dataView = new DataView(arrayBuffer);
  52649. this._byteOffset = 0;
  52650. }
  52651. BinaryReader.prototype.getPosition = function () {
  52652. return this._byteOffset;
  52653. };
  52654. BinaryReader.prototype.getLength = function () {
  52655. return this._arrayBuffer.byteLength;
  52656. };
  52657. BinaryReader.prototype.readUint32 = function () {
  52658. var value = this._dataView.getUint32(this._byteOffset, true);
  52659. this._byteOffset += 4;
  52660. return value;
  52661. };
  52662. BinaryReader.prototype.readUint8Array = function (length) {
  52663. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  52664. this._byteOffset += length;
  52665. return value;
  52666. };
  52667. BinaryReader.prototype.skipBytes = function (length) {
  52668. this._byteOffset += length;
  52669. };
  52670. return BinaryReader;
  52671. }());
  52672. if (BABYLON.SceneLoader) {
  52673. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  52674. }
  52675. })(BABYLON || (BABYLON = {}));
  52676. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  52677. var BABYLON;
  52678. (function (BABYLON) {
  52679. var GLTF1;
  52680. (function (GLTF1) {
  52681. /**
  52682. * Enums
  52683. */
  52684. var EComponentType;
  52685. (function (EComponentType) {
  52686. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  52687. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  52688. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  52689. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  52690. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  52691. })(EComponentType = GLTF1.EComponentType || (GLTF1.EComponentType = {}));
  52692. var EShaderType;
  52693. (function (EShaderType) {
  52694. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  52695. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  52696. })(EShaderType = GLTF1.EShaderType || (GLTF1.EShaderType = {}));
  52697. var EParameterType;
  52698. (function (EParameterType) {
  52699. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  52700. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  52701. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  52702. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  52703. EParameterType[EParameterType["INT"] = 5124] = "INT";
  52704. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  52705. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  52706. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  52707. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  52708. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  52709. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  52710. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  52711. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  52712. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  52713. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  52714. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  52715. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  52716. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  52717. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  52718. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  52719. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  52720. })(EParameterType = GLTF1.EParameterType || (GLTF1.EParameterType = {}));
  52721. var ETextureWrapMode;
  52722. (function (ETextureWrapMode) {
  52723. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  52724. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  52725. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  52726. })(ETextureWrapMode = GLTF1.ETextureWrapMode || (GLTF1.ETextureWrapMode = {}));
  52727. var ETextureFilterType;
  52728. (function (ETextureFilterType) {
  52729. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  52730. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  52731. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  52732. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  52733. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  52734. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  52735. })(ETextureFilterType = GLTF1.ETextureFilterType || (GLTF1.ETextureFilterType = {}));
  52736. var ETextureFormat;
  52737. (function (ETextureFormat) {
  52738. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  52739. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  52740. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  52741. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  52742. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  52743. })(ETextureFormat = GLTF1.ETextureFormat || (GLTF1.ETextureFormat = {}));
  52744. var ECullingType;
  52745. (function (ECullingType) {
  52746. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  52747. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  52748. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  52749. })(ECullingType = GLTF1.ECullingType || (GLTF1.ECullingType = {}));
  52750. var EBlendingFunction;
  52751. (function (EBlendingFunction) {
  52752. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  52753. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  52754. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  52755. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  52756. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  52757. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  52758. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  52759. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  52760. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  52761. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  52762. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  52763. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  52764. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  52765. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  52766. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  52767. })(EBlendingFunction = GLTF1.EBlendingFunction || (GLTF1.EBlendingFunction = {}));
  52768. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  52769. })(BABYLON || (BABYLON = {}));
  52770. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  52771. var BABYLON;
  52772. (function (BABYLON) {
  52773. var GLTF1;
  52774. (function (GLTF1) {
  52775. /**
  52776. * Tokenizer. Used for shaders compatibility
  52777. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  52778. */
  52779. var ETokenType;
  52780. (function (ETokenType) {
  52781. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  52782. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  52783. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  52784. })(ETokenType || (ETokenType = {}));
  52785. var Tokenizer = /** @class */ (function () {
  52786. function Tokenizer(toParse) {
  52787. this._pos = 0;
  52788. this.currentToken = ETokenType.UNKNOWN;
  52789. this.currentIdentifier = "";
  52790. this.currentString = "";
  52791. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  52792. this._toParse = toParse;
  52793. this._maxPos = toParse.length;
  52794. }
  52795. Tokenizer.prototype.getNextToken = function () {
  52796. if (this.isEnd())
  52797. return ETokenType.END_OF_INPUT;
  52798. this.currentString = this.read();
  52799. this.currentToken = ETokenType.UNKNOWN;
  52800. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  52801. this.currentToken = ETokenType.IDENTIFIER;
  52802. this.currentIdentifier = this.currentString;
  52803. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  52804. this.currentIdentifier += this.currentString;
  52805. this.forward();
  52806. }
  52807. }
  52808. return this.currentToken;
  52809. };
  52810. Tokenizer.prototype.peek = function () {
  52811. return this._toParse[this._pos];
  52812. };
  52813. Tokenizer.prototype.read = function () {
  52814. return this._toParse[this._pos++];
  52815. };
  52816. Tokenizer.prototype.forward = function () {
  52817. this._pos++;
  52818. };
  52819. Tokenizer.prototype.isEnd = function () {
  52820. return this._pos >= this._maxPos;
  52821. };
  52822. return Tokenizer;
  52823. }());
  52824. /**
  52825. * Values
  52826. */
  52827. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  52828. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  52829. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  52830. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  52831. /**
  52832. * Parse
  52833. */
  52834. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  52835. for (var buf in parsedBuffers) {
  52836. var parsedBuffer = parsedBuffers[buf];
  52837. gltfRuntime.buffers[buf] = parsedBuffer;
  52838. gltfRuntime.buffersCount++;
  52839. }
  52840. };
  52841. var parseShaders = function (parsedShaders, gltfRuntime) {
  52842. for (var sha in parsedShaders) {
  52843. var parsedShader = parsedShaders[sha];
  52844. gltfRuntime.shaders[sha] = parsedShader;
  52845. gltfRuntime.shaderscount++;
  52846. }
  52847. };
  52848. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  52849. for (var object in parsedObjects) {
  52850. var parsedObject = parsedObjects[object];
  52851. gltfRuntime[runtimeProperty][object] = parsedObject;
  52852. }
  52853. };
  52854. /**
  52855. * Utils
  52856. */
  52857. var normalizeUVs = function (buffer) {
  52858. if (!buffer) {
  52859. return;
  52860. }
  52861. for (var i = 0; i < buffer.length / 2; i++) {
  52862. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  52863. }
  52864. };
  52865. var getAttribute = function (attributeParameter) {
  52866. if (attributeParameter.semantic === "NORMAL") {
  52867. return "normal";
  52868. }
  52869. else if (attributeParameter.semantic === "POSITION") {
  52870. return "position";
  52871. }
  52872. else if (attributeParameter.semantic === "JOINT") {
  52873. return "matricesIndices";
  52874. }
  52875. else if (attributeParameter.semantic === "WEIGHT") {
  52876. return "matricesWeights";
  52877. }
  52878. else if (attributeParameter.semantic === "COLOR") {
  52879. return "color";
  52880. }
  52881. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  52882. var channel = Number(attributeParameter.semantic.split("_")[1]);
  52883. return "uv" + (channel === 0 ? "" : channel + 1);
  52884. }
  52885. return null;
  52886. };
  52887. /**
  52888. * Loads and creates animations
  52889. */
  52890. var loadAnimations = function (gltfRuntime) {
  52891. for (var anim in gltfRuntime.animations) {
  52892. var animation = gltfRuntime.animations[anim];
  52893. if (!animation.channels || !animation.samplers) {
  52894. continue;
  52895. }
  52896. var lastAnimation = null;
  52897. for (var i = 0; i < animation.channels.length; i++) {
  52898. // Get parameters and load buffers
  52899. var channel = animation.channels[i];
  52900. var sampler = animation.samplers[channel.sampler];
  52901. if (!sampler) {
  52902. continue;
  52903. }
  52904. var inputData = null;
  52905. var outputData = null;
  52906. if (animation.parameters) {
  52907. inputData = animation.parameters[sampler.input];
  52908. outputData = animation.parameters[sampler.output];
  52909. }
  52910. else {
  52911. inputData = sampler.input;
  52912. outputData = sampler.output;
  52913. }
  52914. var bufferInput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  52915. var bufferOutput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  52916. var targetID = channel.target.id;
  52917. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  52918. if (targetNode === null) {
  52919. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  52920. }
  52921. if (targetNode === null) {
  52922. BABYLON.Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  52923. continue;
  52924. }
  52925. var isBone = targetNode instanceof BABYLON.Bone;
  52926. // Get target path (position, rotation or scaling)
  52927. var targetPath = channel.target.path;
  52928. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  52929. if (targetPathIndex !== -1) {
  52930. targetPath = babylonAnimationPaths[targetPathIndex];
  52931. }
  52932. // Determine animation type
  52933. var animationType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  52934. if (!isBone) {
  52935. if (targetPath === "rotationQuaternion") {
  52936. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  52937. targetNode.rotationQuaternion = new BABYLON.Quaternion();
  52938. }
  52939. else {
  52940. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  52941. }
  52942. }
  52943. // Create animation and key frames
  52944. var babylonAnimation = null;
  52945. var keys = [];
  52946. var arrayOffset = 0;
  52947. var modifyKey = false;
  52948. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  52949. babylonAnimation = lastAnimation;
  52950. modifyKey = true;
  52951. }
  52952. if (!modifyKey) {
  52953. babylonAnimation = new BABYLON.Animation(anim, isBone ? "_matrix" : targetPath, 1, animationType, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
  52954. }
  52955. // For each frame
  52956. for (var j = 0; j < bufferInput.length; j++) {
  52957. var value = null;
  52958. if (targetPath === "rotationQuaternion") { // VEC4
  52959. value = BABYLON.Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  52960. arrayOffset += 4;
  52961. }
  52962. else { // Position and scaling are VEC3
  52963. value = BABYLON.Vector3.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  52964. arrayOffset += 3;
  52965. }
  52966. if (isBone) {
  52967. var bone = targetNode;
  52968. var translation = BABYLON.Vector3.Zero();
  52969. var rotationQuaternion = new BABYLON.Quaternion();
  52970. var scaling = BABYLON.Vector3.Zero();
  52971. // Warning on decompose
  52972. var mat = bone.getBaseMatrix();
  52973. if (modifyKey && lastAnimation) {
  52974. mat = lastAnimation.getKeys()[j].value;
  52975. }
  52976. mat.decompose(scaling, rotationQuaternion, translation);
  52977. if (targetPath === "position") {
  52978. translation = value;
  52979. }
  52980. else if (targetPath === "rotationQuaternion") {
  52981. rotationQuaternion = value;
  52982. }
  52983. else {
  52984. scaling = value;
  52985. }
  52986. value = BABYLON.Matrix.Compose(scaling, rotationQuaternion, translation);
  52987. }
  52988. if (!modifyKey) {
  52989. keys.push({
  52990. frame: bufferInput[j],
  52991. value: value
  52992. });
  52993. }
  52994. else if (lastAnimation) {
  52995. lastAnimation.getKeys()[j].value = value;
  52996. }
  52997. }
  52998. // Finish
  52999. if (!modifyKey && babylonAnimation) {
  53000. babylonAnimation.setKeys(keys);
  53001. targetNode.animations.push(babylonAnimation);
  53002. }
  53003. lastAnimation = babylonAnimation;
  53004. gltfRuntime.scene.stopAnimation(targetNode);
  53005. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  53006. }
  53007. }
  53008. };
  53009. /**
  53010. * Returns the bones transformation matrix
  53011. */
  53012. var configureBoneTransformation = function (node) {
  53013. var mat = null;
  53014. if (node.translation || node.rotation || node.scale) {
  53015. var scale = BABYLON.Vector3.FromArray(node.scale || [1, 1, 1]);
  53016. var rotation = BABYLON.Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
  53017. var position = BABYLON.Vector3.FromArray(node.translation || [0, 0, 0]);
  53018. mat = BABYLON.Matrix.Compose(scale, rotation, position);
  53019. }
  53020. else {
  53021. mat = BABYLON.Matrix.FromArray(node.matrix);
  53022. }
  53023. return mat;
  53024. };
  53025. /**
  53026. * Returns the parent bone
  53027. */
  53028. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  53029. // Try to find
  53030. for (var i = 0; i < newSkeleton.bones.length; i++) {
  53031. if (newSkeleton.bones[i].name === jointName) {
  53032. return newSkeleton.bones[i];
  53033. }
  53034. }
  53035. // Not found, search in gltf nodes
  53036. var nodes = gltfRuntime.nodes;
  53037. for (var nde in nodes) {
  53038. var node = nodes[nde];
  53039. if (!node.jointName) {
  53040. continue;
  53041. }
  53042. var children = node.children;
  53043. for (var i = 0; i < children.length; i++) {
  53044. var child = gltfRuntime.nodes[children[i]];
  53045. if (!child.jointName) {
  53046. continue;
  53047. }
  53048. if (child.jointName === jointName) {
  53049. var mat = configureBoneTransformation(node);
  53050. var bone = new BABYLON.Bone(node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  53051. bone.id = nde;
  53052. return bone;
  53053. }
  53054. }
  53055. }
  53056. return null;
  53057. };
  53058. /**
  53059. * Returns the appropriate root node
  53060. */
  53061. var getNodeToRoot = function (nodesToRoot, id) {
  53062. for (var i = 0; i < nodesToRoot.length; i++) {
  53063. var nodeToRoot = nodesToRoot[i];
  53064. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  53065. var child = nodeToRoot.node.children[j];
  53066. if (child === id) {
  53067. return nodeToRoot.bone;
  53068. }
  53069. }
  53070. }
  53071. return null;
  53072. };
  53073. /**
  53074. * Returns the node with the joint name
  53075. */
  53076. var getJointNode = function (gltfRuntime, jointName) {
  53077. var nodes = gltfRuntime.nodes;
  53078. var node = nodes[jointName];
  53079. if (node) {
  53080. return {
  53081. node: node,
  53082. id: jointName
  53083. };
  53084. }
  53085. for (var nde in nodes) {
  53086. node = nodes[nde];
  53087. if (node.jointName === jointName) {
  53088. return {
  53089. node: node,
  53090. id: nde
  53091. };
  53092. }
  53093. }
  53094. return null;
  53095. };
  53096. /**
  53097. * Checks if a nodes is in joints
  53098. */
  53099. var nodeIsInJoints = function (skins, id) {
  53100. for (var i = 0; i < skins.jointNames.length; i++) {
  53101. if (skins.jointNames[i] === id) {
  53102. return true;
  53103. }
  53104. }
  53105. return false;
  53106. };
  53107. /**
  53108. * Fills the nodes to root for bones and builds hierarchy
  53109. */
  53110. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  53111. // Creates nodes for root
  53112. for (var nde in gltfRuntime.nodes) {
  53113. var node = gltfRuntime.nodes[nde];
  53114. var id = nde;
  53115. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  53116. continue;
  53117. }
  53118. // Create node to root bone
  53119. var mat = configureBoneTransformation(node);
  53120. var bone = new BABYLON.Bone(node.name || "", newSkeleton, null, mat);
  53121. bone.id = id;
  53122. nodesToRoot.push({ bone: bone, node: node, id: id });
  53123. }
  53124. // Parenting
  53125. for (var i = 0; i < nodesToRoot.length; i++) {
  53126. var nodeToRoot = nodesToRoot[i];
  53127. var children = nodeToRoot.node.children;
  53128. for (var j = 0; j < children.length; j++) {
  53129. var child = null;
  53130. for (var k = 0; k < nodesToRoot.length; k++) {
  53131. if (nodesToRoot[k].id === children[j]) {
  53132. child = nodesToRoot[k];
  53133. break;
  53134. }
  53135. }
  53136. if (child) {
  53137. child.bone._parent = nodeToRoot.bone;
  53138. nodeToRoot.bone.children.push(child.bone);
  53139. }
  53140. }
  53141. }
  53142. };
  53143. /**
  53144. * Imports a skeleton
  53145. */
  53146. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  53147. if (!newSkeleton) {
  53148. newSkeleton = new BABYLON.Skeleton(skins.name || "", "", gltfRuntime.scene);
  53149. }
  53150. if (!skins.babylonSkeleton) {
  53151. return newSkeleton;
  53152. }
  53153. // Find the root bones
  53154. var nodesToRoot = [];
  53155. var nodesToRootToAdd = [];
  53156. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  53157. newSkeleton.bones = [];
  53158. // Joints
  53159. for (var i = 0; i < skins.jointNames.length; i++) {
  53160. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  53161. if (!jointNode) {
  53162. continue;
  53163. }
  53164. var node = jointNode.node;
  53165. if (!node) {
  53166. BABYLON.Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
  53167. continue;
  53168. }
  53169. var id = jointNode.id;
  53170. // Optimize, if the bone already exists...
  53171. var existingBone = gltfRuntime.scene.getBoneByID(id);
  53172. if (existingBone) {
  53173. newSkeleton.bones.push(existingBone);
  53174. continue;
  53175. }
  53176. // Search for parent bone
  53177. var foundBone = false;
  53178. var parentBone = null;
  53179. for (var j = 0; j < i; j++) {
  53180. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  53181. if (!jointNode_1) {
  53182. continue;
  53183. }
  53184. var joint = jointNode_1.node;
  53185. if (!joint) {
  53186. BABYLON.Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  53187. continue;
  53188. }
  53189. var children = joint.children;
  53190. if (!children) {
  53191. continue;
  53192. }
  53193. foundBone = false;
  53194. for (var k = 0; k < children.length; k++) {
  53195. if (children[k] === id) {
  53196. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  53197. foundBone = true;
  53198. break;
  53199. }
  53200. }
  53201. if (foundBone) {
  53202. break;
  53203. }
  53204. }
  53205. // Create bone
  53206. var mat = configureBoneTransformation(node);
  53207. if (!parentBone && nodesToRoot.length > 0) {
  53208. parentBone = getNodeToRoot(nodesToRoot, id);
  53209. if (parentBone) {
  53210. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  53211. nodesToRootToAdd.push(parentBone);
  53212. }
  53213. }
  53214. }
  53215. var bone = new BABYLON.Bone(node.jointName || "", newSkeleton, parentBone, mat);
  53216. bone.id = id;
  53217. }
  53218. // Polish
  53219. var bones = newSkeleton.bones;
  53220. newSkeleton.bones = [];
  53221. for (var i = 0; i < skins.jointNames.length; i++) {
  53222. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  53223. if (!jointNode) {
  53224. continue;
  53225. }
  53226. for (var j = 0; j < bones.length; j++) {
  53227. if (bones[j].id === jointNode.id) {
  53228. newSkeleton.bones.push(bones[j]);
  53229. break;
  53230. }
  53231. }
  53232. }
  53233. newSkeleton.prepare();
  53234. // Finish
  53235. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  53236. newSkeleton.bones.push(nodesToRootToAdd[i]);
  53237. }
  53238. return newSkeleton;
  53239. };
  53240. /**
  53241. * Imports a mesh and its geometries
  53242. */
  53243. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  53244. if (!newMesh) {
  53245. newMesh = new BABYLON.Mesh(node.name || "", gltfRuntime.scene);
  53246. newMesh.id = id;
  53247. }
  53248. if (!node.babylonNode) {
  53249. return newMesh;
  53250. }
  53251. var subMaterials = [];
  53252. var vertexData = null;
  53253. var verticesStarts = new Array();
  53254. var verticesCounts = new Array();
  53255. var indexStarts = new Array();
  53256. var indexCounts = new Array();
  53257. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  53258. var meshID = meshes[meshIndex];
  53259. var mesh = gltfRuntime.meshes[meshID];
  53260. if (!mesh) {
  53261. continue;
  53262. }
  53263. // Positions, normals and UVs
  53264. for (var i = 0; i < mesh.primitives.length; i++) {
  53265. // Temporary vertex data
  53266. var tempVertexData = new BABYLON.VertexData();
  53267. var primitive = mesh.primitives[i];
  53268. if (primitive.mode !== 4) {
  53269. // continue;
  53270. }
  53271. var attributes = primitive.attributes;
  53272. var accessor = null;
  53273. var buffer = null;
  53274. // Set positions, normal and uvs
  53275. for (var semantic in attributes) {
  53276. // Link accessor and buffer view
  53277. accessor = gltfRuntime.accessors[attributes[semantic]];
  53278. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  53279. if (semantic === "NORMAL") {
  53280. tempVertexData.normals = new Float32Array(buffer.length);
  53281. tempVertexData.normals.set(buffer);
  53282. }
  53283. else if (semantic === "POSITION") {
  53284. if (BABYLON.GLTFFileLoader.HomogeneousCoordinates) {
  53285. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  53286. for (var j = 0; j < buffer.length; j += 4) {
  53287. tempVertexData.positions[j] = buffer[j];
  53288. tempVertexData.positions[j + 1] = buffer[j + 1];
  53289. tempVertexData.positions[j + 2] = buffer[j + 2];
  53290. }
  53291. }
  53292. else {
  53293. tempVertexData.positions = new Float32Array(buffer.length);
  53294. tempVertexData.positions.set(buffer);
  53295. }
  53296. verticesCounts.push(tempVertexData.positions.length);
  53297. }
  53298. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  53299. var channel = Number(semantic.split("_")[1]);
  53300. var uvKind = BABYLON.VertexBuffer.UVKind + (channel === 0 ? "" : (channel + 1));
  53301. var uvs = new Float32Array(buffer.length);
  53302. uvs.set(buffer);
  53303. normalizeUVs(uvs);
  53304. tempVertexData.set(uvs, uvKind);
  53305. }
  53306. else if (semantic === "JOINT") {
  53307. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  53308. tempVertexData.matricesIndices.set(buffer);
  53309. }
  53310. else if (semantic === "WEIGHT") {
  53311. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  53312. tempVertexData.matricesWeights.set(buffer);
  53313. }
  53314. else if (semantic === "COLOR") {
  53315. tempVertexData.colors = new Float32Array(buffer.length);
  53316. tempVertexData.colors.set(buffer);
  53317. }
  53318. }
  53319. // Indices
  53320. accessor = gltfRuntime.accessors[primitive.indices];
  53321. if (accessor) {
  53322. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  53323. tempVertexData.indices = new Int32Array(buffer.length);
  53324. tempVertexData.indices.set(buffer);
  53325. indexCounts.push(tempVertexData.indices.length);
  53326. }
  53327. else {
  53328. // Set indices on the fly
  53329. var indices = [];
  53330. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  53331. indices.push(j);
  53332. }
  53333. tempVertexData.indices = new Int32Array(indices);
  53334. indexCounts.push(tempVertexData.indices.length);
  53335. }
  53336. if (!vertexData) {
  53337. vertexData = tempVertexData;
  53338. }
  53339. else {
  53340. vertexData.merge(tempVertexData);
  53341. }
  53342. // Sub material
  53343. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  53344. subMaterials.push(material_1 === null ? GLTF1.GLTFUtils.GetDefaultMaterial(gltfRuntime.scene) : material_1);
  53345. // Update vertices start and index start
  53346. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  53347. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  53348. }
  53349. }
  53350. var material;
  53351. if (subMaterials.length > 1) {
  53352. material = new BABYLON.MultiMaterial("multimat" + id, gltfRuntime.scene);
  53353. material.subMaterials = subMaterials;
  53354. }
  53355. else {
  53356. material = new BABYLON.StandardMaterial("multimat" + id, gltfRuntime.scene);
  53357. }
  53358. if (subMaterials.length === 1) {
  53359. material = subMaterials[0];
  53360. }
  53361. if (!newMesh.material) {
  53362. newMesh.material = material;
  53363. }
  53364. // Apply geometry
  53365. new BABYLON.Geometry(id, gltfRuntime.scene, vertexData, false, newMesh);
  53366. newMesh.computeWorldMatrix(true);
  53367. // Apply submeshes
  53368. newMesh.subMeshes = [];
  53369. var index = 0;
  53370. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  53371. var meshID = meshes[meshIndex];
  53372. var mesh = gltfRuntime.meshes[meshID];
  53373. if (!mesh) {
  53374. continue;
  53375. }
  53376. for (var i = 0; i < mesh.primitives.length; i++) {
  53377. if (mesh.primitives[i].mode !== 4) {
  53378. //continue;
  53379. }
  53380. BABYLON.SubMesh.AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  53381. index++;
  53382. }
  53383. }
  53384. // Finish
  53385. return newMesh;
  53386. };
  53387. /**
  53388. * Configure node transformation from position, rotation and scaling
  53389. */
  53390. var configureNode = function (newNode, position, rotation, scaling) {
  53391. if (newNode.position) {
  53392. newNode.position = position;
  53393. }
  53394. if (newNode.rotationQuaternion || newNode.rotation) {
  53395. newNode.rotationQuaternion = rotation;
  53396. }
  53397. if (newNode.scaling) {
  53398. newNode.scaling = scaling;
  53399. }
  53400. };
  53401. /**
  53402. * Configures node from transformation matrix
  53403. */
  53404. var configureNodeFromMatrix = function (newNode, node, parent) {
  53405. if (node.matrix) {
  53406. var position = new BABYLON.Vector3(0, 0, 0);
  53407. var rotation = new BABYLON.Quaternion();
  53408. var scaling = new BABYLON.Vector3(0, 0, 0);
  53409. var mat = BABYLON.Matrix.FromArray(node.matrix);
  53410. mat.decompose(scaling, rotation, position);
  53411. configureNode(newNode, position, rotation, scaling);
  53412. }
  53413. else if (node.translation && node.rotation && node.scale) {
  53414. configureNode(newNode, BABYLON.Vector3.FromArray(node.translation), BABYLON.Quaternion.FromArray(node.rotation), BABYLON.Vector3.FromArray(node.scale));
  53415. }
  53416. newNode.computeWorldMatrix(true);
  53417. };
  53418. /**
  53419. * Imports a node
  53420. */
  53421. var importNode = function (gltfRuntime, node, id, parent) {
  53422. var lastNode = null;
  53423. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  53424. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  53425. return null;
  53426. }
  53427. }
  53428. // Meshes
  53429. if (node.skin) {
  53430. if (node.meshes) {
  53431. var skin = gltfRuntime.skins[node.skin];
  53432. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  53433. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  53434. if (newMesh.skeleton === null) {
  53435. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  53436. if (!skin.babylonSkeleton) {
  53437. skin.babylonSkeleton = newMesh.skeleton;
  53438. }
  53439. }
  53440. lastNode = newMesh;
  53441. }
  53442. }
  53443. else if (node.meshes) {
  53444. /**
  53445. * Improve meshes property
  53446. */
  53447. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  53448. lastNode = newMesh;
  53449. }
  53450. // Lights
  53451. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  53452. var light = gltfRuntime.lights[node.light];
  53453. if (light) {
  53454. if (light.type === "ambient") {
  53455. var ambienLight = light[light.type];
  53456. var hemiLight = new BABYLON.HemisphericLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  53457. hemiLight.name = node.name || "";
  53458. if (ambienLight.color) {
  53459. hemiLight.diffuse = BABYLON.Color3.FromArray(ambienLight.color);
  53460. }
  53461. lastNode = hemiLight;
  53462. }
  53463. else if (light.type === "directional") {
  53464. var directionalLight = light[light.type];
  53465. var dirLight = new BABYLON.DirectionalLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  53466. dirLight.name = node.name || "";
  53467. if (directionalLight.color) {
  53468. dirLight.diffuse = BABYLON.Color3.FromArray(directionalLight.color);
  53469. }
  53470. lastNode = dirLight;
  53471. }
  53472. else if (light.type === "point") {
  53473. var pointLight = light[light.type];
  53474. var ptLight = new BABYLON.PointLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  53475. ptLight.name = node.name || "";
  53476. if (pointLight.color) {
  53477. ptLight.diffuse = BABYLON.Color3.FromArray(pointLight.color);
  53478. }
  53479. lastNode = ptLight;
  53480. }
  53481. else if (light.type === "spot") {
  53482. var spotLight = light[light.type];
  53483. var spLight = new BABYLON.SpotLight(node.light, BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 0, 0, gltfRuntime.scene);
  53484. spLight.name = node.name || "";
  53485. if (spotLight.color) {
  53486. spLight.diffuse = BABYLON.Color3.FromArray(spotLight.color);
  53487. }
  53488. if (spotLight.fallOfAngle) {
  53489. spLight.angle = spotLight.fallOfAngle;
  53490. }
  53491. if (spotLight.fallOffExponent) {
  53492. spLight.exponent = spotLight.fallOffExponent;
  53493. }
  53494. lastNode = spLight;
  53495. }
  53496. }
  53497. }
  53498. // Cameras
  53499. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  53500. var camera = gltfRuntime.cameras[node.camera];
  53501. if (camera) {
  53502. if (camera.type === "orthographic") {
  53503. var orthoCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene, false);
  53504. orthoCamera.name = node.name || "";
  53505. orthoCamera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
  53506. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  53507. lastNode = orthoCamera;
  53508. }
  53509. else if (camera.type === "perspective") {
  53510. var perspectiveCamera = camera[camera.type];
  53511. var persCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene, false);
  53512. persCamera.name = node.name || "";
  53513. persCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  53514. if (!perspectiveCamera.aspectRatio) {
  53515. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  53516. }
  53517. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  53518. persCamera.maxZ = perspectiveCamera.zfar;
  53519. persCamera.minZ = perspectiveCamera.znear;
  53520. }
  53521. lastNode = persCamera;
  53522. }
  53523. }
  53524. }
  53525. // Empty node
  53526. if (!node.jointName) {
  53527. if (node.babylonNode) {
  53528. return node.babylonNode;
  53529. }
  53530. else if (lastNode === null) {
  53531. var dummy = new BABYLON.Mesh(node.name || "", gltfRuntime.scene);
  53532. node.babylonNode = dummy;
  53533. lastNode = dummy;
  53534. }
  53535. }
  53536. if (lastNode !== null) {
  53537. if (node.matrix && lastNode instanceof BABYLON.Mesh) {
  53538. configureNodeFromMatrix(lastNode, node, parent);
  53539. }
  53540. else {
  53541. var translation = node.translation || [0, 0, 0];
  53542. var rotation = node.rotation || [0, 0, 0, 1];
  53543. var scale = node.scale || [1, 1, 1];
  53544. configureNode(lastNode, BABYLON.Vector3.FromArray(translation), BABYLON.Quaternion.FromArray(rotation), BABYLON.Vector3.FromArray(scale));
  53545. }
  53546. lastNode.updateCache(true);
  53547. node.babylonNode = lastNode;
  53548. }
  53549. return lastNode;
  53550. };
  53551. /**
  53552. * Traverses nodes and creates them
  53553. */
  53554. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  53555. if (meshIncluded === void 0) { meshIncluded = false; }
  53556. var node = gltfRuntime.nodes[id];
  53557. var newNode = null;
  53558. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  53559. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  53560. meshIncluded = true;
  53561. }
  53562. else {
  53563. meshIncluded = false;
  53564. }
  53565. }
  53566. else {
  53567. meshIncluded = true;
  53568. }
  53569. if (!node.jointName && meshIncluded) {
  53570. newNode = importNode(gltfRuntime, node, id, parent);
  53571. if (newNode !== null) {
  53572. newNode.id = id;
  53573. newNode.parent = parent;
  53574. }
  53575. }
  53576. if (node.children) {
  53577. for (var i = 0; i < node.children.length; i++) {
  53578. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  53579. }
  53580. }
  53581. };
  53582. /**
  53583. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  53584. */
  53585. var postLoad = function (gltfRuntime) {
  53586. // Nodes
  53587. var currentScene = gltfRuntime.currentScene;
  53588. if (currentScene) {
  53589. for (var i = 0; i < currentScene.nodes.length; i++) {
  53590. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  53591. }
  53592. }
  53593. else {
  53594. for (var thing in gltfRuntime.scenes) {
  53595. currentScene = gltfRuntime.scenes[thing];
  53596. for (var i = 0; i < currentScene.nodes.length; i++) {
  53597. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  53598. }
  53599. }
  53600. }
  53601. // Set animations
  53602. loadAnimations(gltfRuntime);
  53603. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  53604. var skeleton = gltfRuntime.scene.skeletons[i];
  53605. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  53606. }
  53607. };
  53608. /**
  53609. * onBind shaderrs callback to set uniforms and matrices
  53610. */
  53611. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  53612. var materialValues = material.values || technique.parameters;
  53613. for (var unif in unTreatedUniforms) {
  53614. var uniform = unTreatedUniforms[unif];
  53615. var type = uniform.type;
  53616. if (type === GLTF1.EParameterType.FLOAT_MAT2 || type === GLTF1.EParameterType.FLOAT_MAT3 || type === GLTF1.EParameterType.FLOAT_MAT4) {
  53617. if (uniform.semantic && !uniform.source && !uniform.node) {
  53618. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  53619. }
  53620. else if (uniform.semantic && (uniform.source || uniform.node)) {
  53621. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  53622. if (source === null) {
  53623. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  53624. }
  53625. if (source === null) {
  53626. continue;
  53627. }
  53628. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  53629. }
  53630. }
  53631. else {
  53632. var value = materialValues[technique.uniforms[unif]];
  53633. if (!value) {
  53634. continue;
  53635. }
  53636. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  53637. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  53638. if (texture === null || texture === undefined) {
  53639. continue;
  53640. }
  53641. shaderMaterial.getEffect().setTexture(unif, texture);
  53642. }
  53643. else {
  53644. GLTF1.GLTFUtils.SetUniform((shaderMaterial.getEffect()), unif, value, type);
  53645. }
  53646. }
  53647. }
  53648. onSuccess(shaderMaterial);
  53649. };
  53650. /**
  53651. * Prepare uniforms to send the only one time
  53652. * Loads the appropriate textures
  53653. */
  53654. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  53655. var materialValues = material.values || technique.parameters;
  53656. var techniqueUniforms = technique.uniforms;
  53657. /**
  53658. * Prepare values here (not matrices)
  53659. */
  53660. for (var unif in unTreatedUniforms) {
  53661. var uniform = unTreatedUniforms[unif];
  53662. var type = uniform.type;
  53663. var value = materialValues[techniqueUniforms[unif]];
  53664. if (value === undefined) {
  53665. // In case the value is the same for all materials
  53666. value = uniform.value;
  53667. }
  53668. if (!value) {
  53669. continue;
  53670. }
  53671. var onLoadTexture = function (uniformName) {
  53672. return function (texture) {
  53673. if (uniform.value && uniformName) {
  53674. // Static uniform
  53675. shaderMaterial.setTexture(uniformName, texture);
  53676. delete unTreatedUniforms[uniformName];
  53677. }
  53678. };
  53679. };
  53680. // Texture (sampler2D)
  53681. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  53682. GLTF1.GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  53683. }
  53684. // Others
  53685. else {
  53686. if (uniform.value && GLTF1.GLTFUtils.SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  53687. // Static uniform
  53688. delete unTreatedUniforms[unif];
  53689. }
  53690. }
  53691. }
  53692. };
  53693. /**
  53694. * Shader compilation failed
  53695. */
  53696. var onShaderCompileError = function (program, shaderMaterial, onError) {
  53697. return function (effect, error) {
  53698. shaderMaterial.dispose(true);
  53699. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  53700. };
  53701. };
  53702. /**
  53703. * Shader compilation success
  53704. */
  53705. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  53706. return function (_) {
  53707. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  53708. shaderMaterial.onBind = function (mesh) {
  53709. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  53710. };
  53711. };
  53712. };
  53713. /**
  53714. * Returns the appropriate uniform if already handled by babylon
  53715. */
  53716. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  53717. for (var unif in technique.uniforms) {
  53718. var uniform = technique.uniforms[unif];
  53719. var uniformParameter = technique.parameters[uniform];
  53720. if (tokenizer.currentIdentifier === unif) {
  53721. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  53722. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  53723. if (transformIndex !== -1) {
  53724. delete unTreatedUniforms[unif];
  53725. return babylonTransforms[transformIndex];
  53726. }
  53727. }
  53728. }
  53729. }
  53730. return tokenizer.currentIdentifier;
  53731. };
  53732. /**
  53733. * All shaders loaded. Create materials one by one
  53734. */
  53735. var importMaterials = function (gltfRuntime) {
  53736. // Create materials
  53737. for (var mat in gltfRuntime.materials) {
  53738. GLTF1.GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  53739. }
  53740. };
  53741. /**
  53742. * Implementation of the base glTF spec
  53743. */
  53744. var GLTFLoaderBase = /** @class */ (function () {
  53745. function GLTFLoaderBase() {
  53746. }
  53747. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  53748. var gltfRuntime = {
  53749. extensions: {},
  53750. accessors: {},
  53751. buffers: {},
  53752. bufferViews: {},
  53753. meshes: {},
  53754. lights: {},
  53755. cameras: {},
  53756. nodes: {},
  53757. images: {},
  53758. textures: {},
  53759. shaders: {},
  53760. programs: {},
  53761. samplers: {},
  53762. techniques: {},
  53763. materials: {},
  53764. animations: {},
  53765. skins: {},
  53766. extensionsUsed: [],
  53767. scenes: {},
  53768. buffersCount: 0,
  53769. shaderscount: 0,
  53770. scene: scene,
  53771. rootUrl: rootUrl,
  53772. loadedBufferCount: 0,
  53773. loadedBufferViews: {},
  53774. loadedShaderCount: 0,
  53775. importOnlyMeshes: false,
  53776. dummyNodes: []
  53777. };
  53778. // Parse
  53779. if (parsedData.extensions) {
  53780. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  53781. }
  53782. if (parsedData.extensionsUsed) {
  53783. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  53784. }
  53785. if (parsedData.buffers) {
  53786. parseBuffers(parsedData.buffers, gltfRuntime);
  53787. }
  53788. if (parsedData.bufferViews) {
  53789. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  53790. }
  53791. if (parsedData.accessors) {
  53792. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  53793. }
  53794. if (parsedData.meshes) {
  53795. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  53796. }
  53797. if (parsedData.lights) {
  53798. parseObject(parsedData.lights, "lights", gltfRuntime);
  53799. }
  53800. if (parsedData.cameras) {
  53801. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  53802. }
  53803. if (parsedData.nodes) {
  53804. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  53805. }
  53806. if (parsedData.images) {
  53807. parseObject(parsedData.images, "images", gltfRuntime);
  53808. }
  53809. if (parsedData.textures) {
  53810. parseObject(parsedData.textures, "textures", gltfRuntime);
  53811. }
  53812. if (parsedData.shaders) {
  53813. parseShaders(parsedData.shaders, gltfRuntime);
  53814. }
  53815. if (parsedData.programs) {
  53816. parseObject(parsedData.programs, "programs", gltfRuntime);
  53817. }
  53818. if (parsedData.samplers) {
  53819. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  53820. }
  53821. if (parsedData.techniques) {
  53822. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  53823. }
  53824. if (parsedData.materials) {
  53825. parseObject(parsedData.materials, "materials", gltfRuntime);
  53826. }
  53827. if (parsedData.animations) {
  53828. parseObject(parsedData.animations, "animations", gltfRuntime);
  53829. }
  53830. if (parsedData.skins) {
  53831. parseObject(parsedData.skins, "skins", gltfRuntime);
  53832. }
  53833. if (parsedData.scenes) {
  53834. gltfRuntime.scenes = parsedData.scenes;
  53835. }
  53836. if (parsedData.scene && parsedData.scenes) {
  53837. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  53838. }
  53839. return gltfRuntime;
  53840. };
  53841. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  53842. var buffer = gltfRuntime.buffers[id];
  53843. if (BABYLON.Tools.IsBase64(buffer.uri)) {
  53844. setTimeout(function () { return onSuccess(new Uint8Array(BABYLON.Tools.DecodeBase64(buffer.uri))); });
  53845. }
  53846. else {
  53847. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  53848. if (request) {
  53849. onError(request.status + " " + request.statusText);
  53850. }
  53851. });
  53852. }
  53853. };
  53854. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  53855. var texture = gltfRuntime.textures[id];
  53856. if (!texture || !texture.source) {
  53857. onError("");
  53858. return;
  53859. }
  53860. if (texture.babylonTexture) {
  53861. onSuccess(null);
  53862. return;
  53863. }
  53864. var source = gltfRuntime.images[texture.source];
  53865. if (BABYLON.Tools.IsBase64(source.uri)) {
  53866. setTimeout(function () { return onSuccess(new Uint8Array(BABYLON.Tools.DecodeBase64(source.uri))); });
  53867. }
  53868. else {
  53869. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  53870. if (request) {
  53871. onError(request.status + " " + request.statusText);
  53872. }
  53873. });
  53874. }
  53875. };
  53876. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  53877. var texture = gltfRuntime.textures[id];
  53878. if (texture.babylonTexture) {
  53879. onSuccess(texture.babylonTexture);
  53880. return;
  53881. }
  53882. var sampler = gltfRuntime.samplers[texture.sampler];
  53883. var createMipMaps = (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST) ||
  53884. (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_LINEAR) ||
  53885. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST) ||
  53886. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR);
  53887. var samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  53888. var blob = new Blob([buffer]);
  53889. var blobURL = URL.createObjectURL(blob);
  53890. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  53891. var newTexture = new BABYLON.Texture(blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  53892. if (sampler.wrapS !== undefined) {
  53893. newTexture.wrapU = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapS);
  53894. }
  53895. if (sampler.wrapT !== undefined) {
  53896. newTexture.wrapV = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapT);
  53897. }
  53898. newTexture.name = id;
  53899. texture.babylonTexture = newTexture;
  53900. onSuccess(newTexture);
  53901. };
  53902. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  53903. var shader = gltfRuntime.shaders[id];
  53904. if (BABYLON.Tools.IsBase64(shader.uri)) {
  53905. var shaderString = atob(shader.uri.split(",")[1]);
  53906. if (onSuccess) {
  53907. onSuccess(shaderString);
  53908. }
  53909. }
  53910. else {
  53911. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  53912. if (request && onError) {
  53913. onError(request.status + " " + request.statusText);
  53914. }
  53915. });
  53916. }
  53917. };
  53918. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  53919. var material = gltfRuntime.materials[id];
  53920. if (!material.technique) {
  53921. if (onError) {
  53922. onError("No technique found.");
  53923. }
  53924. return;
  53925. }
  53926. var technique = gltfRuntime.techniques[material.technique];
  53927. if (!technique) {
  53928. var defaultMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  53929. defaultMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  53930. defaultMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  53931. onSuccess(defaultMaterial);
  53932. return;
  53933. }
  53934. var program = gltfRuntime.programs[technique.program];
  53935. var states = technique.states;
  53936. var vertexShader = BABYLON.Effect.ShadersStore[program.vertexShader + "VertexShader"];
  53937. var pixelShader = BABYLON.Effect.ShadersStore[program.fragmentShader + "PixelShader"];
  53938. var newVertexShader = "";
  53939. var newPixelShader = "";
  53940. var vertexTokenizer = new Tokenizer(vertexShader);
  53941. var pixelTokenizer = new Tokenizer(pixelShader);
  53942. var unTreatedUniforms = {};
  53943. var uniforms = [];
  53944. var attributes = [];
  53945. var samplers = [];
  53946. // Fill uniform, sampler2D and attributes
  53947. for (var unif in technique.uniforms) {
  53948. var uniform = technique.uniforms[unif];
  53949. var uniformParameter = technique.parameters[uniform];
  53950. unTreatedUniforms[unif] = uniformParameter;
  53951. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  53952. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  53953. if (transformIndex !== -1) {
  53954. uniforms.push(babylonTransforms[transformIndex]);
  53955. delete unTreatedUniforms[unif];
  53956. }
  53957. else {
  53958. uniforms.push(unif);
  53959. }
  53960. }
  53961. else if (uniformParameter.type === GLTF1.EParameterType.SAMPLER_2D) {
  53962. samplers.push(unif);
  53963. }
  53964. else {
  53965. uniforms.push(unif);
  53966. }
  53967. }
  53968. for (var attr in technique.attributes) {
  53969. var attribute = technique.attributes[attr];
  53970. var attributeParameter = technique.parameters[attribute];
  53971. if (attributeParameter.semantic) {
  53972. attributes.push(getAttribute(attributeParameter));
  53973. }
  53974. }
  53975. // Configure vertex shader
  53976. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  53977. var tokenType = vertexTokenizer.currentToken;
  53978. if (tokenType !== ETokenType.IDENTIFIER) {
  53979. newVertexShader += vertexTokenizer.currentString;
  53980. continue;
  53981. }
  53982. var foundAttribute = false;
  53983. for (var attr in technique.attributes) {
  53984. var attribute = technique.attributes[attr];
  53985. var attributeParameter = technique.parameters[attribute];
  53986. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  53987. newVertexShader += getAttribute(attributeParameter);
  53988. foundAttribute = true;
  53989. break;
  53990. }
  53991. }
  53992. if (foundAttribute) {
  53993. continue;
  53994. }
  53995. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  53996. }
  53997. // Configure pixel shader
  53998. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  53999. var tokenType = pixelTokenizer.currentToken;
  54000. if (tokenType !== ETokenType.IDENTIFIER) {
  54001. newPixelShader += pixelTokenizer.currentString;
  54002. continue;
  54003. }
  54004. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  54005. }
  54006. // Create shader material
  54007. var shaderPath = {
  54008. vertex: program.vertexShader + id,
  54009. fragment: program.fragmentShader + id
  54010. };
  54011. var options = {
  54012. attributes: attributes,
  54013. uniforms: uniforms,
  54014. samplers: samplers,
  54015. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  54016. };
  54017. BABYLON.Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  54018. BABYLON.Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  54019. var shaderMaterial = new BABYLON.ShaderMaterial(id, gltfRuntime.scene, shaderPath, options);
  54020. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  54021. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  54022. shaderMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  54023. if (states && states.functions) {
  54024. var functions = states.functions;
  54025. if (functions.cullFace && functions.cullFace[0] !== GLTF1.ECullingType.BACK) {
  54026. shaderMaterial.backFaceCulling = false;
  54027. }
  54028. var blendFunc = functions.blendFuncSeparate;
  54029. if (blendFunc) {
  54030. if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_ALPHA && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54031. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
  54032. }
  54033. else if (blendFunc[0] === GLTF1.EBlendingFunction.ONE && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54034. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ONEONE;
  54035. }
  54036. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54037. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ADD;
  54038. }
  54039. else if (blendFunc[0] === GLTF1.EBlendingFunction.ZERO && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54040. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_SUBTRACT;
  54041. }
  54042. else if (blendFunc[0] === GLTF1.EBlendingFunction.DST_COLOR && blendFunc[1] === GLTF1.EBlendingFunction.ZERO && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54043. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MULTIPLY;
  54044. }
  54045. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  54046. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MAXIMIZED;
  54047. }
  54048. }
  54049. }
  54050. };
  54051. return GLTFLoaderBase;
  54052. }());
  54053. GLTF1.GLTFLoaderBase = GLTFLoaderBase;
  54054. /**
  54055. * glTF V1 Loader
  54056. */
  54057. var GLTFLoader = /** @class */ (function () {
  54058. function GLTFLoader() {
  54059. // #region Stubs for IGLTFLoader interface
  54060. this.coordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode.AUTO;
  54061. this.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.FIRST;
  54062. this.compileMaterials = false;
  54063. this.useClipPlane = false;
  54064. this.compileShadowGenerators = false;
  54065. this.transparencyAsCoverage = false;
  54066. this._normalizeAnimationGroupsToBeginAtZero = true;
  54067. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  54068. this.onMeshLoadedObservable = new BABYLON.Observable();
  54069. this.onTextureLoadedObservable = new BABYLON.Observable();
  54070. this.onMaterialLoadedObservable = new BABYLON.Observable();
  54071. this.onCameraLoadedObservable = new BABYLON.Observable();
  54072. this.onCompleteObservable = new BABYLON.Observable();
  54073. this.onDisposeObservable = new BABYLON.Observable();
  54074. this.onExtensionLoadedObservable = new BABYLON.Observable();
  54075. this.state = null;
  54076. }
  54077. GLTFLoader.RegisterExtension = function (extension) {
  54078. if (GLTFLoader.Extensions[extension.name]) {
  54079. BABYLON.Tools.Error("Tool with the same name \"" + extension.name + "\" already exists");
  54080. return;
  54081. }
  54082. GLTFLoader.Extensions[extension.name] = extension;
  54083. };
  54084. GLTFLoader.prototype.dispose = function () { };
  54085. // #endregion
  54086. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  54087. var _this = this;
  54088. scene.useRightHandedSystem = true;
  54089. GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  54090. gltfRuntime.importOnlyMeshes = true;
  54091. if (meshesNames === "") {
  54092. gltfRuntime.importMeshesNames = [];
  54093. }
  54094. else if (typeof meshesNames === "string") {
  54095. gltfRuntime.importMeshesNames = [meshesNames];
  54096. }
  54097. else if (meshesNames && !(meshesNames instanceof Array)) {
  54098. gltfRuntime.importMeshesNames = [meshesNames];
  54099. }
  54100. else {
  54101. gltfRuntime.importMeshesNames = [];
  54102. BABYLON.Tools.Warn("Argument meshesNames must be of type string or string[]");
  54103. }
  54104. // Create nodes
  54105. _this._createNodes(gltfRuntime);
  54106. var meshes = new Array();
  54107. var skeletons = new Array();
  54108. // Fill arrays of meshes and skeletons
  54109. for (var nde in gltfRuntime.nodes) {
  54110. var node = gltfRuntime.nodes[nde];
  54111. if (node.babylonNode instanceof BABYLON.AbstractMesh) {
  54112. meshes.push(node.babylonNode);
  54113. }
  54114. }
  54115. for (var skl in gltfRuntime.skins) {
  54116. var skin = gltfRuntime.skins[skl];
  54117. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  54118. skeletons.push(skin.babylonSkeleton);
  54119. }
  54120. }
  54121. // Load buffers, shaders, materials, etc.
  54122. _this._loadBuffersAsync(gltfRuntime, function () {
  54123. _this._loadShadersAsync(gltfRuntime, function () {
  54124. importMaterials(gltfRuntime);
  54125. postLoad(gltfRuntime);
  54126. if (!BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  54127. onSuccess(meshes, skeletons);
  54128. }
  54129. });
  54130. }, onProgress);
  54131. if (BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  54132. onSuccess(meshes, skeletons);
  54133. }
  54134. }, onError);
  54135. return true;
  54136. };
  54137. /**
  54138. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  54139. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  54140. * @param scene the scene the meshes should be added to
  54141. * @param data gltf data containing information of the meshes in a loaded file
  54142. * @param rootUrl root url to load from
  54143. * @param onProgress event that fires when loading progress has occured
  54144. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  54145. */
  54146. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  54147. var _this = this;
  54148. return new Promise(function (resolve, reject) {
  54149. _this._importMeshAsync(meshesNames, scene, data, rootUrl, function (meshes, skeletons) {
  54150. resolve({
  54151. meshes: meshes,
  54152. particleSystems: [],
  54153. skeletons: skeletons,
  54154. animationGroups: []
  54155. });
  54156. }, onProgress, function (message) {
  54157. reject(new Error(message));
  54158. });
  54159. });
  54160. };
  54161. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  54162. var _this = this;
  54163. scene.useRightHandedSystem = true;
  54164. GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  54165. // Load runtime extensios
  54166. GLTF1.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  54167. // Create nodes
  54168. _this._createNodes(gltfRuntime);
  54169. // Load buffers, shaders, materials, etc.
  54170. _this._loadBuffersAsync(gltfRuntime, function () {
  54171. _this._loadShadersAsync(gltfRuntime, function () {
  54172. importMaterials(gltfRuntime);
  54173. postLoad(gltfRuntime);
  54174. if (!BABYLON.GLTFFileLoader.IncrementalLoading) {
  54175. onSuccess();
  54176. }
  54177. });
  54178. });
  54179. if (BABYLON.GLTFFileLoader.IncrementalLoading) {
  54180. onSuccess();
  54181. }
  54182. }, onError);
  54183. }, onError);
  54184. };
  54185. /**
  54186. * Imports all objects from a loaded gltf file and adds them to the scene
  54187. * @param scene the scene the objects should be added to
  54188. * @param data gltf data containing information of the meshes in a loaded file
  54189. * @param rootUrl root url to load from
  54190. * @param onProgress event that fires when loading progress has occured
  54191. * @returns a promise which completes when objects have been loaded to the scene
  54192. */
  54193. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  54194. var _this = this;
  54195. return new Promise(function (resolve, reject) {
  54196. _this._loadAsync(scene, data, rootUrl, function () {
  54197. resolve();
  54198. }, onProgress, function (message) {
  54199. reject(new Error(message));
  54200. });
  54201. });
  54202. };
  54203. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  54204. var hasShaders = false;
  54205. var processShader = function (sha, shader) {
  54206. GLTF1.GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  54207. if (shaderString instanceof ArrayBuffer) {
  54208. return;
  54209. }
  54210. gltfRuntime.loadedShaderCount++;
  54211. if (shaderString) {
  54212. BABYLON.Effect.ShadersStore[sha + (shader.type === GLTF1.EShaderType.VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  54213. }
  54214. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  54215. onload();
  54216. }
  54217. }, function () {
  54218. BABYLON.Tools.Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  54219. });
  54220. };
  54221. for (var sha in gltfRuntime.shaders) {
  54222. hasShaders = true;
  54223. var shader = gltfRuntime.shaders[sha];
  54224. if (shader) {
  54225. processShader.bind(this, sha, shader)();
  54226. }
  54227. else {
  54228. BABYLON.Tools.Error("No shader named: " + sha);
  54229. }
  54230. }
  54231. if (!hasShaders) {
  54232. onload();
  54233. }
  54234. };
  54235. ;
  54236. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  54237. var hasBuffers = false;
  54238. var processBuffer = function (buf, buffer) {
  54239. GLTF1.GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  54240. gltfRuntime.loadedBufferCount++;
  54241. if (bufferView) {
  54242. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  54243. BABYLON.Tools.Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  54244. }
  54245. gltfRuntime.loadedBufferViews[buf] = bufferView;
  54246. }
  54247. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  54248. onLoad();
  54249. }
  54250. }, function () {
  54251. BABYLON.Tools.Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  54252. });
  54253. };
  54254. for (var buf in gltfRuntime.buffers) {
  54255. hasBuffers = true;
  54256. var buffer = gltfRuntime.buffers[buf];
  54257. if (buffer) {
  54258. processBuffer.bind(this, buf, buffer)();
  54259. }
  54260. else {
  54261. BABYLON.Tools.Error("No buffer named: " + buf);
  54262. }
  54263. }
  54264. if (!hasBuffers) {
  54265. onLoad();
  54266. }
  54267. };
  54268. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  54269. var currentScene = gltfRuntime.currentScene;
  54270. if (currentScene) {
  54271. // Only one scene even if multiple scenes are defined
  54272. for (var i = 0; i < currentScene.nodes.length; i++) {
  54273. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  54274. }
  54275. }
  54276. else {
  54277. // Load all scenes
  54278. for (var thing in gltfRuntime.scenes) {
  54279. currentScene = gltfRuntime.scenes[thing];
  54280. for (var i = 0; i < currentScene.nodes.length; i++) {
  54281. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  54282. }
  54283. }
  54284. }
  54285. };
  54286. GLTFLoader.Extensions = {};
  54287. return GLTFLoader;
  54288. }());
  54289. GLTF1.GLTFLoader = GLTFLoader;
  54290. ;
  54291. BABYLON.GLTFFileLoader._CreateGLTFLoaderV1 = function () { return new GLTFLoader(); };
  54292. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  54293. })(BABYLON || (BABYLON = {}));
  54294. //# sourceMappingURL=babylon.glTFLoader.js.map
  54295. var BABYLON;
  54296. (function (BABYLON) {
  54297. var GLTF1;
  54298. (function (GLTF1) {
  54299. /**
  54300. * Utils functions for GLTF
  54301. */
  54302. var GLTFUtils = /** @class */ (function () {
  54303. function GLTFUtils() {
  54304. }
  54305. /**
  54306. * Sets the given "parameter" matrix
  54307. * @param scene: the {BABYLON.Scene} object
  54308. * @param source: the source node where to pick the matrix
  54309. * @param parameter: the GLTF technique parameter
  54310. * @param uniformName: the name of the shader's uniform
  54311. * @param shaderMaterial: the shader material
  54312. */
  54313. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  54314. var mat = null;
  54315. if (parameter.semantic === "MODEL") {
  54316. mat = source.getWorldMatrix();
  54317. }
  54318. else if (parameter.semantic === "PROJECTION") {
  54319. mat = scene.getProjectionMatrix();
  54320. }
  54321. else if (parameter.semantic === "VIEW") {
  54322. mat = scene.getViewMatrix();
  54323. }
  54324. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  54325. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  54326. }
  54327. else if (parameter.semantic === "MODELVIEW") {
  54328. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  54329. }
  54330. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  54331. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  54332. }
  54333. else if (parameter.semantic === "MODELINVERSE") {
  54334. mat = source.getWorldMatrix().invert();
  54335. }
  54336. else if (parameter.semantic === "VIEWINVERSE") {
  54337. mat = scene.getViewMatrix().invert();
  54338. }
  54339. else if (parameter.semantic === "PROJECTIONINVERSE") {
  54340. mat = scene.getProjectionMatrix().invert();
  54341. }
  54342. else if (parameter.semantic === "MODELVIEWINVERSE") {
  54343. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  54344. }
  54345. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  54346. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  54347. }
  54348. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  54349. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().invert());
  54350. }
  54351. else {
  54352. debugger;
  54353. }
  54354. if (mat) {
  54355. switch (parameter.type) {
  54356. case GLTF1.EParameterType.FLOAT_MAT2:
  54357. shaderMaterial.setMatrix2x2(uniformName, BABYLON.Matrix.GetAsMatrix2x2(mat));
  54358. break;
  54359. case GLTF1.EParameterType.FLOAT_MAT3:
  54360. shaderMaterial.setMatrix3x3(uniformName, BABYLON.Matrix.GetAsMatrix3x3(mat));
  54361. break;
  54362. case GLTF1.EParameterType.FLOAT_MAT4:
  54363. shaderMaterial.setMatrix(uniformName, mat);
  54364. break;
  54365. default: break;
  54366. }
  54367. }
  54368. };
  54369. /**
  54370. * Sets the given "parameter" matrix
  54371. * @param shaderMaterial: the shader material
  54372. * @param uniform: the name of the shader's uniform
  54373. * @param value: the value of the uniform
  54374. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  54375. */
  54376. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  54377. switch (type) {
  54378. case GLTF1.EParameterType.FLOAT:
  54379. shaderMaterial.setFloat(uniform, value);
  54380. return true;
  54381. case GLTF1.EParameterType.FLOAT_VEC2:
  54382. shaderMaterial.setVector2(uniform, BABYLON.Vector2.FromArray(value));
  54383. return true;
  54384. case GLTF1.EParameterType.FLOAT_VEC3:
  54385. shaderMaterial.setVector3(uniform, BABYLON.Vector3.FromArray(value));
  54386. return true;
  54387. case GLTF1.EParameterType.FLOAT_VEC4:
  54388. shaderMaterial.setVector4(uniform, BABYLON.Vector4.FromArray(value));
  54389. return true;
  54390. default: return false;
  54391. }
  54392. };
  54393. /**
  54394. * Returns the wrap mode of the texture
  54395. * @param mode: the mode value
  54396. */
  54397. GLTFUtils.GetWrapMode = function (mode) {
  54398. switch (mode) {
  54399. case GLTF1.ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  54400. case GLTF1.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  54401. case GLTF1.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  54402. default: return BABYLON.Texture.WRAP_ADDRESSMODE;
  54403. }
  54404. };
  54405. /**
  54406. * Returns the byte stride giving an accessor
  54407. * @param accessor: the GLTF accessor objet
  54408. */
  54409. GLTFUtils.GetByteStrideFromType = function (accessor) {
  54410. // Needs this function since "byteStride" isn't requiered in glTF format
  54411. var type = accessor.type;
  54412. switch (type) {
  54413. case "VEC2": return 2;
  54414. case "VEC3": return 3;
  54415. case "VEC4": return 4;
  54416. case "MAT2": return 4;
  54417. case "MAT3": return 9;
  54418. case "MAT4": return 16;
  54419. default: return 1;
  54420. }
  54421. };
  54422. /**
  54423. * Returns the texture filter mode giving a mode value
  54424. * @param mode: the filter mode value
  54425. */
  54426. GLTFUtils.GetTextureFilterMode = function (mode) {
  54427. switch (mode) {
  54428. case GLTF1.ETextureFilterType.LINEAR:
  54429. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST:
  54430. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  54431. case GLTF1.ETextureFilterType.NEAREST:
  54432. case GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_SAMPLINGMODE;
  54433. default: return BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  54434. }
  54435. };
  54436. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  54437. var byteOffset = bufferView.byteOffset + byteOffset;
  54438. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  54439. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  54440. throw new Error("Buffer access is out of range");
  54441. }
  54442. var buffer = loadedBufferView.buffer;
  54443. byteOffset += loadedBufferView.byteOffset;
  54444. switch (componentType) {
  54445. case GLTF1.EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  54446. case GLTF1.EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  54447. case GLTF1.EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  54448. case GLTF1.EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  54449. default: return new Float32Array(buffer, byteOffset, byteLength);
  54450. }
  54451. };
  54452. /**
  54453. * Returns a buffer from its accessor
  54454. * @param gltfRuntime: the GLTF runtime
  54455. * @param accessor: the GLTF accessor
  54456. */
  54457. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  54458. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  54459. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  54460. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  54461. };
  54462. /**
  54463. * Decodes a buffer view into a string
  54464. * @param view: the buffer view
  54465. */
  54466. GLTFUtils.DecodeBufferToText = function (view) {
  54467. var result = "";
  54468. var length = view.byteLength;
  54469. for (var i = 0; i < length; ++i) {
  54470. result += String.fromCharCode(view[i]);
  54471. }
  54472. return result;
  54473. };
  54474. /**
  54475. * Returns the default material of gltf. Related to
  54476. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  54477. * @param scene: the Babylon.js scene
  54478. */
  54479. GLTFUtils.GetDefaultMaterial = function (scene) {
  54480. if (!GLTFUtils._DefaultMaterial) {
  54481. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  54482. "precision highp float;",
  54483. "",
  54484. "uniform mat4 worldView;",
  54485. "uniform mat4 projection;",
  54486. "",
  54487. "attribute vec3 position;",
  54488. "",
  54489. "void main(void)",
  54490. "{",
  54491. " gl_Position = projection * worldView * vec4(position, 1.0);",
  54492. "}"
  54493. ].join("\n");
  54494. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  54495. "precision highp float;",
  54496. "",
  54497. "uniform vec4 u_emission;",
  54498. "",
  54499. "void main(void)",
  54500. "{",
  54501. " gl_FragColor = u_emission;",
  54502. "}"
  54503. ].join("\n");
  54504. var shaderPath = {
  54505. vertex: "GLTFDefaultMaterial",
  54506. fragment: "GLTFDefaultMaterial"
  54507. };
  54508. var options = {
  54509. attributes: ["position"],
  54510. uniforms: ["worldView", "projection", "u_emission"],
  54511. samplers: new Array(),
  54512. needAlphaBlending: false
  54513. };
  54514. GLTFUtils._DefaultMaterial = new BABYLON.ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
  54515. GLTFUtils._DefaultMaterial.setColor4("u_emission", new BABYLON.Color4(0.5, 0.5, 0.5, 1.0));
  54516. }
  54517. return GLTFUtils._DefaultMaterial;
  54518. };
  54519. // The GLTF default material
  54520. GLTFUtils._DefaultMaterial = null;
  54521. return GLTFUtils;
  54522. }());
  54523. GLTF1.GLTFUtils = GLTFUtils;
  54524. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  54525. })(BABYLON || (BABYLON = {}));
  54526. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  54527. var BABYLON;
  54528. (function (BABYLON) {
  54529. var GLTF1;
  54530. (function (GLTF1) {
  54531. var GLTFLoaderExtension = /** @class */ (function () {
  54532. function GLTFLoaderExtension(name) {
  54533. this._name = name;
  54534. }
  54535. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  54536. get: function () {
  54537. return this._name;
  54538. },
  54539. enumerable: true,
  54540. configurable: true
  54541. });
  54542. /**
  54543. * Defines an override for loading the runtime
  54544. * Return true to stop further extensions from loading the runtime
  54545. */
  54546. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  54547. return false;
  54548. };
  54549. /**
  54550. * Defines an onverride for creating gltf runtime
  54551. * Return true to stop further extensions from creating the runtime
  54552. */
  54553. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  54554. return false;
  54555. };
  54556. /**
  54557. * Defines an override for loading buffers
  54558. * Return true to stop further extensions from loading this buffer
  54559. */
  54560. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  54561. return false;
  54562. };
  54563. /**
  54564. * Defines an override for loading texture buffers
  54565. * Return true to stop further extensions from loading this texture data
  54566. */
  54567. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  54568. return false;
  54569. };
  54570. /**
  54571. * Defines an override for creating textures
  54572. * Return true to stop further extensions from loading this texture
  54573. */
  54574. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  54575. return false;
  54576. };
  54577. /**
  54578. * Defines an override for loading shader strings
  54579. * Return true to stop further extensions from loading this shader data
  54580. */
  54581. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  54582. return false;
  54583. };
  54584. /**
  54585. * Defines an override for loading materials
  54586. * Return true to stop further extensions from loading this material
  54587. */
  54588. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  54589. return false;
  54590. };
  54591. // ---------
  54592. // Utilities
  54593. // ---------
  54594. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  54595. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54596. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  54597. }, function () {
  54598. setTimeout(function () {
  54599. if (!onSuccess) {
  54600. return;
  54601. }
  54602. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  54603. });
  54604. });
  54605. };
  54606. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  54607. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54608. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  54609. }, function () {
  54610. setTimeout(function () {
  54611. onSuccess();
  54612. });
  54613. });
  54614. };
  54615. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  54616. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54617. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  54618. }, function () {
  54619. GLTF1.GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  54620. });
  54621. };
  54622. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  54623. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  54624. if (buffer) {
  54625. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  54626. }
  54627. }, onError);
  54628. };
  54629. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  54630. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54631. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  54632. }, function () {
  54633. GLTF1.GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  54634. });
  54635. };
  54636. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  54637. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54638. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  54639. }, function () {
  54640. GLTF1.GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  54641. });
  54642. };
  54643. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  54644. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54645. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  54646. }, function () {
  54647. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  54648. });
  54649. };
  54650. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  54651. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  54652. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  54653. }, function () {
  54654. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  54655. });
  54656. };
  54657. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  54658. for (var extensionName in GLTF1.GLTFLoader.Extensions) {
  54659. var loaderExtension = GLTF1.GLTFLoader.Extensions[extensionName];
  54660. if (func(loaderExtension)) {
  54661. return;
  54662. }
  54663. }
  54664. defaultFunc();
  54665. };
  54666. return GLTFLoaderExtension;
  54667. }());
  54668. GLTF1.GLTFLoaderExtension = GLTFLoaderExtension;
  54669. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  54670. })(BABYLON || (BABYLON = {}));
  54671. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  54672. var BABYLON;
  54673. (function (BABYLON) {
  54674. var GLTF1;
  54675. (function (GLTF1) {
  54676. var BinaryExtensionBufferName = "binary_glTF";
  54677. ;
  54678. ;
  54679. var GLTFBinaryExtension = /** @class */ (function (_super) {
  54680. __extends(GLTFBinaryExtension, _super);
  54681. function GLTFBinaryExtension() {
  54682. return _super.call(this, "KHR_binary_glTF") || this;
  54683. }
  54684. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  54685. var extensionsUsed = data.json.extensionsUsed;
  54686. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  54687. return false;
  54688. }
  54689. this._bin = data.bin;
  54690. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  54691. return true;
  54692. };
  54693. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  54694. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  54695. return false;
  54696. }
  54697. if (id !== BinaryExtensionBufferName) {
  54698. return false;
  54699. }
  54700. onSuccess(this._bin);
  54701. return true;
  54702. };
  54703. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  54704. var texture = gltfRuntime.textures[id];
  54705. var source = gltfRuntime.images[texture.source];
  54706. if (!source.extensions || !(this.name in source.extensions)) {
  54707. return false;
  54708. }
  54709. var sourceExt = source.extensions[this.name];
  54710. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  54711. var buffer = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  54712. onSuccess(buffer);
  54713. return true;
  54714. };
  54715. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  54716. var shader = gltfRuntime.shaders[id];
  54717. if (!shader.extensions || !(this.name in shader.extensions)) {
  54718. return false;
  54719. }
  54720. var binaryExtensionShader = shader.extensions[this.name];
  54721. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  54722. var shaderBytes = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  54723. setTimeout(function () {
  54724. var shaderString = GLTF1.GLTFUtils.DecodeBufferToText(shaderBytes);
  54725. onSuccess(shaderString);
  54726. });
  54727. return true;
  54728. };
  54729. return GLTFBinaryExtension;
  54730. }(GLTF1.GLTFLoaderExtension));
  54731. GLTF1.GLTFBinaryExtension = GLTFBinaryExtension;
  54732. GLTF1.GLTFLoader.RegisterExtension(new GLTFBinaryExtension());
  54733. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  54734. })(BABYLON || (BABYLON = {}));
  54735. //# sourceMappingURL=babylon.glTFBinaryExtension.js.map
  54736. var BABYLON;
  54737. (function (BABYLON) {
  54738. var GLTF1;
  54739. (function (GLTF1) {
  54740. ;
  54741. ;
  54742. ;
  54743. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  54744. __extends(GLTFMaterialsCommonExtension, _super);
  54745. function GLTFMaterialsCommonExtension() {
  54746. return _super.call(this, "KHR_materials_common") || this;
  54747. }
  54748. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  54749. if (!gltfRuntime.extensions)
  54750. return false;
  54751. var extension = gltfRuntime.extensions[this.name];
  54752. if (!extension)
  54753. return false;
  54754. // Create lights
  54755. var lights = extension.lights;
  54756. if (lights) {
  54757. for (var thing in lights) {
  54758. var light = lights[thing];
  54759. switch (light.type) {
  54760. case "ambient":
  54761. var ambientLight = new BABYLON.HemisphericLight(light.name, new BABYLON.Vector3(0, 1, 0), gltfRuntime.scene);
  54762. var ambient = light.ambient;
  54763. if (ambient) {
  54764. ambientLight.diffuse = BABYLON.Color3.FromArray(ambient.color || [1, 1, 1]);
  54765. }
  54766. break;
  54767. case "point":
  54768. var pointLight = new BABYLON.PointLight(light.name, new BABYLON.Vector3(10, 10, 10), gltfRuntime.scene);
  54769. var point = light.point;
  54770. if (point) {
  54771. pointLight.diffuse = BABYLON.Color3.FromArray(point.color || [1, 1, 1]);
  54772. }
  54773. break;
  54774. case "directional":
  54775. var dirLight = new BABYLON.DirectionalLight(light.name, new BABYLON.Vector3(0, -1, 0), gltfRuntime.scene);
  54776. var directional = light.directional;
  54777. if (directional) {
  54778. dirLight.diffuse = BABYLON.Color3.FromArray(directional.color || [1, 1, 1]);
  54779. }
  54780. break;
  54781. case "spot":
  54782. var spot = light.spot;
  54783. if (spot) {
  54784. var spotLight = new BABYLON.SpotLight(light.name, new BABYLON.Vector3(0, 10, 0), new BABYLON.Vector3(0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  54785. spotLight.diffuse = BABYLON.Color3.FromArray(spot.color || [1, 1, 1]);
  54786. }
  54787. break;
  54788. default:
  54789. BABYLON.Tools.Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  54790. break;
  54791. }
  54792. }
  54793. }
  54794. return false;
  54795. };
  54796. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  54797. var material = gltfRuntime.materials[id];
  54798. if (!material || !material.extensions)
  54799. return false;
  54800. var extension = material.extensions[this.name];
  54801. if (!extension)
  54802. return false;
  54803. var standardMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  54804. standardMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  54805. if (extension.technique === "CONSTANT") {
  54806. standardMaterial.disableLighting = true;
  54807. }
  54808. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  54809. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  54810. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  54811. // Ambient
  54812. if (typeof extension.values.ambient === "string") {
  54813. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  54814. }
  54815. else {
  54816. standardMaterial.ambientColor = BABYLON.Color3.FromArray(extension.values.ambient || [0, 0, 0]);
  54817. }
  54818. // Diffuse
  54819. if (typeof extension.values.diffuse === "string") {
  54820. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  54821. }
  54822. else {
  54823. standardMaterial.diffuseColor = BABYLON.Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
  54824. }
  54825. // Emission
  54826. if (typeof extension.values.emission === "string") {
  54827. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  54828. }
  54829. else {
  54830. standardMaterial.emissiveColor = BABYLON.Color3.FromArray(extension.values.emission || [0, 0, 0]);
  54831. }
  54832. // Specular
  54833. if (typeof extension.values.specular === "string") {
  54834. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  54835. }
  54836. else {
  54837. standardMaterial.specularColor = BABYLON.Color3.FromArray(extension.values.specular || [0, 0, 0]);
  54838. }
  54839. return true;
  54840. };
  54841. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  54842. // Create buffer from texture url
  54843. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  54844. // Create texture from buffer
  54845. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  54846. }, onError);
  54847. };
  54848. return GLTFMaterialsCommonExtension;
  54849. }(GLTF1.GLTFLoaderExtension));
  54850. GLTF1.GLTFMaterialsCommonExtension = GLTFMaterialsCommonExtension;
  54851. GLTF1.GLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
  54852. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  54853. })(BABYLON || (BABYLON = {}));
  54854. //# sourceMappingURL=babylon.glTFMaterialsCommonExtension.js.map
  54855. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  54856. /**
  54857. * Defines the module used to import/export glTF 2.0 assets
  54858. */
  54859. var BABYLON;
  54860. (function (BABYLON) {
  54861. var GLTF2;
  54862. (function (GLTF2) {
  54863. var _ArrayItem = /** @class */ (function () {
  54864. function _ArrayItem() {
  54865. }
  54866. _ArrayItem.Assign = function (values) {
  54867. if (values) {
  54868. for (var index = 0; index < values.length; index++) {
  54869. values[index]._index = index;
  54870. }
  54871. }
  54872. };
  54873. return _ArrayItem;
  54874. }());
  54875. /**
  54876. * Loader for loading a glTF 2.0 asset
  54877. */
  54878. var GLTFLoader = /** @class */ (function () {
  54879. function GLTFLoader() {
  54880. /** @hidden */
  54881. this._completePromises = new Array();
  54882. /** @hidden */
  54883. this._onReadyObservable = new BABYLON.Observable();
  54884. this._disposed = false;
  54885. this._state = null;
  54886. this._extensions = {};
  54887. this._defaultSampler = {};
  54888. this._defaultBabylonMaterials = {};
  54889. this._requests = new Array();
  54890. /**
  54891. * Mode that determines the coordinate system to use.
  54892. */
  54893. this.coordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode.AUTO;
  54894. /**
  54895. * Mode that determines what animations will start.
  54896. */
  54897. this.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.FIRST;
  54898. /**
  54899. * Defines if the loader should compile materials.
  54900. */
  54901. this.compileMaterials = false;
  54902. /**
  54903. * Defines if the loader should also compile materials with clip planes.
  54904. */
  54905. this.useClipPlane = false;
  54906. /**
  54907. * Defines if the loader should compile shadow generators.
  54908. */
  54909. this.compileShadowGenerators = false;
  54910. /**
  54911. * Defines if the Alpha blended materials are only applied as coverage.
  54912. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  54913. * If true, no extra effects are applied to transparent pixels.
  54914. */
  54915. this.transparencyAsCoverage = false;
  54916. /** @hidden */
  54917. this._normalizeAnimationGroupsToBeginAtZero = true;
  54918. /**
  54919. * Function called before loading a url referenced by the asset.
  54920. */
  54921. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  54922. /**
  54923. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  54924. */
  54925. this.onMeshLoadedObservable = new BABYLON.Observable();
  54926. /**
  54927. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  54928. */
  54929. this.onTextureLoadedObservable = new BABYLON.Observable();
  54930. /**
  54931. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  54932. */
  54933. this.onMaterialLoadedObservable = new BABYLON.Observable();
  54934. /**
  54935. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  54936. */
  54937. this.onCameraLoadedObservable = new BABYLON.Observable();
  54938. /**
  54939. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  54940. * For assets with LODs, raised when all of the LODs are complete.
  54941. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  54942. */
  54943. this.onCompleteObservable = new BABYLON.Observable();
  54944. /**
  54945. * Observable raised after the loader is disposed.
  54946. */
  54947. this.onDisposeObservable = new BABYLON.Observable();
  54948. /**
  54949. * Observable raised after a loader extension is created.
  54950. * Set additional options for a loader extension in this event.
  54951. */
  54952. this.onExtensionLoadedObservable = new BABYLON.Observable();
  54953. }
  54954. /** @hidden */
  54955. GLTFLoader._Register = function (name, factory) {
  54956. if (GLTFLoader._ExtensionFactories[name]) {
  54957. BABYLON.Tools.Error("Extension with the name '" + name + "' already exists");
  54958. return;
  54959. }
  54960. GLTFLoader._ExtensionFactories[name] = factory;
  54961. // Keep the order of registration so that extensions registered first are called first.
  54962. GLTFLoader._ExtensionNames.push(name);
  54963. };
  54964. Object.defineProperty(GLTFLoader.prototype, "state", {
  54965. /**
  54966. * Loader state or null if the loader is not active.
  54967. */
  54968. get: function () {
  54969. return this._state;
  54970. },
  54971. enumerable: true,
  54972. configurable: true
  54973. });
  54974. /**
  54975. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  54976. */
  54977. GLTFLoader.prototype.dispose = function () {
  54978. if (this._disposed) {
  54979. return;
  54980. }
  54981. this._disposed = true;
  54982. this.onDisposeObservable.notifyObservers(this);
  54983. this.onDisposeObservable.clear();
  54984. this._clear();
  54985. };
  54986. /**
  54987. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  54988. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  54989. * @param scene the scene the meshes should be added to
  54990. * @param data the glTF data to load
  54991. * @param rootUrl root url to load from
  54992. * @param onProgress event that fires when loading progress has occured
  54993. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  54994. */
  54995. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  54996. var _this = this;
  54997. return Promise.resolve().then(function () {
  54998. _this._babylonScene = scene;
  54999. _this._rootUrl = rootUrl;
  55000. _this._progressCallback = onProgress;
  55001. _this._loadData(data);
  55002. var nodes = null;
  55003. if (meshesNames) {
  55004. var nodeMap_1 = {};
  55005. if (_this._gltf.nodes) {
  55006. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  55007. var node = _a[_i];
  55008. if (node.name) {
  55009. nodeMap_1[node.name] = node;
  55010. }
  55011. }
  55012. }
  55013. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  55014. nodes = names.map(function (name) {
  55015. var node = nodeMap_1[name];
  55016. if (!node) {
  55017. throw new Error("Failed to find node '" + name + "'");
  55018. }
  55019. return node;
  55020. });
  55021. }
  55022. return _this._loadAsync(nodes).then(function () {
  55023. return {
  55024. meshes: _this._getMeshes(),
  55025. particleSystems: [],
  55026. skeletons: _this._getSkeletons(),
  55027. animationGroups: _this._getAnimationGroups()
  55028. };
  55029. });
  55030. });
  55031. };
  55032. /**
  55033. * Imports all objects from the loaded glTF data and adds them to the scene
  55034. * @param scene the scene the objects should be added to
  55035. * @param data the glTF data to load
  55036. * @param rootUrl root url to load from
  55037. * @param onProgress event that fires when loading progress has occured
  55038. * @returns a promise which completes when objects have been loaded to the scene
  55039. */
  55040. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  55041. var _this = this;
  55042. return Promise.resolve().then(function () {
  55043. _this._babylonScene = scene;
  55044. _this._rootUrl = rootUrl;
  55045. _this._progressCallback = onProgress;
  55046. _this._loadData(data);
  55047. return _this._loadAsync(null);
  55048. });
  55049. };
  55050. GLTFLoader.prototype._loadAsync = function (nodes) {
  55051. var _this = this;
  55052. return Promise.resolve().then(function () {
  55053. _this._state = BABYLON.GLTFLoaderState.LOADING;
  55054. _this._loadExtensions();
  55055. _this._checkExtensions();
  55056. var promises = new Array();
  55057. if (nodes) {
  55058. promises.push(_this._loadNodesAsync(nodes));
  55059. }
  55060. else {
  55061. var scene = GLTFLoader._GetProperty("#/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  55062. promises.push(_this._loadSceneAsync("#/scenes/" + scene._index, scene));
  55063. }
  55064. if (_this.compileMaterials) {
  55065. promises.push(_this._compileMaterialsAsync());
  55066. }
  55067. if (_this.compileShadowGenerators) {
  55068. promises.push(_this._compileShadowGeneratorsAsync());
  55069. }
  55070. var resultPromise = Promise.all(promises).then(function () {
  55071. _this._state = BABYLON.GLTFLoaderState.READY;
  55072. _this._onReadyObservable.notifyObservers(_this);
  55073. _this._startAnimations();
  55074. });
  55075. resultPromise.then(function () {
  55076. if (_this._rootBabylonMesh) {
  55077. _this._rootBabylonMesh.setEnabled(true);
  55078. }
  55079. BABYLON.Tools.SetImmediate(function () {
  55080. if (!_this._disposed) {
  55081. Promise.all(_this._completePromises).then(function () {
  55082. _this._state = BABYLON.GLTFLoaderState.COMPLETE;
  55083. _this.onCompleteObservable.notifyObservers(_this);
  55084. _this.onCompleteObservable.clear();
  55085. _this._clear();
  55086. }).catch(function (error) {
  55087. BABYLON.Tools.Error("glTF Loader: " + error.message);
  55088. _this._clear();
  55089. });
  55090. }
  55091. });
  55092. });
  55093. return resultPromise;
  55094. }).catch(function (error) {
  55095. if (!_this._disposed) {
  55096. BABYLON.Tools.Error("glTF Loader: " + error.message);
  55097. _this._clear();
  55098. throw error;
  55099. }
  55100. });
  55101. };
  55102. GLTFLoader.prototype._loadData = function (data) {
  55103. this._gltf = data.json;
  55104. this._setupData();
  55105. if (data.bin) {
  55106. var buffers = this._gltf.buffers;
  55107. if (buffers && buffers[0] && !buffers[0].uri) {
  55108. var binaryBuffer = buffers[0];
  55109. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  55110. BABYLON.Tools.Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  55111. }
  55112. binaryBuffer._data = Promise.resolve(data.bin);
  55113. }
  55114. else {
  55115. BABYLON.Tools.Warn("Unexpected BIN chunk");
  55116. }
  55117. }
  55118. };
  55119. GLTFLoader.prototype._setupData = function () {
  55120. _ArrayItem.Assign(this._gltf.accessors);
  55121. _ArrayItem.Assign(this._gltf.animations);
  55122. _ArrayItem.Assign(this._gltf.buffers);
  55123. _ArrayItem.Assign(this._gltf.bufferViews);
  55124. _ArrayItem.Assign(this._gltf.cameras);
  55125. _ArrayItem.Assign(this._gltf.images);
  55126. _ArrayItem.Assign(this._gltf.materials);
  55127. _ArrayItem.Assign(this._gltf.meshes);
  55128. _ArrayItem.Assign(this._gltf.nodes);
  55129. _ArrayItem.Assign(this._gltf.samplers);
  55130. _ArrayItem.Assign(this._gltf.scenes);
  55131. _ArrayItem.Assign(this._gltf.skins);
  55132. _ArrayItem.Assign(this._gltf.textures);
  55133. if (this._gltf.nodes) {
  55134. var nodeParents = {};
  55135. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  55136. var node = _a[_i];
  55137. if (node.children) {
  55138. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  55139. var index = _c[_b];
  55140. nodeParents[index] = node._index;
  55141. }
  55142. }
  55143. }
  55144. var rootNode = this._createRootNode();
  55145. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  55146. var node = _e[_d];
  55147. var parentIndex = nodeParents[node._index];
  55148. node._parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  55149. }
  55150. }
  55151. };
  55152. GLTFLoader.prototype._loadExtensions = function () {
  55153. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  55154. var name_1 = _a[_i];
  55155. var extension = GLTFLoader._ExtensionFactories[name_1](this);
  55156. this._extensions[name_1] = extension;
  55157. this.onExtensionLoadedObservable.notifyObservers(extension);
  55158. }
  55159. this.onExtensionLoadedObservable.clear();
  55160. };
  55161. GLTFLoader.prototype._checkExtensions = function () {
  55162. if (this._gltf.extensionsRequired) {
  55163. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  55164. var name_2 = _a[_i];
  55165. var extension = this._extensions[name_2];
  55166. if (!extension || !extension.enabled) {
  55167. throw new Error("Require extension " + name_2 + " is not available");
  55168. }
  55169. }
  55170. }
  55171. };
  55172. GLTFLoader.prototype._createRootNode = function () {
  55173. this._rootBabylonMesh = new BABYLON.Mesh("__root__", this._babylonScene);
  55174. this._rootBabylonMesh.setEnabled(false);
  55175. var rootNode = { _babylonMesh: this._rootBabylonMesh };
  55176. switch (this.coordinateSystemMode) {
  55177. case BABYLON.GLTFLoaderCoordinateSystemMode.AUTO: {
  55178. if (!this._babylonScene.useRightHandedSystem) {
  55179. rootNode.rotation = [0, 1, 0, 0];
  55180. rootNode.scale = [1, 1, -1];
  55181. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  55182. }
  55183. break;
  55184. }
  55185. case BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
  55186. this._babylonScene.useRightHandedSystem = true;
  55187. break;
  55188. }
  55189. default: {
  55190. throw new Error("Invalid coordinate system mode (" + this.coordinateSystemMode + ")");
  55191. }
  55192. }
  55193. this.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  55194. return rootNode;
  55195. };
  55196. GLTFLoader.prototype._loadNodesAsync = function (nodes) {
  55197. var promises = new Array();
  55198. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  55199. var node = nodes_1[_i];
  55200. promises.push(this._loadNodeAsync("#/nodes/" + node._index, node));
  55201. }
  55202. promises.push(this._loadAnimationsAsync());
  55203. return Promise.all(promises).then(function () { });
  55204. };
  55205. /** @hidden */
  55206. GLTFLoader.prototype._loadSceneAsync = function (context, scene) {
  55207. var promise = GLTF2.GLTFLoaderExtension._LoadSceneAsync(this, context, scene);
  55208. if (promise) {
  55209. return promise;
  55210. }
  55211. var promises = new Array();
  55212. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  55213. var index = _a[_i];
  55214. var node = GLTFLoader._GetProperty(context + "/nodes/" + index, this._gltf.nodes, index);
  55215. promises.push(this._loadNodeAsync("#/nodes/" + node._index, node));
  55216. }
  55217. promises.push(this._loadAnimationsAsync());
  55218. return Promise.all(promises).then(function () { });
  55219. };
  55220. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  55221. if (node._primitiveBabylonMeshes) {
  55222. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  55223. var babylonMesh = _a[_i];
  55224. callback(babylonMesh);
  55225. }
  55226. }
  55227. else {
  55228. callback(node._babylonMesh);
  55229. }
  55230. };
  55231. GLTFLoader.prototype._getMeshes = function () {
  55232. var meshes = new Array();
  55233. // Root mesh is always first.
  55234. meshes.push(this._rootBabylonMesh);
  55235. var nodes = this._gltf.nodes;
  55236. if (nodes) {
  55237. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  55238. var node = nodes_2[_i];
  55239. if (node._babylonMesh) {
  55240. meshes.push(node._babylonMesh);
  55241. }
  55242. if (node._primitiveBabylonMeshes) {
  55243. for (var _a = 0, _b = node._primitiveBabylonMeshes; _a < _b.length; _a++) {
  55244. var babylonMesh = _b[_a];
  55245. meshes.push(babylonMesh);
  55246. }
  55247. }
  55248. }
  55249. }
  55250. return meshes;
  55251. };
  55252. GLTFLoader.prototype._getSkeletons = function () {
  55253. var skeletons = new Array();
  55254. var skins = this._gltf.skins;
  55255. if (skins) {
  55256. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  55257. var skin = skins_1[_i];
  55258. if (skin._babylonSkeleton) {
  55259. skeletons.push(skin._babylonSkeleton);
  55260. }
  55261. }
  55262. }
  55263. return skeletons;
  55264. };
  55265. GLTFLoader.prototype._getAnimationGroups = function () {
  55266. var animationGroups = new Array();
  55267. var animations = this._gltf.animations;
  55268. if (animations) {
  55269. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  55270. var animation = animations_1[_i];
  55271. if (animation._babylonAnimationGroup) {
  55272. animationGroups.push(animation._babylonAnimationGroup);
  55273. }
  55274. }
  55275. }
  55276. return animationGroups;
  55277. };
  55278. GLTFLoader.prototype._startAnimations = function () {
  55279. switch (this.animationStartMode) {
  55280. case BABYLON.GLTFLoaderAnimationStartMode.NONE: {
  55281. // do nothing
  55282. break;
  55283. }
  55284. case BABYLON.GLTFLoaderAnimationStartMode.FIRST: {
  55285. var babylonAnimationGroups = this._getAnimationGroups();
  55286. if (babylonAnimationGroups.length !== 0) {
  55287. babylonAnimationGroups[0].start(true);
  55288. }
  55289. break;
  55290. }
  55291. case BABYLON.GLTFLoaderAnimationStartMode.ALL: {
  55292. var babylonAnimationGroups = this._getAnimationGroups();
  55293. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  55294. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  55295. babylonAnimationGroup.start(true);
  55296. }
  55297. break;
  55298. }
  55299. default: {
  55300. BABYLON.Tools.Error("Invalid animation start mode (" + this.animationStartMode + ")");
  55301. return;
  55302. }
  55303. }
  55304. };
  55305. /** @hidden */
  55306. GLTFLoader.prototype._loadNodeAsync = function (context, node) {
  55307. var promise = GLTF2.GLTFLoaderExtension._LoadNodeAsync(this, context, node);
  55308. if (promise) {
  55309. return promise;
  55310. }
  55311. if (node._babylonMesh) {
  55312. throw new Error(context + ": Invalid recursive node hierarchy");
  55313. }
  55314. var promises = new Array();
  55315. var babylonMesh = new BABYLON.Mesh(node.name || "node" + node._index, this._babylonScene, node._parent ? node._parent._babylonMesh : null);
  55316. node._babylonMesh = babylonMesh;
  55317. GLTFLoader._LoadTransform(node, babylonMesh);
  55318. if (node.mesh != undefined) {
  55319. var mesh = GLTFLoader._GetProperty(context + "/mesh", this._gltf.meshes, node.mesh);
  55320. promises.push(this._loadMeshAsync("#/meshes/" + mesh._index, node, mesh, babylonMesh));
  55321. }
  55322. if (node.camera != undefined) {
  55323. var camera = GLTFLoader._GetProperty(context + "/camera", this._gltf.cameras, node.camera);
  55324. this._loadCamera("#/cameras/" + camera._index, camera, babylonMesh);
  55325. }
  55326. if (node.children) {
  55327. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  55328. var index = _a[_i];
  55329. var childNode = GLTFLoader._GetProperty(context + "/children/" + index, this._gltf.nodes, index);
  55330. promises.push(this._loadNodeAsync("#/nodes/" + index, childNode));
  55331. }
  55332. }
  55333. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  55334. return Promise.all(promises).then(function () { });
  55335. };
  55336. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, babylonMesh) {
  55337. var _this = this;
  55338. var promises = new Array();
  55339. var primitives = mesh.primitives;
  55340. if (!primitives || primitives.length === 0) {
  55341. throw new Error(context + ": Primitives are missing");
  55342. }
  55343. _ArrayItem.Assign(primitives);
  55344. if (primitives.length === 1) {
  55345. var primitive = primitives[0];
  55346. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, babylonMesh));
  55347. }
  55348. else {
  55349. node._primitiveBabylonMeshes = [];
  55350. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  55351. var primitive = primitives_1[_i];
  55352. var primitiveBabylonMesh = new BABYLON.Mesh((mesh.name || babylonMesh.name) + "_" + primitive._index, this._babylonScene, babylonMesh);
  55353. node._primitiveBabylonMeshes.push(primitiveBabylonMesh);
  55354. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, primitiveBabylonMesh));
  55355. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  55356. }
  55357. }
  55358. if (node.skin != undefined) {
  55359. var skin = GLTFLoader._GetProperty(context + "/skin", this._gltf.skins, node.skin);
  55360. promises.push(this._loadSkinAsync("#/skins/" + skin._index, node, mesh, skin));
  55361. }
  55362. return Promise.all(promises).then(function () {
  55363. _this._forEachPrimitive(node, function (babylonMesh) {
  55364. babylonMesh._refreshBoundingInfo(true);
  55365. });
  55366. });
  55367. };
  55368. GLTFLoader.prototype._loadPrimitiveAsync = function (context, node, mesh, primitive, babylonMesh) {
  55369. var _this = this;
  55370. var promises = new Array();
  55371. this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
  55372. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(function (babylonGeometry) {
  55373. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry).then(function () {
  55374. babylonGeometry.applyToMesh(babylonMesh);
  55375. });
  55376. }));
  55377. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  55378. if (primitive.material == undefined) {
  55379. babylonMesh.material = this._getDefaultMaterial(babylonDrawMode);
  55380. }
  55381. else {
  55382. var material = GLTFLoader._GetProperty(context + "/material}", this._gltf.materials, primitive.material);
  55383. promises.push(this._loadMaterialAsync("#/materials/" + material._index, material, mesh, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  55384. babylonMesh.material = babylonMaterial;
  55385. }));
  55386. }
  55387. return Promise.all(promises).then(function () { });
  55388. };
  55389. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  55390. var _this = this;
  55391. var promise = GLTF2.GLTFLoaderExtension._LoadVertexDataAsync(this, context, primitive, babylonMesh);
  55392. if (promise) {
  55393. return promise;
  55394. }
  55395. var attributes = primitive.attributes;
  55396. if (!attributes) {
  55397. throw new Error(context + ": Attributes are missing");
  55398. }
  55399. var promises = new Array();
  55400. var babylonGeometry = new BABYLON.Geometry(babylonMesh.name, this._babylonScene);
  55401. if (primitive.indices == undefined) {
  55402. babylonMesh.isUnIndexed = true;
  55403. }
  55404. else {
  55405. var accessor = GLTFLoader._GetProperty(context + "/indices", this._gltf.accessors, primitive.indices);
  55406. promises.push(this._loadIndicesAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  55407. babylonGeometry.setIndices(data);
  55408. }));
  55409. }
  55410. var loadAttribute = function (attribute, kind, callback) {
  55411. if (attributes[attribute] == undefined) {
  55412. return;
  55413. }
  55414. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  55415. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  55416. babylonMesh._delayInfo.push(kind);
  55417. }
  55418. var accessor = GLTFLoader._GetProperty(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  55419. promises.push(_this._loadVertexAccessorAsync("#/accessors/" + accessor._index, accessor, kind).then(function (babylonVertexBuffer) {
  55420. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  55421. }));
  55422. if (callback) {
  55423. callback(accessor);
  55424. }
  55425. };
  55426. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  55427. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  55428. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  55429. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  55430. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  55431. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  55432. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  55433. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind, function (accessor) {
  55434. if (accessor.type === "VEC4" /* VEC4 */) {
  55435. babylonMesh.hasVertexAlpha = true;
  55436. }
  55437. });
  55438. return Promise.all(promises).then(function () {
  55439. return babylonGeometry;
  55440. });
  55441. };
  55442. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  55443. if (!primitive.targets) {
  55444. return;
  55445. }
  55446. if (node._numMorphTargets == undefined) {
  55447. node._numMorphTargets = primitive.targets.length;
  55448. }
  55449. else if (primitive.targets.length !== node._numMorphTargets) {
  55450. throw new Error(context + ": Primitives do not have the same number of targets");
  55451. }
  55452. babylonMesh.morphTargetManager = new BABYLON.MorphTargetManager();
  55453. for (var index = 0; index < primitive.targets.length; index++) {
  55454. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  55455. babylonMesh.morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  55456. // TODO: tell the target whether it has positions, normals, tangents
  55457. }
  55458. };
  55459. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  55460. if (!primitive.targets) {
  55461. return Promise.resolve();
  55462. }
  55463. var promises = new Array();
  55464. var morphTargetManager = babylonMesh.morphTargetManager;
  55465. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  55466. var babylonMorphTarget = morphTargetManager.getTarget(index);
  55467. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  55468. }
  55469. return Promise.all(promises).then(function () { });
  55470. };
  55471. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  55472. var _this = this;
  55473. var promises = new Array();
  55474. var loadAttribute = function (attribute, kind, setData) {
  55475. if (attributes[attribute] == undefined) {
  55476. return;
  55477. }
  55478. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  55479. if (!babylonVertexBuffer) {
  55480. return;
  55481. }
  55482. var accessor = GLTFLoader._GetProperty(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  55483. promises.push(_this._loadFloatAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  55484. setData(babylonVertexBuffer, data);
  55485. }));
  55486. };
  55487. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind, function (babylonVertexBuffer, data) {
  55488. babylonVertexBuffer.forEach(data.length, function (value, index) {
  55489. data[index] += value;
  55490. });
  55491. babylonMorphTarget.setPositions(data);
  55492. });
  55493. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind, function (babylonVertexBuffer, data) {
  55494. babylonVertexBuffer.forEach(data.length, function (value, index) {
  55495. data[index] += value;
  55496. });
  55497. babylonMorphTarget.setNormals(data);
  55498. });
  55499. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind, function (babylonVertexBuffer, data) {
  55500. var dataIndex = 0;
  55501. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  55502. // Tangent data for morph targets is stored as xyz delta.
  55503. // The vertexData.tangent is stored as xyzw.
  55504. // So we need to skip every fourth vertexData.tangent.
  55505. if (((index + 1) % 4) !== 0) {
  55506. data[dataIndex++] += value;
  55507. }
  55508. });
  55509. babylonMorphTarget.setTangents(data);
  55510. });
  55511. return Promise.all(promises).then(function () { });
  55512. };
  55513. GLTFLoader._LoadTransform = function (node, babylonNode) {
  55514. var position = BABYLON.Vector3.Zero();
  55515. var rotation = BABYLON.Quaternion.Identity();
  55516. var scaling = BABYLON.Vector3.One();
  55517. if (node.matrix) {
  55518. var matrix = BABYLON.Matrix.FromArray(node.matrix);
  55519. matrix.decompose(scaling, rotation, position);
  55520. }
  55521. else {
  55522. if (node.translation)
  55523. position = BABYLON.Vector3.FromArray(node.translation);
  55524. if (node.rotation)
  55525. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  55526. if (node.scale)
  55527. scaling = BABYLON.Vector3.FromArray(node.scale);
  55528. }
  55529. babylonNode.position = position;
  55530. babylonNode.rotationQuaternion = rotation;
  55531. babylonNode.scaling = scaling;
  55532. };
  55533. GLTFLoader.prototype._loadSkinAsync = function (context, node, mesh, skin) {
  55534. var _this = this;
  55535. var assignSkeleton = function (skeleton) {
  55536. _this._forEachPrimitive(node, function (babylonMesh) {
  55537. babylonMesh.skeleton = skeleton;
  55538. });
  55539. // Ignore the TRS of skinned nodes.
  55540. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  55541. node._babylonMesh.parent = _this._rootBabylonMesh;
  55542. node._babylonMesh.position = BABYLON.Vector3.Zero();
  55543. node._babylonMesh.rotationQuaternion = BABYLON.Quaternion.Identity();
  55544. node._babylonMesh.scaling = BABYLON.Vector3.One();
  55545. };
  55546. if (skin._loaded) {
  55547. return skin._loaded.then(function () {
  55548. assignSkeleton(skin._babylonSkeleton);
  55549. });
  55550. }
  55551. var skeletonId = "skeleton" + skin._index;
  55552. var babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
  55553. skin._babylonSkeleton = babylonSkeleton;
  55554. this._loadBones(context, skin);
  55555. assignSkeleton(babylonSkeleton);
  55556. return (skin._loaded = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  55557. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  55558. }));
  55559. };
  55560. GLTFLoader.prototype._loadBones = function (context, skin) {
  55561. var babylonBones = {};
  55562. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  55563. var index = _a[_i];
  55564. var node = GLTFLoader._GetProperty(context + "/joints/" + index, this._gltf.nodes, index);
  55565. this._loadBone(node, skin, babylonBones);
  55566. }
  55567. };
  55568. GLTFLoader.prototype._loadBone = function (node, skin, babylonBones) {
  55569. var babylonBone = babylonBones[node._index];
  55570. if (babylonBone) {
  55571. return babylonBone;
  55572. }
  55573. var babylonParentBone = null;
  55574. if (node._parent && node._parent._babylonMesh !== this._rootBabylonMesh) {
  55575. babylonParentBone = this._loadBone(node._parent, skin, babylonBones);
  55576. }
  55577. var boneIndex = skin.joints.indexOf(node._index);
  55578. babylonBone = new BABYLON.Bone(node.name || "joint" + node._index, skin._babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  55579. babylonBones[node._index] = babylonBone;
  55580. node._babylonBones = node._babylonBones || [];
  55581. node._babylonBones.push(babylonBone);
  55582. return babylonBone;
  55583. };
  55584. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  55585. if (skin.inverseBindMatrices == undefined) {
  55586. return Promise.resolve(null);
  55587. }
  55588. var accessor = GLTFLoader._GetProperty(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  55589. return this._loadFloatAccessorAsync("#/accessors/" + accessor._index, accessor);
  55590. };
  55591. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  55592. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  55593. var babylonBone = _a[_i];
  55594. var baseMatrix = BABYLON.Matrix.Identity();
  55595. var boneIndex = babylonBone._index;
  55596. if (inverseBindMatricesData && boneIndex !== -1) {
  55597. BABYLON.Matrix.FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  55598. baseMatrix.invertToRef(baseMatrix);
  55599. }
  55600. var babylonParentBone = babylonBone.getParent();
  55601. if (babylonParentBone) {
  55602. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  55603. }
  55604. babylonBone.updateMatrix(baseMatrix, false, false);
  55605. babylonBone._updateDifferenceMatrix(undefined, false);
  55606. }
  55607. };
  55608. GLTFLoader.prototype._getNodeMatrix = function (node) {
  55609. return node.matrix ?
  55610. BABYLON.Matrix.FromArray(node.matrix) :
  55611. BABYLON.Matrix.Compose(node.scale ? BABYLON.Vector3.FromArray(node.scale) : BABYLON.Vector3.One(), node.rotation ? BABYLON.Quaternion.FromArray(node.rotation) : BABYLON.Quaternion.Identity(), node.translation ? BABYLON.Vector3.FromArray(node.translation) : BABYLON.Vector3.Zero());
  55612. };
  55613. GLTFLoader.prototype._loadCamera = function (context, camera, babylonMesh) {
  55614. var babylonCamera = new BABYLON.FreeCamera(camera.name || "camera" + camera._index, BABYLON.Vector3.Zero(), this._babylonScene, false);
  55615. babylonCamera.parent = babylonMesh;
  55616. babylonCamera.rotation = new BABYLON.Vector3(0, Math.PI, 0);
  55617. switch (camera.type) {
  55618. case "perspective" /* PERSPECTIVE */: {
  55619. var perspective = camera.perspective;
  55620. if (!perspective) {
  55621. throw new Error(context + ": Camera perspective properties are missing");
  55622. }
  55623. babylonCamera.fov = perspective.yfov;
  55624. babylonCamera.minZ = perspective.znear;
  55625. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  55626. break;
  55627. }
  55628. case "orthographic" /* ORTHOGRAPHIC */: {
  55629. if (!camera.orthographic) {
  55630. throw new Error(context + ": Camera orthographic properties are missing");
  55631. }
  55632. babylonCamera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
  55633. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  55634. babylonCamera.orthoRight = camera.orthographic.xmag;
  55635. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  55636. babylonCamera.orthoTop = camera.orthographic.ymag;
  55637. babylonCamera.minZ = camera.orthographic.znear;
  55638. babylonCamera.maxZ = camera.orthographic.zfar;
  55639. break;
  55640. }
  55641. default: {
  55642. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  55643. }
  55644. }
  55645. this.onCameraLoadedObservable.notifyObservers(babylonCamera);
  55646. };
  55647. GLTFLoader.prototype._loadAnimationsAsync = function () {
  55648. var animations = this._gltf.animations;
  55649. if (!animations) {
  55650. return Promise.resolve();
  55651. }
  55652. var promises = new Array();
  55653. for (var index = 0; index < animations.length; index++) {
  55654. var animation = animations[index];
  55655. promises.push(this._loadAnimationAsync("#/animations/" + index, animation));
  55656. }
  55657. return Promise.all(promises).then(function () { });
  55658. };
  55659. GLTFLoader.prototype._loadAnimationAsync = function (context, animation) {
  55660. var _this = this;
  55661. var babylonAnimationGroup = new BABYLON.AnimationGroup(animation.name || "animation" + animation._index, this._babylonScene);
  55662. animation._babylonAnimationGroup = babylonAnimationGroup;
  55663. var promises = new Array();
  55664. _ArrayItem.Assign(animation.channels);
  55665. _ArrayItem.Assign(animation.samplers);
  55666. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  55667. var channel = _a[_i];
  55668. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel._index, context, animation, channel, babylonAnimationGroup));
  55669. }
  55670. return Promise.all(promises).then(function () {
  55671. babylonAnimationGroup.normalize(_this._normalizeAnimationGroupsToBeginAtZero ? 0 : null);
  55672. });
  55673. };
  55674. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup) {
  55675. var _this = this;
  55676. var targetNode = GLTFLoader._GetProperty(context + "/target/node", this._gltf.nodes, channel.target.node);
  55677. // Ignore animations that have no animation targets.
  55678. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  55679. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonMesh)) {
  55680. return Promise.resolve();
  55681. }
  55682. // Ignore animations targeting TRS of skinned nodes.
  55683. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  55684. if (targetNode.skin != undefined && channel.target.path !== "weights" /* WEIGHTS */) {
  55685. return Promise.resolve();
  55686. }
  55687. var sampler = GLTFLoader._GetProperty(context + "/sampler", animation.samplers, channel.sampler);
  55688. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  55689. var targetPath;
  55690. var animationType;
  55691. switch (channel.target.path) {
  55692. case "translation" /* TRANSLATION */: {
  55693. targetPath = "position";
  55694. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  55695. break;
  55696. }
  55697. case "rotation" /* ROTATION */: {
  55698. targetPath = "rotationQuaternion";
  55699. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  55700. break;
  55701. }
  55702. case "scale" /* SCALE */: {
  55703. targetPath = "scaling";
  55704. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  55705. break;
  55706. }
  55707. case "weights" /* WEIGHTS */: {
  55708. targetPath = "influence";
  55709. animationType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  55710. break;
  55711. }
  55712. default: {
  55713. throw new Error(context + ": Invalid target path (" + channel.target.path + ")");
  55714. }
  55715. }
  55716. var outputBufferOffset = 0;
  55717. var getNextOutputValue;
  55718. switch (targetPath) {
  55719. case "position": {
  55720. getNextOutputValue = function () {
  55721. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  55722. outputBufferOffset += 3;
  55723. return value;
  55724. };
  55725. break;
  55726. }
  55727. case "rotationQuaternion": {
  55728. getNextOutputValue = function () {
  55729. var value = BABYLON.Quaternion.FromArray(data.output, outputBufferOffset);
  55730. outputBufferOffset += 4;
  55731. return value;
  55732. };
  55733. break;
  55734. }
  55735. case "scaling": {
  55736. getNextOutputValue = function () {
  55737. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  55738. outputBufferOffset += 3;
  55739. return value;
  55740. };
  55741. break;
  55742. }
  55743. case "influence": {
  55744. getNextOutputValue = function () {
  55745. var value = new Array(targetNode._numMorphTargets);
  55746. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  55747. value[i] = data.output[outputBufferOffset++];
  55748. }
  55749. return value;
  55750. };
  55751. break;
  55752. }
  55753. }
  55754. var getNextKey;
  55755. switch (data.interpolation) {
  55756. case "STEP" /* STEP */: {
  55757. getNextKey = function (frameIndex) { return ({
  55758. frame: data.input[frameIndex],
  55759. value: getNextOutputValue(),
  55760. interpolation: BABYLON.AnimationKeyInterpolation.STEP
  55761. }); };
  55762. break;
  55763. }
  55764. case "LINEAR" /* LINEAR */: {
  55765. getNextKey = function (frameIndex) { return ({
  55766. frame: data.input[frameIndex],
  55767. value: getNextOutputValue()
  55768. }); };
  55769. break;
  55770. }
  55771. case "CUBICSPLINE" /* CUBICSPLINE */: {
  55772. getNextKey = function (frameIndex) { return ({
  55773. frame: data.input[frameIndex],
  55774. inTangent: getNextOutputValue(),
  55775. value: getNextOutputValue(),
  55776. outTangent: getNextOutputValue()
  55777. }); };
  55778. break;
  55779. }
  55780. }
  55781. var keys = new Array(data.input.length);
  55782. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  55783. keys[frameIndex] = getNextKey(frameIndex);
  55784. }
  55785. if (targetPath === "influence") {
  55786. var _loop_1 = function (targetIndex) {
  55787. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  55788. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  55789. babylonAnimation.setKeys(keys.map(function (key) { return ({
  55790. frame: key.frame,
  55791. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  55792. value: key.value[targetIndex],
  55793. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  55794. }); }));
  55795. _this._forEachPrimitive(targetNode, function (babylonMesh) {
  55796. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  55797. var babylonAnimationClone = babylonAnimation.clone();
  55798. morphTarget.animations.push(babylonAnimationClone);
  55799. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  55800. });
  55801. };
  55802. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  55803. _loop_1(targetIndex);
  55804. }
  55805. }
  55806. else {
  55807. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  55808. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  55809. babylonAnimation.setKeys(keys);
  55810. if (targetNode._babylonBones) {
  55811. var babylonAnimationTargets = [targetNode._babylonMesh].concat(targetNode._babylonBones);
  55812. for (var _i = 0, babylonAnimationTargets_1 = babylonAnimationTargets; _i < babylonAnimationTargets_1.length; _i++) {
  55813. var babylonAnimationTarget = babylonAnimationTargets_1[_i];
  55814. babylonAnimationTarget.animations.push(babylonAnimation);
  55815. }
  55816. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, babylonAnimationTargets);
  55817. }
  55818. else {
  55819. targetNode._babylonMesh.animations.push(babylonAnimation);
  55820. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonMesh);
  55821. }
  55822. }
  55823. });
  55824. };
  55825. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  55826. if (sampler._data) {
  55827. return sampler._data;
  55828. }
  55829. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  55830. switch (interpolation) {
  55831. case "STEP" /* STEP */:
  55832. case "LINEAR" /* LINEAR */:
  55833. case "CUBICSPLINE" /* CUBICSPLINE */: {
  55834. break;
  55835. }
  55836. default: {
  55837. throw new Error(context + ": Invalid interpolation (" + sampler.interpolation + ")");
  55838. }
  55839. }
  55840. var inputAccessor = GLTFLoader._GetProperty(context + "/input", this._gltf.accessors, sampler.input);
  55841. var outputAccessor = GLTFLoader._GetProperty(context + "/output", this._gltf.accessors, sampler.output);
  55842. sampler._data = Promise.all([
  55843. this._loadFloatAccessorAsync("#/accessors/" + inputAccessor._index, inputAccessor),
  55844. this._loadFloatAccessorAsync("#/accessors/" + outputAccessor._index, outputAccessor)
  55845. ]).then(function (_a) {
  55846. var inputData = _a[0], outputData = _a[1];
  55847. return {
  55848. input: inputData,
  55849. interpolation: interpolation,
  55850. output: outputData,
  55851. };
  55852. });
  55853. return sampler._data;
  55854. };
  55855. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  55856. if (buffer._data) {
  55857. return buffer._data;
  55858. }
  55859. if (!buffer.uri) {
  55860. throw new Error(context + ": Uri is missing");
  55861. }
  55862. buffer._data = this._loadUriAsync(context, buffer.uri);
  55863. return buffer._data;
  55864. };
  55865. /** @hidden */
  55866. GLTFLoader.prototype._loadBufferViewAsync = function (context, bufferView) {
  55867. if (bufferView._data) {
  55868. return bufferView._data;
  55869. }
  55870. var buffer = GLTFLoader._GetProperty(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  55871. bufferView._data = this._loadBufferAsync("#/buffers/" + buffer._index, buffer).then(function (data) {
  55872. try {
  55873. return new Uint8Array(data.buffer, data.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  55874. }
  55875. catch (e) {
  55876. throw new Error(context + ": " + e.message);
  55877. }
  55878. });
  55879. return bufferView._data;
  55880. };
  55881. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  55882. if (accessor.type !== "SCALAR" /* SCALAR */) {
  55883. throw new Error(context + ": Invalid type " + accessor.type);
  55884. }
  55885. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  55886. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  55887. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  55888. throw new Error(context + ": Invalid component type " + accessor.componentType);
  55889. }
  55890. if (accessor._data) {
  55891. return accessor._data;
  55892. }
  55893. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  55894. accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
  55895. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  55896. });
  55897. return accessor._data;
  55898. };
  55899. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  55900. // TODO: support normalized and stride
  55901. var _this = this;
  55902. if (accessor.componentType !== 5126 /* FLOAT */) {
  55903. throw new Error("Invalid component type " + accessor.componentType);
  55904. }
  55905. if (accessor._data) {
  55906. return accessor._data;
  55907. }
  55908. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  55909. var length = numComponents * accessor.count;
  55910. if (accessor.bufferView == undefined) {
  55911. accessor._data = Promise.resolve(new Float32Array(length));
  55912. }
  55913. else {
  55914. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  55915. accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
  55916. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  55917. });
  55918. }
  55919. if (accessor.sparse) {
  55920. var sparse_1 = accessor.sparse;
  55921. accessor._data = accessor._data.then(function (data) {
  55922. var indicesBufferView = GLTFLoader._GetProperty(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  55923. var valuesBufferView = GLTFLoader._GetProperty(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  55924. return Promise.all([
  55925. _this._loadBufferViewAsync("#/bufferViews/" + indicesBufferView._index, indicesBufferView),
  55926. _this._loadBufferViewAsync("#/bufferViews/" + valuesBufferView._index, valuesBufferView)
  55927. ]).then(function (_a) {
  55928. var indicesData = _a[0], valuesData = _a[1];
  55929. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  55930. var values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, numComponents * sparse_1.count);
  55931. var valuesIndex = 0;
  55932. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  55933. var dataIndex = indices[indicesIndex] * numComponents;
  55934. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  55935. data[dataIndex++] = values[valuesIndex++];
  55936. }
  55937. }
  55938. return data;
  55939. });
  55940. });
  55941. }
  55942. return accessor._data;
  55943. };
  55944. /** @hidden */
  55945. GLTFLoader.prototype._loadVertexBufferViewAsync = function (context, bufferView, kind) {
  55946. var _this = this;
  55947. if (bufferView._babylonBuffer) {
  55948. return bufferView._babylonBuffer;
  55949. }
  55950. bufferView._babylonBuffer = this._loadBufferViewAsync(context, bufferView).then(function (data) {
  55951. return new BABYLON.Buffer(_this._babylonScene.getEngine(), data, false);
  55952. });
  55953. return bufferView._babylonBuffer;
  55954. };
  55955. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  55956. var _this = this;
  55957. if (accessor._babylonVertexBuffer) {
  55958. return accessor._babylonVertexBuffer;
  55959. }
  55960. if (accessor.sparse) {
  55961. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
  55962. return new BABYLON.VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
  55963. });
  55964. }
  55965. else {
  55966. var bufferView_1 = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  55967. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync("#/bufferViews/" + bufferView_1._index, bufferView_1, kind).then(function (buffer) {
  55968. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  55969. return new BABYLON.VertexBuffer(_this._babylonScene.getEngine(), buffer, kind, false, false, bufferView_1.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  55970. });
  55971. }
  55972. return accessor._babylonVertexBuffer;
  55973. };
  55974. GLTFLoader.prototype._getDefaultMaterial = function (drawMode) {
  55975. var babylonMaterial = this._defaultBabylonMaterials[drawMode];
  55976. if (!babylonMaterial) {
  55977. babylonMaterial = this._createMaterial("__gltf_default", drawMode);
  55978. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  55979. babylonMaterial.metallic = 1;
  55980. babylonMaterial.roughness = 1;
  55981. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  55982. }
  55983. return babylonMaterial;
  55984. };
  55985. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, material, babylonMaterial) {
  55986. var promises = new Array();
  55987. // Ensure metallic workflow
  55988. babylonMaterial.metallic = 1;
  55989. babylonMaterial.roughness = 1;
  55990. var properties = material.pbrMetallicRoughness;
  55991. if (properties) {
  55992. if (properties.baseColorFactor) {
  55993. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.baseColorFactor);
  55994. babylonMaterial.alpha = properties.baseColorFactor[3];
  55995. }
  55996. else {
  55997. babylonMaterial.albedoColor = BABYLON.Color3.White();
  55998. }
  55999. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  56000. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  56001. if (properties.baseColorTexture) {
  56002. promises.push(this._loadTextureAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  56003. babylonMaterial.albedoTexture = texture;
  56004. }));
  56005. }
  56006. if (properties.metallicRoughnessTexture) {
  56007. promises.push(this._loadTextureAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  56008. babylonMaterial.metallicTexture = texture;
  56009. }));
  56010. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  56011. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  56012. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  56013. }
  56014. }
  56015. this._loadMaterialAlphaProperties(context, material, babylonMaterial);
  56016. return Promise.all(promises).then(function () { });
  56017. };
  56018. /** @hidden */
  56019. GLTFLoader.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56020. var promise = GLTF2.GLTFLoaderExtension._LoadMaterialAsync(this, context, material, mesh, babylonMesh, babylonDrawMode, assign);
  56021. if (promise) {
  56022. return promise;
  56023. }
  56024. material._babylonData = material._babylonData || {};
  56025. var babylonData = material._babylonData[babylonDrawMode];
  56026. if (!babylonData) {
  56027. var promises = new Array();
  56028. var name_3 = material.name || "material_" + material._index;
  56029. var babylonMaterial = this._createMaterial(name_3, babylonDrawMode);
  56030. promises.push(this._loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  56031. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial));
  56032. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  56033. babylonData = {
  56034. material: babylonMaterial,
  56035. meshes: [],
  56036. loaded: Promise.all(promises).then(function () { })
  56037. };
  56038. material._babylonData[babylonDrawMode] = babylonData;
  56039. }
  56040. babylonData.meshes.push(babylonMesh);
  56041. assign(babylonData.material);
  56042. return babylonData.loaded;
  56043. };
  56044. /** @hidden */
  56045. GLTFLoader.prototype._createMaterial = function (name, drawMode) {
  56046. var babylonMaterial = new BABYLON.PBRMaterial(name, this._babylonScene);
  56047. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation;
  56048. babylonMaterial.fillMode = drawMode;
  56049. babylonMaterial.enableSpecularAntiAliasing = true;
  56050. babylonMaterial.useRadianceOverAlpha = !this.transparencyAsCoverage;
  56051. babylonMaterial.useSpecularOverAlpha = !this.transparencyAsCoverage;
  56052. return babylonMaterial;
  56053. };
  56054. /** @hidden */
  56055. GLTFLoader.prototype._loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  56056. var promises = new Array();
  56057. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  56058. if (material.doubleSided) {
  56059. babylonMaterial.backFaceCulling = false;
  56060. babylonMaterial.twoSidedLighting = true;
  56061. }
  56062. if (material.normalTexture) {
  56063. promises.push(this._loadTextureAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  56064. babylonMaterial.bumpTexture = texture;
  56065. }));
  56066. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  56067. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  56068. if (material.normalTexture.scale != undefined) {
  56069. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  56070. }
  56071. }
  56072. if (material.occlusionTexture) {
  56073. promises.push(this._loadTextureAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  56074. babylonMaterial.ambientTexture = texture;
  56075. }));
  56076. babylonMaterial.useAmbientInGrayScale = true;
  56077. if (material.occlusionTexture.strength != undefined) {
  56078. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  56079. }
  56080. }
  56081. if (material.emissiveTexture) {
  56082. promises.push(this._loadTextureAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  56083. babylonMaterial.emissiveTexture = texture;
  56084. }));
  56085. }
  56086. return Promise.all(promises).then(function () { });
  56087. };
  56088. /** @hidden */
  56089. GLTFLoader.prototype._loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  56090. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  56091. switch (alphaMode) {
  56092. case "OPAQUE" /* OPAQUE */: {
  56093. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  56094. break;
  56095. }
  56096. case "MASK" /* MASK */: {
  56097. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHATEST;
  56098. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  56099. if (babylonMaterial.albedoTexture) {
  56100. babylonMaterial.albedoTexture.hasAlpha = true;
  56101. }
  56102. break;
  56103. }
  56104. case "BLEND" /* BLEND */: {
  56105. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
  56106. if (babylonMaterial.albedoTexture) {
  56107. babylonMaterial.albedoTexture.hasAlpha = true;
  56108. babylonMaterial.useAlphaFromAlbedoTexture = true;
  56109. }
  56110. break;
  56111. }
  56112. default: {
  56113. throw new Error(context + ": Invalid alpha mode (" + material.alphaMode + ")");
  56114. }
  56115. }
  56116. };
  56117. /** @hidden */
  56118. GLTFLoader.prototype._loadTextureAsync = function (context, textureInfo, assign) {
  56119. var _this = this;
  56120. var promise = GLTF2.GLTFLoaderExtension._LoadTextureAsync(this, context, textureInfo, assign);
  56121. if (promise) {
  56122. return promise;
  56123. }
  56124. var texture = GLTFLoader._GetProperty(context + "/index", this._gltf.textures, textureInfo.index);
  56125. context = "#/textures/" + textureInfo.index;
  56126. var promises = new Array();
  56127. var sampler = (texture.sampler == undefined ? this._defaultSampler : GLTFLoader._GetProperty(context + "/sampler", this._gltf.samplers, texture.sampler));
  56128. var samplerData = this._loadSampler("#/samplers/" + sampler._index, sampler);
  56129. var deferred = new BABYLON.Deferred();
  56130. var babylonTexture = new BABYLON.Texture(null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  56131. if (!_this._disposed) {
  56132. deferred.resolve();
  56133. }
  56134. }, function (message, exception) {
  56135. if (!_this._disposed) {
  56136. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  56137. }
  56138. });
  56139. promises.push(deferred.promise);
  56140. babylonTexture.name = texture.name || "texture" + texture._index;
  56141. babylonTexture.wrapU = samplerData.wrapU;
  56142. babylonTexture.wrapV = samplerData.wrapV;
  56143. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  56144. var image = GLTFLoader._GetProperty(context + "/source", this._gltf.images, texture.source);
  56145. promises.push(this._loadImageAsync("#/images/" + image._index, image).then(function (blob) {
  56146. var dataUrl = "data:" + _this._rootUrl + (image.uri || "image" + image._index);
  56147. babylonTexture.updateURL(dataUrl, blob);
  56148. }));
  56149. assign(babylonTexture);
  56150. this.onTextureLoadedObservable.notifyObservers(babylonTexture);
  56151. return Promise.all(promises).then(function () { });
  56152. };
  56153. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  56154. if (!sampler._data) {
  56155. sampler._data = {
  56156. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  56157. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler.magFilter, sampler.minFilter),
  56158. wrapU: GLTFLoader._GetTextureWrapMode(context, sampler.wrapS),
  56159. wrapV: GLTFLoader._GetTextureWrapMode(context, sampler.wrapT)
  56160. };
  56161. }
  56162. ;
  56163. return sampler._data;
  56164. };
  56165. GLTFLoader.prototype._loadImageAsync = function (context, image) {
  56166. if (image._blob) {
  56167. return image._blob;
  56168. }
  56169. var promise;
  56170. if (image.uri) {
  56171. promise = this._loadUriAsync(context, image.uri);
  56172. }
  56173. else {
  56174. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  56175. promise = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView);
  56176. }
  56177. image._blob = promise.then(function (data) {
  56178. return new Blob([data], { type: image.mimeType });
  56179. });
  56180. return image._blob;
  56181. };
  56182. /** @hidden */
  56183. GLTFLoader.prototype._loadUriAsync = function (context, uri) {
  56184. var _this = this;
  56185. var promise = GLTF2.GLTFLoaderExtension._LoadUriAsync(this, context, uri);
  56186. if (promise) {
  56187. return promise;
  56188. }
  56189. if (!GLTFLoader._ValidateUri(uri)) {
  56190. throw new Error(context + ": Uri '" + uri + "' is invalid");
  56191. }
  56192. if (BABYLON.Tools.IsBase64(uri)) {
  56193. return Promise.resolve(new Uint8Array(BABYLON.Tools.DecodeBase64(uri)));
  56194. }
  56195. return this.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  56196. return new Promise(function (resolve, reject) {
  56197. if (!_this._disposed) {
  56198. var request_1 = BABYLON.Tools.LoadFile(url, function (data) {
  56199. if (!_this._disposed) {
  56200. resolve(new Uint8Array(data));
  56201. }
  56202. }, function (event) {
  56203. if (!_this._disposed) {
  56204. try {
  56205. if (request_1 && _this._state === BABYLON.GLTFLoaderState.LOADING) {
  56206. request_1._lengthComputable = event.lengthComputable;
  56207. request_1._loaded = event.loaded;
  56208. request_1._total = event.total;
  56209. _this._onProgress();
  56210. }
  56211. }
  56212. catch (e) {
  56213. reject(e);
  56214. }
  56215. }
  56216. }, _this._babylonScene.database, true, function (request, exception) {
  56217. if (!_this._disposed) {
  56218. reject(new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  56219. }
  56220. });
  56221. _this._requests.push(request_1);
  56222. }
  56223. });
  56224. });
  56225. };
  56226. GLTFLoader.prototype._onProgress = function () {
  56227. if (!this._progressCallback) {
  56228. return;
  56229. }
  56230. var lengthComputable = true;
  56231. var loaded = 0;
  56232. var total = 0;
  56233. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  56234. var request = _a[_i];
  56235. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  56236. return;
  56237. }
  56238. lengthComputable = lengthComputable && request._lengthComputable;
  56239. loaded += request._loaded;
  56240. total += request._total;
  56241. }
  56242. this._progressCallback(new BABYLON.SceneLoaderProgressEvent(lengthComputable, loaded, lengthComputable ? total : 0));
  56243. };
  56244. /** @hidden */
  56245. GLTFLoader._GetProperty = function (context, array, index) {
  56246. if (!array || index == undefined || !array[index]) {
  56247. throw new Error(context + ": Failed to find index (" + index + ")");
  56248. }
  56249. return array[index];
  56250. };
  56251. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  56252. // Set defaults if undefined
  56253. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  56254. switch (mode) {
  56255. case 33071 /* CLAMP_TO_EDGE */: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  56256. case 33648 /* MIRRORED_REPEAT */: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  56257. case 10497 /* REPEAT */: return BABYLON.Texture.WRAP_ADDRESSMODE;
  56258. default:
  56259. BABYLON.Tools.Warn(context + ": Invalid texture wrap mode (" + mode + ")");
  56260. return BABYLON.Texture.WRAP_ADDRESSMODE;
  56261. }
  56262. };
  56263. GLTFLoader._GetTextureSamplingMode = function (context, magFilter, minFilter) {
  56264. // Set defaults if undefined
  56265. magFilter = magFilter == undefined ? 9729 /* LINEAR */ : magFilter;
  56266. minFilter = minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : minFilter;
  56267. if (magFilter === 9729 /* LINEAR */) {
  56268. switch (minFilter) {
  56269. case 9728 /* NEAREST */: return BABYLON.Texture.LINEAR_NEAREST;
  56270. case 9729 /* LINEAR */: return BABYLON.Texture.LINEAR_LINEAR;
  56271. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  56272. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  56273. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  56274. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  56275. default:
  56276. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  56277. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  56278. }
  56279. }
  56280. else {
  56281. if (magFilter !== 9728 /* NEAREST */) {
  56282. BABYLON.Tools.Warn(context + ": Invalid texture magnification filter (" + magFilter + ")");
  56283. }
  56284. switch (minFilter) {
  56285. case 9728 /* NEAREST */: return BABYLON.Texture.NEAREST_NEAREST;
  56286. case 9729 /* LINEAR */: return BABYLON.Texture.NEAREST_LINEAR;
  56287. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  56288. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  56289. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  56290. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  56291. default:
  56292. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  56293. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  56294. }
  56295. }
  56296. };
  56297. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  56298. var buffer = bufferView.buffer;
  56299. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  56300. try {
  56301. switch (componentType) {
  56302. case 5120 /* BYTE */: return new Int8Array(buffer, byteOffset, length);
  56303. case 5121 /* UNSIGNED_BYTE */: return new Uint8Array(buffer, byteOffset, length);
  56304. case 5122 /* SHORT */: return new Int16Array(buffer, byteOffset, length);
  56305. case 5123 /* UNSIGNED_SHORT */: return new Uint16Array(buffer, byteOffset, length);
  56306. case 5125 /* UNSIGNED_INT */: return new Uint32Array(buffer, byteOffset, length);
  56307. case 5126 /* FLOAT */: return new Float32Array(buffer, byteOffset, length);
  56308. default: throw new Error("Invalid component type " + componentType);
  56309. }
  56310. }
  56311. catch (e) {
  56312. throw new Error(context + ": " + e);
  56313. }
  56314. };
  56315. GLTFLoader._GetNumComponents = function (context, type) {
  56316. switch (type) {
  56317. case "SCALAR": return 1;
  56318. case "VEC2": return 2;
  56319. case "VEC3": return 3;
  56320. case "VEC4": return 4;
  56321. case "MAT2": return 4;
  56322. case "MAT3": return 9;
  56323. case "MAT4": return 16;
  56324. }
  56325. throw new Error(context + ": Invalid type (" + type + ")");
  56326. };
  56327. GLTFLoader._ValidateUri = function (uri) {
  56328. return (BABYLON.Tools.IsBase64(uri) || uri.indexOf("..") === -1);
  56329. };
  56330. GLTFLoader._GetDrawMode = function (context, mode) {
  56331. if (mode == undefined) {
  56332. mode = 4 /* TRIANGLES */;
  56333. }
  56334. switch (mode) {
  56335. case 0 /* POINTS */: return BABYLON.Material.PointListDrawMode;
  56336. case 1 /* LINES */: return BABYLON.Material.LineListDrawMode;
  56337. case 2 /* LINE_LOOP */: return BABYLON.Material.LineLoopDrawMode;
  56338. case 3 /* LINE_STRIP */: return BABYLON.Material.LineStripDrawMode;
  56339. case 4 /* TRIANGLES */: return BABYLON.Material.TriangleFillMode;
  56340. case 5 /* TRIANGLE_STRIP */: return BABYLON.Material.TriangleStripDrawMode;
  56341. case 6 /* TRIANGLE_FAN */: return BABYLON.Material.TriangleFanDrawMode;
  56342. }
  56343. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  56344. };
  56345. GLTFLoader.prototype._compileMaterialsAsync = function () {
  56346. var promises = new Array();
  56347. if (this._gltf.materials) {
  56348. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  56349. var material = _a[_i];
  56350. if (material._babylonData) {
  56351. for (var babylonDrawMode in material._babylonData) {
  56352. var babylonData = material._babylonData[babylonDrawMode];
  56353. for (var _b = 0, _c = babylonData.meshes; _b < _c.length; _b++) {
  56354. var babylonMesh = _c[_b];
  56355. // Ensure nonUniformScaling is set if necessary.
  56356. babylonMesh.computeWorldMatrix(true);
  56357. var babylonMaterial = babylonData.material;
  56358. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  56359. if (this.useClipPlane) {
  56360. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  56361. }
  56362. }
  56363. }
  56364. }
  56365. }
  56366. }
  56367. return Promise.all(promises).then(function () { });
  56368. };
  56369. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  56370. var promises = new Array();
  56371. var lights = this._babylonScene.lights;
  56372. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  56373. var light = lights_1[_i];
  56374. var generator = light.getShadowGenerator();
  56375. if (generator) {
  56376. promises.push(generator.forceCompilationAsync());
  56377. }
  56378. }
  56379. return Promise.all(promises).then(function () { });
  56380. };
  56381. GLTFLoader.prototype._clear = function () {
  56382. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  56383. var request = _a[_i];
  56384. request.abort();
  56385. }
  56386. this._requests.length = 0;
  56387. delete this._gltf;
  56388. delete this._babylonScene;
  56389. this._completePromises.length = 0;
  56390. this._onReadyObservable.clear();
  56391. for (var name_4 in this._extensions) {
  56392. this._extensions[name_4].dispose();
  56393. }
  56394. this._extensions = {};
  56395. delete this._rootBabylonMesh;
  56396. delete this._progressCallback;
  56397. this.onMeshLoadedObservable.clear();
  56398. this.onTextureLoadedObservable.clear();
  56399. this.onMaterialLoadedObservable.clear();
  56400. this.onCameraLoadedObservable.clear();
  56401. };
  56402. /** @hidden */
  56403. GLTFLoader.prototype._applyExtensions = function (actionAsync) {
  56404. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  56405. var name_5 = _a[_i];
  56406. var extension = this._extensions[name_5];
  56407. if (extension.enabled) {
  56408. var promise = actionAsync(extension);
  56409. if (promise) {
  56410. return promise;
  56411. }
  56412. }
  56413. }
  56414. return null;
  56415. };
  56416. GLTFLoader._ExtensionNames = new Array();
  56417. GLTFLoader._ExtensionFactories = {};
  56418. return GLTFLoader;
  56419. }());
  56420. GLTF2.GLTFLoader = GLTFLoader;
  56421. BABYLON.GLTFFileLoader._CreateGLTFLoaderV2 = function () { return new GLTFLoader(); };
  56422. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56423. })(BABYLON || (BABYLON = {}));
  56424. //# sourceMappingURL=babylon.glTFLoader.js.map
  56425. var BABYLON;
  56426. (function (BABYLON) {
  56427. var GLTF2;
  56428. (function (GLTF2) {
  56429. /**
  56430. * Abstract class that can be implemented to extend existing glTF loader behavior.
  56431. */
  56432. var GLTFLoaderExtension = /** @class */ (function () {
  56433. /**
  56434. * Creates new GLTFLoaderExtension
  56435. * @param loader defines the GLTFLoader to use
  56436. */
  56437. function GLTFLoaderExtension(loader) {
  56438. /**
  56439. * Gets or sets a boolean indicating if the extension is enabled
  56440. */
  56441. this.enabled = true;
  56442. this._loader = loader;
  56443. }
  56444. /**
  56445. * Release all resources
  56446. */
  56447. GLTFLoaderExtension.prototype.dispose = function () {
  56448. delete this._loader;
  56449. };
  56450. // #region Overridable Methods
  56451. /**
  56452. * Override this method to modify the default behavior for loading scenes.
  56453. * @hidden
  56454. */
  56455. GLTFLoaderExtension.prototype._loadSceneAsync = function (context, node) { return null; };
  56456. /**
  56457. * Override this method to modify the default behavior for loading nodes.
  56458. * @hidden
  56459. */
  56460. GLTFLoaderExtension.prototype._loadNodeAsync = function (context, node) { return null; };
  56461. /**
  56462. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  56463. * @hidden
  56464. */
  56465. GLTFLoaderExtension.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) { return null; };
  56466. /**
  56467. * Override this method to modify the default behavior for loading materials.
  56468. * @hidden
  56469. */
  56470. GLTFLoaderExtension.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) { return null; };
  56471. /**
  56472. * Override this method to modify the default behavior for loading textures.
  56473. * @hidden
  56474. */
  56475. GLTFLoaderExtension.prototype._loadTextureAsync = function (context, textureInfo, assign) { return null; };
  56476. /**
  56477. * Override this method to modify the default behavior for loading uris.
  56478. * @hidden
  56479. */
  56480. GLTFLoaderExtension.prototype._loadUriAsync = function (context, uri) { return null; };
  56481. // #endregion
  56482. /**
  56483. * Helper method called by a loader extension to load an glTF extension.
  56484. * @hidden
  56485. */
  56486. GLTFLoaderExtension.prototype._loadExtensionAsync = function (context, property, actionAsync) {
  56487. if (!property.extensions) {
  56488. return null;
  56489. }
  56490. var extensions = property.extensions;
  56491. var extension = extensions[this.name];
  56492. if (!extension) {
  56493. return null;
  56494. }
  56495. // Clear out the extension before executing the action to avoid infinite recursion.
  56496. delete extensions[this.name];
  56497. try {
  56498. return actionAsync(context + "/extensions/" + this.name, extension);
  56499. }
  56500. finally {
  56501. // Restore the extension after executing the action.
  56502. extensions[this.name] = extension;
  56503. }
  56504. };
  56505. /**
  56506. * Helper method called by the loader to allow extensions to override loading scenes.
  56507. * @hidden
  56508. */
  56509. GLTFLoaderExtension.prototype._loadExtrasValueAsync = function (context, property, actionAsync) {
  56510. if (!property.extras) {
  56511. return null;
  56512. }
  56513. var extras = property.extras;
  56514. var value = extras[this.name];
  56515. if (value === undefined) {
  56516. return null;
  56517. }
  56518. // Clear out the extras value before executing the action to avoid infinite recursion.
  56519. delete extras[this.name];
  56520. try {
  56521. return actionAsync(context + "/extras/" + this.name, value);
  56522. }
  56523. finally {
  56524. // Restore the extras value after executing the action.
  56525. extras[this.name] = value;
  56526. }
  56527. };
  56528. /**
  56529. * Helper method called by the loader to allow extensions to override loading scenes.
  56530. * @hidden
  56531. */
  56532. GLTFLoaderExtension._LoadSceneAsync = function (loader, context, scene) {
  56533. return loader._applyExtensions(function (extension) { return extension._loadSceneAsync(context, scene); });
  56534. };
  56535. /**
  56536. * Helper method called by the loader to allow extensions to override loading nodes.
  56537. * @hidden
  56538. */
  56539. GLTFLoaderExtension._LoadNodeAsync = function (loader, context, node) {
  56540. return loader._applyExtensions(function (extension) { return extension._loadNodeAsync(context, node); });
  56541. };
  56542. /**
  56543. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  56544. * @hidden
  56545. */
  56546. GLTFLoaderExtension._LoadVertexDataAsync = function (loader, context, primitive, babylonMesh) {
  56547. return loader._applyExtensions(function (extension) { return extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  56548. };
  56549. /**
  56550. * Helper method called by the loader to allow extensions to override loading materials.
  56551. * @hidden
  56552. */
  56553. GLTFLoaderExtension._LoadMaterialAsync = function (loader, context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56554. return loader._applyExtensions(function (extension) { return extension._loadMaterialAsync(context, material, mesh, babylonMesh, babylonDrawMode, assign); });
  56555. };
  56556. /**
  56557. * Helper method called by the loader to allow extensions to override loading textures.
  56558. * @hidden
  56559. */
  56560. GLTFLoaderExtension._LoadTextureAsync = function (loader, context, textureInfo, assign) {
  56561. return loader._applyExtensions(function (extension) { return extension._loadTextureAsync(context, textureInfo, assign); });
  56562. };
  56563. /**
  56564. * Helper method called by the loader to allow extensions to override loading uris.
  56565. * @hidden
  56566. */
  56567. GLTFLoaderExtension._LoadUriAsync = function (loader, context, uri) {
  56568. return loader._applyExtensions(function (extension) { return extension._loadUriAsync(context, uri); });
  56569. };
  56570. return GLTFLoaderExtension;
  56571. }());
  56572. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  56573. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56574. })(BABYLON || (BABYLON = {}));
  56575. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  56576. var BABYLON;
  56577. (function (BABYLON) {
  56578. var GLTF2;
  56579. (function (GLTF2) {
  56580. var Extensions;
  56581. (function (Extensions) {
  56582. var NAME = "MSFT_lod";
  56583. /**
  56584. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  56585. */
  56586. var MSFT_lod = /** @class */ (function (_super) {
  56587. __extends(MSFT_lod, _super);
  56588. function MSFT_lod(loader) {
  56589. var _this = _super.call(this, loader) || this;
  56590. _this.name = NAME;
  56591. /**
  56592. * Maximum number of LODs to load, starting from the lowest LOD.
  56593. */
  56594. _this.maxLODsToLoad = Number.MAX_VALUE;
  56595. /**
  56596. * Observable raised when all node LODs of one level are loaded.
  56597. * The event data is the index of the loaded LOD starting from zero.
  56598. * Dispose the loader to cancel the loading of the next level of LODs.
  56599. */
  56600. _this.onNodeLODsLoadedObservable = new BABYLON.Observable();
  56601. /**
  56602. * Observable raised when all material LODs of one level are loaded.
  56603. * The event data is the index of the loaded LOD starting from zero.
  56604. * Dispose the loader to cancel the loading of the next level of LODs.
  56605. */
  56606. _this.onMaterialLODsLoadedObservable = new BABYLON.Observable();
  56607. _this._loadingNodeLOD = null;
  56608. _this._loadNodeSignals = {};
  56609. _this._loadNodePromises = new Array();
  56610. _this._loadingMaterialLOD = null;
  56611. _this._loadMaterialSignals = {};
  56612. _this._loadMaterialPromises = new Array();
  56613. _this._loader._onReadyObservable.addOnce(function () {
  56614. var _loop_1 = function (indexLOD) {
  56615. Promise.all(_this._loadNodePromises[indexLOD]).then(function () {
  56616. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  56617. });
  56618. };
  56619. for (var indexLOD = 0; indexLOD < _this._loadNodePromises.length; indexLOD++) {
  56620. _loop_1(indexLOD);
  56621. }
  56622. var _loop_2 = function (indexLOD) {
  56623. Promise.all(_this._loadMaterialPromises[indexLOD]).then(function () {
  56624. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  56625. });
  56626. };
  56627. for (var indexLOD = 0; indexLOD < _this._loadMaterialPromises.length; indexLOD++) {
  56628. _loop_2(indexLOD);
  56629. }
  56630. });
  56631. return _this;
  56632. }
  56633. MSFT_lod.prototype.dispose = function () {
  56634. _super.prototype.dispose.call(this);
  56635. this._loadingNodeLOD = null;
  56636. this._loadNodeSignals = {};
  56637. this._loadingMaterialLOD = null;
  56638. this._loadMaterialSignals = {};
  56639. this.onMaterialLODsLoadedObservable.clear();
  56640. this.onNodeLODsLoadedObservable.clear();
  56641. };
  56642. MSFT_lod.prototype._loadNodeAsync = function (context, node) {
  56643. var _this = this;
  56644. return this._loadExtensionAsync(context, node, function (extensionContext, extension) {
  56645. var firstPromise;
  56646. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader._gltf.nodes, extension.ids);
  56647. var _loop_3 = function (indexLOD) {
  56648. var nodeLOD = nodeLODs[indexLOD];
  56649. if (indexLOD !== 0) {
  56650. _this._loadingNodeLOD = nodeLOD;
  56651. if (!_this._loadNodeSignals[nodeLOD._index]) {
  56652. _this._loadNodeSignals[nodeLOD._index] = new BABYLON.Deferred();
  56653. }
  56654. }
  56655. var promise = _this._loader._loadNodeAsync("#/nodes/" + nodeLOD._index, nodeLOD).then(function () {
  56656. if (indexLOD !== 0) {
  56657. var previousNodeLOD = nodeLODs[indexLOD - 1];
  56658. if (previousNodeLOD._babylonMesh) {
  56659. previousNodeLOD._babylonMesh.dispose(false, true);
  56660. delete previousNodeLOD._babylonMesh;
  56661. }
  56662. }
  56663. if (indexLOD !== nodeLODs.length - 1) {
  56664. var nodeIndex = nodeLODs[indexLOD + 1]._index;
  56665. if (_this._loadNodeSignals[nodeIndex]) {
  56666. _this._loadNodeSignals[nodeIndex].resolve();
  56667. delete _this._loadNodeSignals[nodeIndex];
  56668. }
  56669. }
  56670. });
  56671. if (indexLOD === 0) {
  56672. firstPromise = promise;
  56673. }
  56674. else {
  56675. _this._loader._completePromises.push(promise);
  56676. _this._loadingNodeLOD = null;
  56677. }
  56678. _this._loadNodePromises[indexLOD] = _this._loadNodePromises[indexLOD] || [];
  56679. _this._loadNodePromises[indexLOD].push(promise);
  56680. };
  56681. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  56682. _loop_3(indexLOD);
  56683. }
  56684. return firstPromise;
  56685. });
  56686. };
  56687. MSFT_lod.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56688. var _this = this;
  56689. // Don't load material LODs if already loading a node LOD.
  56690. if (this._loadingNodeLOD) {
  56691. return null;
  56692. }
  56693. return this._loadExtensionAsync(context, material, function (extensionContext, extension) {
  56694. var firstPromise;
  56695. var materialLODs = _this._getLODs(extensionContext, material, _this._loader._gltf.materials, extension.ids);
  56696. var _loop_4 = function (indexLOD) {
  56697. var materialLOD = materialLODs[indexLOD];
  56698. if (indexLOD !== 0) {
  56699. _this._loadingMaterialLOD = materialLOD;
  56700. if (!_this._loadMaterialSignals[materialLOD._index]) {
  56701. _this._loadMaterialSignals[materialLOD._index] = new BABYLON.Deferred();
  56702. }
  56703. }
  56704. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD._index, materialLOD, mesh, babylonMesh, babylonDrawMode, indexLOD === 0 ? assign : function () { }).then(function () {
  56705. if (indexLOD !== 0) {
  56706. var babylonDataLOD = materialLOD._babylonData;
  56707. assign(babylonDataLOD[babylonDrawMode].material);
  56708. var previousBabylonDataLOD = materialLODs[indexLOD - 1]._babylonData;
  56709. if (previousBabylonDataLOD[babylonDrawMode]) {
  56710. previousBabylonDataLOD[babylonDrawMode].material.dispose();
  56711. delete previousBabylonDataLOD[babylonDrawMode];
  56712. }
  56713. }
  56714. if (indexLOD !== materialLODs.length - 1) {
  56715. var materialIndex = materialLODs[indexLOD + 1]._index;
  56716. if (_this._loadMaterialSignals[materialIndex]) {
  56717. _this._loadMaterialSignals[materialIndex].resolve();
  56718. delete _this._loadMaterialSignals[materialIndex];
  56719. }
  56720. }
  56721. });
  56722. if (indexLOD === 0) {
  56723. firstPromise = promise;
  56724. }
  56725. else {
  56726. _this._loader._completePromises.push(promise);
  56727. _this._loadingMaterialLOD = null;
  56728. }
  56729. _this._loadMaterialPromises[indexLOD] = _this._loadMaterialPromises[indexLOD] || [];
  56730. _this._loadMaterialPromises[indexLOD].push(promise);
  56731. };
  56732. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  56733. _loop_4(indexLOD);
  56734. }
  56735. return firstPromise;
  56736. });
  56737. };
  56738. MSFT_lod.prototype._loadUriAsync = function (context, uri) {
  56739. var _this = this;
  56740. // Defer the loading of uris if loading a material or node LOD.
  56741. if (this._loadingMaterialLOD) {
  56742. var index = this._loadingMaterialLOD._index;
  56743. return this._loadMaterialSignals[index].promise.then(function () {
  56744. return _this._loader._loadUriAsync(context, uri);
  56745. });
  56746. }
  56747. else if (this._loadingNodeLOD) {
  56748. var index = this._loadingNodeLOD._index;
  56749. return this._loadNodeSignals[index].promise.then(function () {
  56750. return _this._loader._loadUriAsync(context, uri);
  56751. });
  56752. }
  56753. return null;
  56754. };
  56755. /**
  56756. * Gets an array of LOD properties from lowest to highest.
  56757. */
  56758. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  56759. if (this.maxLODsToLoad <= 0) {
  56760. throw new Error("maxLODsToLoad must be greater than zero");
  56761. }
  56762. var properties = new Array();
  56763. for (var i = ids.length - 1; i >= 0; i--) {
  56764. properties.push(GLTF2.GLTFLoader._GetProperty(context + "/ids/" + ids[i], array, ids[i]));
  56765. if (properties.length === this.maxLODsToLoad) {
  56766. return properties;
  56767. }
  56768. }
  56769. properties.push(property);
  56770. return properties;
  56771. };
  56772. return MSFT_lod;
  56773. }(GLTF2.GLTFLoaderExtension));
  56774. Extensions.MSFT_lod = MSFT_lod;
  56775. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new MSFT_lod(loader); });
  56776. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  56777. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56778. })(BABYLON || (BABYLON = {}));
  56779. //# sourceMappingURL=MSFT_lod.js.map
  56780. var BABYLON;
  56781. (function (BABYLON) {
  56782. var GLTF2;
  56783. (function (GLTF2) {
  56784. var Extensions;
  56785. (function (Extensions) {
  56786. var NAME = "MSFT_minecraftMesh";
  56787. /** @hidden */
  56788. var MSFT_minecraftMesh = /** @class */ (function (_super) {
  56789. __extends(MSFT_minecraftMesh, _super);
  56790. function MSFT_minecraftMesh() {
  56791. var _this = _super !== null && _super.apply(this, arguments) || this;
  56792. _this.name = NAME;
  56793. return _this;
  56794. }
  56795. MSFT_minecraftMesh.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56796. var _this = this;
  56797. return this._loadExtrasValueAsync(context, mesh, function (extensionContext, value) {
  56798. if (value) {
  56799. return _this._loader._loadMaterialAsync(context, material, mesh, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  56800. if (babylonMaterial.needAlphaBlending()) {
  56801. babylonMaterial.forceDepthWrite = true;
  56802. babylonMaterial.separateCullingPass = true;
  56803. }
  56804. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  56805. babylonMaterial.twoSidedLighting = true;
  56806. assign(babylonMaterial);
  56807. });
  56808. }
  56809. return null;
  56810. });
  56811. };
  56812. return MSFT_minecraftMesh;
  56813. }(GLTF2.GLTFLoaderExtension));
  56814. Extensions.MSFT_minecraftMesh = MSFT_minecraftMesh;
  56815. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  56816. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  56817. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56818. })(BABYLON || (BABYLON = {}));
  56819. //# sourceMappingURL=MSFT_minecraftMesh.js.map
  56820. var BABYLON;
  56821. (function (BABYLON) {
  56822. var GLTF2;
  56823. (function (GLTF2) {
  56824. var Extensions;
  56825. (function (Extensions) {
  56826. var NAME = "MSFT_sRGBFactors";
  56827. /** @hidden */
  56828. var MSFT_sRGBFactors = /** @class */ (function (_super) {
  56829. __extends(MSFT_sRGBFactors, _super);
  56830. function MSFT_sRGBFactors() {
  56831. var _this = _super !== null && _super.apply(this, arguments) || this;
  56832. _this.name = NAME;
  56833. return _this;
  56834. }
  56835. MSFT_sRGBFactors.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56836. var _this = this;
  56837. return this._loadExtrasValueAsync(context, material, function (extensionContext, value) {
  56838. if (value) {
  56839. return _this._loader._loadMaterialAsync(context, material, mesh, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  56840. if (!babylonMaterial.albedoTexture) {
  56841. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  56842. }
  56843. if (!babylonMaterial.reflectivityTexture) {
  56844. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  56845. }
  56846. assign(babylonMaterial);
  56847. });
  56848. }
  56849. return null;
  56850. });
  56851. };
  56852. return MSFT_sRGBFactors;
  56853. }(GLTF2.GLTFLoaderExtension));
  56854. Extensions.MSFT_sRGBFactors = MSFT_sRGBFactors;
  56855. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  56856. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  56857. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56858. })(BABYLON || (BABYLON = {}));
  56859. //# sourceMappingURL=MSFT_sRGBFactors.js.map
  56860. var BABYLON;
  56861. (function (BABYLON) {
  56862. var GLTF2;
  56863. (function (GLTF2) {
  56864. var Extensions;
  56865. (function (Extensions) {
  56866. var NAME = "KHR_draco_mesh_compression";
  56867. /**
  56868. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  56869. */
  56870. var KHR_draco_mesh_compression = /** @class */ (function (_super) {
  56871. __extends(KHR_draco_mesh_compression, _super);
  56872. function KHR_draco_mesh_compression(loader) {
  56873. var _this = _super.call(this, loader) || this;
  56874. _this.name = NAME;
  56875. _this._dracoCompression = null;
  56876. // Disable extension if decoder is not available.
  56877. if (!BABYLON.DracoCompression.DecoderAvailable) {
  56878. _this.enabled = false;
  56879. }
  56880. return _this;
  56881. }
  56882. KHR_draco_mesh_compression.prototype.dispose = function () {
  56883. if (this._dracoCompression) {
  56884. this._dracoCompression.dispose();
  56885. }
  56886. _super.prototype.dispose.call(this);
  56887. };
  56888. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  56889. var _this = this;
  56890. return this._loadExtensionAsync(context, primitive, function (extensionContext, extension) {
  56891. if (primitive.mode != undefined) {
  56892. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  56893. primitive.mode !== 4 /* TRIANGLES */) {
  56894. throw new Error(context + ": Unsupported mode " + primitive.mode);
  56895. }
  56896. // TODO: handle triangle strips
  56897. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  56898. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  56899. }
  56900. }
  56901. var attributes = {};
  56902. var loadAttribute = function (name, kind) {
  56903. var uniqueId = extension.attributes[name];
  56904. if (uniqueId == undefined) {
  56905. return;
  56906. }
  56907. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  56908. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  56909. babylonMesh._delayInfo.push(kind);
  56910. }
  56911. attributes[kind] = uniqueId;
  56912. };
  56913. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  56914. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  56915. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  56916. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  56917. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  56918. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  56919. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  56920. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
  56921. var bufferView = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._loader._gltf.bufferViews, extension.bufferView);
  56922. if (!bufferView._dracoBabylonGeometry) {
  56923. bufferView._dracoBabylonGeometry = _this._loader._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
  56924. if (!_this._dracoCompression) {
  56925. _this._dracoCompression = new BABYLON.DracoCompression();
  56926. }
  56927. return _this._dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  56928. var babylonGeometry = new BABYLON.Geometry(babylonMesh.name, _this._loader._babylonScene);
  56929. babylonVertexData.applyToGeometry(babylonGeometry);
  56930. return babylonGeometry;
  56931. }).catch(function (error) {
  56932. throw new Error(context + ": " + error.message);
  56933. });
  56934. });
  56935. }
  56936. return bufferView._dracoBabylonGeometry;
  56937. });
  56938. };
  56939. return KHR_draco_mesh_compression;
  56940. }(GLTF2.GLTFLoaderExtension));
  56941. Extensions.KHR_draco_mesh_compression = KHR_draco_mesh_compression;
  56942. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  56943. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  56944. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  56945. })(BABYLON || (BABYLON = {}));
  56946. //# sourceMappingURL=KHR_draco_mesh_compression.js.map
  56947. var BABYLON;
  56948. (function (BABYLON) {
  56949. var GLTF2;
  56950. (function (GLTF2) {
  56951. var Extensions;
  56952. (function (Extensions) {
  56953. var NAME = "KHR_materials_pbrSpecularGlossiness";
  56954. /**
  56955. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  56956. */
  56957. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function (_super) {
  56958. __extends(KHR_materials_pbrSpecularGlossiness, _super);
  56959. function KHR_materials_pbrSpecularGlossiness() {
  56960. var _this = _super !== null && _super.apply(this, arguments) || this;
  56961. _this.name = NAME;
  56962. return _this;
  56963. }
  56964. KHR_materials_pbrSpecularGlossiness.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  56965. var _this = this;
  56966. return this._loadExtensionAsync(context, material, function (extensionContext, extension) {
  56967. material._babylonData = material._babylonData || {};
  56968. var babylonData = material._babylonData[babylonDrawMode];
  56969. if (!babylonData) {
  56970. var promises = new Array();
  56971. var name_1 = material.name || "materialSG_" + material._index;
  56972. var babylonMaterial = _this._loader._createMaterial(name_1, babylonDrawMode);
  56973. promises.push(_this._loader._loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  56974. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  56975. _this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  56976. babylonData = {
  56977. material: babylonMaterial,
  56978. meshes: [],
  56979. loaded: Promise.all(promises).then(function () { })
  56980. };
  56981. material._babylonData[babylonDrawMode] = babylonData;
  56982. }
  56983. babylonData.meshes.push(babylonMesh);
  56984. assign(babylonData.material);
  56985. return babylonData.loaded;
  56986. });
  56987. };
  56988. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  56989. var promises = new Array();
  56990. if (properties.diffuseFactor) {
  56991. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.diffuseFactor);
  56992. babylonMaterial.alpha = properties.diffuseFactor[3];
  56993. }
  56994. else {
  56995. babylonMaterial.albedoColor = BABYLON.Color3.White();
  56996. }
  56997. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : BABYLON.Color3.White();
  56998. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  56999. if (properties.diffuseTexture) {
  57000. promises.push(this._loader._loadTextureAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  57001. babylonMaterial.albedoTexture = texture;
  57002. }));
  57003. }
  57004. if (properties.specularGlossinessTexture) {
  57005. promises.push(this._loader._loadTextureAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  57006. babylonMaterial.reflectivityTexture = texture;
  57007. }));
  57008. babylonMaterial.reflectivityTexture.hasAlpha = true;
  57009. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  57010. }
  57011. this._loader._loadMaterialAlphaProperties(context, material, babylonMaterial);
  57012. return Promise.all(promises).then(function () { });
  57013. };
  57014. return KHR_materials_pbrSpecularGlossiness;
  57015. }(GLTF2.GLTFLoaderExtension));
  57016. Extensions.KHR_materials_pbrSpecularGlossiness = KHR_materials_pbrSpecularGlossiness;
  57017. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  57018. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  57019. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  57020. })(BABYLON || (BABYLON = {}));
  57021. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map
  57022. var BABYLON;
  57023. (function (BABYLON) {
  57024. var GLTF2;
  57025. (function (GLTF2) {
  57026. var Extensions;
  57027. (function (Extensions) {
  57028. var NAME = "KHR_materials_unlit";
  57029. /**
  57030. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  57031. */
  57032. var KHR_materials_unlit = /** @class */ (function (_super) {
  57033. __extends(KHR_materials_unlit, _super);
  57034. function KHR_materials_unlit() {
  57035. var _this = _super !== null && _super.apply(this, arguments) || this;
  57036. _this.name = NAME;
  57037. return _this;
  57038. }
  57039. KHR_materials_unlit.prototype._loadMaterialAsync = function (context, material, mesh, babylonMesh, babylonDrawMode, assign) {
  57040. var _this = this;
  57041. return this._loadExtensionAsync(context, material, function () {
  57042. material._babylonData = material._babylonData || {};
  57043. var babylonData = material._babylonData[babylonDrawMode];
  57044. if (!babylonData) {
  57045. var name_1 = material.name || "materialUnlit_" + material._index;
  57046. var babylonMaterial = _this._loader._createMaterial(name_1, babylonDrawMode);
  57047. babylonMaterial.unlit = true;
  57048. var promise = _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  57049. _this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  57050. babylonData = {
  57051. material: babylonMaterial,
  57052. meshes: [],
  57053. loaded: promise
  57054. };
  57055. material._babylonData[babylonDrawMode] = babylonData;
  57056. }
  57057. babylonData.meshes.push(babylonMesh);
  57058. assign(babylonData.material);
  57059. return babylonData.loaded;
  57060. });
  57061. };
  57062. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  57063. var promises = new Array();
  57064. // Ensure metallic workflow
  57065. babylonMaterial.metallic = 1;
  57066. babylonMaterial.roughness = 1;
  57067. var properties = material.pbrMetallicRoughness;
  57068. if (properties) {
  57069. if (properties.baseColorFactor) {
  57070. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.baseColorFactor);
  57071. babylonMaterial.alpha = properties.baseColorFactor[3];
  57072. }
  57073. else {
  57074. babylonMaterial.albedoColor = BABYLON.Color3.White();
  57075. }
  57076. if (properties.baseColorTexture) {
  57077. promises.push(this._loader._loadTextureAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  57078. babylonMaterial.albedoTexture = texture;
  57079. }));
  57080. }
  57081. }
  57082. if (material.doubleSided) {
  57083. babylonMaterial.backFaceCulling = false;
  57084. babylonMaterial.twoSidedLighting = true;
  57085. }
  57086. this._loader._loadMaterialAlphaProperties(context, material, babylonMaterial);
  57087. return Promise.all(promises).then(function () { });
  57088. };
  57089. return KHR_materials_unlit;
  57090. }(GLTF2.GLTFLoaderExtension));
  57091. Extensions.KHR_materials_unlit = KHR_materials_unlit;
  57092. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  57093. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  57094. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  57095. })(BABYLON || (BABYLON = {}));
  57096. //# sourceMappingURL=KHR_materials_unlit.js.map
  57097. var BABYLON;
  57098. (function (BABYLON) {
  57099. var GLTF2;
  57100. (function (GLTF2) {
  57101. var Extensions;
  57102. (function (Extensions) {
  57103. var NAME = "KHR_lights";
  57104. var LightType;
  57105. (function (LightType) {
  57106. LightType["AMBIENT"] = "ambient";
  57107. LightType["DIRECTIONAL"] = "directional";
  57108. LightType["POINT"] = "point";
  57109. LightType["SPOT"] = "spot";
  57110. })(LightType || (LightType = {}));
  57111. /**
  57112. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  57113. */
  57114. var KHR_lights = /** @class */ (function (_super) {
  57115. __extends(KHR_lights, _super);
  57116. function KHR_lights() {
  57117. var _this = _super !== null && _super.apply(this, arguments) || this;
  57118. _this.name = NAME;
  57119. return _this;
  57120. }
  57121. KHR_lights.prototype._loadSceneAsync = function (context, scene) {
  57122. var _this = this;
  57123. return this._loadExtensionAsync(context, scene, function (extensionContext, extension) {
  57124. var promise = _this._loader._loadSceneAsync(extensionContext, scene);
  57125. var light = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._lights, extension.light);
  57126. if (light.type !== LightType.AMBIENT) {
  57127. throw new Error(extensionContext + ": Only ambient lights are allowed on a scene");
  57128. }
  57129. _this._loader._babylonScene.ambientColor = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.Black();
  57130. return promise;
  57131. });
  57132. };
  57133. KHR_lights.prototype._loadNodeAsync = function (context, node) {
  57134. var _this = this;
  57135. return this._loadExtensionAsync(context, node, function (extensionContext, extension) {
  57136. var promise = _this._loader._loadNodeAsync(extensionContext, node);
  57137. var babylonLight;
  57138. var light = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._lights, extension.light);
  57139. var name = node._babylonMesh.name;
  57140. switch (light.type) {
  57141. case LightType.AMBIENT: {
  57142. throw new Error(extensionContext + ": Ambient lights are not allowed on a node");
  57143. }
  57144. case LightType.DIRECTIONAL: {
  57145. babylonLight = new BABYLON.DirectionalLight(name, BABYLON.Vector3.Forward(), _this._loader._babylonScene);
  57146. break;
  57147. }
  57148. case LightType.POINT: {
  57149. babylonLight = new BABYLON.PointLight(name, BABYLON.Vector3.Zero(), _this._loader._babylonScene);
  57150. break;
  57151. }
  57152. case LightType.SPOT: {
  57153. var spotLight = light;
  57154. // TODO: support inner and outer cone angles
  57155. //const innerConeAngle = spotLight.innerConeAngle || 0;
  57156. var outerConeAngle = spotLight.outerConeAngle || Math.PI / 4;
  57157. babylonLight = new BABYLON.SpotLight(name, BABYLON.Vector3.Zero(), BABYLON.Vector3.Forward(), outerConeAngle, 2, _this._loader._babylonScene);
  57158. break;
  57159. }
  57160. default: {
  57161. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  57162. }
  57163. }
  57164. babylonLight.diffuse = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.White();
  57165. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  57166. babylonLight.parent = node._babylonMesh;
  57167. return promise;
  57168. });
  57169. };
  57170. Object.defineProperty(KHR_lights.prototype, "_lights", {
  57171. get: function () {
  57172. var extensions = this._loader._gltf.extensions;
  57173. if (!extensions || !extensions[this.name]) {
  57174. throw new Error("#/extensions: '" + this.name + "' not found");
  57175. }
  57176. var extension = extensions[this.name];
  57177. return extension.lights;
  57178. },
  57179. enumerable: true,
  57180. configurable: true
  57181. });
  57182. return KHR_lights;
  57183. }(GLTF2.GLTFLoaderExtension));
  57184. Extensions.KHR_lights = KHR_lights;
  57185. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_lights(loader); });
  57186. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  57187. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  57188. })(BABYLON || (BABYLON = {}));
  57189. var BABYLON;
  57190. (function (BABYLON) {
  57191. var GLTF2;
  57192. (function (GLTF2) {
  57193. var Extensions;
  57194. (function (Extensions) {
  57195. var NAME = "KHR_texture_transform";
  57196. /**
  57197. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  57198. */
  57199. var KHR_texture_transform = /** @class */ (function (_super) {
  57200. __extends(KHR_texture_transform, _super);
  57201. function KHR_texture_transform() {
  57202. var _this = _super !== null && _super.apply(this, arguments) || this;
  57203. _this.name = NAME;
  57204. return _this;
  57205. }
  57206. KHR_texture_transform.prototype._loadTextureAsync = function (context, textureInfo, assign) {
  57207. var _this = this;
  57208. return this._loadExtensionAsync(context, textureInfo, function (extensionContext, extension) {
  57209. return _this._loader._loadTextureAsync(context, textureInfo, function (babylonTexture) {
  57210. if (extension.offset) {
  57211. babylonTexture.uOffset = extension.offset[0];
  57212. babylonTexture.vOffset = extension.offset[1];
  57213. }
  57214. // Always rotate around the origin.
  57215. babylonTexture.uRotationCenter = 0;
  57216. babylonTexture.vRotationCenter = 0;
  57217. if (extension.rotation) {
  57218. babylonTexture.wAng = -extension.rotation;
  57219. }
  57220. if (extension.scale) {
  57221. babylonTexture.uScale = extension.scale[0];
  57222. babylonTexture.vScale = extension.scale[1];
  57223. }
  57224. if (extension.texCoord != undefined) {
  57225. babylonTexture.coordinatesIndex = extension.texCoord;
  57226. }
  57227. assign(babylonTexture);
  57228. });
  57229. });
  57230. };
  57231. return KHR_texture_transform;
  57232. }(GLTF2.GLTFLoaderExtension));
  57233. Extensions.KHR_texture_transform = KHR_texture_transform;
  57234. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_texture_transform(loader); });
  57235. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  57236. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  57237. })(BABYLON || (BABYLON = {}));
  57238. return BABYLON;
  57239. });
  57240. /***/ }),
  57241. /* 15 */
  57242. /***/ (function(module, exports, __webpack_require__) {
  57243. module.exports = __webpack_require__(16);
  57244. /***/ }),
  57245. /* 16 */
  57246. /***/ (function(module, exports, __webpack_require__) {
  57247. "use strict";
  57248. function __export(m) {
  57249. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  57250. }
  57251. Object.defineProperty(exports, "__esModule", { value: true });
  57252. var mappers_1 = __webpack_require__(3);
  57253. exports.mapperManager = mappers_1.mapperManager;
  57254. var globals_1 = __webpack_require__(4);
  57255. exports.viewerGlobals = globals_1.viewerGlobals;
  57256. var viewerManager_1 = __webpack_require__(7);
  57257. exports.viewerManager = viewerManager_1.viewerManager;
  57258. var defaultViewer_1 = __webpack_require__(8);
  57259. exports.DefaultViewer = defaultViewer_1.DefaultViewer;
  57260. var viewer_1 = __webpack_require__(9);
  57261. exports.AbstractViewer = viewer_1.AbstractViewer;
  57262. var telemetryManager_1 = __webpack_require__(6);
  57263. exports.telemetryManager = telemetryManager_1.telemetryManager;
  57264. var modelLoader_1 = __webpack_require__(13);
  57265. exports.ModelLoader = modelLoader_1.ModelLoader;
  57266. var viewerModel_1 = __webpack_require__(5);
  57267. exports.ViewerModel = viewerModel_1.ViewerModel;
  57268. exports.ModelState = viewerModel_1.ModelState;
  57269. /**
  57270. * BabylonJS Viewer
  57271. *
  57272. * An HTML-Based viewer for 3D models, based on BabylonJS and its extensions.
  57273. */
  57274. var BABYLON = __webpack_require__(0);
  57275. exports.BABYLON = BABYLON;
  57276. // load needed modules.
  57277. __webpack_require__(14);
  57278. __webpack_require__(64);
  57279. var initializer_1 = __webpack_require__(65);
  57280. exports.InitTags = initializer_1.InitTags;
  57281. // promise polyfill, if needed!
  57282. BABYLON.PromisePolyfill.Apply();
  57283. initializer_1.initListeners();
  57284. //deprectaed, here for backwards compatibility
  57285. var disableInit = globals_1.viewerGlobals.disableInit;
  57286. exports.disableInit = disableInit;
  57287. /**
  57288. * Dispose all viewers currently registered
  57289. */
  57290. function disposeAll() {
  57291. viewerManager_1.viewerManager.dispose();
  57292. mappers_1.mapperManager.dispose();
  57293. telemetryManager_1.telemetryManager.dispose();
  57294. }
  57295. exports.disposeAll = disposeAll;
  57296. var Version = globals_1.viewerGlobals.version;
  57297. exports.Version = Version;
  57298. console.log("Babylon.js viewer (v" + Version + ")");
  57299. // export publicliy all configuration interfaces
  57300. __export(__webpack_require__(10));
  57301. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtREFBd0Q7QUE4Q3lFLHdCQTlDeEgsdUJBQWEsQ0E4Q3dIO0FBN0M5SSxtREFBd0Q7QUE2Q1ksd0JBN0MzRCx1QkFBYSxDQTZDMkQ7QUE1Q2pGLHdEQUF1RDtBQTRDMkQsd0JBNUN6Ryw2QkFBYSxDQTRDeUc7QUEzQy9ILHdEQUF1RDtBQTJDbEIsd0JBM0M1Qiw2QkFBYSxDQTJDNEI7QUExQ2xELDBDQUFpRDtBQTBDRyx5QkExQzNDLHVCQUFjLENBMEMyQztBQXpDbEUsZ0VBQStEO0FBeUNvQiwyQkF6QzFFLG1DQUFnQixDQXlDMEU7QUF4Q25HLG9EQUFtRDtBQXdDeUcsc0JBeENuSix5QkFBVyxDQXdDbUo7QUF2Q3ZLLG1EQUE4RDtBQXVDMkcsc0JBdkNoSyx5QkFBVyxDQXVDZ0s7QUFBcUMscUJBdkNuTSx3QkFBVSxDQXVDbU07QUFuQ25POzs7O0dBSUc7QUFFSCxtQ0FBcUM7QUE2QjVCLDBCQUFPO0FBM0JoQix1QkFBdUI7QUFDdkIsNkJBQTJCO0FBQzNCLGlCQUFlO0FBRWYsNkNBQXdEO0FBdUI3QixtQkF2Qkgsc0JBQVEsQ0F1Qkc7QUFyQm5DLCtCQUErQjtBQUMvQixPQUFPLENBQUMsZUFBZSxDQUFDLEtBQUssRUFBRSxDQUFDO0FBQ2hDLDJCQUFhLEVBQUUsQ0FBQztBQUVoQiw4Q0FBOEM7QUFDOUMsSUFBSSxXQUFXLEdBQVksdUJBQWEsQ0FBQyxXQUFXLENBQUM7QUFnQmdELGtDQUFXO0FBZGhIOztHQUVHO0FBQ0g7SUFDSSw2QkFBYSxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ3hCLHVCQUFhLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDeEIsbUNBQWdCLENBQUMsT0FBTyxFQUFFLENBQUM7QUFDL0IsQ0FBQztBQU8rSSxnQ0FBVTtBQUwxSixJQUFNLE9BQU8sR0FBRyx1QkFBYSxDQUFDLE9BQU8sQ0FBQztBQUtwQiwwQkFBTztBQUh6QixPQUFPLENBQUMsR0FBRyxDQUFDLHNCQUFzQixHQUFHLE9BQU8sR0FBRyxHQUFHLENBQUMsQ0FBQztBQUlwRCxnREFBZ0Q7QUFDaEQscUNBQWdDIn0=
  57302. /***/ }),
  57303. /* 17 */
  57304. /***/ (function(module, exports) {
  57305. var g;
  57306. // This works in non-strict mode
  57307. g = (function() {
  57308. return this;
  57309. })();
  57310. try {
  57311. // This works if eval is allowed (see CSP)
  57312. g = g || Function("return this")() || (1,eval)("this");
  57313. } catch(e) {
  57314. // This works if the window reference is available
  57315. if(typeof window === "object")
  57316. g = window;
  57317. }
  57318. // g can still be undefined, but nothing to do about it...
  57319. // We return undefined, instead of nothing here, so it's
  57320. // easier to handle this case. if(!global) { ...}
  57321. module.exports = g;
  57322. /***/ }),
  57323. /* 18 */
  57324. /***/ (function(module, exports) {
  57325. if(typeof CANNON === 'undefined') {var e = new Error("Cannot find module \"CANNON\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
  57326. module.exports = CANNON;
  57327. /***/ }),
  57328. /* 19 */
  57329. /***/ (function(module, exports) {
  57330. if(typeof OIMO === 'undefined') {var e = new Error("Cannot find module \"OIMO\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
  57331. module.exports = OIMO;
  57332. /***/ }),
  57333. /* 20 */
  57334. /***/ (function(module, exports) {
  57335. if(typeof earcut === 'undefined') {var e = new Error("Cannot find module \"earcut\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
  57336. module.exports = earcut;
  57337. /***/ }),
  57338. /* 21 */
  57339. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  57340. "use strict";
  57341. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  57342. var isMergeableObject = function isMergeableObject(value) {
  57343. return isNonNullObject(value)
  57344. && !isSpecial(value)
  57345. };
  57346. function isNonNullObject(value) {
  57347. return !!value && typeof value === 'object'
  57348. }
  57349. function isSpecial(value) {
  57350. var stringValue = Object.prototype.toString.call(value);
  57351. return stringValue === '[object RegExp]'
  57352. || stringValue === '[object Date]'
  57353. || isReactElement(value)
  57354. }
  57355. // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
  57356. var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
  57357. var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
  57358. function isReactElement(value) {
  57359. return value.$$typeof === REACT_ELEMENT_TYPE
  57360. }
  57361. function emptyTarget(val) {
  57362. return Array.isArray(val) ? [] : {}
  57363. }
  57364. function cloneUnlessOtherwiseSpecified(value, options) {
  57365. return (options.clone !== false && options.isMergeableObject(value))
  57366. ? deepmerge(emptyTarget(value), value, options)
  57367. : value
  57368. }
  57369. function defaultArrayMerge(target, source, options) {
  57370. return target.concat(source).map(function(element) {
  57371. return cloneUnlessOtherwiseSpecified(element, options)
  57372. })
  57373. }
  57374. function mergeObject(target, source, options) {
  57375. var destination = {};
  57376. if (options.isMergeableObject(target)) {
  57377. Object.keys(target).forEach(function(key) {
  57378. destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
  57379. });
  57380. }
  57381. Object.keys(source).forEach(function(key) {
  57382. if (!options.isMergeableObject(source[key]) || !target[key]) {
  57383. destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
  57384. } else {
  57385. destination[key] = deepmerge(target[key], source[key], options);
  57386. }
  57387. });
  57388. return destination
  57389. }
  57390. function deepmerge(target, source, options) {
  57391. options = options || {};
  57392. options.arrayMerge = options.arrayMerge || defaultArrayMerge;
  57393. options.isMergeableObject = options.isMergeableObject || isMergeableObject;
  57394. var sourceIsArray = Array.isArray(source);
  57395. var targetIsArray = Array.isArray(target);
  57396. var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
  57397. if (!sourceAndTargetTypesMatch) {
  57398. return cloneUnlessOtherwiseSpecified(source, options)
  57399. } else if (sourceIsArray) {
  57400. return options.arrayMerge(target, source, options)
  57401. } else {
  57402. return mergeObject(target, source, options)
  57403. }
  57404. }
  57405. deepmerge.all = function deepmergeAll(array, options) {
  57406. if (!Array.isArray(array)) {
  57407. throw new Error('first argument should be an array')
  57408. }
  57409. return array.reduce(function(prev, next) {
  57410. return deepmerge(prev, next, options)
  57411. }, {})
  57412. };
  57413. var deepmerge_1 = deepmerge;
  57414. /* harmony default export */ __webpack_exports__["default"] = (deepmerge_1);
  57415. /***/ }),
  57416. /* 22 */
  57417. /***/ (function(module, exports, __webpack_require__) {
  57418. "use strict";
  57419. Object.defineProperty(exports, "__esModule", { value: true });
  57420. var babylonjs_1 = __webpack_require__(0);
  57421. var configuration_1 = __webpack_require__(10);
  57422. var viewerModel_1 = __webpack_require__(5);
  57423. var helper_1 = __webpack_require__(1);
  57424. var viewerLabs_1 = __webpack_require__(24);
  57425. var _1 = __webpack_require__(26);
  57426. var SceneManager = /** @class */ (function () {
  57427. function SceneManager(_engine, _configurationContainer, _observablesManager) {
  57428. var _this = this;
  57429. this._engine = _engine;
  57430. this._configurationContainer = _configurationContainer;
  57431. this._observablesManager = _observablesManager;
  57432. this._animationBlendingEnabled = true;
  57433. this._white = babylonjs_1.Color3.White();
  57434. this._forceShadowUpdate = false;
  57435. this._processShadows = true;
  57436. this._groundEnabled = true;
  57437. this._groundMirrorEnabled = true;
  57438. this._defaultRenderingPipelineEnabled = false;
  57439. this._globalConfiguration = {};
  57440. this._defaultRenderingPipelineShouldBuild = true;
  57441. // default from rendering pipeline
  57442. this._bloomEnabled = false;
  57443. // default from rendering pipeline
  57444. this._fxaaEnabled = false;
  57445. this._focusOnModel = function (model) {
  57446. var boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
  57447. var sizeVec = boundingInfo.max.subtract(boundingInfo.min);
  57448. var halfSizeVec = sizeVec.scale(0.5);
  57449. var center = boundingInfo.min.add(halfSizeVec);
  57450. _this.camera.setTarget(center);
  57451. _this.camera.alpha = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.alpha) || _this.camera.alpha;
  57452. _this.camera.beta = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.beta) || _this.camera.beta;
  57453. _this.camera.radius = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.radius) || _this.camera.radius;
  57454. /*this.scene.lights.filter(light => light instanceof ShadowLight).forEach(light => {
  57455. // casting ais safe, due to the constraints tested before
  57456. (<ShadowLight>light).setDirectionToTarget(center);
  57457. });*/
  57458. };
  57459. this._cameraBehaviorMapping = {};
  57460. this.models = [];
  57461. this.onCameraConfiguredObservable = new babylonjs_1.Observable();
  57462. this.onLightsConfiguredObservable = new babylonjs_1.Observable();
  57463. this.onModelsConfiguredObservable = new babylonjs_1.Observable();
  57464. this.onSceneConfiguredObservable = new babylonjs_1.Observable();
  57465. this.onSceneInitObservable = new babylonjs_1.Observable();
  57466. this.onSceneOptimizerConfiguredObservable = new babylonjs_1.Observable();
  57467. this.onEnvironmentConfiguredObservable = new babylonjs_1.Observable();
  57468. //this._viewer.onEngineInitObservable.add(() => {
  57469. this._handleHardwareLimitations();
  57470. //});
  57471. this.onSceneInitObservable.add(function (scene) {
  57472. _this.scene.animationPropertiesOverride = _this.scene.animationPropertiesOverride || new babylonjs_1.AnimationPropertiesOverride();
  57473. _this.labs = new viewerLabs_1.ViewerLabs(scene);
  57474. var updateShadows = function () {
  57475. for (var _i = 0, _a = _this.scene.lights; _i < _a.length; _i++) {
  57476. var light = _a[_i];
  57477. var generator = light.getShadowGenerator();
  57478. if (generator) {
  57479. // Processing shadows if animates
  57480. var shadowMap = generator.getShadowMap();
  57481. if (shadowMap) {
  57482. shadowMap.refreshRate = babylonjs_1.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
  57483. }
  57484. }
  57485. }
  57486. };
  57487. scene.registerBeforeRender(function () {
  57488. if (_this._forceShadowUpdate || (scene.animatables && scene.animatables.length > 0)) {
  57489. // make sure all models are loaded
  57490. updateShadows();
  57491. _this._forceShadowUpdate = false;
  57492. }
  57493. else if (!(_this.models.every(function (model) {
  57494. if (!model.shadowsRenderedAfterLoad) {
  57495. model.shadowsRenderedAfterLoad = true;
  57496. return false;
  57497. }
  57498. return model.state === viewerModel_1.ModelState.COMPLETE && !model.currentAnimation;
  57499. }))) {
  57500. updateShadows();
  57501. }
  57502. });
  57503. return _this._observablesManager && _this._observablesManager.onSceneInitObservable.notifyObserversWithPromise(_this.scene);
  57504. });
  57505. if (this._observablesManager) {
  57506. this._observablesManager.onModelLoadedObservable.add(function (model) {
  57507. for (var _i = 0, _a = _this.scene.lights; _i < _a.length; _i++) {
  57508. var light = _a[_i];
  57509. var generator = light.getShadowGenerator();
  57510. if (generator) {
  57511. // Processing shadows if animates
  57512. var shadowMap = generator.getShadowMap();
  57513. if (shadowMap) {
  57514. shadowMap.refreshRate = babylonjs_1.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
  57515. }
  57516. }
  57517. }
  57518. _this._focusOnModel(model);
  57519. });
  57520. this._observablesManager.onModelAddedObservable.add(function (model) {
  57521. _this.models.push(model);
  57522. });
  57523. this._observablesManager.onModelRemovedObservable.add(function (model) {
  57524. _this.models.splice(_this.models.indexOf(model), 1);
  57525. });
  57526. }
  57527. }
  57528. Object.defineProperty(SceneManager.prototype, "defaultRenderingPipeline", {
  57529. get: function () {
  57530. return this._defaultRenderingPipeline;
  57531. },
  57532. enumerable: true,
  57533. configurable: true
  57534. });
  57535. Object.defineProperty(SceneManager.prototype, "isHdrSupported", {
  57536. /**
  57537. * Returns a boolean representing HDR support
  57538. */
  57539. get: function () {
  57540. return this._hdrSupport;
  57541. },
  57542. enumerable: true,
  57543. configurable: true
  57544. });
  57545. Object.defineProperty(SceneManager.prototype, "mainColor", {
  57546. /**
  57547. * Return the main color defined in the configuration.
  57548. */
  57549. get: function () {
  57550. return this._configurationContainer.mainColor;
  57551. },
  57552. enumerable: true,
  57553. configurable: true
  57554. });
  57555. Object.defineProperty(SceneManager.prototype, "reflectionColor", {
  57556. get: function () {
  57557. return this._configurationContainer.reflectionColor;
  57558. },
  57559. enumerable: true,
  57560. configurable: true
  57561. });
  57562. Object.defineProperty(SceneManager.prototype, "animationBlendingEnabled", {
  57563. get: function () {
  57564. return this.scene && this.scene.animationPropertiesOverride.enableBlending;
  57565. },
  57566. set: function (value) {
  57567. this.scene.animationPropertiesOverride.enableBlending = value;
  57568. },
  57569. enumerable: true,
  57570. configurable: true
  57571. });
  57572. Object.defineProperty(SceneManager.prototype, "observablesManager", {
  57573. get: function () {
  57574. return this._observablesManager;
  57575. },
  57576. enumerable: true,
  57577. configurable: true
  57578. });
  57579. Object.defineProperty(SceneManager.prototype, "processShadows", {
  57580. /**
  57581. * The flag defining whether shadows are rendered constantly or once.
  57582. */
  57583. get: function () {
  57584. return this._processShadows;
  57585. },
  57586. /**
  57587. * Should shadows be rendered every frame, or only once and stop.
  57588. * This can be used to optimize a scene.
  57589. *
  57590. * Not that the shadows will NOT disapear but will remain in place.
  57591. * @param process if true shadows will be updated once every frame. if false they will stop being updated.
  57592. */
  57593. set: function (process) {
  57594. var refreshType = process ? babylonjs_1.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME : babylonjs_1.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
  57595. for (var _i = 0, _a = this.scene.lights; _i < _a.length; _i++) {
  57596. var light = _a[_i];
  57597. var generator = light.getShadowGenerator();
  57598. if (generator) {
  57599. var shadowMap = generator.getShadowMap();
  57600. if (shadowMap) {
  57601. shadowMap.refreshRate = refreshType;
  57602. }
  57603. }
  57604. }
  57605. this._processShadows = process;
  57606. },
  57607. enumerable: true,
  57608. configurable: true
  57609. });
  57610. Object.defineProperty(SceneManager.prototype, "groundEnabled", {
  57611. get: function () {
  57612. return this._groundEnabled;
  57613. },
  57614. set: function (newValue) {
  57615. if (newValue === this._groundEnabled)
  57616. return;
  57617. this._groundEnabled = newValue;
  57618. if (this.environmentHelper && this.environmentHelper.ground) {
  57619. this.environmentHelper.ground.setEnabled(this._groundEnabled);
  57620. }
  57621. },
  57622. enumerable: true,
  57623. configurable: true
  57624. });
  57625. Object.defineProperty(SceneManager.prototype, "groundMirrorEnabled", {
  57626. /**
  57627. * gets wether the reflection is disabled.
  57628. */
  57629. get: function () {
  57630. return this._groundMirrorEnabled;
  57631. },
  57632. /**
  57633. * sets wether the reflection is disabled.
  57634. */
  57635. set: function (value) {
  57636. if (this._groundMirrorEnabled === value) {
  57637. return;
  57638. }
  57639. this._groundMirrorEnabled = value;
  57640. if (this.environmentHelper && this.environmentHelper.groundMaterial && this.environmentHelper.groundMirror) {
  57641. if (!value) {
  57642. this.environmentHelper.groundMaterial.reflectionTexture = null;
  57643. }
  57644. else {
  57645. this.environmentHelper.groundMaterial.reflectionTexture = this.environmentHelper.groundMirror;
  57646. }
  57647. }
  57648. },
  57649. enumerable: true,
  57650. configurable: true
  57651. });
  57652. Object.defineProperty(SceneManager.prototype, "defaultRenderingPipelineEnabled", {
  57653. get: function () {
  57654. return this._defaultRenderingPipelineEnabled;
  57655. },
  57656. set: function (value) {
  57657. if (value === this._defaultRenderingPipelineEnabled) {
  57658. return;
  57659. }
  57660. this._defaultRenderingPipelineEnabled = value;
  57661. this._rebuildPostprocesses();
  57662. if (this._defaultRenderingPipeline) {
  57663. this._defaultRenderingPipelineShouldBuild = false;
  57664. this._defaultRenderingPipeline.prepare();
  57665. this.scene.imageProcessingConfiguration.applyByPostProcess = true;
  57666. }
  57667. },
  57668. enumerable: true,
  57669. configurable: true
  57670. });
  57671. /**
  57672. * Sets the engine flags to unlock all babylon features.
  57673. * Can also be configured using the scene.flags configuration object
  57674. */
  57675. SceneManager.prototype.unlockBabylonFeatures = function () {
  57676. this.scene.shadowsEnabled = true;
  57677. this.scene.particlesEnabled = true;
  57678. this.scene.postProcessesEnabled = true;
  57679. this.scene.collisionsEnabled = true;
  57680. this.scene.lightsEnabled = true;
  57681. this.scene.texturesEnabled = true;
  57682. this.scene.lensFlaresEnabled = true;
  57683. this.scene.proceduralTexturesEnabled = true;
  57684. this.scene.renderTargetsEnabled = true;
  57685. this.scene.spritesEnabled = true;
  57686. this.scene.skeletonsEnabled = true;
  57687. this.scene.audioEnabled = true;
  57688. };
  57689. /**
  57690. * initialize the scene. Calling this function again will dispose the old scene, if exists.
  57691. */
  57692. SceneManager.prototype.initScene = function (sceneConfiguration, optimizerConfiguration) {
  57693. if (sceneConfiguration === void 0) { sceneConfiguration = {}; }
  57694. // if the scen exists, dispose it.
  57695. if (this.scene) {
  57696. this.scene.dispose();
  57697. }
  57698. // create a new scene
  57699. this.scene = new babylonjs_1.Scene(this._engine);
  57700. // set a default PBR material
  57701. if (!sceneConfiguration.defaultMaterial) {
  57702. var defaultMaterial = new BABYLON.PBRMaterial('defaultMaterial', this.scene);
  57703. defaultMaterial.reflectivityColor = new BABYLON.Color3(0.1, 0.1, 0.1);
  57704. defaultMaterial.microSurface = 0.6;
  57705. if (this.scene.defaultMaterial) {
  57706. this.scene.defaultMaterial.dispose();
  57707. }
  57708. this.scene.defaultMaterial = defaultMaterial;
  57709. }
  57710. this.scene.animationPropertiesOverride = new babylonjs_1.AnimationPropertiesOverride();
  57711. babylonjs_1.Animation.AllowMatricesInterpolation = true;
  57712. /*if (sceneConfiguration.glow) {
  57713. let options: Partial<IGlowLayerOptions> = {
  57714. mainTextureFixedSize: 512
  57715. };
  57716. if (typeof sceneConfiguration.glow === 'object') {
  57717. options = sceneConfiguration.glow
  57718. }
  57719. var gl = new BABYLON.GlowLayer("glow", this.scene, options);
  57720. }*/
  57721. return this.onSceneInitObservable.notifyObserversWithPromise(this.scene);
  57722. };
  57723. SceneManager.prototype.clearScene = function (clearModels, clearLights) {
  57724. if (clearModels === void 0) { clearModels = true; }
  57725. if (clearLights === void 0) { clearLights = false; }
  57726. if (clearModels) {
  57727. this.models.forEach(function (m) { return m.dispose(); });
  57728. this.models.length = 0;
  57729. }
  57730. if (clearLights) {
  57731. this.scene.lights.forEach(function (l) { return l.dispose(); });
  57732. }
  57733. };
  57734. /**
  57735. * This will update the scene's configuration, including camera, lights, environment.
  57736. * @param newConfiguration the delta that should be configured. This includes only the changes
  57737. * @param globalConfiguration The global configuration object, after the new configuration was merged into it
  57738. */
  57739. SceneManager.prototype.updateConfiguration = function (newConfiguration) {
  57740. var _this = this;
  57741. if (this._configurationContainer) {
  57742. this._globalConfiguration = this._configurationContainer.configuration;
  57743. }
  57744. else {
  57745. this._globalConfiguration = newConfiguration;
  57746. }
  57747. if (newConfiguration.lab) {
  57748. if (newConfiguration.lab.assetsRootURL) {
  57749. this.labs.assetsRootURL = newConfiguration.lab.assetsRootURL;
  57750. }
  57751. }
  57752. // update scene configuration
  57753. if (newConfiguration.scene) {
  57754. this._configureScene(newConfiguration.scene);
  57755. }
  57756. // optimizer
  57757. if (newConfiguration.optimizer !== undefined) {
  57758. this._configureOptimizer(newConfiguration.optimizer);
  57759. }
  57760. // configure model
  57761. /*if (newConfiguration.model && typeof newConfiguration.model === 'object') {
  57762. this._configureModel(newConfiguration.model);
  57763. }*/
  57764. // lights
  57765. this._configureLights(newConfiguration.lights);
  57766. // environment
  57767. if (newConfiguration.skybox !== undefined || newConfiguration.ground !== undefined) {
  57768. this._configureEnvironment(newConfiguration.skybox, newConfiguration.ground);
  57769. }
  57770. // camera
  57771. this._configureCamera(newConfiguration.camera);
  57772. if (newConfiguration.lab) {
  57773. if (newConfiguration.lab.environmentMap) {
  57774. var rot_1 = newConfiguration.lab.environmentMap.rotationY;
  57775. this.labs.loadEnvironment(newConfiguration.lab.environmentMap.texture, function () {
  57776. _this.labs.applyEnvironmentMapConfiguration(rot_1);
  57777. });
  57778. if (!newConfiguration.lab.environmentMap.texture && newConfiguration.lab.environmentMap.rotationY) {
  57779. this.labs.applyEnvironmentMapConfiguration(newConfiguration.lab.environmentMap.rotationY);
  57780. }
  57781. }
  57782. // rendering piplines
  57783. if (newConfiguration.lab.defaultRenderingPipelines) {
  57784. var pipelineConfig = newConfiguration.lab.defaultRenderingPipelines;
  57785. if (typeof pipelineConfig === 'boolean') {
  57786. this.defaultRenderingPipelineEnabled = pipelineConfig;
  57787. }
  57788. else {
  57789. this.defaultRenderingPipelineEnabled = true;
  57790. }
  57791. }
  57792. if (newConfiguration.lab.environmentMainColor) {
  57793. var mainColor = new babylonjs_1.Color3().copyFrom(newConfiguration.lab.environmentMainColor);
  57794. this.environmentHelper.setMainColor(mainColor);
  57795. }
  57796. if (newConfiguration.lab.globalLightRotation !== undefined) {
  57797. // rotate all lights that are shadow lights
  57798. this.scene.lights.filter(function (light) { return light instanceof babylonjs_1.ShadowLight; }).forEach(function (light) {
  57799. // casting and '!' are safe, due to the constraints tested before
  57800. _this.labs.rotateShadowLight(light, newConfiguration.lab.globalLightRotation);
  57801. });
  57802. this._forceShadowUpdate = true;
  57803. }
  57804. }
  57805. if (this._defaultRenderingPipeline && this._defaultRenderingPipeline.imageProcessing) {
  57806. this._defaultRenderingPipeline.imageProcessing.fromLinearSpace = true;
  57807. }
  57808. if (this._defaultRenderingPipelineShouldBuild && this._defaultRenderingPipeline) {
  57809. this._defaultRenderingPipelineShouldBuild = false;
  57810. this._defaultRenderingPipeline.prepare();
  57811. }
  57812. };
  57813. SceneManager.prototype._rebuildPostprocesses = function (configuration) {
  57814. if (!this._defaultRenderingPipelineEnabled || !configuration_1.getConfigurationKey("scene.imageProcessingConfiguration.isEnabled", this._globalConfiguration)) {
  57815. if (this._defaultRenderingPipeline) {
  57816. this._defaultRenderingPipeline.dispose();
  57817. this._defaultRenderingPipeline = null;
  57818. this.scene.autoClearDepthAndStencil = true;
  57819. this.scene.autoClear = true;
  57820. this.scene.imageProcessingConfiguration.applyByPostProcess = false;
  57821. }
  57822. return;
  57823. }
  57824. var pipelineConfig = configuration || (this._globalConfiguration.lab && this._globalConfiguration.lab.defaultRenderingPipelines);
  57825. if (pipelineConfig) {
  57826. if (!this._defaultRenderingPipeline) {
  57827. // Create pipeline in manual mode to avoid triggering multiple shader compilations
  57828. this._defaultRenderingPipeline = new babylonjs_1.DefaultRenderingPipeline("default rendering pipeline", this._hdrSupport, this.scene, [this.camera], false);
  57829. }
  57830. this.scene.autoClear = false;
  57831. this.scene.autoClearDepthAndStencil = false;
  57832. this._defaultRenderingPipelineShouldBuild = true;
  57833. var bloomEnabled = this._bloomEnabled;
  57834. if (typeof pipelineConfig !== 'boolean') {
  57835. helper_1.extendClassWithConfig(this._defaultRenderingPipeline, pipelineConfig);
  57836. this._bloomEnabled = !!pipelineConfig.bloomEnabled;
  57837. this._fxaaEnabled = !!pipelineConfig.fxaaEnabled;
  57838. bloomEnabled = this._bloomEnabled && pipelineConfig.bloomWeight !== undefined && pipelineConfig.bloomWeight > 0;
  57839. this._defaultRenderingPipeline.bloomWeight = (pipelineConfig.bloomWeight !== undefined && pipelineConfig.bloomWeight) || (this._defaultRenderingPipeline.bloomWeight);
  57840. }
  57841. this._defaultRenderingPipeline.bloomEnabled = bloomEnabled;
  57842. this._defaultRenderingPipeline.fxaaEnabled = this.fxaaEnabled;
  57843. }
  57844. };
  57845. Object.defineProperty(SceneManager.prototype, "bloomEnabled", {
  57846. get: function () {
  57847. return this._bloomEnabled;
  57848. },
  57849. set: function (value) {
  57850. if (this._bloomEnabled === value) {
  57851. return;
  57852. }
  57853. this._bloomEnabled = value;
  57854. this._rebuildPostprocesses();
  57855. if (this._defaultRenderingPipeline) {
  57856. this._defaultRenderingPipelineShouldBuild = false;
  57857. this._defaultRenderingPipeline.prepare();
  57858. this.scene.imageProcessingConfiguration.applyByPostProcess = true;
  57859. }
  57860. },
  57861. enumerable: true,
  57862. configurable: true
  57863. });
  57864. Object.defineProperty(SceneManager.prototype, "fxaaEnabled", {
  57865. get: function () {
  57866. return this._fxaaEnabled;
  57867. },
  57868. set: function (value) {
  57869. if (this._fxaaEnabled === value) {
  57870. return;
  57871. }
  57872. this._fxaaEnabled = value;
  57873. this._rebuildPostprocesses();
  57874. if (this._defaultRenderingPipeline) {
  57875. this._defaultRenderingPipelineShouldBuild = false;
  57876. this._defaultRenderingPipeline.prepare();
  57877. this.scene.imageProcessingConfiguration.applyByPostProcess = true;
  57878. }
  57879. },
  57880. enumerable: true,
  57881. configurable: true
  57882. });
  57883. /**
  57884. * internally configure the scene using the provided configuration.
  57885. * The scene will not be recreated, but just updated.
  57886. * @param sceneConfig the (new) scene configuration
  57887. */
  57888. SceneManager.prototype._configureScene = function (sceneConfig) {
  57889. // sanity check!
  57890. if (!this.scene) {
  57891. return;
  57892. }
  57893. var cc = sceneConfig.clearColor;
  57894. var oldcc = this.scene.clearColor;
  57895. if (cc) {
  57896. if (cc.r !== undefined) {
  57897. oldcc.r = cc.r;
  57898. }
  57899. if (cc.g !== undefined) {
  57900. oldcc.g = cc.g;
  57901. }
  57902. if (cc.b !== undefined) {
  57903. oldcc.b = cc.b;
  57904. }
  57905. if (cc.a !== undefined) {
  57906. oldcc.a = cc.a;
  57907. }
  57908. }
  57909. // image processing configuration - optional.
  57910. if (sceneConfig.imageProcessingConfiguration) {
  57911. helper_1.extendClassWithConfig(this.scene.imageProcessingConfiguration, sceneConfig.imageProcessingConfiguration);
  57912. }
  57913. //animation properties override
  57914. if (sceneConfig.animationPropertiesOverride) {
  57915. helper_1.extendClassWithConfig(this.scene.animationPropertiesOverride, sceneConfig.animationPropertiesOverride);
  57916. }
  57917. if (sceneConfig.environmentTexture) {
  57918. if (!(this.scene.environmentTexture && this.scene.environmentTexture.url === sceneConfig.environmentTexture)) {
  57919. if (this.scene.environmentTexture && this.scene.environmentTexture.dispose) {
  57920. this.scene.environmentTexture.dispose();
  57921. }
  57922. var environmentTexture = babylonjs_1.CubeTexture.CreateFromPrefilteredData(sceneConfig.environmentTexture, this.scene);
  57923. this.scene.environmentTexture = environmentTexture;
  57924. }
  57925. }
  57926. if (sceneConfig.debug === true) {
  57927. this.scene.debugLayer.show();
  57928. }
  57929. else if (sceneConfig.debug === false) {
  57930. if (this.scene.debugLayer.isVisible()) {
  57931. this.scene.debugLayer.hide();
  57932. }
  57933. }
  57934. if (sceneConfig.disableHdr) {
  57935. this._handleHardwareLimitations(false);
  57936. }
  57937. else {
  57938. this._handleHardwareLimitations(true);
  57939. }
  57940. if (sceneConfig.renderInBackground !== undefined) {
  57941. this._engine.renderEvenInBackground = !!sceneConfig.renderInBackground;
  57942. }
  57943. var canvas = this._engine.getRenderingCanvas();
  57944. if (canvas) {
  57945. if (this.camera && sceneConfig.disableCameraControl) {
  57946. this.camera.detachControl(canvas);
  57947. }
  57948. else if (this.camera && sceneConfig.disableCameraControl === false) {
  57949. this.camera.attachControl(canvas);
  57950. }
  57951. }
  57952. // process mainColor changes:
  57953. if (sceneConfig.mainColor) {
  57954. this._configurationContainer.mainColor = this.mainColor || babylonjs_1.Color3.White();
  57955. var mc = sceneConfig.mainColor;
  57956. if (mc.r !== undefined) {
  57957. this.mainColor.r = mc.r;
  57958. }
  57959. if (mc.g !== undefined) {
  57960. this.mainColor.g = mc.g;
  57961. }
  57962. if (mc.b !== undefined) {
  57963. this.mainColor.b = mc.b;
  57964. }
  57965. this.reflectionColor.copyFrom(this.mainColor);
  57966. var environmentTint = configuration_1.getConfigurationKey("lab.environmentMap.tintLevel", this._globalConfiguration) || 0;
  57967. // reflection color
  57968. this.reflectionColor.toLinearSpaceToRef(this.reflectionColor);
  57969. this.reflectionColor.scaleToRef(1 / this.scene.imageProcessingConfiguration.exposure, this.reflectionColor);
  57970. var tmpColor3 = babylonjs_1.Color3.Lerp(this._white, this.reflectionColor, environmentTint);
  57971. this.reflectionColor.copyFrom(tmpColor3);
  57972. //update the environment, if exists
  57973. if (this.environmentHelper) {
  57974. if (this.environmentHelper.groundMaterial) {
  57975. this.environmentHelper.groundMaterial._perceptualColor = this.mainColor;
  57976. }
  57977. if (this.environmentHelper.skyboxMaterial) {
  57978. this.environmentHelper.skyboxMaterial._perceptualColor = this.mainColor;
  57979. }
  57980. }
  57981. }
  57982. if (sceneConfig.defaultMaterial) {
  57983. var conf = sceneConfig.defaultMaterial;
  57984. if ((conf.materialType === 'standard' && this.scene.defaultMaterial.getClassName() !== 'StandardMaterial') ||
  57985. (conf.materialType === 'pbr' && this.scene.defaultMaterial.getClassName() !== 'PBRMaterial')) {
  57986. this.scene.defaultMaterial.dispose();
  57987. if (conf.materialType === 'standard') {
  57988. this.scene.defaultMaterial = new babylonjs_1.StandardMaterial("defaultMaterial", this.scene);
  57989. }
  57990. else {
  57991. this.scene.defaultMaterial = new babylonjs_1.PBRMaterial("defaultMaterial", this.scene);
  57992. }
  57993. }
  57994. helper_1.extendClassWithConfig(this.scene.defaultMaterial, conf);
  57995. }
  57996. if (sceneConfig.flags) {
  57997. helper_1.extendClassWithConfig(this.scene, sceneConfig.flags);
  57998. }
  57999. this.onSceneConfiguredObservable.notifyObservers({
  58000. sceneManager: this,
  58001. object: this.scene,
  58002. newConfiguration: sceneConfig
  58003. });
  58004. };
  58005. /**
  58006. * Configure the scene optimizer.
  58007. * The existing scene optimizer will be disposed and a new one will be created.
  58008. * @param optimizerConfig the (new) optimizer configuration
  58009. */
  58010. SceneManager.prototype._configureOptimizer = function (optimizerConfig) {
  58011. var _this = this;
  58012. if (typeof optimizerConfig === 'boolean') {
  58013. if (this.sceneOptimizer) {
  58014. this.sceneOptimizer.stop();
  58015. this.sceneOptimizer.dispose();
  58016. delete this.sceneOptimizer;
  58017. }
  58018. if (optimizerConfig) {
  58019. this.sceneOptimizer = new babylonjs_1.SceneOptimizer(this.scene);
  58020. this.sceneOptimizer.start();
  58021. }
  58022. }
  58023. else {
  58024. var optimizerOptions = new babylonjs_1.SceneOptimizerOptions(optimizerConfig.targetFrameRate, optimizerConfig.trackerDuration);
  58025. // check for degradation
  58026. if (optimizerConfig.degradation) {
  58027. switch (optimizerConfig.degradation) {
  58028. case "low":
  58029. optimizerOptions = babylonjs_1.SceneOptimizerOptions.LowDegradationAllowed(optimizerConfig.targetFrameRate);
  58030. break;
  58031. case "moderate":
  58032. optimizerOptions = babylonjs_1.SceneOptimizerOptions.ModerateDegradationAllowed(optimizerConfig.targetFrameRate);
  58033. break;
  58034. case "hight":
  58035. optimizerOptions = babylonjs_1.SceneOptimizerOptions.HighDegradationAllowed(optimizerConfig.targetFrameRate);
  58036. break;
  58037. }
  58038. }
  58039. if (this.sceneOptimizer) {
  58040. this.sceneOptimizer.stop();
  58041. this.sceneOptimizer.dispose();
  58042. }
  58043. if (optimizerConfig.custom) {
  58044. var customOptimizer_1 = _1.getCustomOptimizerByName(optimizerConfig.custom, optimizerConfig.improvementMode);
  58045. if (customOptimizer_1) {
  58046. optimizerOptions.addCustomOptimization(function () {
  58047. return customOptimizer_1(_this);
  58048. }, function () {
  58049. return "Babylon Viewer " + optimizerConfig.custom + " custom optimization";
  58050. });
  58051. }
  58052. }
  58053. this.sceneOptimizer = new babylonjs_1.SceneOptimizer(this.scene, optimizerOptions, optimizerConfig.autoGeneratePriorities, optimizerConfig.improvementMode);
  58054. this.sceneOptimizer.start();
  58055. }
  58056. this.onSceneOptimizerConfiguredObservable.notifyObservers({
  58057. sceneManager: this,
  58058. object: this.sceneOptimizer,
  58059. newConfiguration: optimizerConfig
  58060. });
  58061. };
  58062. /**
  58063. * configure all models using the configuration.
  58064. * @param modelConfiguration the configuration to use to reconfigure the models
  58065. */
  58066. /*protected _configureModel(modelConfiguration: Partial<IModelConfiguration>) {
  58067. this.models.forEach(model => {
  58068. model.updateConfiguration(modelConfiguration);
  58069. });
  58070. this.onModelsConfiguredObservable.notifyObservers({
  58071. sceneManager: this,
  58072. object: this.models,
  58073. newConfiguration: modelConfiguration
  58074. });
  58075. }*/
  58076. /**
  58077. * (Re) configure the camera. The camera will only be created once and from this point will only be reconfigured.
  58078. * @param cameraConfig the new camera configuration
  58079. * @param model optionally use the model to configure the camera.
  58080. */
  58081. SceneManager.prototype._configureCamera = function (cameraConfig) {
  58082. var _this = this;
  58083. if (cameraConfig === void 0) { cameraConfig = {}; }
  58084. if (!this.scene.activeCamera) {
  58085. var attachControl = true;
  58086. if (this._globalConfiguration.scene && this._globalConfiguration.scene.disableCameraControl) {
  58087. attachControl = false;
  58088. }
  58089. this.scene.createDefaultCamera(true, true, attachControl);
  58090. this.camera = this.scene.activeCamera;
  58091. this.camera.setTarget(babylonjs_1.Vector3.Zero());
  58092. }
  58093. if (cameraConfig.position) {
  58094. var newPosition = this.camera.position.clone();
  58095. helper_1.extendClassWithConfig(newPosition, cameraConfig.position);
  58096. this.camera.setPosition(newPosition);
  58097. }
  58098. if (cameraConfig.target) {
  58099. var newTarget = this.camera.target.clone();
  58100. helper_1.extendClassWithConfig(newTarget, cameraConfig.target);
  58101. this.camera.setTarget(newTarget);
  58102. } /*else if (this.models.length && !cameraConfig.disableAutoFocus) {
  58103. this._focusOnModel(this.models[0]);
  58104. }*/
  58105. if (cameraConfig.rotation) {
  58106. this.camera.rotationQuaternion = new babylonjs_1.Quaternion(cameraConfig.rotation.x || 0, cameraConfig.rotation.y || 0, cameraConfig.rotation.z || 0, cameraConfig.rotation.w || 0);
  58107. }
  58108. if (cameraConfig.behaviors) {
  58109. for (var name_1 in cameraConfig.behaviors) {
  58110. if (cameraConfig.behaviors[name_1] !== undefined) {
  58111. this._setCameraBehavior(name_1, cameraConfig.behaviors[name_1]);
  58112. }
  58113. }
  58114. }
  58115. ;
  58116. var sceneExtends = this.scene.getWorldExtends(function (mesh) {
  58117. return !_this.environmentHelper || (mesh !== _this.environmentHelper.ground && mesh !== _this.environmentHelper.rootMesh && mesh !== _this.environmentHelper.skybox);
  58118. });
  58119. var sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
  58120. var sceneDiagonalLenght = sceneDiagonal.length();
  58121. if (isFinite(sceneDiagonalLenght))
  58122. this.camera.upperRadiusLimit = sceneDiagonalLenght * 4;
  58123. else {
  58124. this.camera.upperRadiusLimit = 10;
  58125. }
  58126. // sanity check!
  58127. if (this.scene.imageProcessingConfiguration) {
  58128. this.scene.imageProcessingConfiguration.colorCurvesEnabled = true;
  58129. this.scene.imageProcessingConfiguration.vignetteEnabled = true;
  58130. this.scene.imageProcessingConfiguration.toneMappingEnabled = !!configuration_1.getConfigurationKey("camera.toneMappingEnabled", this._globalConfiguration);
  58131. }
  58132. helper_1.extendClassWithConfig(this.camera, cameraConfig);
  58133. this.onCameraConfiguredObservable.notifyObservers({
  58134. sceneManager: this,
  58135. object: this.camera,
  58136. newConfiguration: cameraConfig
  58137. });
  58138. };
  58139. SceneManager.prototype._configureEnvironment = function (skyboxConifguration, groundConfiguration) {
  58140. var _this = this;
  58141. if (!skyboxConifguration && !groundConfiguration) {
  58142. if (this.environmentHelper) {
  58143. this.environmentHelper.dispose();
  58144. delete this.environmentHelper;
  58145. }
  58146. ;
  58147. }
  58148. else {
  58149. var options = {
  58150. createGround: !!groundConfiguration && this._groundEnabled,
  58151. createSkybox: !!skyboxConifguration,
  58152. setupImageProcessing: false,
  58153. };
  58154. // will that cause problems with model ground configuration?
  58155. /*if (model) {
  58156. const boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
  58157. const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
  58158. const halfSizeVec = sizeVec.scale(0.5);
  58159. const center = boundingInfo.min.add(halfSizeVec);
  58160. options.groundYBias = -center.y;
  58161. }*/
  58162. if (groundConfiguration) {
  58163. var groundConfig_1 = (typeof groundConfiguration === 'boolean') ? {} : groundConfiguration;
  58164. var groundSize = groundConfig_1.size || (typeof skyboxConifguration === 'object' && skyboxConifguration.scale);
  58165. if (groundSize) {
  58166. options.groundSize = groundSize;
  58167. }
  58168. options.enableGroundShadow = groundConfig_1 === true || groundConfig_1.receiveShadows;
  58169. if (groundConfig_1.shadowLevel !== undefined) {
  58170. options.groundShadowLevel = groundConfig_1.shadowLevel;
  58171. }
  58172. options.enableGroundMirror = !!groundConfig_1.mirror && this.groundMirrorEnabled;
  58173. if (groundConfig_1.texture) {
  58174. options.groundTexture = this.labs.getAssetUrl(groundConfig_1.texture);
  58175. }
  58176. if (groundConfig_1.color) {
  58177. options.groundColor = new babylonjs_1.Color3(groundConfig_1.color.r, groundConfig_1.color.g, groundConfig_1.color.b);
  58178. }
  58179. if (groundConfig_1.opacity !== undefined) {
  58180. options.groundOpacity = groundConfig_1.opacity;
  58181. }
  58182. if (groundConfig_1.mirror) {
  58183. options.enableGroundMirror = true;
  58184. // to prevent undefines
  58185. if (typeof groundConfig_1.mirror === "object") {
  58186. if (groundConfig_1.mirror.amount !== undefined)
  58187. options.groundMirrorAmount = groundConfig_1.mirror.amount;
  58188. if (groundConfig_1.mirror.sizeRatio !== undefined)
  58189. options.groundMirrorSizeRatio = groundConfig_1.mirror.sizeRatio;
  58190. if (groundConfig_1.mirror.blurKernel !== undefined)
  58191. options.groundMirrorBlurKernel = groundConfig_1.mirror.blurKernel;
  58192. if (groundConfig_1.mirror.fresnelWeight !== undefined)
  58193. options.groundMirrorFresnelWeight = groundConfig_1.mirror.fresnelWeight;
  58194. if (groundConfig_1.mirror.fallOffDistance !== undefined)
  58195. options.groundMirrorFallOffDistance = groundConfig_1.mirror.fallOffDistance;
  58196. if (this._defaultPipelineTextureType !== undefined)
  58197. options.groundMirrorTextureType = this._defaultPipelineTextureType;
  58198. }
  58199. }
  58200. }
  58201. var postInitSkyboxMaterial = false;
  58202. if (skyboxConifguration) {
  58203. var conf = skyboxConifguration === true ? {} : skyboxConifguration;
  58204. if (conf.material && conf.material.imageProcessingConfiguration) {
  58205. options.setupImageProcessing = false; // will be configured later manually.
  58206. }
  58207. var skyboxSize = conf.scale;
  58208. if (skyboxSize) {
  58209. options.skyboxSize = skyboxSize;
  58210. }
  58211. options.sizeAuto = !options.skyboxSize;
  58212. if (conf.color) {
  58213. options.skyboxColor = new babylonjs_1.Color3(conf.color.r, conf.color.g, conf.color.b);
  58214. }
  58215. if (conf.cubeTexture && conf.cubeTexture.url) {
  58216. if (typeof conf.cubeTexture.url === "string") {
  58217. options.skyboxTexture = this.labs.getAssetUrl(conf.cubeTexture.url);
  58218. }
  58219. else {
  58220. // init later!
  58221. postInitSkyboxMaterial = true;
  58222. }
  58223. }
  58224. if (conf.material) {
  58225. postInitSkyboxMaterial = true;
  58226. }
  58227. }
  58228. options.setupImageProcessing = false; // TMP
  58229. if (!this.environmentHelper) {
  58230. this.environmentHelper = this.scene.createDefaultEnvironment(options);
  58231. }
  58232. else {
  58233. // unlikely, but there might be a new scene! we need to dispose.
  58234. // get the scene used by the envHelper
  58235. var scene = this.environmentHelper.rootMesh.getScene();
  58236. // is it a different scene? Oh no!
  58237. if (scene !== this.scene) {
  58238. this.environmentHelper.dispose();
  58239. this.environmentHelper = this.scene.createDefaultEnvironment(options);
  58240. }
  58241. else {
  58242. this.environmentHelper.updateOptions(options);
  58243. }
  58244. }
  58245. if (this.environmentHelper.rootMesh && this._globalConfiguration.scene && this._globalConfiguration.scene.environmentRotationY !== undefined) {
  58246. this.environmentHelper.rootMesh.rotation.y = this._globalConfiguration.scene.environmentRotationY;
  58247. }
  58248. var groundConfig = (typeof groundConfiguration === 'boolean') ? {} : groundConfiguration;
  58249. if (this.environmentHelper.groundMaterial && groundConfig) {
  58250. this.environmentHelper.groundMaterial._perceptualColor = this.mainColor;
  58251. if (groundConfig.material) {
  58252. helper_1.extendClassWithConfig(this.environmentHelper.groundMaterial, groundConfig.material);
  58253. }
  58254. if (this.environmentHelper.groundMirror) {
  58255. var mirrorClearColor = this.environmentHelper.groundMaterial._perceptualColor.toLinearSpace();
  58256. // TODO user camera exposure value to set the mirror clear color
  58257. var exposure = Math.pow(2.0, -this.scene.imageProcessingConfiguration.exposure) * Math.PI;
  58258. mirrorClearColor.scaleToRef(1 / exposure, mirrorClearColor);
  58259. this.environmentHelper.groundMirror.clearColor.r = babylonjs_1.Scalar.Clamp(mirrorClearColor.r);
  58260. this.environmentHelper.groundMirror.clearColor.g = babylonjs_1.Scalar.Clamp(mirrorClearColor.g);
  58261. this.environmentHelper.groundMirror.clearColor.b = babylonjs_1.Scalar.Clamp(mirrorClearColor.b);
  58262. this.environmentHelper.groundMirror.clearColor.a = 1;
  58263. if (!this.groundMirrorEnabled) {
  58264. this.environmentHelper.groundMaterial.reflectionTexture = null;
  58265. }
  58266. }
  58267. }
  58268. var skyboxMaterial = this.environmentHelper.skyboxMaterial;
  58269. if (skyboxMaterial) {
  58270. skyboxMaterial._perceptualColor = this.mainColor;
  58271. if (postInitSkyboxMaterial) {
  58272. if (typeof skyboxConifguration === 'object' && skyboxConifguration.material) {
  58273. helper_1.extendClassWithConfig(skyboxMaterial, skyboxConifguration.material);
  58274. }
  58275. }
  58276. }
  58277. }
  58278. this._observablesManager && this._observablesManager.onModelLoadedObservable.add(function (model) {
  58279. _this._updateGroundMirrorRenderList(model);
  58280. });
  58281. this.onEnvironmentConfiguredObservable.notifyObservers({
  58282. sceneManager: this,
  58283. object: this.environmentHelper,
  58284. newConfiguration: {
  58285. skybox: skyboxConifguration,
  58286. ground: groundConfiguration
  58287. }
  58288. });
  58289. };
  58290. /**
  58291. * configure the lights.
  58292. *
  58293. * @param lightsConfiguration the (new) light(s) configuration
  58294. * @param model optionally use the model to configure the camera.
  58295. */
  58296. SceneManager.prototype._configureLights = function (lightsConfiguration) {
  58297. var _this = this;
  58298. if (lightsConfiguration === void 0) { lightsConfiguration = {}; }
  58299. // sanity check!
  58300. var lightKeys = Object.keys(lightsConfiguration).filter(function (name) { return name !== 'globalRotation'; });
  58301. if (!lightKeys.length) {
  58302. if (!this.scene.lights.length)
  58303. this.scene.createDefaultLight(true);
  58304. }
  58305. else {
  58306. var lightsAvailable_1 = this.scene.lights.map(function (light) { return light.name; });
  58307. // compare to the global (!) configuration object and dispose unneeded:
  58308. var lightsToConfigure_1 = Object.keys(this._globalConfiguration.lights || []);
  58309. if (Object.keys(lightsToConfigure_1).length !== lightsAvailable_1.length) {
  58310. lightsAvailable_1.forEach(function (lName) {
  58311. if (lightsToConfigure_1.indexOf(lName) === -1) {
  58312. _this.scene.getLightByName(lName).dispose();
  58313. }
  58314. });
  58315. }
  58316. lightKeys.forEach(function (name, idx) {
  58317. var lightConfig = { type: 0 };
  58318. if (typeof lightsConfiguration[name] === 'object') {
  58319. lightConfig = lightsConfiguration[name];
  58320. }
  58321. if (typeof lightsConfiguration[name] === 'number') {
  58322. lightConfig.type = lightsConfiguration[name];
  58323. }
  58324. lightConfig.name = name;
  58325. var light;
  58326. // light is not already available
  58327. if (lightsAvailable_1.indexOf(name) === -1) {
  58328. var constructor = babylonjs_1.Light.GetConstructorFromName(lightConfig.type, lightConfig.name, _this.scene);
  58329. if (!constructor)
  58330. return;
  58331. light = constructor();
  58332. }
  58333. else {
  58334. // available? get it from the scene
  58335. light = _this.scene.getLightByName(name);
  58336. if (typeof lightsConfiguration[name] === 'boolean') {
  58337. lightConfig.type = light.getTypeID();
  58338. }
  58339. lightsAvailable_1 = lightsAvailable_1.filter(function (ln) { return ln !== name; });
  58340. if (lightConfig.type !== undefined && light.getTypeID() !== lightConfig.type) {
  58341. light.dispose();
  58342. var constructor = babylonjs_1.Light.GetConstructorFromName(lightConfig.type, lightConfig.name, _this.scene);
  58343. if (!constructor)
  58344. return;
  58345. light = constructor();
  58346. }
  58347. }
  58348. // if config set the light to false, dispose it.
  58349. if (lightsConfiguration[name] === false) {
  58350. light.dispose();
  58351. return;
  58352. }
  58353. //enabled
  58354. var enabled = lightConfig.enabled !== undefined ? lightConfig.enabled : !lightConfig.disabled;
  58355. light.setEnabled(enabled);
  58356. helper_1.extendClassWithConfig(light, lightConfig);
  58357. //position. Some lights don't support shadows
  58358. if (light instanceof babylonjs_1.ShadowLight) {
  58359. // set default values
  58360. light.shadowMinZ = light.shadowMinZ || 0.2;
  58361. light.shadowMaxZ = Math.min(10, light.shadowMaxZ || 10); //large far clips reduce shadow depth precision
  58362. if (lightConfig.target) {
  58363. if (light.setDirectionToTarget) {
  58364. var target = babylonjs_1.Vector3.Zero().copyFrom(lightConfig.target);
  58365. light.setDirectionToTarget(target);
  58366. }
  58367. }
  58368. else if (lightConfig.direction) {
  58369. var direction = babylonjs_1.Vector3.Zero().copyFrom(lightConfig.direction);
  58370. light.direction = direction;
  58371. }
  58372. var isShadowEnabled = false;
  58373. if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_DIRECTIONALLIGHT) {
  58374. light.shadowFrustumSize = lightConfig.shadowFrustumSize || 2;
  58375. isShadowEnabled = true;
  58376. }
  58377. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_SPOTLIGHT) {
  58378. var spotLight = light;
  58379. if (lightConfig.spotAngle !== undefined) {
  58380. spotLight.angle = lightConfig.spotAngle * Math.PI / 180;
  58381. }
  58382. if (spotLight.angle && lightConfig.shadowFieldOfView) {
  58383. spotLight.shadowAngleScale = lightConfig.shadowFieldOfView / spotLight.angle;
  58384. }
  58385. isShadowEnabled = true;
  58386. }
  58387. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_POINTLIGHT) {
  58388. if (lightConfig.shadowFieldOfView) {
  58389. light.shadowAngle = lightConfig.shadowFieldOfView * Math.PI / 180;
  58390. }
  58391. isShadowEnabled = true;
  58392. }
  58393. var shadowGenerator_1 = light.getShadowGenerator();
  58394. if (isShadowEnabled && lightConfig.shadowEnabled && _this._maxShadows) {
  58395. var bufferSize = lightConfig.shadowBufferSize || 256;
  58396. if (!shadowGenerator_1) {
  58397. shadowGenerator_1 = new babylonjs_1.ShadowGenerator(bufferSize, light);
  58398. }
  58399. var blurKernel = _this.getBlurKernel(light, bufferSize);
  58400. shadowGenerator_1.bias = _this._shadowGeneratorBias;
  58401. shadowGenerator_1.blurKernel = blurKernel;
  58402. //override defaults
  58403. helper_1.extendClassWithConfig(shadowGenerator_1, lightConfig.shadowConfig || {});
  58404. // add the focues meshes to the shadow list
  58405. _this._observablesManager && _this._observablesManager.onModelLoadedObservable.add(function (model) {
  58406. _this._updateShadowRenderList(shadowGenerator_1, model);
  58407. });
  58408. //if (model) {
  58409. _this._updateShadowRenderList(shadowGenerator_1);
  58410. //}
  58411. }
  58412. else if (shadowGenerator_1) {
  58413. shadowGenerator_1.dispose();
  58414. }
  58415. }
  58416. });
  58417. // render priority
  58418. var globalLightsConfiguration_1 = this._globalConfiguration.lights || {};
  58419. Object.keys(globalLightsConfiguration_1).sort().forEach(function (name, idx) {
  58420. var configuration = globalLightsConfiguration_1[name];
  58421. var light = _this.scene.getLightByName(name);
  58422. // sanity check
  58423. if (!light)
  58424. return;
  58425. light.renderPriority = -idx;
  58426. });
  58427. }
  58428. this.onLightsConfiguredObservable.notifyObservers({
  58429. sceneManager: this,
  58430. object: this.scene.lights,
  58431. newConfiguration: lightsConfiguration
  58432. });
  58433. };
  58434. SceneManager.prototype._updateShadowRenderList = function (shadowGenerator, model, resetList) {
  58435. var focusMeshes = model ? model.meshes : this.scene.meshes;
  58436. // add the focues meshes to the shadow list
  58437. var shadownMap = shadowGenerator.getShadowMap();
  58438. if (!shadownMap)
  58439. return;
  58440. if (resetList && shadownMap.renderList) {
  58441. shadownMap.renderList.length = 0;
  58442. }
  58443. else {
  58444. shadownMap.renderList = shadownMap.renderList || [];
  58445. }
  58446. for (var index = 0; index < focusMeshes.length; index++) {
  58447. var mesh = focusMeshes[index];
  58448. if (babylonjs_1.Tags.MatchesQuery(mesh, 'castShadow') && shadownMap.renderList.indexOf(mesh) === -1) {
  58449. shadownMap.renderList.push(mesh);
  58450. }
  58451. }
  58452. if (!this._shadowGroundPlane) {
  58453. if (shadowGenerator.useBlurCloseExponentialShadowMap) {
  58454. var shadowGroundPlane = babylonjs_1.Mesh.CreatePlane("shadowGroundPlane", 100, this.scene, false);
  58455. shadowGroundPlane.useVertexColors = false;
  58456. //material isn't ever used in rendering, just used to set back face culling
  58457. shadowGroundPlane.material = new babylonjs_1.StandardMaterial('shadowGroundPlaneMaterial', this.scene);
  58458. shadowGroundPlane.material.backFaceCulling = false;
  58459. shadowGroundPlane.rotation.x = Math.PI * 0.5;
  58460. shadowGroundPlane.freezeWorldMatrix();
  58461. this._shadowGroundPlane = shadowGroundPlane;
  58462. this.scene.removeMesh(shadowGroundPlane);
  58463. }
  58464. }
  58465. else {
  58466. if (!shadowGenerator.useBlurCloseExponentialShadowMap) {
  58467. this._shadowGroundPlane.dispose();
  58468. this._shadowGroundPlane = null;
  58469. }
  58470. }
  58471. if (this._shadowGroundPlane && shadownMap.renderList.indexOf(this._shadowGroundPlane) === -1) {
  58472. shadownMap.renderList.push(this._shadowGroundPlane);
  58473. }
  58474. };
  58475. SceneManager.prototype._updateGroundMirrorRenderList = function (model, resetList) {
  58476. if (this.environmentHelper.groundMirror && this.environmentHelper.groundMirror.renderList) {
  58477. var focusMeshes = model ? model.meshes : this.scene.meshes;
  58478. var renderList = this.environmentHelper.groundMirror.renderList;
  58479. if (resetList) {
  58480. renderList.length = 0;
  58481. }
  58482. for (var index = 0; index < focusMeshes.length; index++) {
  58483. var mesh = focusMeshes[index];
  58484. if (renderList.indexOf(mesh) === -1) {
  58485. renderList.push(mesh);
  58486. }
  58487. }
  58488. }
  58489. };
  58490. /**
  58491. * Gets the shadow map blur kernel according to the light configuration.
  58492. * @param light The light used to generate the shadows
  58493. * @param bufferSize The size of the shadow map
  58494. * @return the kernel blur size
  58495. */
  58496. SceneManager.prototype.getBlurKernel = function (light, bufferSize) {
  58497. var normalizedBlurKernel = 0.05; // TODO Should come from the config.
  58498. if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_DIRECTIONALLIGHT) {
  58499. normalizedBlurKernel = normalizedBlurKernel / light.shadowFrustumSize;
  58500. }
  58501. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_POINTLIGHT) {
  58502. normalizedBlurKernel = normalizedBlurKernel / light.shadowAngle;
  58503. }
  58504. else if (light.getTypeID() === BABYLON.Light.LIGHTTYPEID_SPOTLIGHT) {
  58505. normalizedBlurKernel = normalizedBlurKernel / (light.angle * light.shadowAngleScale);
  58506. }
  58507. var minimumBlurKernel = 5 / (bufferSize / 256); //magic number that aims to keep away sawtooth shadows
  58508. var blurKernel = Math.max(bufferSize * normalizedBlurKernel, minimumBlurKernel);
  58509. return blurKernel;
  58510. };
  58511. /**
  58512. * Alters render settings to reduce features based on hardware feature limitations
  58513. * @param enableHDR Allows the viewer to run in HDR mode.
  58514. */
  58515. SceneManager.prototype._handleHardwareLimitations = function (enableHDR) {
  58516. if (enableHDR === void 0) { enableHDR = true; }
  58517. //flip rendering settings switches based on hardware support
  58518. var maxVaryingRows = this._engine.getCaps().maxVaryingVectors;
  58519. var maxFragmentSamplers = this._engine.getCaps().maxTexturesImageUnits;
  58520. //shadows are disabled if there's not enough varyings for a single shadow
  58521. if ((maxVaryingRows < 8) || (maxFragmentSamplers < 8)) {
  58522. this._maxShadows = 0;
  58523. }
  58524. else {
  58525. this._maxShadows = 3;
  58526. }
  58527. //can we render to any >= 16-bit targets (required for HDR)
  58528. var caps = this._engine.getCaps();
  58529. var linearHalfFloatTargets = caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering;
  58530. var linearFloatTargets = caps.textureFloatRender && caps.textureFloatLinearFiltering;
  58531. this._hdrSupport = enableHDR && !!(linearFloatTargets || linearHalfFloatTargets);
  58532. if (linearHalfFloatTargets) {
  58533. this._defaultHighpTextureType = babylonjs_1.Engine.TEXTURETYPE_HALF_FLOAT;
  58534. this._shadowGeneratorBias = 0.002;
  58535. }
  58536. else if (linearFloatTargets) {
  58537. this._defaultHighpTextureType = babylonjs_1.Engine.TEXTURETYPE_FLOAT;
  58538. this._shadowGeneratorBias = 0.001;
  58539. }
  58540. else {
  58541. this._defaultHighpTextureType = babylonjs_1.Engine.TEXTURETYPE_UNSIGNED_INT;
  58542. this._shadowGeneratorBias = 0.001;
  58543. }
  58544. this._defaultPipelineTextureType = this._hdrSupport ? this._defaultHighpTextureType : babylonjs_1.Engine.TEXTURETYPE_UNSIGNED_INT;
  58545. };
  58546. /**
  58547. * Dispoe the entire viewer including the scene and the engine
  58548. */
  58549. SceneManager.prototype.dispose = function () {
  58550. // this.onCameraConfiguredObservable.clear();
  58551. this.onEnvironmentConfiguredObservable.clear();
  58552. this.onLightsConfiguredObservable.clear();
  58553. this.onModelsConfiguredObservable.clear();
  58554. this.onSceneConfiguredObservable.clear();
  58555. this.onSceneInitObservable.clear();
  58556. this.onSceneOptimizerConfiguredObservable.clear();
  58557. if (this.sceneOptimizer) {
  58558. this.sceneOptimizer.stop();
  58559. this.sceneOptimizer.dispose();
  58560. }
  58561. if (this.environmentHelper) {
  58562. this.environmentHelper.dispose();
  58563. }
  58564. this.models.forEach(function (model) {
  58565. model.dispose();
  58566. });
  58567. if (this._defaultRenderingPipeline) {
  58568. this._defaultRenderingPipeline.dispose();
  58569. }
  58570. this.models.length = 0;
  58571. if (this.scene) {
  58572. this.scene.dispose();
  58573. }
  58574. };
  58575. SceneManager.prototype._setCameraBehavior = function (name, behaviorConfig, payload) {
  58576. var behavior;
  58577. var type;
  58578. if (typeof behaviorConfig === 'object') {
  58579. type = behaviorConfig.type;
  58580. }
  58581. else if (typeof behaviorConfig === 'number') {
  58582. type = behaviorConfig;
  58583. }
  58584. else {
  58585. type = this._cameraBehaviorMapping[name];
  58586. }
  58587. if (type === undefined)
  58588. return;
  58589. var config = (typeof behaviorConfig === "object") ? behaviorConfig : {};
  58590. var enabled = true;
  58591. if (typeof behaviorConfig === 'boolean') {
  58592. enabled = behaviorConfig;
  58593. }
  58594. // constructing behavior
  58595. switch (type) {
  58596. case 0 /* AUTOROTATION */:
  58597. this.camera.useAutoRotationBehavior = enabled;
  58598. behavior = this.camera.autoRotationBehavior;
  58599. break;
  58600. case 1 /* BOUNCING */:
  58601. this.camera.useBouncingBehavior = enabled;
  58602. behavior = this.camera.bouncingBehavior;
  58603. break;
  58604. case 2 /* FRAMING */:
  58605. this.camera.useFramingBehavior = enabled;
  58606. behavior = this.camera.framingBehavior;
  58607. break;
  58608. default:
  58609. behavior = null;
  58610. break;
  58611. }
  58612. if (behavior) {
  58613. this._cameraBehaviorMapping[name] = type;
  58614. if (typeof behaviorConfig === "object") {
  58615. helper_1.extendClassWithConfig(behavior, behaviorConfig);
  58616. }
  58617. }
  58618. // post attach configuration. Some functionalities require the attached camera.
  58619. switch (type) {
  58620. case 0 /* AUTOROTATION */:
  58621. break;
  58622. case 1 /* BOUNCING */:
  58623. break;
  58624. case 2 /* FRAMING */:
  58625. this._observablesManager && this._observablesManager.onModelLoadedObservable.add(function (model) {
  58626. if (config.zoomOnBoundingInfo) {
  58627. behavior.zoomOnMeshHierarchy(model.rootMesh);
  58628. }
  58629. });
  58630. break;
  58631. }
  58632. };
  58633. return SceneManager;
  58634. }());
  58635. exports.SceneManager = SceneManager;
  58636. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NlbmVNYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21hbmFnZXJzL3NjZW5lTWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVDQUErakI7QUFDL2pCLGtEQUFtUjtBQUNuUixvREFBK0Q7QUFDL0Qsb0NBQWtEO0FBRWxELGlEQUFnRDtBQUNoRCx5Q0FBZ0U7QUFnQmhFO0lBc0ZJLHNCQUFvQixPQUFlLEVBQVUsdUJBQStDLEVBQVUsbUJBQXdDO1FBQTlJLGlCQXlFQztRQXpFbUIsWUFBTyxHQUFQLE9BQU8sQ0FBUTtRQUFVLDRCQUF1QixHQUF2Qix1QkFBdUIsQ0FBd0I7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z0JBQ3BDLDhCQUFxQixDQUFDLFFBQVEsRUFBRSxjQUFjLENBQUMsQ0FBQzthQUNuRDtTQUNKO1FBRUQsK0VBQStFO1FBQy9FLFFBQVEsSUFBSSxFQUFFO1lBQ1Y7Z0JBQ0ksTUFBTTtZQUNWO2dCQUNJLE1BQU07WUFDVjtnQkFDSSxJQUFJLENBQUMsbUJBQW1CLElBQUksSUFBSSxDQUFDLG1CQUFtQixDQUFDLHVCQUF1QixDQUFDLEdBQUcsQ0FBQyxVQUFDLEtBQUs7b0JBQ25GLElBQUksTUFBTSxDQUFDLGtCQUFrQixFQUFFO3dCQUNULFFBQVMsQ0FBQyxtQkFBbUIsQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDLENBQUM7cUJBQ25FO2dCQUNMLENBQUMsQ0FBQyxDQUFDO2dCQUNILE1BQU07U0FDYjtJQUNMLENBQUM7SUFDTCxtQkFBQztBQUFELENBQUMsQUF4MkNELElBdzJDQztBQXgyQ1ksb0NBQVkifQ==
  58637. /***/ }),
  58638. /* 23 */
  58639. /***/ (function(module, exports, __webpack_require__) {
  58640. "use strict";
  58641. Object.defineProperty(exports, "__esModule", { value: true });
  58642. /**
  58643. * The GroupModelAnimation is an implementation of the IModelAnimation interface using BABYLON's
  58644. * native GroupAnimation class.
  58645. */
  58646. var GroupModelAnimation = /** @class */ (function () {
  58647. /**
  58648. * Create a new GroupModelAnimation object using an AnimationGroup object
  58649. * @param _animationGroup The aniamtion group to base the class on
  58650. */
  58651. function GroupModelAnimation(_animationGroup) {
  58652. var _this = this;
  58653. this._animationGroup = _animationGroup;
  58654. this._state = 0 /* INIT */;
  58655. this._playMode = 1 /* LOOP */;
  58656. this._animationGroup.onAnimationEndObservable.add(function () {
  58657. _this.stop();
  58658. _this._state = 4 /* ENDED */;
  58659. });
  58660. }
  58661. Object.defineProperty(GroupModelAnimation.prototype, "name", {
  58662. /**
  58663. * Get the animation's name
  58664. */
  58665. get: function () {
  58666. return this._animationGroup.name;
  58667. },
  58668. enumerable: true,
  58669. configurable: true
  58670. });
  58671. Object.defineProperty(GroupModelAnimation.prototype, "state", {
  58672. /**
  58673. * Get the current animation's state
  58674. */
  58675. get: function () {
  58676. return this._state;
  58677. },
  58678. enumerable: true,
  58679. configurable: true
  58680. });
  58681. Object.defineProperty(GroupModelAnimation.prototype, "speedRatio", {
  58682. /**
  58683. * Gets the speed ratio to use for all animations
  58684. */
  58685. get: function () {
  58686. return this._animationGroup.speedRatio;
  58687. },
  58688. /**
  58689. * Sets the speed ratio to use for all animations
  58690. */
  58691. set: function (value) {
  58692. this._animationGroup.speedRatio = value;
  58693. },
  58694. enumerable: true,
  58695. configurable: true
  58696. });
  58697. Object.defineProperty(GroupModelAnimation.prototype, "frames", {
  58698. /**
  58699. * Get the max numbers of frame available in the animation group
  58700. *
  58701. * In correlation to an arry, this would be ".length"
  58702. */
  58703. get: function () {
  58704. return this._animationGroup.to - this._animationGroup.from;
  58705. },
  58706. enumerable: true,
  58707. configurable: true
  58708. });
  58709. Object.defineProperty(GroupModelAnimation.prototype, "currentFrame", {
  58710. /**
  58711. * Get the current frame playing right now.
  58712. * This can be used to poll the frame currently playing (and, for exmaple, display a progress bar with the data)
  58713. *
  58714. * In correlation to an array, this would be the current index
  58715. */
  58716. get: function () {
  58717. if (this._animationGroup.targetedAnimations[0] && this._animationGroup.targetedAnimations[0].animation.runtimeAnimations[0]) {
  58718. return this._animationGroup.targetedAnimations[0].animation.runtimeAnimations[0].currentFrame - this._animationGroup.from;
  58719. }
  58720. else {
  58721. return 0;
  58722. }
  58723. },
  58724. enumerable: true,
  58725. configurable: true
  58726. });
  58727. Object.defineProperty(GroupModelAnimation.prototype, "fps", {
  58728. /**
  58729. * Get the FPS value of this animation
  58730. */
  58731. get: function () {
  58732. // get the first currentFrame found
  58733. for (var i = 0; i < this._animationGroup.animatables.length; ++i) {
  58734. var animatable = this._animationGroup.animatables[i];
  58735. var animations = animatable.getAnimations();
  58736. if (!animations || !animations.length) {
  58737. continue;
  58738. }
  58739. for (var idx = 0; idx < animations.length; ++idx) {
  58740. if (animations[idx].animation && animations[idx].animation.framePerSecond) {
  58741. return animations[idx].animation.framePerSecond;
  58742. }
  58743. }
  58744. }
  58745. return 0;
  58746. },
  58747. enumerable: true,
  58748. configurable: true
  58749. });
  58750. Object.defineProperty(GroupModelAnimation.prototype, "playMode", {
  58751. /**
  58752. * What is the animation'S play mode (looping or played once)
  58753. */
  58754. get: function () {
  58755. return this._playMode;
  58756. },
  58757. /**
  58758. * Set the play mode.
  58759. * If the animation is played, it will continue playing at least once more, depending on the new play mode set.
  58760. * If the animation is not set, the will be initialized and will wait for the user to start playing it.
  58761. */
  58762. set: function (value) {
  58763. if (value === this._playMode) {
  58764. return;
  58765. }
  58766. this._playMode = value;
  58767. if (this.state === 1 /* PLAYING */) {
  58768. this._animationGroup.play(this._playMode === 1 /* LOOP */);
  58769. }
  58770. else {
  58771. this._animationGroup.reset();
  58772. this._state = 0 /* INIT */;
  58773. }
  58774. },
  58775. enumerable: true,
  58776. configurable: true
  58777. });
  58778. /**
  58779. * Reset the animation group
  58780. */
  58781. GroupModelAnimation.prototype.reset = function () {
  58782. this._animationGroup.reset();
  58783. };
  58784. /**
  58785. * Restart the animation group
  58786. */
  58787. GroupModelAnimation.prototype.restart = function () {
  58788. if (this.state === 2 /* PAUSED */)
  58789. this._animationGroup.restart();
  58790. else
  58791. this.start();
  58792. };
  58793. /**
  58794. *
  58795. * @param frameNumber Go to a specific frame in the animation
  58796. */
  58797. GroupModelAnimation.prototype.goToFrame = function (frameNumber) {
  58798. this._animationGroup.goToFrame(frameNumber + this._animationGroup.from);
  58799. };
  58800. /**
  58801. * Start playing the animation.
  58802. */
  58803. GroupModelAnimation.prototype.start = function () {
  58804. this._animationGroup.start(this.playMode === 1 /* LOOP */, this.speedRatio);
  58805. if (this._animationGroup.isStarted) {
  58806. this._state = 1 /* PLAYING */;
  58807. }
  58808. };
  58809. /**
  58810. * Pause the animation
  58811. */
  58812. GroupModelAnimation.prototype.pause = function () {
  58813. this._animationGroup.pause();
  58814. this._state = 2 /* PAUSED */;
  58815. };
  58816. /**
  58817. * Stop the animation.
  58818. * This will fail silently if the animation group is already stopped.
  58819. */
  58820. GroupModelAnimation.prototype.stop = function () {
  58821. this._animationGroup.stop();
  58822. if (!this._animationGroup.isStarted) {
  58823. this._state = 3 /* STOPPED */;
  58824. }
  58825. };
  58826. /**
  58827. * Dispose this animation object.
  58828. */
  58829. GroupModelAnimation.prototype.dispose = function () {
  58830. this._animationGroup.dispose();
  58831. };
  58832. return GroupModelAnimation;
  58833. }());
  58834. exports.GroupModelAnimation = GroupModelAnimation;
  58835. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kZWxBbmltYXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbW9kZWwvbW9kZWxBbmltYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUF3SUE7OztHQUdHO0FBQ0g7SUFLSTs7O09BR0c7SUFDSCw2QkFBb0IsZUFBK0I7UUFBbkQsaUJBUUM7UUFSbUIsb0JBQWUsR0FBZixlQUFlLENBQWdCO1FBQy9DLElBQUksQ0FBQyxNQUFNLGVBQXNCLENBQUM7UUFDbEMsSUFBSSxDQUFDLFNBQVMsZUFBeUIsQ0FBQztRQUV4QyxJQUFJLENBQUMsZUFBZSxDQUFDLHdCQUF3QixDQUFDLEdBQUcsQ0FBQztZQUM5QyxLQUFJLENBQUMsSUFBSSxFQUFFLENBQUM7WUFDWixLQUFJLENBQUMsTUFBTSxnQkFBdUIsQ0FBQztRQUN2QyxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUM7SUFLRCxzQkFBVyxxQ0FBSTtRQUhmOztXQUVHO2FBQ0g7WUFDSSxPQUFPLElBQUksQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDO1FBQ3JDLENBQUM7OztPQUFBO0lBS0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Q0gsbUNBQUssR0FBTDtRQUNJLElBQUksQ0FBQyxlQUFlLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDN0IsSUFBSSxDQUFDLE1BQU0saUJBQXdCLENBQUM7SUFDeEMsQ0FBQztJQUVEOzs7T0FHRztJQUNJLGtDQUFJLEdBQVg7UUFDSSxJQUFJLENBQUMsZUFBZSxDQUFDLElBQUksRUFBRSxDQUFDO1FBQzVCLElBQUksQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLFNBQVMsRUFBRTtZQUNqQyxJQUFJLENBQUMsTUFBTSxrQkFBeUIsQ0FBQztTQUN4QztJQUNMLENBQUM7SUFFRDs7T0FFRztJQUNJLHFDQUFPLEdBQWQ7UUFDSSxJQUFJLENBQUMsZUFBZSxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ25DLENBQUM7SUFDTCwwQkFBQztBQUFELENBQUMsQUFqTEQsSUFpTEM7QUFqTFksa0RBQW1CIn0=
  58836. /***/ }),
  58837. /* 24 */
  58838. /***/ (function(module, exports, __webpack_require__) {
  58839. "use strict";
  58840. Object.defineProperty(exports, "__esModule", { value: true });
  58841. var environmentSerializer_1 = __webpack_require__(25);
  58842. var babylonjs_1 = __webpack_require__(0);
  58843. var texture_1 = __webpack_require__(12);
  58844. /**
  58845. * The ViewerLabs class will hold functions that are not (!) backwards compatible.
  58846. * The APIs in all labs-related classes and configuration might change.
  58847. * Once stable, lab features will be moved to the publis API and configuration object.
  58848. */
  58849. var ViewerLabs = /** @class */ (function () {
  58850. function ViewerLabs(_scene) {
  58851. this._scene = _scene;
  58852. this.environment = {
  58853. //irradiance
  58854. irradiancePolynomialCoefficients: {
  58855. x: new babylonjs_1.Vector3(0, 0, 0),
  58856. y: new babylonjs_1.Vector3(0, 0, 0),
  58857. z: new babylonjs_1.Vector3(0, 0, 0),
  58858. xx: new babylonjs_1.Vector3(0, 0, 0),
  58859. yy: new babylonjs_1.Vector3(0, 0, 0),
  58860. zz: new babylonjs_1.Vector3(0, 0, 0),
  58861. yz: new babylonjs_1.Vector3(0, 0, 0),
  58862. zx: new babylonjs_1.Vector3(0, 0, 0),
  58863. xy: new babylonjs_1.Vector3(0, 0, 0)
  58864. },
  58865. textureIntensityScale: 1.0
  58866. };
  58867. }
  58868. ViewerLabs.prototype.loadEnvironment = function (data, onSuccess, onProgress, onError) {
  58869. var _this = this;
  58870. //@! todo: should loadEnvironment cancel any currently loading environments?
  58871. if (data instanceof ArrayBuffer) {
  58872. this.environment = environmentSerializer_1.EnvironmentDeserializer.Parse(data);
  58873. if (onSuccess)
  58874. onSuccess(this.environment);
  58875. }
  58876. else if (typeof data === 'string') {
  58877. var url = this.getAssetUrl(data);
  58878. this._scene._loadFile(url, function (arrayBuffer) {
  58879. _this.environment = environmentSerializer_1.EnvironmentDeserializer.Parse(arrayBuffer);
  58880. if (onSuccess)
  58881. onSuccess(_this.environment);
  58882. }, function (progressEvent) { if (onProgress)
  58883. onProgress(progressEvent.loaded, progressEvent.total); }, false, true, function (r, e) {
  58884. if (onError) {
  58885. onError(e);
  58886. }
  58887. });
  58888. }
  58889. else {
  58890. //data assumed to be PBREnvironment object
  58891. this.environment = data;
  58892. if (onSuccess)
  58893. onSuccess(data);
  58894. }
  58895. };
  58896. /**
  58897. * Applies an `EnvironmentMapConfiguration` to the scene
  58898. * @param environmentMapConfiguration Environment map configuration to apply
  58899. */
  58900. ViewerLabs.prototype.applyEnvironmentMapConfiguration = function (rotationY) {
  58901. if (!this.environment)
  58902. return;
  58903. //set orientation
  58904. var rotatquatRotationionY = babylonjs_1.Quaternion.RotationAxis(babylonjs_1.Axis.Y, rotationY || 0);
  58905. // Add env texture to the scene.
  58906. if (this.environment.specularTexture) {
  58907. // IE crashes when disposing the old texture and setting a new one
  58908. if (!this._scene.environmentTexture) {
  58909. this._scene.environmentTexture = texture_1.TextureUtils.GetBabylonCubeTexture(this._scene, this.environment.specularTexture, false, true);
  58910. }
  58911. if (this._scene.environmentTexture) {
  58912. this._scene.environmentTexture.level = this.environment.textureIntensityScale;
  58913. this._scene.environmentTexture.invertZ = true;
  58914. this._scene.environmentTexture.lodLevelInAlpha = true;
  58915. var poly = this._scene.environmentTexture.sphericalPolynomial || new babylonjs_1.SphericalPolynomial();
  58916. poly.x = this.environment.irradiancePolynomialCoefficients.x;
  58917. poly.y = this.environment.irradiancePolynomialCoefficients.y;
  58918. poly.z = this.environment.irradiancePolynomialCoefficients.z;
  58919. poly.xx = this.environment.irradiancePolynomialCoefficients.xx;
  58920. poly.xy = this.environment.irradiancePolynomialCoefficients.xy;
  58921. poly.yy = this.environment.irradiancePolynomialCoefficients.yy;
  58922. poly.yz = this.environment.irradiancePolynomialCoefficients.yz;
  58923. poly.zx = this.environment.irradiancePolynomialCoefficients.zx;
  58924. poly.zz = this.environment.irradiancePolynomialCoefficients.zz;
  58925. this._scene.environmentTexture.sphericalPolynomial = poly;
  58926. //set orientation
  58927. babylonjs_1.Matrix.FromQuaternionToRef(rotatquatRotationionY, this._scene.environmentTexture.getReflectionTextureMatrix());
  58928. }
  58929. }
  58930. };
  58931. /**
  58932. * Get an environment asset url by using the configuration if the path is not absolute.
  58933. * @param url Asset url
  58934. * @returns The Asset url using the `environmentAssetsRootURL` if the url is not an absolute path.
  58935. */
  58936. ViewerLabs.prototype.getAssetUrl = function (url) {
  58937. var returnUrl = url;
  58938. if (url && url.toLowerCase().indexOf("//") === -1) {
  58939. if (!this.assetsRootURL) {
  58940. // Tools.Warn("Please, specify the root url of your assets before loading the configuration (labs.environmentAssetsRootURL) or disable the background through the viewer options.");
  58941. return url;
  58942. }
  58943. returnUrl = this.assetsRootURL + returnUrl;
  58944. }
  58945. return returnUrl;
  58946. };
  58947. ViewerLabs.prototype.rotateShadowLight = function (shadowLight, amount, point, axis, target) {
  58948. if (point === void 0) { point = babylonjs_1.Vector3.Zero(); }
  58949. if (axis === void 0) { axis = babylonjs_1.Axis.Y; }
  58950. if (target === void 0) { target = babylonjs_1.Vector3.Zero(); }
  58951. axis.normalize();
  58952. point.subtractToRef(shadowLight.position, babylonjs_1.Tmp.Vector3[0]);
  58953. babylonjs_1.Matrix.TranslationToRef(babylonjs_1.Tmp.Vector3[0].x, babylonjs_1.Tmp.Vector3[0].y, babylonjs_1.Tmp.Vector3[0].z, babylonjs_1.Tmp.Matrix[0]);
  58954. babylonjs_1.Tmp.Matrix[0].invertToRef(babylonjs_1.Tmp.Matrix[2]);
  58955. babylonjs_1.Matrix.RotationAxisToRef(axis, amount, babylonjs_1.Tmp.Matrix[1]);
  58956. babylonjs_1.Tmp.Matrix[2].multiplyToRef(babylonjs_1.Tmp.Matrix[1], babylonjs_1.Tmp.Matrix[2]);
  58957. babylonjs_1.Tmp.Matrix[2].multiplyToRef(babylonjs_1.Tmp.Matrix[0], babylonjs_1.Tmp.Matrix[2]);
  58958. babylonjs_1.Tmp.Matrix[2].decompose(babylonjs_1.Tmp.Vector3[0], babylonjs_1.Tmp.Quaternion[0], babylonjs_1.Tmp.Vector3[1]);
  58959. shadowLight.position.addInPlace(babylonjs_1.Tmp.Vector3[1]);
  58960. shadowLight.setDirectionToTarget(target);
  58961. };
  58962. return ViewerLabs;
  58963. }());
  58964. exports.ViewerLabs = ViewerLabs;
  58965. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlld2VyTGFicy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9sYWJzL3ZpZXdlckxhYnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpRUFBa0Y7QUFFbEYsdUNBQW1IO0FBQ25ILHFDQUF5QztBQUV6Qzs7OztHQUlHO0FBQ0g7SUFFSSxvQkFBb0IsTUFBYTtRQUFiLFdBQU0sR0FBTixNQUFNLENBQU87UUFHMUIsZ0JBQVcsR0FBbUI7WUFDakMsWUFBWTtZQUNaLGdDQUFnQyxFQUFFO2dCQUM5QixDQUFDLEVBQUUsSUFBSSxtQkFBT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Object.defineProperty(exports, "__esModule", { value: true });
  58971. var babylonjs_1 = __webpack_require__(0);
  58972. var texture_1 = __webpack_require__(12);
  58973. /**
  58974. * A static class proving methods to aid parsing Spectre environment files
  58975. */
  58976. var EnvironmentDeserializer = /** @class */ (function () {
  58977. function EnvironmentDeserializer() {
  58978. }
  58979. /**
  58980. * Parses an arraybuffer into a new PBREnvironment object
  58981. * @param arrayBuffer The arraybuffer of the Spectre environment file
  58982. * @return a PBREnvironment object
  58983. */
  58984. EnvironmentDeserializer.Parse = function (arrayBuffer) {
  58985. var environment = {
  58986. //irradiance
  58987. irradiancePolynomialCoefficients: {
  58988. x: new babylonjs_1.Vector3(0, 0, 0),
  58989. y: new babylonjs_1.Vector3(0, 0, 0),
  58990. z: new babylonjs_1.Vector3(0, 0, 0),
  58991. xx: new babylonjs_1.Vector3(0, 0, 0),
  58992. yy: new babylonjs_1.Vector3(0, 0, 0),
  58993. zz: new babylonjs_1.Vector3(0, 0, 0),
  58994. yz: new babylonjs_1.Vector3(0, 0, 0),
  58995. zx: new babylonjs_1.Vector3(0, 0, 0),
  58996. xy: new babylonjs_1.Vector3(0, 0, 0)
  58997. },
  58998. //specular
  58999. textureIntensityScale: 1.0,
  59000. };
  59001. //read .env
  59002. var littleEndian = false;
  59003. var magicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
  59004. var dataView = new DataView(arrayBuffer);
  59005. var pos = 0;
  59006. for (var i = 0; i < magicBytes.length; i++) {
  59007. if (dataView.getUint8(pos++) !== magicBytes[i]) {
  59008. babylonjs_1.Tools.Error('Not a Spectre environment map');
  59009. }
  59010. }
  59011. var version = dataView.getUint16(pos, littleEndian);
  59012. pos += 2;
  59013. if (version !== 1) {
  59014. babylonjs_1.Tools.Warn('Unsupported Spectre environment map version "' + version + '"');
  59015. }
  59016. //read json descriptor - collect characters up to null terminator
  59017. var descriptorString = '';
  59018. var charCode = 0x00;
  59019. while ((charCode = dataView.getUint8(pos++))) {
  59020. descriptorString += String.fromCharCode(charCode);
  59021. }
  59022. var descriptor = JSON.parse(descriptorString);
  59023. var payloadPos = pos;
  59024. //irradiance
  59025. switch (descriptor.irradiance.type) {
  59026. case 'irradiance_sh_coefficients_9':
  59027. //irradiance
  59028. var harmonics = descriptor.irradiance;
  59029. EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance(harmonics);
  59030. //harmonics now represent radiance
  59031. EnvironmentDeserializer._ConvertSHToSP(harmonics, environment.irradiancePolynomialCoefficients);
  59032. break;
  59033. default:
  59034. babylonjs_1.Tools.Error('Unhandled MapType descriptor.irradiance.type (' + descriptor.irradiance.type + ')');
  59035. }
  59036. //specular
  59037. switch (descriptor.specular.type) {
  59038. case 'cubemap_faces':
  59039. var specularDescriptor = descriptor.specular;
  59040. var specularTexture = environment.specularTexture = new texture_1.TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */);
  59041. environment.textureIntensityScale = specularDescriptor.multiplier != null ? specularDescriptor.multiplier : 1.0;
  59042. var mipmaps = specularDescriptor.mipmaps;
  59043. var imageType = specularDescriptor.imageType;
  59044. for (var l = 0; l < mipmaps.length; l++) {
  59045. var faceRanges = mipmaps[l];
  59046. specularTexture.source[l] = [];
  59047. for (var i = 0; i < 6; i++) {
  59048. var range = faceRanges[i];
  59049. var bytes = new Uint8Array(arrayBuffer, payloadPos + range.pos, range.length);
  59050. switch (imageType) {
  59051. case 'png':
  59052. //construct image element from bytes
  59053. var image = new Image();
  59054. var src = URL.createObjectURL(new Blob([bytes], { type: 'image/png' }));
  59055. image.src = src;
  59056. specularTexture.source[l][i] = image;
  59057. break;
  59058. default:
  59059. babylonjs_1.Tools.Error('Unhandled ImageType descriptor.specular.imageType (' + imageType + ')');
  59060. }
  59061. }
  59062. }
  59063. break;
  59064. default:
  59065. babylonjs_1.Tools.Error('Unhandled MapType descriptor.specular.type (' + descriptor.specular.type + ')');
  59066. }
  59067. return environment;
  59068. };
  59069. /**
  59070. * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
  59071. * L = (1/pi) * E * rho
  59072. *
  59073. * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
  59074. * @param harmonics Spherical harmonic coefficients (9)
  59075. */
  59076. EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance = function (harmonics) {
  59077. EnvironmentDeserializer._ScaleSH(harmonics, 1 / Math.PI);
  59078. // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
  59079. // (The pixel shader must apply albedo after texture fetches, etc).
  59080. };
  59081. /**
  59082. * Convert spherical harmonics to spherical polynomial coefficients
  59083. * @param harmonics Spherical harmonic coefficients (9)
  59084. * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
  59085. */
  59086. EnvironmentDeserializer._ConvertSHToSP = function (harmonics, outPolynomialCoefficents) {
  59087. var rPi = 1 / Math.PI;
  59088. //x
  59089. outPolynomialCoefficents.x.x = 1.02333 * harmonics.l11[0] * rPi;
  59090. outPolynomialCoefficents.x.y = 1.02333 * harmonics.l11[1] * rPi;
  59091. outPolynomialCoefficents.x.z = 1.02333 * harmonics.l11[2] * rPi;
  59092. outPolynomialCoefficents.y.x = 1.02333 * harmonics.l1_1[0] * rPi;
  59093. outPolynomialCoefficents.y.y = 1.02333 * harmonics.l1_1[1] * rPi;
  59094. outPolynomialCoefficents.y.z = 1.02333 * harmonics.l1_1[2] * rPi;
  59095. outPolynomialCoefficents.z.x = 1.02333 * harmonics.l10[0] * rPi;
  59096. outPolynomialCoefficents.z.y = 1.02333 * harmonics.l10[1] * rPi;
  59097. outPolynomialCoefficents.z.z = 1.02333 * harmonics.l10[2] * rPi;
  59098. //xx
  59099. outPolynomialCoefficents.xx.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] + 0.429043 * harmonics.l22[0]) * rPi;
  59100. outPolynomialCoefficents.xx.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] + 0.429043 * harmonics.l22[1]) * rPi;
  59101. outPolynomialCoefficents.xx.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] + 0.429043 * harmonics.l22[2]) * rPi;
  59102. outPolynomialCoefficents.yy.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] - 0.429043 * harmonics.l22[0]) * rPi;
  59103. outPolynomialCoefficents.yy.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] - 0.429043 * harmonics.l22[1]) * rPi;
  59104. outPolynomialCoefficents.yy.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] - 0.429043 * harmonics.l22[2]) * rPi;
  59105. outPolynomialCoefficents.zz.x = (0.886277 * harmonics.l00[0] + 0.495417 * harmonics.l20[0]) * rPi;
  59106. outPolynomialCoefficents.zz.y = (0.886277 * harmonics.l00[1] + 0.495417 * harmonics.l20[1]) * rPi;
  59107. outPolynomialCoefficents.zz.z = (0.886277 * harmonics.l00[2] + 0.495417 * harmonics.l20[2]) * rPi;
  59108. //yz
  59109. outPolynomialCoefficents.yz.x = 0.858086 * harmonics.l2_1[0] * rPi;
  59110. outPolynomialCoefficents.yz.y = 0.858086 * harmonics.l2_1[1] * rPi;
  59111. outPolynomialCoefficents.yz.z = 0.858086 * harmonics.l2_1[2] * rPi;
  59112. outPolynomialCoefficents.zx.x = 0.858086 * harmonics.l21[0] * rPi;
  59113. outPolynomialCoefficents.zx.y = 0.858086 * harmonics.l21[1] * rPi;
  59114. outPolynomialCoefficents.zx.z = 0.858086 * harmonics.l21[2] * rPi;
  59115. outPolynomialCoefficents.xy.x = 0.858086 * harmonics.l2_2[0] * rPi;
  59116. outPolynomialCoefficents.xy.y = 0.858086 * harmonics.l2_2[1] * rPi;
  59117. outPolynomialCoefficents.xy.z = 0.858086 * harmonics.l2_2[2] * rPi;
  59118. };
  59119. /**
  59120. * Multiplies harmonic coefficients in place
  59121. * @param harmonics Spherical harmonic coefficients (9)
  59122. * @param scaleFactor Value to multiply by
  59123. */
  59124. EnvironmentDeserializer._ScaleSH = function (harmonics, scaleFactor) {
  59125. harmonics.l00[0] *= scaleFactor;
  59126. harmonics.l00[1] *= scaleFactor;
  59127. harmonics.l00[2] *= scaleFactor;
  59128. harmonics.l1_1[0] *= scaleFactor;
  59129. harmonics.l1_1[1] *= scaleFactor;
  59130. harmonics.l1_1[2] *= scaleFactor;
  59131. harmonics.l10[0] *= scaleFactor;
  59132. harmonics.l10[1] *= scaleFactor;
  59133. harmonics.l10[2] *= scaleFactor;
  59134. harmonics.l11[0] *= scaleFactor;
  59135. harmonics.l11[1] *= scaleFactor;
  59136. harmonics.l11[2] *= scaleFactor;
  59137. harmonics.l2_2[0] *= scaleFactor;
  59138. harmonics.l2_2[1] *= scaleFactor;
  59139. harmonics.l2_2[2] *= scaleFactor;
  59140. harmonics.l2_1[0] *= scaleFactor;
  59141. harmonics.l2_1[1] *= scaleFactor;
  59142. harmonics.l2_1[2] *= scaleFactor;
  59143. harmonics.l20[0] *= scaleFactor;
  59144. harmonics.l20[1] *= scaleFactor;
  59145. harmonics.l20[2] *= scaleFactor;
  59146. harmonics.l21[0] *= scaleFactor;
  59147. harmonics.l21[1] *= scaleFactor;
  59148. harmonics.l21[2] *= scaleFactor;
  59149. harmonics.l22[0] *= scaleFactor;
  59150. harmonics.l22[1] *= scaleFactor;
  59151. harmonics.l22[2] *= scaleFactor;
  59152. };
  59153. return EnvironmentDeserializer;
  59154. }());
  59155. exports.EnvironmentDeserializer = EnvironmentDeserializer;
  59156. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52aXJvbm1lbnRTZXJpYWxpemVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xhYnMvZW52aXJvbm1lbnRTZXJpYWxpemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsdUNBQTJDO0FBQzNDLHFDQUFnRTtB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ztRQUNqQyxTQUFTLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNqQyxTQUFTLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNqQyxTQUFTLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNqQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztRQUNoQyxTQUFTLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLFdBQVcsQ0FBQztJQUNwQyxDQUFDO0lBQ0wsOEJBQUM7QUFBRCxDQUFDLEFBck5ELElBcU5DO0FBck5ZLDBEQUF1QiJ9
  59157. /***/ }),
  59158. /* 26 */
  59159. /***/ (function(module, exports, __webpack_require__) {
  59160. "use strict";
  59161. Object.defineProperty(exports, "__esModule", { value: true });
  59162. var extended_1 = __webpack_require__(27);
  59163. var cache = {};
  59164. /**
  59165. *
  59166. * @param name the name of the custom optimizer configuration
  59167. * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
  59168. */
  59169. function getCustomOptimizerByName(name, upgrade) {
  59170. if (!cache[name]) {
  59171. switch (name) {
  59172. case 'extended':
  59173. if (upgrade) {
  59174. return extended_1.extendedUpgrade;
  59175. }
  59176. else {
  59177. return extended_1.extendedDegrade;
  59178. }
  59179. }
  59180. }
  59181. return cache[name];
  59182. }
  59183. exports.getCustomOptimizerByName = getCustomOptimizerByName;
  59184. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvb3B0aW1pemVyL2N1c3RvbS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVDQUE4RDtBQUc5RCxJQUFNLEtBQUssR0FBK0QsRUFBRSxDQUFDO0FBRTdFOzs7O0dBSUc7QUFDSCxrQ0FBeUMsSUFBWSxFQUFFLE9BQWlCO0lBQ3BFLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLEVBQUU7UUFDZCxRQUFRLElBQUksRUFBRTtZQUNWLEtBQUssVUFBVTtnQkFDWCxJQUFJLE9BQU8sRUFBRTtvQkFDVCxPQUFPLDBCQUFlLENBQUM7aUJBQzFCO3FCQUNJO29CQUNELE9BQU8sMEJBQWUsQ0FBQztpQkFDMUI7U0FDUjtLQUNKO0lBRUQsT0FBTyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7QUFDdkIsQ0FBQztBQWRELDREQWNDIn0=
  59185. /***/ }),
  59186. /* 27 */
  59187. /***/ (function(module, exports, __webpack_require__) {
  59188. "use strict";
  59189. Object.defineProperty(exports, "__esModule", { value: true });
  59190. var babylonjs_1 = __webpack_require__(0);
  59191. /**
  59192. * A custom upgrade-oriented function configuration for the scene optimizer.
  59193. *
  59194. * @param viewer the viewer to optimize
  59195. */
  59196. function extendedUpgrade(sceneManager) {
  59197. var defaultPipeline = sceneManager.defaultRenderingPipeline;
  59198. // if (!this.Scene.BackgroundHelper) {
  59199. // this.Scene.EngineScene.autoClear = false;
  59200. // this.Scene.BackgroundHelper = true;
  59201. // Would require a dedicated clear color;
  59202. // return false;
  59203. // }
  59204. if (sceneManager.scene.getEngine().getHardwareScalingLevel() > 1) {
  59205. var scaling = babylonjs_1.Scalar.Clamp(sceneManager.scene.getEngine().getHardwareScalingLevel() - 0.25, 0, 1);
  59206. sceneManager.scene.getEngine().setHardwareScalingLevel(scaling);
  59207. return false;
  59208. }
  59209. if (!sceneManager.scene.postProcessesEnabled) {
  59210. sceneManager.scene.postProcessesEnabled = true;
  59211. return false;
  59212. }
  59213. if (!sceneManager.groundEnabled) {
  59214. sceneManager.groundEnabled = true;
  59215. return false;
  59216. }
  59217. if (defaultPipeline && !sceneManager.fxaaEnabled) {
  59218. sceneManager.fxaaEnabled = true;
  59219. return false;
  59220. }
  59221. var hardwareScalingLevel = Math.max(1 / 2, 1 / (window.devicePixelRatio || 2));
  59222. if (sceneManager.scene.getEngine().getHardwareScalingLevel() > hardwareScalingLevel) {
  59223. var scaling = babylonjs_1.Scalar.Clamp(sceneManager.scene.getEngine().getHardwareScalingLevel() - 0.25, 0, hardwareScalingLevel);
  59224. sceneManager.scene.getEngine().setHardwareScalingLevel(scaling);
  59225. return false;
  59226. }
  59227. if (!sceneManager.processShadows) {
  59228. sceneManager.processShadows = true;
  59229. return false;
  59230. }
  59231. if (defaultPipeline && !sceneManager.bloomEnabled) {
  59232. sceneManager.bloomEnabled = true;
  59233. return false;
  59234. }
  59235. if (!sceneManager.groundMirrorEnabled) {
  59236. sceneManager.groundMirrorEnabled = true;
  59237. return false;
  59238. }
  59239. return true;
  59240. }
  59241. exports.extendedUpgrade = extendedUpgrade;
  59242. /**
  59243. * A custom degrade-oriented function configuration for the scene optimizer.
  59244. *
  59245. * @param viewer the viewer to optimize
  59246. */
  59247. function extendedDegrade(sceneManager) {
  59248. var defaultPipeline = sceneManager.defaultRenderingPipeline;
  59249. if (sceneManager.groundMirrorEnabled) {
  59250. sceneManager.groundMirrorEnabled = false;
  59251. return false;
  59252. }
  59253. if (defaultPipeline && sceneManager.bloomEnabled) {
  59254. sceneManager.bloomEnabled = false;
  59255. return false;
  59256. }
  59257. if (sceneManager.processShadows) {
  59258. sceneManager.processShadows = false;
  59259. return false;
  59260. }
  59261. if (sceneManager.scene.getEngine().getHardwareScalingLevel() < 1) {
  59262. var scaling = babylonjs_1.Scalar.Clamp(sceneManager.scene.getEngine().getHardwareScalingLevel() + 0.25, 0, 1);
  59263. sceneManager.scene.getEngine().setHardwareScalingLevel(scaling);
  59264. return false;
  59265. }
  59266. if (defaultPipeline && sceneManager.fxaaEnabled) {
  59267. sceneManager.fxaaEnabled = false;
  59268. return false;
  59269. }
  59270. if (sceneManager.groundEnabled) {
  59271. sceneManager.groundEnabled = false;
  59272. return false;
  59273. }
  59274. if (sceneManager.scene.postProcessesEnabled) {
  59275. sceneManager.scene.postProcessesEnabled = false;
  59276. return false;
  59277. }
  59278. if (sceneManager.scene.getEngine().getHardwareScalingLevel() < 1.25) {
  59279. var scaling = babylonjs_1.Scalar.Clamp(sceneManager.scene.getEngine().getHardwareScalingLevel() + 0.25, 0, 1.25);
  59280. sceneManager.scene.getEngine().setHardwareScalingLevel(scaling);
  59281. return false;
  59282. }
  59283. // if (this.Scene.BackgroundHelper) {
  59284. // this.Scene.EngineScene.autoClear = true;
  59285. // this.Scene.BackgroundHelper = false;
  59286. // Would require a dedicated clear color;
  59287. // return false;
  59288. // }
  59289. return true;
  59290. }
  59291. exports.extendedDegrade = extendedDegrade;
  59292. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXh0ZW5kZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvb3B0aW1pemVyL2N1c3RvbS9leHRlbmRl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QUNoQjtJQUNELElBQUksWUFBWSxDQUFDLGFBQWEsRUFBRTtRQUM1QixZQUFZLENBQUMsYUFBYSxHQUFHLEtBQUssQ0FBQztRQUNuQyxPQUFPLEtBQUssQ0FBQztLQUNoQjtJQUNELElBQUksWUFBWSxDQUFDLEtBQUssQ0FBQyxvQkFBb0IsRUFBRTtRQUN6QyxZQUFZLENBQUMsS0FBSyxDQUFDLG9CQUFvQixHQUFHLEtBQUssQ0FBQztRQUNoRCxPQUFPLEtBQUssQ0FBQztLQUNoQjtJQUNELElBQUksWUFBWSxDQUFDLEtBQUssQ0FBQyxTQUFTLEVBQUUsQ0FBQyx1QkFBdUIsRUFBRSxHQUFHLElBQUksRUFBRTtRQUNqRSxJQUFJLE9BQU8sR0FBRyxrQkFBTSxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLFNBQVMsRUFBRSxDQUFDLHVCQUF1QixFQUFFLEdBQUcsSUFBSSxFQUFFLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQztRQUNyRyxZQUFZLENBQUMsS0FBSyxDQUFDLFNBQVMsRUFBRSxDQUFDLHVCQUF1QixDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQ2hFLE9BQU8sS0FBSyxDQUFDO0tBQ2hCO0lBQ0QscUNBQXFDO0lBQ3JDLDRDQUE0QztJQUM1Qyx1Q0FBdUM7SUFDdkMseUNBQXlDO0lBQ3pDLGdCQUFnQjtJQUNoQixJQUFJO0lBQ0osT0FBTyxJQUFJLENBQUM7QUFDaEIsQ0FBQztBQTVDRCwwQ0E0Q0MifQ==
  59293. /***/ }),
  59294. /* 28 */
  59295. /***/ (function(module, exports, __webpack_require__) {
  59296. "use strict";
  59297. Object.defineProperty(exports, "__esModule", { value: true });
  59298. var mappers_1 = __webpack_require__(3);
  59299. var types_1 = __webpack_require__(29);
  59300. var configurationCompatibility_1 = __webpack_require__(53);
  59301. var _1 = __webpack_require__(1);
  59302. var babylonjs_1 = __webpack_require__(0);
  59303. /**
  59304. * The configuration loader will load the configuration object from any source and will use the defined mapper to
  59305. * parse the object and return a conform ViewerConfiguration.
  59306. * It is a private member of the scene.
  59307. */
  59308. var ConfigurationLoader = /** @class */ (function () {
  59309. function ConfigurationLoader(_enableCache) {
  59310. if (_enableCache === void 0) { _enableCache = false; }
  59311. this._enableCache = _enableCache;
  59312. this._configurationCache = {};
  59313. this._loadRequests = [];
  59314. }
  59315. /**
  59316. * load a configuration object that is defined in the initial configuration provided.
  59317. * The viewer configuration can extend different types of configuration objects and have an extra configuration defined.
  59318. *
  59319. * @param initConfig the initial configuration that has the definitions of further configuration to load.
  59320. * @param callback an optional callback that will be called sync, if noconfiguration needs to be loaded or configuration is payload-only
  59321. * @returns A promise that delivers the extended viewer configuration, when done.
  59322. */
  59323. ConfigurationLoader.prototype.loadConfiguration = function (initConfig, callback) {
  59324. var _this = this;
  59325. if (initConfig === void 0) { initConfig = {}; }
  59326. var loadedConfig = _1.deepmerge({}, initConfig);
  59327. var extendedConfiguration = types_1.getConfigurationType(loadedConfig.extends || "");
  59328. if (loadedConfig.configuration) {
  59329. var mapperType_1 = "json";
  59330. return Promise.resolve().then(function () {
  59331. if (typeof loadedConfig.configuration === "string" || (loadedConfig.configuration && loadedConfig.configuration.url)) {
  59332. // a file to load
  59333. var url = '';
  59334. if (typeof loadedConfig.configuration === "string") {
  59335. url = loadedConfig.configuration;
  59336. }
  59337. // if configuration is an object
  59338. if (typeof loadedConfig.configuration === "object" && loadedConfig.configuration.url) {
  59339. url = loadedConfig.configuration.url;
  59340. var type = loadedConfig.configuration.mapper;
  59341. // empty string?
  59342. if (!type) {
  59343. // load mapper type from filename / url
  59344. type = loadedConfig.configuration.url.split('.').pop();
  59345. }
  59346. mapperType_1 = type || mapperType_1;
  59347. }
  59348. return _this._loadFile(url);
  59349. }
  59350. else {
  59351. if (typeof loadedConfig.configuration === "object") {
  59352. mapperType_1 = loadedConfig.configuration.mapper || mapperType_1;
  59353. return loadedConfig.configuration.payload || {};
  59354. }
  59355. return {};
  59356. }
  59357. }).then(function (data) {
  59358. var mapper = mappers_1.mapperManager.getMapper(mapperType_1);
  59359. var parsed = _1.deepmerge(mapper.map(data), loadedConfig);
  59360. var merged = _1.deepmerge(extendedConfiguration, parsed);
  59361. configurationCompatibility_1.processConfigurationCompatibility(merged);
  59362. if (callback)
  59363. callback(merged);
  59364. return merged;
  59365. });
  59366. }
  59367. else {
  59368. loadedConfig = _1.deepmerge(extendedConfiguration, loadedConfig);
  59369. configurationCompatibility_1.processConfigurationCompatibility(loadedConfig);
  59370. if (callback)
  59371. callback(loadedConfig);
  59372. return Promise.resolve(loadedConfig);
  59373. }
  59374. };
  59375. /**
  59376. * Dispose the configuration loader. This will cancel file requests, if active.
  59377. */
  59378. ConfigurationLoader.prototype.dispose = function () {
  59379. this._loadRequests.forEach(function (request) {
  59380. request.abort();
  59381. });
  59382. this._loadRequests.length = 0;
  59383. };
  59384. ConfigurationLoader.prototype._loadFile = function (url) {
  59385. var _this = this;
  59386. var cacheReference = this._configurationCache;
  59387. if (this._enableCache && cacheReference[url]) {
  59388. return Promise.resolve(cacheReference[url]);
  59389. }
  59390. return new Promise(function (resolve, reject) {
  59391. var fileRequest = babylonjs_1.Tools.LoadFile(url, function (result) {
  59392. var idx = _this._loadRequests.indexOf(fileRequest);
  59393. if (idx !== -1)
  59394. _this._loadRequests.splice(idx, 1);
  59395. if (_this._enableCache)
  59396. cacheReference[url] = result;
  59397. resolve(result);
  59398. }, undefined, undefined, false, function (request, error) {
  59399. var idx = _this._loadRequests.indexOf(fileRequest);
  59400. if (idx !== -1)
  59401. _this._loadRequests.splice(idx, 1);
  59402. reject(error);
  59403. });
  59404. _this._loadRequests.push(fileRequest);
  59405. });
  59406. };
  59407. return ConfigurationLoader;
  59408. }());
  59409. exports.ConfigurationLoader = ConfigurationLoader;
  59410. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZGVyLmpzIiwic291cmNlUm9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0FBQyxDQUFDO1lBQ0gsS0FBSSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUM7UUFDekMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDO0lBRUwsMEJBQUM7QUFBRCxDQUFDLEFBMUdELElBMEdDO0FBMUdZLGtEQUFtQiJ9
  59411. /***/ }),
  59412. /* 29 */
  59413. /***/ (function(module, exports, __webpack_require__) {
  59414. "use strict";
  59415. Object.defineProperty(exports, "__esModule", { value: true });
  59416. var minimal_1 = __webpack_require__(30);
  59417. exports.minimalConfiguration = minimal_1.minimalConfiguration;
  59418. var default_1 = __webpack_require__(49);
  59419. exports.defaultConfiguration = default_1.defaultConfiguration;
  59420. var extended_1 = __webpack_require__(50);
  59421. var shadowLight_1 = __webpack_require__(51);
  59422. var environmentMap_1 = __webpack_require__(52);
  59423. var _1 = __webpack_require__(1);
  59424. /**
  59425. * Get the configuration type you need to use as the base for your viewer.
  59426. * The types can either be a single string, or comma separated types that will extend each other. for example:
  59427. *
  59428. * "default, environmentMap" will first load the default configuration and will extend it using the environmentMap configuration.
  59429. *
  59430. * @param types a comma-separated string of the type(s) or configuration to load.
  59431. */
  59432. var getConfigurationType = function (types) {
  59433. var config = {};
  59434. var typesSeparated = types.split(",");
  59435. typesSeparated.forEach(function (type) {
  59436. switch (type.trim()) {
  59437. case 'environmentMap':
  59438. config = _1.deepmerge(config, environmentMap_1.environmentMapConfiguration);
  59439. break;
  59440. case 'shadowDirectionalLight':
  59441. config = _1.deepmerge(config, shadowLight_1.shadowDirectionalLightConfiguration);
  59442. break;
  59443. case 'shadowSpotLight':
  59444. config = _1.deepmerge(config, shadowLight_1.shadowSpotlLightConfiguration);
  59445. break;
  59446. case 'extended':
  59447. config = _1.deepmerge(config, extended_1.extendedConfiguration);
  59448. break;
  59449. case 'minimal':
  59450. config = _1.deepmerge(config, minimal_1.minimalConfiguration);
  59451. break;
  59452. case 'none':
  59453. break;
  59454. case 'default':
  59455. default:
  59456. config = _1.deepmerge(config, default_1.defaultConfiguration);
  59457. break;
  59458. }
  59459. if (config.extends) {
  59460. config = _1.deepmerge(config, getConfigurationType(config.extends));
  59461. }
  59462. });
  59463. return config;
  59464. };
  59465. exports.getConfigurationType = getConfigurationType;
  59466. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvY29uZmlndXJhdGlvbi90eXBlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHFDQUFpRDtBQW9ESSwrQkFwRDVDLDhCQUFvQixDQW9ENEM7QUFuRHpFLHFDQUFpRDtBQW1EbEIsK0JBbkR0Qiw4QkFBb0IsQ0FtRHNCO0FBbERuRCx1Q0FBbUQ7QUFFbkQsNkNBQW1HO0FBQ25HLG1EQUErRDtBQUMvRCxrQ0FBMEM7QUFFMUM7Ozs7Ozs7R0FPRztBQUNILElBQUksb0JBQW9CLEdBQUcsVUFBVSxLQUFhO0lBQzlDLElBQUksTUFBTSxHQUF3QixFQUFFLENBQUM7SUFDckMsSUFBSSxjQUFjLEdBQUcsS0FBSyxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQztJQUN0QyxjQUFjLENBQUMsT0FBTyxDQUFDLFVBQUEsSUFBSTtRQUN2QixRQUFRLElBQUksQ0FBQyxJQUFJLEVBQUUsRUFBRTtZQUNqQixLQUFLLGdCQUFnQjtnQkFDakIsTUFBTSxHQUFHLFlBQVMsQ0FBQyxNQUFNLEVBQUUsNENBQTJCLENBQUMsQ0FBQztnQkFDeEQsTUFBTTtZQUNWLEtBQUssd0JBQXdCO2dCQUN6QixNQUFNLEdBQUcsWUFBUyxDQUFDLE1BQU0sRUFBRSxpREFBbUMsQ0FBQyxDQUFDO2dCQUNoRSxNQUFNO1lBQ1YsS0FBSyxpQkFBaUI7Z0JBQ2xCLE1BQU0sR0FBRyxZQUFTLENBQUMsTUFBTSxFQUFFLDJDQUE2QixDQUFDLENBQUM7Z0JBQzFELE1BQU07WUFDVixLQUFLLFVBQVU7Z0JBQ1gsTUFBTSxHQUFHLFlBQVMsQ0FBQyxNQUFNLEVBQUUsZ0NBQXFCLENBQUMsQ0FBQztnQkFDbEQsTUFBTTtZQUNWLEtBQUssU0FBUztnQkFDVixNQUFNLEdBQUcsWUFBUyxDQUFDLE1BQU0sRUFBRSw4QkFBb0IsQ0FBQyxDQUFDO2dCQUNqRCxNQUFNO1lBQ1YsS0FBSyxNQUFNO2dCQUNQLE1BQU07WUFDVixLQUFLLFNBQVMsQ0FBQztZQUNmO2dCQUNJLE1BQU0sR0FBRyxZQUFTLENBQUMsTUFBTSxFQUFFLDhCQUFvQixDQUFDLENBQUM7Z0JBQ2pELE1BQU07U0FDYjtRQUVELElBQUksTUFBTSxDQUFDLE9BQU8sRUFBRTtZQUNoQixNQUFNLEdBQUcsWUFBUyxDQUFDLE1BQU0sRUFBRSxvQkFBb0IsQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQztTQUNwRTtJQUNMLENBQUMsQ0FBQyxDQUFDO0lBQ0gsT0FBTyxNQUFNLENBQUM7QUFFbEIsQ0FBQyxDQUFBO0FBRVEsb0RBQW9CIn0=
  59467. /***/ }),
  59468. /* 30 */
  59469. /***/ (function(module, exports, __webpack_require__) {
  59470. "use strict";
  59471. Object.defineProperty(exports, "__esModule", { value: true });
  59472. var babylonjs_viewer_assets_1 = __webpack_require__(2);
  59473. var babylonjs_viewer_assets_2 = __webpack_require__(2);
  59474. /**
  59475. * The minimal configuration needed to make the viewer work.
  59476. * Some functionalities might not work correctly (like fill-screen)
  59477. */
  59478. exports.minimalConfiguration = {
  59479. version: "0.1",
  59480. templates: {
  59481. main: {
  59482. html: babylonjs_viewer_assets_1.defaultTemplate
  59483. },
  59484. fillContainer: {
  59485. html: babylonjs_viewer_assets_1.fillContainer,
  59486. params: {
  59487. disable: false
  59488. }
  59489. },
  59490. loadingScreen: {
  59491. html: babylonjs_viewer_assets_1.loadingScreen,
  59492. params: {
  59493. backgroundColor: "#000000",
  59494. loadingImage: babylonjs_viewer_assets_2.loading
  59495. }
  59496. },
  59497. viewer: {
  59498. html: babylonjs_viewer_assets_1.defaultViewer,
  59499. },
  59500. overlay: {
  59501. html: babylonjs_viewer_assets_1.overlay,
  59502. params: {
  59503. closeImage: babylonjs_viewer_assets_2.close,
  59504. closeText: 'Close'
  59505. }
  59506. },
  59507. error: {
  59508. html: babylonjs_viewer_assets_1.error
  59509. }
  59510. },
  59511. engine: {
  59512. antialiasing: true
  59513. }
  59514. };
  59515. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWluaW1hbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL3R5cGVzL21pbmltYWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxtRUFBdUg7QUFDdkgsbUVBQXlEO0FBRXpEOzs7R0FHRztBQUNRLFFBQUEsb0JBQW9CLEdBQXdCO0lBQ25ELE9BQU8sRUFBRSxLQUFLO0lBQ2QsU0FBUyxFQUFFO1FBQ1AsSUFBSSxFQUFFO1lBQ0YsSUFBSSxFQUFFLHlDQUFlO1NBQ3hCO1FBQ0QsYUFBYSxFQUFFO1lBQ1gsSUFBSSxFQUFFLHVDQUFhO1lBQ25CLE1BQU0sRUFBRTtnQkFDSixPQUFPLEVBQUUsS0FBSzthQUNqQjtTQUNKO1FBQ0QsYUFBYSxFQUFFO1lBQ1gsSUFBSSxFQUFFLHVDQUFhO1lBQ25CLE1BQU0sRUFBRTtnQkFDSixlQUFlLEVBQUUsU0FBUztnQkFDMUIsWUFBWSxFQUFFLGlDQUFPO2FBQ3hCO1NBQ0o7UUFDRCxNQUFNLEVBQUU7WUFDSixJQUFJLEVBQUUsdUNBQWE7U0FDdEI7UUFDRCxPQUFPLEVBQUU7WUFDTCxJQUFJLEVBQUUsaUNBQU87WUFDYixNQUFNLEVBQUU7Z0JBQ0osVUFBVSxFQUFFLCtCQUFLO2dCQUNqQixTQUFTLEVBQUUsT0FBTzthQUNyQjtTQUNKO1FBQ0QsS0FBSyxFQUFFO1lBQ0gsSUFBSSxFQUFFLCtCQUFLO1NBQ2Q7S0FFSjtJQUNELE1BQU0sRUFBRTtRQUNKLFlBQVksRUFBRSxJQUFJO0tBQ3JCO0NBQ0osQ0FBQSJ9
  59516. /***/ }),
  59517. /* 31 */
  59518. /***/ (function(module, exports, __webpack_require__) {
  59519. "use strict";
  59520. Object.defineProperty(exports, "__esModule", { value: true });
  59521. exports.babylonFont = __webpack_require__(32);
  59522. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9udC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9hc3NldHMvZm9udC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFhLFFBQUEsV0FBVyxHQUFHLE9BQU8sQ0FBQywyQkFBMkIsQ0FBQyxDQUFDIn0=
  59523. /***/ }),
  59524. /* 32 */
  59525. /***/ (function(module, exports) {
  59526. module.exports = "data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAABIgAA8AAAAAH7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABWAAAAEcAAABgSlp9rlZETVgAAAGgAAACBQAABeCBXolxY21hcAAAA6gAAABxAAAAsqyRvzljdnQgAAAEHAAAACAAAAAqCdkJr2ZwZ20AAAQ8AAAA8AAAAVn8nuaOZ2FzcAAABSwAAAAMAAAADAAIABtnbHlmAAAFOAAABlUAAAh+MHVDHWhlYWQAAAuQAAAAMgAAADb+LvI4aGhlYQAAC8QAAAAVAAAAJBABCAZobXR4AAAL3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OiWwLq7Z1GeK2glkU9PcpQtrjzYFoUugfxl2nNCRr8si9jaG/1vbOXtKTBnIDM2xo84ls1ldlEHn/cm4rvdmADNpc3Hkr3sLkL/NNQXJlDLX9FY+a/bEsamS1Bft1zarFtf0ZtVkidF23ex4ULOgN/npM9p+1UrfmTl794YoX2WcH4x3RJVuezv/Igua4O78F5z6X2t57JtMX+Vj9+A9ejXajN6P3o3ehnXnGFMJ9ndB7yHVrWyjDH4Ivg0ZdXMXNA3Ei9mIfwCJoYWxAHjaY2BmAIP/fgzlDFgAACkqAcgAeNrbwKDNsImRk0mbcRMXiNzO1ZobaqvKwKG9nTs12EFPBsTiifCw0JAEsXidzbXlhUEsPh0VGREeEItfTkKYjwPEEuDj4WRnAbEEwQDEEtowoSDAAMhi2M4IN5oJbjQz3GgWuNGscKPZ5CShRrPDjeaAG80JN3qTMCO79gYGBdfaTAkXAMQBKBoAAAA="
  59527. /***/ }),
  59528. /* 33 */
  59529. /***/ (function(module, exports, __webpack_require__) {
  59530. "use strict";
  59531. Object.defineProperty(exports, "__esModule", { value: true });
  59532. exports.babylonLogo = __webpack_require__(34);
  59533. exports.close = __webpack_require__(35);
  59534. exports.fullscreen = __webpack_require__(36);
  59535. exports.helpCircle = __webpack_require__(37);
  59536. exports.loading = __webpack_require__(38);
  59537. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2Fzc2V0cy9pbWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBYSxRQUFBLFdBQVcsR0FBRyxPQUFPLENBQUMsMkNBQTJDLENBQUMsQ0FBQztBQUNuRSxRQUFBLEtBQUssR0FBRyxPQUFPLENBQUMsNEJBQTRCLENBQUMsQ0FBQztBQUM5QyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsaUNBQWlDLENBQUMsQ0FBQztBQUN4RCxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsa0NBQWtDLENBQUMsQ0FBQztBQUN6RCxRQUFBLE9BQU8sR0FBRyxPQUFPLENBQUMsOEJBQThCLENBQUMsQ0FBQyJ9
  59538. /***/ }),
  59539. /* 34 */
  59540. /***/ (function(module, exports) {
  59541. module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB7MAAAgHCAYAAABZmyd0AAAACXBIWXMAAC4jAAAuIwF4pT92AAAgAElEQVR42uzd7XEb6Zm24Wtc+5/IgO0IyDcCtiMQNwLBEYgTgaAIhhOBpQhMRSAwghEjWCoCixHw/fE0DIKiKAIE+vM4qlDi1I531/fYRDdOPHf/dn9/HwAAAAAmb5bkNMnSKAAAgD74HyMAAAAAmJwqJVyfJqmbP4+a/9m3JIskH40JAADo0m9OZgMAAACM2ukTr6MX/OtEbQAAoFNiNgAAAMB41FkH6yrJ2R7+d4raAABAJ8RsAAAAgOFZPd+6znpl+MmB/2+K2gAAQKvEbAAAAIB+q/LjmvDjDv//EbUBAIBWiNkAAAAA/bFaD746df3S51t3QdQGAAAOSswGAAAA6Mbj09ZnA/33IWoDAAAHIWYDAAAAHF6dzXB9MsJ/j6I2AACwV2I2AAAAwP7MsrkivOvnW3dB1AYAAPZCzAYAAADYTZV1sK6bvz42lv8StQEAgFcRswEAAAB+bRWtq6xPXR8Zy4uI2gAAwE7EbAAAAIBNddbh+jTJmZHshagNAABsRcwGAAAApmr1fOuHrxNjOThRGwAAeBExGwAAAJiCVbiusw7Xnm/dLVEbAAB4lpgNAAAAjE2VdbCu4/nWfSdqAwAATxKzAQAAgCF7vCbc862HS9QGAAA2iNkAAADAUNRZR+sqwvVYidoAAEASMRsAAADon4fPt66an0+MZXJEbQAAmDgxGwAAAOhSlR9XhR8bCw+I2gAAMFFiNgAAANCW1Xrw1anr0yRHxsILidoAADAxYjYAAABwCHU2T117vjX7ImoDAMBEiNkAAADAa9XZXBPu+da0QdQGAICRE7MBAACA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XlNkAAPTJNKXQPqnkeaywAQAAAOCZlNkAAPTNLMnlwJ9hk1JgNz5OAAAAAHgeZTYAAH00T/JhYL/mXcp7v+dJ1j5CAAAAAHgZZTYAAH21SvJ2AL/O+xX2Msmtjw0AAAAA2qHMBgCgryYpC+fXPfy1WWEDAAAAQMeU2QAA9Nk0ZaF90pNfzzb7d2FbYQMAAABAh5TZAAD03SzJ5ZF/DYuUAnvl4wAAAACAw1BmAwAwBE2S8wP/f1phAwAAAMARKbMBABiKdZLTA/z/WGEDAAAAQA8oswEAGIpJkpt08/7sbUqBPY8VNgAAAAD0gjIbAIAhmSb51uL/3lVKib0ULQAAAAD0izIbAIChmSW5fMHff7/CblKW3gAAAABADymzAQAYoibJ+RP/HitsAAAAABgQZTYAAEO1TnL6i79ml/27sG9EBgAAAADDocwGAGCo3qQU2icP/HfX2Z8SBwAAAAAGSJkNAMCQnSX5evefrbABAAAAoCLKbAAAhu5dkkmssAEAAACgKv8F3qtfY+YVvDIAAAAASUVORK5CYII="
  59542. /***/ }),
  59543. /* 35 */
  59544. /***/ (function(module, exports) {
  59545. module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAt0lEQVR42u2WAQbDQBBFQ9IbRtDcrrqK3LBbXrEH6OuHEPMBjPd2xHyZKtdNpcLMg11Pr7y4/YdvwIdd4jtw4BU0Rjrbz9mNzkjzgpU3wNhCvH5M3i1fKzzeK3K8V+R4r8jxTpHjlULhc0WOd8fU6e4I8y3y13tFjHel4GswwAvFSR/ZN6Zv2gjvmzbGhwqPzxUenys83is8Pld4vFac/9sy8/SVNrbgYJl8WGhsvkpoA1+pVK6ZLyLNXm2txsT5AAAAAElFTkSuQmCC"
  59546. /***/ }),
  59547. /* 36 */
  59548. /***/ (function(module, exports) {
  59549. module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQAAAAB/ecQqAAAAAnRSTlMAAHaTzTgAAAAeSURBVHgBY6ASsP/A/wcXZQNGhCkyAfE24HUndQAAXlkXcQ24P7gAAAAASUVORK5CYII="
  59550. /***/ }),
  59551. /* 37 */
  59552. /***/ (function(module, exports) {
  59553. module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAB/ElEQVR42u3Xs4JdQRzH8X9sqYrNNnbqtPELxKgWD7AsI71B7BcI21W9rNa+d27zjSac/5kzZ2J8yqPfGUn++xMwis2UcpsGuilQoJt6blHCJkbKt2I+FbSRpJVy5kos5nAVQxrDJWbFfP4wXYTqYL9kwRiuk9VFRksYJvKEGA+ZEPb3+udrOcNaJjGJtZyhTo8IKIVaOXmOMfKrrnsCo1WU+HFE/fxu9dk9asR+f8fswnU08fmTuDo8nZarat2P/DjobtFPP3dY8bGi6jNUE/MxuM58vNsFVvfHiHNqleqjmwo0a+zdW3zutr26Dk2ZPqW1oZli7/fzuT57dQqaFmUaZDNZ9HoDYIMbUEoWt+xb69EVuwG3CdfNcvtWNbqbbkB9ePVgK4DFDKGrcwO6CNPHJvvGdGpI0uEGGELk2WGfn8or33OxAUc/TulP8cnHVVENI5Vhp+mIa+TT9tm9pKkN7ab6tHEDRVo3LUGjTxuNpClyAzaRSiwGSbPeDRhJC99Ls7rno5zvpUw0zMMQQV1wdFzmezgvSZhJR1Aj+3QyW5Jx8JsD9okfV74p4ELIceNudMAjRodtfh8T4yETg7fvEf3pAqMlCw7QQah29kl2zOIiedLkOc9MicVcymkhSQtlzJVvxUg2UMxNaunCYOiihpsUsZ6R8t8f4DUz8hFGPnrb0AAAAABJRU5ErkJggg=="
  59554. /***/ }),
  59555. /* 38 */
  59556. /***/ (function(module, exports) {
  59557. module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAStUlEQVR42uyaA7TrShiFn23btm3btm3btm3btm372LWd9+318nSRNk2mtz3trLXX5PbmZOafPT9nxmq1VmuKFggEZs1ms0uVSqUj8vn8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Zsa3WaZckf5yD4EXGuTq89nb50az5t94G6VV6khQs3h7zSUMnAs6q7S87xRoiiBH/2UYF+YMjra8ifR40IjeLc30vmeAlxXoAn7AV6L9r9K0oOcELVnhUD51k5w1mForNtjB8YjV4WeWOZ4yG52gryhF0K30uPraYciNZT076gXFPnSWfVanxvYK/WpElHxMs3IpXlWOgi4sQ8L1IBp4laFc0/iO/WZKR84c9EJE8WCrDaqxfI2z976FlFzhWfG4B7VSvIvj5ZpNaMTbpbbda/fLknDDv09Sz2p9JsbqPYKRptRCLd1Dhj5Pe3CgL1P7ke1V5UfL/WHXiy5HrFWAyAG763EGXwfYVmhANDbd6Ogsokfaahw6k0h7hvDNEQ58KZYcQ5r7HFbbBz/wbO+YJZkavri9o3hyzAyobZwULtmyPgMR9lhWx71d0Z8Q7FauTlnVB3azWIGxux4G4KoWYNcGiX0n1ELr7CZwssRXgpzAp1vVYjodv39cYCdspILRaGjUsf/gHJaAWdrW+QG0Rv/QrFbPHSBywngFzzDeiEkB2zovybktEch90C9wcI/zQjSelhUQ3DJTkpdrCxwD+IJroCvCdPXnMAg2PLfDU6qoF/eX6TZVl8Lclzax0dsyrVqBpO4pqAQHcDecz3EvxQwkI16kGkp9m0v2ljxoU/UGfElBUCxYCMK/HKejMj5LpRriWVx1yNIgfmhyz+83U4WzFvDsAZUa1yYwfcLAh4P3kwI+S6RMybBcrHjKg8XQshTiOZESR+bS+prONUK1niITtvezTcAGYEid2zasSpGUY1ekSztpgRcpHpsK5co1er1YRDu6DelsCMOL5d6DmVo78FBgRzcRy+pgTzFeiqVq1Ki43KZo0b/wP23paVqC/D3gAAAABJRU5ErkJggg=="
  59558. /***/ }),
  59559. /* 39 */
  59560. /***/ (function(module, exports, __webpack_require__) {
  59561. "use strict";
  59562. Object.defineProperty(exports, "__esModule", { value: true });
  59563. exports.defaultTemplate = __webpack_require__(40);
  59564. exports.defaultViewer = __webpack_require__(41);
  59565. exports.error = __webpack_require__(42);
  59566. exports.fillContainer = __webpack_require__(43);
  59567. exports.help = __webpack_require__(44);
  59568. exports.loadingScreen = __webpack_require__(45);
  59569. exports.navbar = __webpack_require__(46);
  59570. exports.overlay = __webpack_require__(47);
  59571. exports.share = __webpack_require__(48);
  59572. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVtcGxhdGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2Fzc2V0cy90ZW1wbGF0ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBYSxRQUFBLGVBQWUsR0FBRyxPQUFPLENBQUMscURBQXFELENBQUMsQ0FBQztBQUNqRixRQUFBLGFBQWEsR0FBRyxPQUFPLENBQUMsbURBQW1ELENBQUMsQ0FBQztBQUM3RSxRQUFBLEtBQUssR0FBRyxPQUFPLENBQUMsMkNBQTJDLENBQUMsQ0FBQztBQUM3RCxRQUFBLGFBQWEsR0FBRyxPQUFPLENBQUMsbURBQW1ELENBQUMsQ0FBQztBQUM3RSxRQUFBLElBQUksR0FBRyxPQUFPLENBQUMsMENBQTBDLENBQUMsQ0FBQztBQUMzRCxRQUFBLGFBQWEsR0FBRyxPQUFPLENBQUMsbURBQW1ELENBQUMsQ0FBQztBQUM3RSxRQUFBLE1BQU0sR0FBRyxPQUFPLENBQUMsNENBQTRDLENBQUMsQ0FBQztBQUMvRCxRQUFBLE9BQU8sR0FBRyxPQUFPLENBQUMsNkNBQTZDLENBQUMsQ0FBQztBQUNqRSxRQUFBLEtBQUssR0FBRyxPQUFPLENBQUMsMkNBQTJDLENBQUMsQ0FBQyJ9
  59573. /***/ }),
  59574. /* 40 */
  59575. /***/ (function(module, exports) {
  59576. module.exports = "<style>@font-face{font-family:babylon;src:url({{babylonFont}}) format('woff');font-weight:400;font-style:normal}.icon{font-family:babylon}</style> {{#if fillScreen}} <style>body,html{width:100%;height:100%;margin:0;padding:0}</style> {{/if}} <fill-container></fill-container>";
  59577. /***/ }),
  59578. /* 41 */
  59579. /***/ (function(module, exports) {
  59580. module.exports = "<style>viewer{position:relative;overflow:hidden;z-index:1;justify-content:center;align-items:center;width:100%;height:100%}.babylonjs-canvas{flex:1;width:100%;height:100%;touch-action:none}</style> <canvas class=babylonjs-canvas touch-action=none> </canvas> <nav-bar></nav-bar>";
  59581. /***/ }),
  59582. /* 42 */
  59583. /***/ (function(module, exports) {
  59584. module.exports = "Error loading the model";
  59585. /***/ }),
  59586. /* 43 */
  59587. /***/ (function(module, exports) {
  59588. module.exports = "<style>fill-container{display:flex}fill-container>*{touch-action:none}</style> {{#unless disable}} <style>fill-container{width:100%;height:100%;justify-content:flex-start;align-items:stretch;align-content:stretch}fill-container>*{flex:1 1 auto;flex-direction:row;justify-content:flex-start;align-items:stretch;align-content:stretch}</style> {{/unless}} <viewer></viewer> <loading-screen></loading-screen> <overlay></overlay>";
  59589. /***/ }),
  59590. /* 44 */
  59591. /***/ (function(module, exports) {
  59592. module.exports = "HELP";
  59593. /***/ }),
  59594. /* 45 */
  59595. /***/ (function(module, exports) {
  59596. module.exports = "<style>loading-screen{position:absolute;left:0;z-index:100;opacity:1;pointer-events:none;display:flex;justify-content:center;align-items:center;-webkit-transition:opacity 1s ease;-moz-transition:opacity 1s ease;transition:opacity 1s ease}img.loading-image{-webkit-animation:spin 2s linear infinite;animation:spin 2s linear infinite}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style> <img class=loading-image src={{loadingImage}}>";
  59597. /***/ }),
  59598. /* 46 */
  59599. /***/ (function(module, exports) {
  59600. module.exports = "<style>nav-bar{position:absolute;height:48px;width:100%;bottom:10px;display:flex;justify-content:center}nav-bar .nav-container{display:flex;flex-direction:row;margin:0 10px;height:100%;width:100%;justify-content:center}nav-bar .animation-control{background-color:rgba(91,93,107,.75);display:flex;flex-direction:row;height:100%;width:100%;max-width:1280px;justify-content:center}nav-bar .flex-container{display:flex;flex-direction:row;justify-content:center;height:100%;width:100%}nav-bar button{background:0 0;border:none;color:#fff;margin:0;padding:0;height:100%;min-width:48px;cursor:pointer}nav-bar button:active,nav-bar button:focus,nav-bar button:hover{background:0 0;border:none;outline:0}nav-bar button:hover{background-color:rgba(22,24,26,.2)}nav-bar .control-text{font-family:\"Segoe UI\";font-size:12px;font-weight:400;pointer-events:none}nav-bar .icon,nav-bar img{pointer-events:none}.logo-button{display:flex;align-items:center;flex-direction:row;justify-content:center;background-color:rgba(91,93,107,.75);height:48px;min-width:48px;margin-right:4px}.logo-button img{height:20px;width:20px}.types{display:flex;flex-direction:column;width:48px}.speed .flex-container,.types .flex-container{align-items:center}.menu-options{position:absolute;bottom:48px;width:48px;background-color:rgba(22,24,26,.9)}.animation-label,.help,.logo-button,.speed,.types-icon{display:none}.types-icon:after{font-size:16px;content:\"\\F6BE\"}.up-icon:after{line-height:16px;font-size:12px;content:\"\\E70E\"}.play-icon:after{font-size:16px;content:\"\\E768\"}.pause-icon:after{font-size:16px;content:\"\\E769\"}.fullscreen-icon:after{font-size:16px;content:\"\\E740\"}.help-icon:after{font-size:16px;content:\"\\EF4E\"}.progress-control{display:flex;flex:1;position:relative;overflow:hidden;cursor:pointer;align-items:center}.animation-number{margin:0 6px}.speed-text{margin-right:6px}.progress-circle{width:12px;height:12px;border:2px solid #fff;border-radius:50%;background-color:#5b5d6b;cursor:pointer;position:relative;bottom:10px;pointer-events:none}.default-control{display:flex;flex-direction:row;height:100%;background-color:rgba(91,93,107,.75)}.menu-options button{width:100%;height:48px;color:#8e939b}.menu-options button{width:100%;height:48px;color:#8e939b}.menu-options button:hover{background-color:transparent;color:#fff}.menu-options .animation-number{margin:0 18px 0 6px}.menu-options .speed-text{margin-right:18px}.menu-options{visibility:hidden}.open .menu-options{visibility:visible}.types .menu-options{width:144px}.types .menu-options button{padding:0 8px;justify-content:left}.types .menu-options button>*{display:flex;margin:8px}.types .menu-options button span.animation-number{display:none}.fullscreen{display:none}@media screen and (min-width:540px){.help,.speed,.types-icon{display:inline-block}.logo-button{display:flex}.types{width:84px}.progress-bar-container{margin:0 12px}.speed{width:64px}.speed .menu-options{width:64px}.fullscreen{display:block}}@media screen and (min-width:1024px){.animation-label{display:block;margin-left:6px;text-overflow:ellipsis;overflow:hidden}nav-bar button.animation-buttons{padding:0 8px;justify-content:left}.icon.up-icon{margin-left:8px}nav-bar button.animation-buttons>div{display:flex;pointer-events:none}.animation-number{display:none}.progress-bar-container{margin:0 12px}.types{width:144px}}.progress-wrapper{-webkit-appearance:none;cursor:pointer;width:100%;outline:0;margin:0 12px;height:30px;background-color:transparent}.progress-wrapper::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border:2px solid #fff;border-radius:50%;background:rgba(91,93,107,1);margin-top:-10px}.progress-wrapper::-webkit-slider-runnable-track{height:2px;-webkit-appearance:none;background-color:#fff}.progress-wrapper::-moz-range-progress{background-color:#fff;height:2px}.progress-wrapper::-moz-range-thumb{width:20px;height:20px;border:2px solid #fff;border-radius:50%;background:rgba(91,93,107,1)}.progress-wrapper::-moz-range-track{background:#fff;height:2px}.progress-wrapper::-ms-track{height:2px;background:0 0;border-color:transparent;border-width:10px 0;color:transparent}.progress-wrapper::-ms-fill-lower{background:#fff;border-radius:5px}.progress-wrapper::-ms-fill-upper{background:#fff;border-radius:5px}.progress-wrapper::-ms-thumb{width:16px;height:16px;border:2px solid #fff;border-radius:50%;background:rgba(91,93,107,1);margin-top:0}span{display:inline-block}</style> {{#if (or (not animations) hideAnimations)}} {{#if hideLogo}} <style>nav-bar .nav-container{justify-content:flex-end}</style> {{else}} <style>nav-bar .nav-container{justify-content:space-between}</style> {{/if}} {{/if}} {{#if disableOnFullscreen}} <style>viewer:fullscreen nav-bar{display:none}viewer:-moz-full-screen nav-bar{display:none}viewer:-webkit-full-screen nav-bar{display:none}</style> {{/if}} <div class=nav-container id=navbar-control> {{#unless hideLogo}} <div class=logo-button title={{logoText}}> {{#if logoLink}} <a href={{logoLink}} target=_blank> <img src={{logoImage}}> </a> {{else}} <img src={{logoImage}}> {{/if}} </div> {{/unless}}{{#unless (or (not animations) hideAnimations)}} <div class=animation-control> <div class=types> <button class=\"flex-container animation-buttons\" id=types-button> <span class=\"icon types-icon\"></span> <span class=\"control-text animation-label\">{{selectedAnimationName}}</span> <span class=\"control-text animation-number\">{{selectedAnimation}}</span> {{#if (gt (count animations) 1)}} <span class=\"icon up-icon\"></span> {{/if}} </button> <div class=menu-options> {{#each animations}} {{#unless (eq ../selectedAnimation (add @index 1))}} <button class=\"flex-container animation-buttons\" id=label-option-button data-value={{this}}> <span class=\"icon types-icon\"></span> <span class=\"control-text animation-label\">{{this}}</span> <span class=\"control-text animation-number\">{{add @index 1}}</span> </button> {{/unless}} {{/each}} </div> </div> <div class=progress-control id=progress-control> <button class=play-pause id=play-pause-button> {{#if paused}} <span class=\"icon play-icon\"></span> {{else}} <span class=\"icon pause-icon\"></span> {{/if}} </button> <input class=progress-wrapper id=progress-wrapper type=range min=0 max=100 step=0.01> </div> <div class=speed> <button class=flex-container id=speed-button> <span class=\"control-text speed-text\">{{selectedSpeed}}</span> <span class=\"icon up-icon\"></span> </button> <div class=menu-options> {{#eachInMap speedList}} {{#unless (eq ../selectedSpeed id)}} <button class=flex-container id=speed-option-button data-value={{value}}> <span class=\"control-text speed-text\">{{id}}</span> </button> {{/unless}} {{/eachInMap}} </div> </div> </div> {{/unless}} <div class=default-control> {{#unless hideHelp}} <button class=help id=help-button title=Help> <span class=\"icon help-icon\"></span> </button> {{/unless}} {{#unless hideFullScreen}} <button class=fullscreen id=fullscreen-button title=Fullscreen> <span class=\"icon fullscreen-icon\"></span> </button> {{/unless}} </div> </div>";
  59601. /***/ }),
  59602. /* 47 */
  59603. /***/ (function(module, exports) {
  59604. module.exports = "<style>overlay{position:absolute;z-index:99;opacity:0;display:flex;justify-content:center;align-items:center;-webkit-transition:opacity 1s ease;-moz-transition:opacity 1s ease;transition:opacity 1s ease}.overlay-item{width:100%;height:100%;display:none;align-items:center;justify-content:center;background-color:rgba(121,121,121,.3)}error.overlay-item{background-color:rgba(121,121,121,1)}div#close-button{position:absolute;top:10px;right:10px;width:30px;height:30px;cursor:pointer}div#close-button img{width:100%}</style> <div id=close-button> <img src={{closeImage}} alt={{closeText}}> </div> <help class=overlay-item></help> <error class=overlay-item></error> <share class=overlay-item></share>";
  59605. /***/ }),
  59606. /* 48 */
  59607. /***/ (function(module, exports) {
  59608. module.exports = "SHARE";
  59609. /***/ }),
  59610. /* 49 */
  59611. /***/ (function(module, exports, __webpack_require__) {
  59612. "use strict";
  59613. Object.defineProperty(exports, "__esModule", { value: true });
  59614. var babylonjs_viewer_assets_1 = __webpack_require__(2);
  59615. var babylonjs_viewer_assets_2 = __webpack_require__(2);
  59616. var images = __webpack_require__(2);
  59617. /**
  59618. * The default configuration of the viewer, including templates (canvas, overly, loading screen)
  59619. * This configuration doesn't hold specific parameters, and only defines objects that are needed for the viewer to fully work correctly.
  59620. */
  59621. exports.defaultConfiguration = {
  59622. version: "3.2.0-alpha4",
  59623. templates: {
  59624. main: {
  59625. html: babylonjs_viewer_assets_1.defaultTemplate,
  59626. params: {
  59627. babylonFont: babylonjs_viewer_assets_2.babylonFont,
  59628. noEscape: true
  59629. }
  59630. },
  59631. fillContainer: {
  59632. html: babylonjs_viewer_assets_1.fillContainer,
  59633. params: {
  59634. disable: false
  59635. }
  59636. },
  59637. loadingScreen: {
  59638. html: babylonjs_viewer_assets_1.loadingScreen,
  59639. params: {
  59640. backgroundColor: "#000000",
  59641. loadingImage: images.loading
  59642. }
  59643. },
  59644. viewer: {
  59645. html: babylonjs_viewer_assets_1.defaultViewer,
  59646. params: {
  59647. enableDragAndDrop: false
  59648. }
  59649. },
  59650. navBar: {
  59651. html: babylonjs_viewer_assets_1.navbar,
  59652. params: {
  59653. speedList: {
  59654. "0.5x": "0.5",
  59655. "1.0x": "1.0",
  59656. "1.5x": "1.5",
  59657. "2.0x": "2.0",
  59658. },
  59659. logoImage: images.babylonLogo,
  59660. logoText: 'BabylonJS',
  59661. logoLink: 'https://babylonjs.com',
  59662. hideHelp: true,
  59663. disableOnFullscreen: false,
  59664. },
  59665. events: {
  59666. pointerdown: {
  59667. 'navbar-control': true,
  59668. 'help-button': true
  59669. },
  59670. input: {
  59671. 'progress-wrapper': true
  59672. },
  59673. pointerup: {
  59674. 'progress-wrapper': true
  59675. }
  59676. }
  59677. },
  59678. overlay: {
  59679. html: babylonjs_viewer_assets_1.overlay,
  59680. params: {
  59681. closeImage: images.close,
  59682. closeText: 'Close'
  59683. }
  59684. },
  59685. help: {
  59686. html: babylonjs_viewer_assets_1.help
  59687. },
  59688. share: {
  59689. html: babylonjs_viewer_assets_1.share
  59690. },
  59691. error: {
  59692. html: babylonjs_viewer_assets_1.error
  59693. }
  59694. },
  59695. camera: {
  59696. behaviors: {
  59697. autoRotate: {
  59698. type: 0
  59699. },
  59700. framing: {
  59701. type: 2,
  59702. zoomOnBoundingInfo: true,
  59703. zoomStopsAnimation: false
  59704. },
  59705. bouncing: {
  59706. type: 1
  59707. }
  59708. },
  59709. wheelPrecision: 200,
  59710. },
  59711. skybox: {},
  59712. ground: {
  59713. receiveShadows: true
  59714. },
  59715. engine: {
  59716. antialiasing: true
  59717. },
  59718. scene: {}
  59719. };
  59720. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL3R5cGVzL2RlZmF1bHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxtRUFBNEk7QUFDNUksbUVBQXNEO0FBQ3RELGdEQUFrRDtBQUVsRDs7O0dBR0c7QUFDUSxRQUFBLG9CQUFvQixHQUF3QjtJQUNuRCxPQUFPLEVBQUUsY0FBYztJQUN2QixTQUFTLEVBQUU7UUFDUC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tCQUFrQixFQUFFLElBQUk7aUJBQzNCO2dCQUNELFNBQVMsRUFBRTtvQkFDUCxrQkFBa0IsRUFBRSxJQUFJO2lCQUMzQjthQUNKO1NBQ0o7UUFDRCxPQUFPLEVBQUU7WUFDTCxJQUFJLEVBQUUsaUNBQU87WUFDYixNQUFNLEVBQUU7Z0JBQ0osVUFBVSxFQUFFLE1BQU0sQ0FBQyxLQUFLO2dCQUN4QixTQUFTLEVBQUUsT0FBTzthQUNyQjtTQUNKO1FBQ0QsSUFBSSxFQUFFO1lBQ0YsSUFBSSxFQUFFLDhCQUFJO1NBQ2I7UUFDRCxLQUFLLEVBQUU7WUFDSCxJQUFJLEVBQUUsK0JBQUs7U0FDZDtRQUNELEtBQUssRUFBRTtZQUNILElBQUksRUFBRSwrQkFBSztTQUNkO0tBRUo7SUFDRCxNQUFNLEVBQUU7UUFDSixTQUFTLEVBQUU7WUFDUCxVQUFVLEVBQUU7Z0JBQ1IsSUFBSSxFQUFFLENBQUM7YUFDVjtZQUNELE9BQU8sRUFBRTtnQkFDTCxJQUFJLEVBQUUsQ0FBQztnQkFDUCxrQkFBa0IsRUFBRSxJQUFJO2dCQUN4QixrQkFBa0IsRUFBRSxLQUFLO2FBQzVCO1lBQ0QsUUFBUSxFQUFFO2dCQUNOLElBQUksRUFBRSxDQUFDO2FBQ1Y7U0FDSjtRQUNELGNBQWMsRUFBRSxHQUFHO0tBQ3RCO0lBQ0QsTUFBTSxFQUFFLEVBQ1A7SUFDRCxNQUFNLEVBQUU7UUFDSixjQUFjLEVBQUUsSUFBSTtLQUN2QjtJQUNELE1BQU0sRUFBRTtRQUNKLFlBQVksRUFBRSxJQUFJO0tBQ3JCO0lBQ0QsS0FBSyxFQUFFLEVBQ047Q0FDSixDQUFBIn0=
  59721. /***/ }),
  59722. /* 50 */
  59723. /***/ (function(module, exports, __webpack_require__) {
  59724. "use strict";
  59725. Object.defineProperty(exports, "__esModule", { value: true });
  59726. var babylonjs_1 = __webpack_require__(0);
  59727. /**
  59728. * The viewer's "extended" configuration.
  59729. * This configuration defines specific obejcts and parameters that we think make any model look good.
  59730. */
  59731. exports.extendedConfiguration = {
  59732. version: "3.2.0",
  59733. extends: "default",
  59734. camera: {
  59735. exposure: 3.034578,
  59736. fov: 0.7853981633974483,
  59737. contrast: 1.6,
  59738. toneMappingEnabled: true,
  59739. upperBetaLimit: 1.3962634015954636 + Math.PI / 2,
  59740. lowerBetaLimit: -1.4835298641951802 + Math.PI / 2,
  59741. behaviors: {
  59742. framing: {
  59743. type: 2,
  59744. mode: 0,
  59745. positionScale: 0.5,
  59746. defaultElevation: 0.2617993877991494,
  59747. elevationReturnWaitTime: 3000,
  59748. elevationReturnTime: 2000,
  59749. framingTime: 500,
  59750. zoomStopsAnimation: false,
  59751. radiusScale: 0.866
  59752. },
  59753. autoRotate: {
  59754. type: 0,
  59755. idleRotationWaitTime: 4000,
  59756. idleRotationSpeed: 0.17453292519943295,
  59757. idleRotationSpinupTime: 2500,
  59758. zoomStopsAnimation: false
  59759. },
  59760. bouncing: {
  59761. type: 1,
  59762. lowerRadiusTransitionRange: 0.05,
  59763. upperRadiusTransitionRange: -0.2
  59764. }
  59765. },
  59766. upperRadiusLimit: 5,
  59767. lowerRadiusLimit: 0.5,
  59768. frameOnModelLoad: true,
  59769. framingElevation: 0.2617993877991494,
  59770. framingRotation: 1.5707963267948966,
  59771. radius: 2,
  59772. alpha: 1.5708,
  59773. beta: Math.PI * 0.5 - 0.2618,
  59774. wheelPrecision: 300,
  59775. minZ: 0.1,
  59776. maxZ: 50,
  59777. fovMode: 0,
  59778. pinchPrecision: 1500,
  59779. panningSensibility: 3000
  59780. },
  59781. lights: {
  59782. light0: {
  59783. type: 0,
  59784. frustumEdgeFalloff: 0,
  59785. intensity: 7,
  59786. intensityMode: 0,
  59787. radius: 0.6,
  59788. range: 0.6,
  59789. spotAngle: 60,
  59790. diffuse: {
  59791. r: 1,
  59792. g: 1,
  59793. b: 1
  59794. },
  59795. position: {
  59796. x: -2,
  59797. y: 2.5,
  59798. z: 2
  59799. },
  59800. target: {
  59801. x: 0,
  59802. y: 0,
  59803. z: 0
  59804. },
  59805. enabled: true,
  59806. shadowEnabled: true,
  59807. shadowBufferSize: 512,
  59808. shadowMinZ: 1,
  59809. shadowMaxZ: 10,
  59810. shadowFieldOfView: 60,
  59811. shadowFrustumSize: 2,
  59812. shadowConfig: {
  59813. useBlurCloseExponentialShadowMap: true,
  59814. useKernelBlur: true,
  59815. blurScale: 1.0,
  59816. bias: 0.001,
  59817. depthScale: 50 * (10 - 1),
  59818. frustumEdgeFalloff: 0
  59819. }
  59820. },
  59821. light1: {
  59822. type: 0,
  59823. frustumEdgeFalloff: 0,
  59824. intensity: 7,
  59825. intensityMode: 0,
  59826. radius: 0.4,
  59827. range: 0.4,
  59828. spotAngle: 57,
  59829. diffuse: {
  59830. r: 1,
  59831. g: 1,
  59832. b: 1
  59833. },
  59834. position: {
  59835. x: 4,
  59836. y: 3,
  59837. z: -0.5
  59838. },
  59839. target: {
  59840. x: 0,
  59841. y: 0,
  59842. z: 0
  59843. },
  59844. enabled: true,
  59845. shadowEnabled: false,
  59846. shadowBufferSize: 512,
  59847. shadowMinZ: 0.2,
  59848. shadowMaxZ: 10,
  59849. shadowFieldOfView: 28,
  59850. shadowFrustumSize: 2
  59851. },
  59852. light2: {
  59853. type: 0,
  59854. frustumEdgeFalloff: 0,
  59855. intensity: 1,
  59856. intensityMode: 0,
  59857. radius: 0.5,
  59858. range: 0.5,
  59859. spotAngle: 42.85,
  59860. diffuse: {
  59861. r: 0.8,
  59862. g: 0.8,
  59863. b: 0.8
  59864. },
  59865. position: {
  59866. x: -1,
  59867. y: 3,
  59868. z: -3
  59869. },
  59870. target: {
  59871. x: 0,
  59872. y: 0,
  59873. z: 0
  59874. },
  59875. enabled: true,
  59876. shadowEnabled: false,
  59877. shadowBufferSize: 512,
  59878. shadowMinZ: 0.2,
  59879. shadowMaxZ: 10,
  59880. shadowFieldOfView: 45,
  59881. shadowFrustumSize: 2
  59882. }
  59883. },
  59884. ground: {
  59885. shadowLevel: 0.9,
  59886. texture: "Ground_2.0-1024.png",
  59887. material: {
  59888. primaryColorHighlightLevel: 0.035,
  59889. primaryColorShadowLevel: 0,
  59890. enableNoise: true,
  59891. useRGBColor: false,
  59892. maxSimultaneousLights: 1,
  59893. diffuseTexture: {
  59894. gammaSpace: true
  59895. }
  59896. },
  59897. opacity: 1,
  59898. mirror: false,
  59899. receiveShadows: true,
  59900. size: 5
  59901. },
  59902. skybox: {
  59903. scale: 11,
  59904. cubeTexture: {
  59905. url: "Skybox_2.0-256.dds"
  59906. },
  59907. material: {
  59908. primaryColorHighlightLevel: 0.03,
  59909. primaryColorShadowLevel: 0.03,
  59910. enableNoise: true,
  59911. useRGBColor: false,
  59912. reflectionTexture: {
  59913. gammaSpace: true
  59914. }
  59915. }
  59916. },
  59917. engine: {
  59918. renderInBackground: true
  59919. },
  59920. scene: {
  59921. flags: {
  59922. shadowsEnabled: true,
  59923. particlesEnabled: false,
  59924. collisionsEnabled: false,
  59925. lightsEnabled: true,
  59926. texturesEnabled: true,
  59927. lensFlaresEnabled: false,
  59928. proceduralTexturesEnabled: false,
  59929. renderTargetsEnabled: true,
  59930. spritesEnabled: false,
  59931. skeletonsEnabled: true,
  59932. audioEnabled: false,
  59933. },
  59934. defaultMaterial: {
  59935. materialType: 'pbr',
  59936. reflectivityColor: {
  59937. r: 0.1,
  59938. g: 0.1,
  59939. b: 0.1
  59940. },
  59941. microSurface: 0.6
  59942. },
  59943. clearColor: {
  59944. r: 0.9,
  59945. g: 0.9,
  59946. b: 0.9,
  59947. a: 1.0
  59948. },
  59949. imageProcessingConfiguration: {
  59950. vignetteCentreX: 0,
  59951. vignetteCentreY: 0,
  59952. vignetteColor: {
  59953. r: 0.086,
  59954. g: 0.184,
  59955. b: 0.259,
  59956. a: 1
  59957. },
  59958. vignetteWeight: 0.855,
  59959. vignetteStretch: 0.5,
  59960. vignetteBlendMode: 0,
  59961. vignetteCameraFov: 0.7853981633974483,
  59962. isEnabled: true,
  59963. colorCurves: {
  59964. shadowsHue: 0,
  59965. shadowsDensity: 0,
  59966. shadowsSaturation: 0,
  59967. shadowsExposure: 0,
  59968. midtonesHue: 0,
  59969. midtonesDensity: 0,
  59970. midtonesExposure: 0,
  59971. midtonesSaturation: 0,
  59972. highlightsHue: 0,
  59973. highlightsDensity: 0,
  59974. highlightsExposure: 0,
  59975. highlightsSaturation: 0
  59976. }
  59977. },
  59978. mainColor: {
  59979. r: 0.8823529411764706,
  59980. g: 0.8823529411764706,
  59981. b: 0.8823529411764706
  59982. }
  59983. },
  59984. loaderPlugins: {
  59985. extendedMaterial: true,
  59986. applyMaterialConfig: true,
  59987. msftLod: true,
  59988. telemetry: true
  59989. },
  59990. model: {
  59991. rotationOffsetAxis: {
  59992. x: 0,
  59993. y: -1,
  59994. z: 0
  59995. },
  59996. rotationOffsetAngle: babylonjs_1.Tools.ToRadians(210),
  59997. material: {
  59998. directEnabled: true,
  59999. directIntensity: 0.884,
  60000. emissiveIntensity: 1.04,
  60001. environmentIntensity: 0.6
  60002. },
  60003. entryAnimation: {
  60004. scaling: {
  60005. x: 0,
  60006. y: 0,
  60007. z: 0
  60008. },
  60009. time: 0.5,
  60010. easingFunction: 4,
  60011. easingMode: 1
  60012. },
  60013. exitAnimation: {
  60014. scaling: {
  60015. x: 0,
  60016. y: 0,
  60017. z: 0
  60018. },
  60019. time: 0.5,
  60020. easingFunction: 4,
  60021. easingMode: 1
  60022. },
  60023. normalize: true,
  60024. castShadow: true,
  60025. receiveShadows: true
  60026. },
  60027. lab: {
  60028. assetsRootURL: 'https://viewer.babylonjs.com/assets/environment/',
  60029. environmentMap: {
  60030. texture: "EnvMap_2.0-256.env",
  60031. rotationY: 3,
  60032. tintLevel: 0.4
  60033. },
  60034. defaultRenderingPipelines: {
  60035. bloomEnabled: true,
  60036. bloomThreshold: 1.0,
  60037. fxaaEnabled: true,
  60038. bloomWeight: 0.05
  60039. }
  60040. }
  60041. };
  60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UFDLEVBQUUsQ0FBQzthQUNQO1lBQ0QsSUFBSSxFQUFFLEdBQUc7WUFDVCxjQUFjLEVBQUUsQ0FBQztZQUNqQixVQUFVLEVBQUUsQ0FBQztTQUNoQjtRQUNELGFBQWEsRUFBRTtZQUNYLE9BQU8sRUFBRTtnQkFDTCxDQUFDLEVBQUUsQ0FBQztnQkFDSixDQUFDLEVBQUUsQ0FBQztnQkFDSixDQUFDLEVBQUUsQ0FBQzthQUNQO1lBQ0QsSUFBSSxFQUFFLEdBQUc7WUFDVCxjQUFjLEVBQUUsQ0FBQztZQUNqQixVQUFVLEVBQUUsQ0FBQztTQUNoQjtRQUNELFNBQVMsRUFBRSxJQUFJO1FBQ2YsVUFBVSxFQUFFLElBQUk7UUFDaEIsY0FBYyxFQUFFLElBQUk7S0FDdkI7SUFDRCxHQUFHLEVBQUU7UUFDRCxhQUFhLEVBQUUsa0RBQWtEO1FBQ2pFLGNBQWMsRUFBRTtZQUNaLE9BQU8sRUFBRSxvQkFBb0I7WUFDN0IsU0FBUyxFQUFFLENBQUM7WUFDWixTQUFTLEVBQUUsR0FBRztTQUNqQjtRQUNELHlCQUF5QixFQUFFO1lBQ3ZCLFlBQVksRUFBRSxJQUFJO1lBQ2xCLGNBQWMsRUFBRSxHQUFHO1lBQ25CLFdBQVcsRUFBRSxJQUFJO1lBQ2pCLFdBQVcsRUFBRSxJQUFJO1NBQ3BCO0tBQ0o7Q0FDSixDQUFBIn0=
  60043. /***/ }),
  60044. /* 51 */
  60045. /***/ (function(module, exports, __webpack_require__) {
  60046. "use strict";
  60047. Object.defineProperty(exports, "__esModule", { value: true });
  60048. /**
  60049. * Defines a default directional shadow light for normalized objects (!)
  60050. */
  60051. exports.shadowDirectionalLightConfiguration = {
  60052. model: {
  60053. receiveShadows: true,
  60054. castShadow: true
  60055. },
  60056. ground: {
  60057. receiveShadows: true
  60058. },
  60059. lights: {
  60060. shadowDirectionalLight: {
  60061. type: 1,
  60062. shadowEnabled: true,
  60063. target: { x: 0, y: 0, z: 0.5 },
  60064. position: { x: 1.49, y: 2.39, z: -1.33 },
  60065. diffuse: { r: 0.867, g: 0.816, b: 0.788 },
  60066. intensity: 4.887,
  60067. intensityMode: 0,
  60068. shadowBufferSize: 1024,
  60069. shadowFrustumSize: 6.0,
  60070. shadowFieldOfView: 50.977,
  60071. shadowMinZ: 0.1,
  60072. shadowMaxZ: 10.0,
  60073. shadowConfig: {
  60074. blurKernel: 32,
  60075. useBlurCloseExponentialShadowMap: true
  60076. }
  60077. }
  60078. }
  60079. };
  60080. /**
  60081. * Defines a default shadow-enabled spot light for normalized objects.
  60082. */
  60083. exports.shadowSpotlLightConfiguration = {
  60084. model: {
  60085. receiveShadows: true,
  60086. castShadow: true
  60087. },
  60088. ground: {
  60089. receiveShadows: true
  60090. },
  60091. lights: {
  60092. shadowSpotLight: {
  60093. type: 2,
  60094. intensity: 2,
  60095. shadowEnabled: true,
  60096. target: { x: 0, y: 0, z: 0.5 },
  60097. position: { x: 0, y: 3.5, z: 3.7 },
  60098. angle: 1,
  60099. shadowOrthoScale: 0.5,
  60100. shadowBufferSize: 1024,
  60101. shadowMinZ: 0.1,
  60102. shadowMaxZ: 50.0,
  60103. shadowConfig: {
  60104. frustumEdgeFalloff: 0.5,
  60105. blurKernel: 32,
  60106. useBlurExponentialShadowMap: true
  60107. }
  60108. }
  60109. }
  60110. };
  60111. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhZG93TGlnaHQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvY29uZmlndXJhdGlvbi90eXBlcy9zaGFkb3dMaWdodC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBOztHQUVHO0FBQ1UsUUFBQSxtQ0FBbUMsR0FBd0I7SUFDcEUsS0FBSyxFQUFFO1FBQ0gsY0FBYyxFQUFFLElBQUk7UUFDcEIsVUFBVSxFQUFFL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UFDYixJQUFJLEVBQUUsQ0FBQztZQUNQLFNBQVMsRUFBRSxDQUFDO1lBQ1osYUFBYSxFQUFFLElBQUk7WUFDbkIsTUFBTSxFQUFFLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxHQUFHLEVBQUU7WUFDOUIsUUFBUSxFQUFFLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsR0FBRyxFQUFFLENBQUMsRUFBRSxHQUFHLEVBQUU7WUFDbEMsS0FBSyxFQUFFLENBQUM7WUFDUixnQkFBZ0IsRUFBRSxHQUFHO1lBQ3JCLGdCQUFnQixFQUFFLElBQUk7WUFDdEIsVUFBVSxFQUFFLEdBQUc7WUFDZixVQUFVLEVBQUUsSUFBSTtZQUNoQixZQUFZLEVBQUU7Z0JBQ1Ysa0JBQWtCLEVBQUUsR0FBRztnQkFDdkIsVUFBVSxFQUFFLEVBQUU7Z0JBQ2QsMkJBQTJCLEVBQUUsSUFBSTthQUNwQztTQUNKO0tBQ0o7Q0FDSixDQUFBIn0=
  60112. /***/ }),
  60113. /* 52 */
  60114. /***/ (function(module, exports, __webpack_require__) {
  60115. "use strict";
  60116. Object.defineProperty(exports, "__esModule", { value: true });
  60117. /**
  60118. * Lab-oriented default .env support
  60119. */
  60120. exports.environmentMapConfiguration = {
  60121. lab: {
  60122. assetsRootURL: '/assets/environment/',
  60123. environmentMap: {
  60124. texture: 'EnvMap_2.0-256.env',
  60125. rotationY: 0,
  60126. tintLevel: 0.4
  60127. }
  60128. }
  60129. };
  60130. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52aXJvbm1lbnRNYXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvY29uZmlndXJhdGlvbi90eXBlcy9lbnZpcm9ubWVudE1hcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBOztHQUVHO0FBQ1UsUUFBQSwyQkFBMkIsR0FBd0I7SUFDNUQsR0FBRyxFQUFFO1FBQ0QsYUFBYSxFQUFFLHNCQUFzQjtRQUNyQyxjQUFjLEVBQUU7WUFDWixPQUFPLEVBQUUsb0JBQW9CO1lBQzdCLFNBQVMsRUFBRSxDQUFDO1lBQ1osU0FBUyxFQUFFLEdBQUc7U0FDakI7S0FDSjtDQUNKLENBQUEifQ==
  60131. /***/ }),
  60132. /* 53 */
  60133. /***/ (function(module, exports, __webpack_require__) {
  60134. "use strict";
  60135. Object.defineProperty(exports, "__esModule", { value: true });
  60136. var configuration_1 = __webpack_require__(11);
  60137. /**
  60138. * This function will make sure the configuration file is taking deprecated fields into account
  60139. * and is setting them to the correct keys and values.
  60140. *
  60141. * @param configuration The configuration to process. Mutable!
  60142. */
  60143. function processConfigurationCompatibility(configuration) {
  60144. if (configuration.camera) {
  60145. // camera contrast -> image processing contrast
  60146. if (configuration.camera.contrast !== undefined) {
  60147. setKeyInObject(configuration, "scene.imageProcessingConfiguration.contrast", configuration.camera.contrast);
  60148. }
  60149. // camera exposure -> image processing exposure
  60150. if (configuration.camera.exposure !== undefined) {
  60151. setKeyInObject(configuration, "scene.imageProcessingConfiguration.exposure", configuration.camera.exposure);
  60152. }
  60153. }
  60154. if (configuration.scene) {
  60155. //glow
  60156. if (configuration.scene.glow) {
  60157. setKeyInObject(configuration, "lab.defaultRenderingPipelines.glowLayerEnabled", true);
  60158. var enabledProcessing = configuration_1.getConfigurationKey("scene.imageProcessingConfiguration.isEnabled", configuration);
  60159. if (enabledProcessing !== false) {
  60160. setKeyInObject(configuration, "scene.imageProcessingConfiguration.isEnabled", true);
  60161. }
  60162. }
  60163. }
  60164. }
  60165. exports.processConfigurationCompatibility = processConfigurationCompatibility;
  60166. function setKeyInObject(object, keys, value, shouldOverwrite) {
  60167. var keySplit = keys.split(".");
  60168. if (keySplit.length === 0)
  60169. return;
  60170. var lastKey = keySplit.pop();
  60171. if (!lastKey)
  60172. return;
  60173. var curObj = object;
  60174. keySplit.forEach(function (key) {
  60175. curObj[key] = curObj[key] || {};
  60176. curObj = curObj[key];
  60177. });
  60178. if (curObj[lastKey] !== undefined && !shouldOverwrite)
  60179. return;
  60180. curObj[lastKey] = value;
  60181. }
  60182. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlndXJhdGlvbkNvbXBhdGliaWxpdHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29uZmlndXJhdGlvbi9jb25maWd1cmF0aW9uQ29tcGF0aWJpbGl0eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGlEQUEwRTtBQUMxRTs7Ozs7R0FLRztBQUNILDJDQUFrRCxhQUFrQztJQUloRixJQUFJLGFBQWEsQ0FBQyxNQUFNLEVBQUU7UUFDdEIsK0NBQStDO1FBQy9DLElBQUksYUFBYSxDQUFDLE1BQU0sQ0FBQyxRQUFRLEtBQUssU0FBUyxFQUFFO1lBQzdDLGNBQWMsQ0FBQyxhQUFhLEVBQUUsNkNBQTZDLEVBQUUsYUFBYSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQztTQUMvRztRQUVELCtDQUErQztRQUMvQyxJQUFJLGFBQWEsQ0FBQyxNQUFNLENBQUMsUUFBUSxLQUFLLFNBQVMsRUFBRTtZQUM3QyxjQUFjLENBQUMsYUFBYSxFQUFFLDZDQUE2QyxFQUFFLGFBQWEsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUM7U0FDL0c7S0FDSjtJQUVELElBQUksYUFBYSxDQUFDLEtBQUssRUFBRTtRQUNyQixNQUFNO1FBQ04sSUFBSSxhQUFhLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRTtZQUMxQixjQUFjLENBQUMsYUFBYSxFQUFFLGdEQUFnRCxFQU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  60186. "use strict";
  60187. Object.defineProperty(exports, "__esModule", { value: true });
  60188. var telemetryLoaderPlugin_1 = __webpack_require__(55);
  60189. exports.TelemetryLoaderPlugin = telemetryLoaderPlugin_1.TelemetryLoaderPlugin;
  60190. var msftLodLoaderPlugin_1 = __webpack_require__(56);
  60191. exports.MSFTLodLoaderPlugin = msftLodLoaderPlugin_1.MSFTLodLoaderPlugin;
  60192. var applyMaterialConfig_1 = __webpack_require__(57);
  60193. exports.ApplyMaterialConfigPlugin = applyMaterialConfig_1.ApplyMaterialConfigPlugin;
  60194. var extendedMaterialLoaderPlugin_1 = __webpack_require__(58);
  60195. exports.ExtendedMaterialLoaderPlugin = extendedMaterialLoaderPlugin_1.ExtendedMaterialLoaderPlugin;
  60196. var babylonjs_1 = __webpack_require__(0);
  60197. var pluginCache = {};
  60198. /**
  60199. * Get a loader plugin according to its name.
  60200. * The plugin will be cached and will be reused if called for again.
  60201. *
  60202. * @param name the name of the plugin
  60203. */
  60204. function getLoaderPluginByName(name) {
  60205. if (!pluginCache[name]) {
  60206. switch (name) {
  60207. case 'telemetry':
  60208. pluginCache[name] = new telemetryLoaderPlugin_1.TelemetryLoaderPlugin();
  60209. break;
  60210. case 'msftLod':
  60211. pluginCache[name] = new msftLodLoaderPlugin_1.MSFTLodLoaderPlugin();
  60212. break;
  60213. case 'applyMaterialConfig':
  60214. pluginCache[name] = new applyMaterialConfig_1.ApplyMaterialConfigPlugin();
  60215. break;
  60216. case 'extendedMaterial':
  60217. pluginCache[name] = new extendedMaterialLoaderPlugin_1.ExtendedMaterialLoaderPlugin();
  60218. break;
  60219. }
  60220. }
  60221. return pluginCache[name];
  60222. }
  60223. exports.getLoaderPluginByName = getLoaderPluginByName;
  60224. /**
  60225. *
  60226. */
  60227. function addLoaderPlugin(name, plugin) {
  60228. if (pluginCache[name]) {
  60229. babylonjs_1.Tools.Warn("Overwriting plugin with the same name - " + name);
  60230. }
  60231. pluginCache[name] = plugin;
  60232. }
  60233. exports.addLoaderPl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QU8sV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDO0FBQzdCLENBQUM7QUFuQkQsc0RBbUJDO0FBRUQ7O0dBRUc7QUFDSCx5QkFBZ0MsSUFBWSxFQUFFLE1BQXFCO0lBQy9ELElBQUksV0FBVyxDQUFDLElBQUksQ0FBQyxFQUFFO1FBQ25CLGlCQUFLLENBQUMsSUFBSSxDQUFDLDBDQUEwQyxHQUFHLElBQUksQ0FBQyxDQUFDO0tBQ2pFO0lBQ0QsV0FBVyxDQUFDLElBQUksQ0FBQyxHQUFHLE1BQU0sQ0FBQztBQUMvQixDQUFDO0FBTEQsMENBS0MifQ==
  60235. /***/ }),
  60236. /* 55 */
  60237. /***/ (function(module, exports, __webpack_require__) {
  60238. "use strict";
  60239. Object.defineProperty(exports, "__esModule", { value: true });
  60240. var telemetryManager_1 = __webpack_require__(6);
  60241. var babylonjs_1 = __webpack_require__(0);
  60242. var TelemetryLoaderPlugin = /** @class */ (function () {
  60243. function TelemetryLoaderPlugin() {
  60244. }
  60245. TelemetryLoaderPlugin.prototype.onInit = function (loader, model) {
  60246. this._model = model;
  60247. this._loadStart = babylonjs_1.Tools.Now;
  60248. };
  60249. TelemetryLoaderPlugin.prototype.onLoaded = function (model) {
  60250. telemetryManager_1.telemetryManager.broadcast("Model Loaded", model.getViewerId(), {
  60251. model: model,
  60252. loadTime: babylonjs_1.Tools.Now - this._loadStart
  60253. });
  60254. telemetryManager_1.telemetryManager.flushWebGLErrors(model.rootMesh.getEngine(), model.getViewerId());
  60255. };
  60256. TelemetryLoaderPlugin.prototype.onError = function (message, exception) {
  60257. this._loadEnd = babylonjs_1.Tools.Now;
  60258. telemetryManager_1.telemetryManager.broadcast("Load Error", this._model.getViewerId(), {
  60259. model: this._model,
  60260. loadTime: this._loadEnd - this._loadStart
  60261. });
  60262. telemetryManager_1.telemetryManager.flushWebGLErrors(this._model.rootMesh.getEngine(), this._model.getViewerId());
  60263. };
  60264. TelemetryLoaderPlugin.prototype.onComplete = function () {
  60265. this._loadEnd = babylonjs_1.Tools.Now;
  60266. telemetryManager_1.telemetryManager.broadcast("Load Complete", this._model.getViewerId(), {
  60267. model: this._model,
  60268. loadTime: this._loadEnd - this._loadStart
  60269. });
  60270. telemetryManager_1.telemetryManager.flushWebGLErrors(this._model.rootMesh.getEngine(), this._model.getViewerId());
  60271. };
  60272. return TelemetryLoaderPlugin;
  60273. }());
  60274. exports.TelemetryLoaderPlugin = TelemetryLoaderPlugin;
  60275. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVsZW1ldHJ5TG9hZGVyUGx1Z2luLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vc3JjL2xvYWRlci9wbHVnaW5zL3RlbGVtZXRyeUxvYWRlclBsdWdpbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLG9FQUFtRTtBQUVuRSx1Q0FBK0U7QUFHL0U7SUFBQTtJQXVDQSxDQUFDO0lBaENVLHNDQUFNLEdBQWIsVUFBYyxNQUFvRCxFQUFFLEtBQWtCO1FBQ2xGLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDO1FBQ3BCLElBQUksQ0FBQyxVQUFVLEdBQUcsaUJBQUssQ0FBQyxHQUFHLENBQUM7SUFDaEMsQ0FBQztJQUVNLHdDQUFRLEdBQWYsVUFBZ0IsS0FBa0I7UUFDOUIsbUNBQWdCLENBQUMsU0FBUyxDQUFDLGNBQWMsRUFBRSxLQUFLLENBQUMsV0FBVyxFQUFFLEVBQUU7WUFDNUQsS0FBSyxFQUFFLEtBQUs7WUFDWixRQUFRLEVBQUUsaUJBQUssQ0FBQyxHQUFHLEdBQUcsSUFBSSxDQUFDLFVBQVU7U0FDeEMsQ0FBQyxDQUFDO1FBQ0gsbUNBQWdCLENBQUMsZ0JBQWdCLENBQUMsS0FBSyxDQUFDLFFBQVEsQ0FBQyxTQUFTLEVBQ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UFDO0lBQ0wsNEJBQUM7QUFBRCxDQUFDLEFBdkNELElBdUNDO0FBdkNZLHNEQUFxQiJ9
  60276. /***/ }),
  60277. /* 56 */
  60278. /***/ (function(module, exports, __webpack_require__) {
  60279. "use strict";
  60280. Object.defineProperty(exports, "__esModule", { value: true });
  60281. /**
  60282. * A loder plugin to use MSFT_lod extension correctly (glTF)
  60283. */
  60284. var MSFTLodLoaderPlugin = /** @class */ (function () {
  60285. function MSFTLodLoaderPlugin() {
  60286. }
  60287. MSFTLodLoaderPlugin.prototype.onInit = function (loader, model) {
  60288. this._model = model;
  60289. };
  60290. MSFTLodLoaderPlugin.prototype.onExtensionLoaded = function (extension) {
  60291. if (extension.name === "MSFT_lod" && this._model.configuration.loaderConfiguration) {
  60292. var MSFT_lod = extension;
  60293. MSFT_lod.enabled = !!this._model.configuration.loaderConfiguration.progressiveLoading;
  60294. MSFT_lod.maxLODsToLoad = this._model.configuration.loaderConfiguration.maxLODsToLoad || Number.MAX_VALUE;
  60295. }
  60296. };
  60297. return MSFTLodLoaderPlugin;
  60298. }());
  60299. exports.MSFTLodLoaderPlugin = MSFTLodLoaderPlugin;
  60300. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXNmdExvZExvYWRlclBsdWdpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9sb2FkZXIvcGx1Z2lucy9tc2Z0TG9kTG9hZGVyUGx1Z2luLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBS0E7O0dBRUc7QUFDSDtJQUFBO0lBZUEsQ0FBQztJQVhVLG9DQUFNLEdBQWIsVUFBYyxNQUFvRCxFQUFFLEtBQWtCO1FBQ2xGLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDO0lBQ3hCLENBQUM7SUFFTSwrQ0FBaUIsR0FBeEIsVUFBeUIsU0FBK0I7UUFDcEQsSUFBSSxTQUFTLENBQUMsSUFBSSxLQUFLLFVBQVUsSUFBSSxJQUFJLENBQUMsTUFBTSxDQUFDLGFBQWEsQ0FBQyxtQkFBbUIsRUFBRTtZQUNoRixJQUFNLFFBQVEsR0FBRyxTQUFzQyxDQUFDO1lBQ3hELFFBQVEsQ0FBQyxPQUFPLEdBQUcsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsYUFBYSxDQUFDLG1CQUFtQixDQUFDLGtCQUFrQixDQUFDO1lBQ3RGLFFBQVEsQ0FBQyxhQUFhLEdBQUcsSUFBSSxDQUFDLE1BQU0sQ0FBQyxhQUFhLENBQUMsbUJBQW1CLENBQUMsYUFBYSxJQUFJLE1BQU0sQ0FBQyxTQUFTLENBQUM7U0FDNUc7SUFDTCxDQUFDO0lBQ0wsMEJBQUM7QUFBRCxDQUFDLEFBZkQsSUFlQztBQWZZLGtEQUFtQiJ9
  60301. /***/ }),
  60302. /* 57 */
  60303. /***/ (function(module, exports, __webpack_require__) {
  60304. "use strict";
  60305. Object.defineProperty(exports, "__esModule", { value: true });
  60306. /**
  60307. * Force-apply material configuration right after a material was loaded.
  60308. */
  60309. var ApplyMaterialConfigPlugin = /** @class */ (function () {
  60310. function ApplyMaterialConfigPlugin() {
  60311. }
  60312. ApplyMaterialConfigPlugin.prototype.onInit = function (loader, model) {
  60313. this._model = model;
  60314. };
  60315. ApplyMaterialConfigPlugin.prototype.onMaterialLoaded = function (material) {
  60316. this._model && this._model._applyModelMaterialConfiguration(material);
  60317. };
  60318. return ApplyMaterialConfigPlugin;
  60319. }());
  60320. exports.ApplyMaterialConfigPlugin = ApplyMaterialConfigPlugin;
  60321. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwbHlNYXRlcmlhbENvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9sb2FkZXIvcGx1Z2lucy9hcHBseU1hdGVyaWFsQ29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBS0E7O0dBRUc7QUFDSDtJQUFBO0lBV0EsQ0FBQztJQVBVLDBDQUFNLEdBQWIsVUFBYyxNQUFvRCxFQUFFLEtBQWtCO1FBQ2xGLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDO0lBQ3hCLENBQUM7SUFFTSxvREFBZ0IsR0FBdkIsVUFBd0IsUUFBa0I7UUFDdEMsSUFBSSxDQUFDLE1BQU0sSUFBSSxJQUFJLENBQUMsTUFBTSxDQUFDLGdDQUFnQyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0lBQzFFLENBQUM7SUFDTCxnQ0FBQztBQUFELENBQUMsQUFYRCxJQVdDO0FBWFksOERBQXlCIn0=
  60322. /***/ }),
  60323. /* 58 */
  60324. /***/ (function(module, exports, __webpack_require__) {
  60325. "use strict";
  60326. Object.defineProperty(exports, "__esModule", { value: true });
  60327. var babylonjs_1 = __webpack_require__(0);
  60328. /**
  60329. * A (PBR) material will be extended using this function.
  60330. * This function will hold extra default configuration for the viewer, if not implemented in Babylon itself.
  60331. */
  60332. var ExtendedMaterialLoaderPlugin = /** @class */ (function () {
  60333. function ExtendedMaterialLoaderPlugin() {
  60334. }
  60335. ExtendedMaterialLoaderPlugin.prototype.onMaterialLoaded = function (baseMaterial) {
  60336. var material = baseMaterial;
  60337. material.alphaMode = babylonjs_1.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
  60338. };
  60339. return ExtendedMaterialLoaderPlugin;
  60340. }());
  60341. exports.ExtendedMaterialLoaderPlugin = ExtendedMaterialLoaderPlugin;
  60342. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXh0ZW5kZWRNYXRlcmlhbExvYWRlclBsdWdpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9sb2FkZXIvcGx1Z2lucy9leHRlbmRlZE1hdGVyaWFsTG9hZGVyUGx1Z2luLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEsdUNBQTRJO0FBRTVJOzs7R0FHRztBQUNIO0lBQUE7SUFNQSxDQUFDO0lBSlUsdURBQWdCLEdBQXZCLFVBQXdCLFlBQXNCO1FBQzFDLElBQUksUUFBUSxHQUFHLFlBQTJCLENBQUM7UUFDM0MsUUFBUSxDQUFDLFNBQVMsR0FBRyxrQkFBTSxDQUFDLDhCQUE4QixDQUFDO0lBQy9ELENBQUM7SUFDTCxtQ0FBQztBQUFELENBQUMsQUFORCxJQU1DO0FBTlksb0VBQTRCIn0=
  60343. /***/ }),
  60344. /* 59 */
  60345. /***/ (function(module, exports, __webpack_require__) {
  60346. "use strict";
  60347. Object.defineProperty(exports, "__esModule", { value: true });
  60348. var babylonjs_1 = __webpack_require__(0);
  60349. var ObservablesManager = /** @class */ (function () {
  60350. function ObservablesManager() {
  60351. this.onSceneInitObservable = new babylonjs_1.Observable();
  60352. this.onEngineInitObservable = new babylonjs_1.Observable();
  60353. this.onModelLoadedObservable = new babylonjs_1.Observable();
  60354. this.onModelLoadProgressObservable = new babylonjs_1.Observable();
  60355. this.onModelLoadErrorObservable = new babylonjs_1.Observable();
  60356. this.onModelAddedObservable = new babylonjs_1.Observable();
  60357. this.onModelRemovedObservable = new babylonjs_1.Observable();
  60358. this.onViewerInitDoneObservable = new babylonjs_1.Observable();
  60359. this.onLoaderInitObservable = new babylonjs_1.Observable();
  60360. this.onFrameRenderedObservable = new babylonjs_1.Observable();
  60361. }
  60362. ObservablesManager.prototype.dispose = function () {
  60363. this.onSceneInitObservable.clear();
  60364. this.onEngineInitObservable.clear();
  60365. this.onModelLoadedObservable.clear();
  60366. this.onModelLoadProgressObservable.clear();
  60367. this.onModelLoadErrorObservable.clear();
  60368. this.onModelAddedObservable.clear();
  60369. this.onModelRemovedObservable.clear();
  60370. this.onViewerInitDoneObservable.clear();
  60371. this.onLoaderInitObservable.clear();
  60372. this.onFrameRenderedObservable.clear();
  60373. };
  60374. return ObservablesManager;
  60375. }());
  60376. exports.ObservablesManager = ObservablesManager;
  60377. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JzZXJ2YWJsZXNNYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21hbmFnZXJzL29ic2VydmFibGVzTWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVDQUE2SDtBQUc3SDtJQStDSTtRQUNJLElBQUksQ0FBQyxxQkFBcUIsR0FBRyxJQUFJLHNCQUFVLEVBQUUsQ0FBQztRQUM5QyxJQUFJLENBQUMsc0JBQXNCLEdBQUcsSUFBSSxzQkFBVSxFQUFFLENBQUM7UUFDL0MsSUFBSSxDQUFDLHVCQUF1QixHQUFHLElBQUksc0JBQVUsRUFBRSxDQUFDO1FBQ2hELElBQUksQ0FBQyw2QkFBNkIsR0FBRyxJQUFJLHNCQUFVLEVBQUUsQ0FBQztRQUN0RCxJQUFJLENBQUMsMEJBQTBCLEdBQUcsSUFBSSxzQkFBVSxFQUFFLENBQUM7UUFDbkQsSUFBSSxDQUFDLHNCQUFzQixHQUFHLElBQUksc0JBQVUsRUFBRSxDQUFDO1FBQy9DLElBQUksQ0FBQyx3QkFBd0IsR0FBRyxJQUFJLHNCQUFVLEVBQUUsQ0FBQztRQUNqRCxJQUFJLENBQUMsMEJBQTBCLEdBQUcsSUFBSSxzQkFBVSxFQUFFLENBQUM7UUFDbkQsSUFBSSxDQUFDLHNCQUFzQixHQUFHLElBQUksc0JBQVUsRUFBRSxDQUFDO1FBQy9DLElBQUksQ0FBQyx5QkFBeUIsR0FBRyxJQUFJLHNCQUFVLEVBQUUsQ0FBQztJQUN0RCxDQUFDO0lBRUQsb0NBQU8sR0FBUDtRQUNJLElBQUksQ0FBQyxxQkFBcUIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUNuQyxJQUFJLENBQUMsc0JBQXNCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDcEMsSUFBSSxDQUFDLHVCQUF1QixDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3JDLElBQUksQ0FBQyw2QkFBNkIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUMzQyxJQUFJLENBQUMsMEJBQTBCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDeEMsSUFBSSxDQUFDLHNCQUFzQixDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3BDLElBQUksQ0FBQyx3QkFBd0IsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUN0QyxJQUFJLENBQUMsMEJBQTBCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDeEMsSUFBSSxDQUFDLHNCQUFzQixDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3BDLElBQUksQ0FBQyx5QkFBeUIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUMzQyxDQUFDO0lBRUwseUJBQUM7QUFBRCxDQUFDLEFBekVELElBeUVDO0FBekVZLGdEQUFrQiJ9
  60378. /***/ }),
  60379. /* 60 */
  60380. /***/ (function(module, exports, __webpack_require__) {
  60381. "use strict";
  60382. Object.defineProperty(exports, "__esModule", { value: true });
  60383. var babylonjs_1 = __webpack_require__(0);
  60384. var ConfigurationContainer = /** @class */ (function () {
  60385. function ConfigurationContainer() {
  60386. this.mainColor = babylonjs_1.Color3.White();
  60387. this.reflectionColor = babylonjs_1.Color3.White();
  60388. }
  60389. return ConfigurationContainer;
  60390. }());
  60391. exports.ConfigurationContainer = ConfigurationContainer;
  60392. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlndXJhdGlvbkNvbnRhaW5lci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWd1cmF0aW9uL2NvbmZpZ3VyYXRpb25Db250YWluZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSx1Q0FBbUM7QUFFbkM7SUFBQTtRQU1XLGNBQVMsR0FBVyxrQkFBTSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ25DLG9CQUFlLEdBQVcsa0JBQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUNwRCxDQUFDO0lBQUQsNkJBQUM7QUFBRCxDQUFDLEFBUkQsSUFRQztBQVJZLHdEQUFzQiJ9
  60393. /***/ }),
  60394. /* 61 */
  60395. /***/ (function(module, exports, __webpack_require__) {
  60396. "use strict";
  60397. Object.defineProperty(exports, "__esModule", { value: true });
  60398. var babylonjs_1 = __webpack_require__(0);
  60399. var helper_1 = __webpack_require__(1);
  60400. var Handlebars = __webpack_require__(62);
  60401. var eventManager_1 = __webpack_require__(63);
  60402. var _1 = __webpack_require__(1);
  60403. /**
  60404. * The template manager, a member of the viewer class, will manage the viewer's templates and generate the HTML.
  60405. * The template manager managers a single viewer and can be seen as the collection of all sub-templates of the viewer.
  60406. */
  60407. var TemplateManager = /** @class */ (function () {
  60408. function TemplateManager(containerElement) {
  60409. this.containerElement = containerElement;
  60410. this.templates = {};
  60411. this.onTemplateInit = new babylonjs_1.Observable();
  60412. this.onTemplateLoaded = new babylonjs_1.Observable();
  60413. this.onTemplateStateChange = new babylonjs_1.Observable();
  60414. this.onAllLoaded = new babylonjs_1.Observable();
  60415. this.onEventTriggered = new babylonjs_1.Observable();
  60416. this.eventManager = new eventManager_1.EventManager(this);
  60417. }
  60418. /**
  60419. * Initialize the template(s) for the viewer. Called bay the Viewer class
  60420. * @param templates the templates to be used to initialize the main template
  60421. */
  60422. TemplateManager.prototype.initTemplate = function (templates) {
  60423. var _this = this;
  60424. var internalInit = function (dependencyMap, name, parentTemplate) {
  60425. //init template
  60426. var template = _this.templates[name];
  60427. var childrenTemplates = Object.keys(dependencyMap).map(function (childName) {
  60428. return internalInit(dependencyMap[childName], childName, template);
  60429. });
  60430. // register the observers
  60431. //template.onLoaded.add(() => {
  60432. var addToParent = function () {
  60433. var containingElement = parentTemplate && parentTemplate.parent.querySelector(helper_1.camelToKebab(name)) || _this.containerElement;
  60434. template.appendTo(containingElement);
  60435. _this._checkLoadedState();
  60436. };
  60437. if (parentTemplate && !parentTemplate.parent) {
  60438. parentTemplate.onAppended.add(function () {
  60439. addToParent();
  60440. });
  60441. }
  60442. else {
  60443. addToParent();
  60444. }
  60445. //});
  60446. return template;
  60447. };
  60448. //build the html tree
  60449. return this._buildHTMLTree(templates).then(function (htmlTree) {
  60450. if (_this.templates['main']) {
  60451. internalInit(htmlTree, 'main');
  60452. }
  60453. else {
  60454. _this._checkLoadedState();
  60455. }
  60456. return;
  60457. });
  60458. };
  60459. /**
  60460. *
  60461. * This function will create a simple map with child-dependencies of the template html tree.
  60462. * It will compile each template, check if its children exist in the configuration and will add them if they do.
  60463. * It is expected that the main template will be called main!
  60464. *
  60465. * @param templates
  60466. */
  60467. TemplateManager.prototype._buildHTMLTree = function (templates) {
  60468. var _this = this;
  60469. var promises = Object.keys(templates).map(function (name) {
  60470. // if the template was overridden
  60471. if (!templates[name])
  60472. return Promise.resolve(false);
  60473. // else - we have a template, let's do our job!
  60474. var template = new Template(name, templates[name]);
  60475. template.onLoaded.add(function () {
  60476. _this.onTemplateLoaded.notifyObservers(template);
  60477. });
  60478. template.onStateChange.add(function () {
  60479. _this.onTemplateStateChange.notifyObservers(template);
  60480. });
  60481. _this.onTemplateInit.notifyObservers(template);
  60482. // make sure the global onEventTriggered is called as well
  60483. template.onEventTriggered.add(function (eventData) { return _this.onEventTriggered.notifyObservers(eventData); });
  60484. _this.templates[name] = template;
  60485. return template.initPromise;
  60486. });
  60487. return Promise.all(promises).then(function () {
  60488. var templateStructure = {};
  60489. // now iterate through all templates and check for children:
  60490. var buildTree = function (parentObject, name) {
  60491. _this.templates[name].isInHtmlTree = true;
  60492. var childNodes = _this.templates[name].getChildElements().filter(function (n) { return !!_this.templates[n]; });
  60493. childNodes.forEach(function (element) {
  60494. parentObject[element] = {};
  60495. buildTree(parentObject[element], element);
  60496. });
  60497. };
  60498. if (_this.templates['main']) {
  60499. buildTree(templateStructure, "main");
  60500. }
  60501. return templateStructure;
  60502. });
  60503. };
  60504. /**
  60505. * Get the canvas in the template tree.
  60506. * There must be one and only one canvas inthe template.
  60507. */
  60508. TemplateManager.prototype.getCanvas = function () {
  60509. return this.containerElement.querySelector('canvas');
  60510. };
  60511. /**
  60512. * Get a specific template from the template tree
  60513. * @param name the name of the template to load
  60514. */
  60515. TemplateManager.prototype.getTemplate = function (name) {
  60516. return this.templates[name];
  60517. };
  60518. TemplateManager.prototype._checkLoadedState = function () {
  60519. var _this = this;
  60520. var done = Object.keys(this.templates).length === 0 || Object.keys(this.templates).every(function (key) {
  60521. return (_this.templates[key].isLoaded && !!_this.templates[key].parent) || !_this.templates[key].isInHtmlTree;
  60522. });
  60523. if (done) {
  60524. this.onAllLoaded.notifyObservers(this);
  60525. }
  60526. };
  60527. /**
  60528. * Dispose the template manager
  60529. */
  60530. TemplateManager.prototype.dispose = function () {
  60531. var _this = this;
  60532. // dispose all templates
  60533. Object.keys(this.templates).forEach(function (template) {
  60534. _this.templates[template].dispose();
  60535. });
  60536. this.templates = {};
  60537. this.eventManager.dispose();
  60538. this.onTemplateInit.clear();
  60539. this.onAllLoaded.clear();
  60540. this.onEventTriggered.clear();
  60541. this.onTemplateLoaded.clear();
  60542. this.onTemplateStateChange.clear();
  60543. };
  60544. return TemplateManager;
  60545. }());
  60546. exports.TemplateManager = TemplateManager;
  60547. // register a new helper. modified https://stackoverflow.com/questions/9838925/is-there-any-method-to-iterate-a-map-with-handlebars-js
  60548. Handlebars.registerHelper('eachInMap', function (map, block) {
  60549. var out = '';
  60550. Object.keys(map).map(function (prop) {
  60551. var data = map[prop];
  60552. if (typeof data === 'object') {
  60553. data.id = data.id || prop;
  60554. out += block.fn(data);
  60555. }
  60556. else {
  60557. out += block.fn({ id: prop, value: data });
  60558. }
  60559. });
  60560. return out;
  60561. });
  60562. Handlebars.registerHelper('add', function (a, b) {
  60563. var out = a + b;
  60564. return out;
  60565. });
  60566. Handlebars.registerHelper('eq', function (a, b) {
  60567. var out = (a == b);
  60568. return out;
  60569. });
  60570. Handlebars.registerHelper('or', function (a, b) {
  60571. var out = a || b;
  60572. return out;
  60573. });
  60574. Handlebars.registerHelper('not', function (a) {
  60575. var out = !a;
  60576. return out;
  60577. });
  60578. Handlebars.registerHelper('count', function (map) {
  60579. return map.length;
  60580. });
  60581. Handlebars.registerHelper('gt', function (a, b) {
  60582. var out = a > b;
  60583. return out;
  60584. });
  60585. /**
  60586. * This class represents a single template in the viewer's template tree.
  60587. * An example for a template is a single canvas, an overlay (containing sub-templates) or the navigation bar.
  60588. * A template is injected using the template manager in the correct position.
  60589. * The template is rendered using Handlebars and can use Handlebars' features (such as parameter injection)
  60590. *
  60591. * For further information please refer to the documentation page, https://doc.babylonjs.com
  60592. */
  60593. var Template = /** @class */ (function () {
  60594. function Template(name, _configuration) {
  60595. var _this = this;
  60596. this.name = name;
  60597. this._configuration = _configuration;
  60598. this.onLoaded = new babylonjs_1.Observable();
  60599. this.onAppended = new babylonjs_1.Observable();
  60600. this.onStateChange = new babylonjs_1.Observable();
  60601. this.onEventTriggered = new babylonjs_1.Observable();
  60602. this.loadRequests = [];
  60603. this.isLoaded = false;
  60604. this.isShown = false;
  60605. this.isInHtmlTree = false;
  60606. var htmlContentPromise = this._getTemplateAsHtml(_configuration);
  60607. this.initPromise = htmlContentPromise.then(function (htmlTemplate) {
  60608. if (htmlTemplate) {
  60609. _this._htmlTemplate = htmlTemplate;
  60610. var compiledTemplate = Handlebars.compile(htmlTemplate, { noEscape: (_this._configuration.params && !!_this._configuration.params.noEscape) });
  60611. var config = _this._configuration.params || {};
  60612. _this._rawHtml = compiledTemplate(config);
  60613. try {
  60614. _this._fragment = document.createRange().createContextualFragment(_this._rawHtml);
  60615. }
  60616. catch (e) {
  60617. var test = document.createElement(_this.name);
  60618. test.innerHTML = _this._rawHtml;
  60619. _this._fragment = test;
  60620. }
  60621. _this.isLoaded = true;
  60622. _this.isShown = true;
  60623. _this.onLoaded.notifyObservers(_this);
  60624. }
  60625. return _this;
  60626. });
  60627. }
  60628. /**
  60629. * Some templates have parameters (like background color for example).
  60630. * The parameters are provided to Handlebars which in turn generates the template.
  60631. * This function will update the template with the new parameters
  60632. *
  60633. * Note that when updating parameters the events will be registered again (after being cleared).
  60634. *
  60635. * @param params the new template parameters
  60636. */
  60637. Template.prototype.updateParams = function (params, append) {
  60638. if (append === void 0) { append = true; }
  60639. if (append) {
  60640. this._configuration.params = _1.deepmerge(this._configuration.params, params);
  60641. }
  60642. else {
  60643. this._configuration.params = params;
  60644. }
  60645. // update the template
  60646. if (this.isLoaded) {
  60647. // this.dispose();
  60648. }
  60649. var compiledTemplate = Handlebars.compile(this._htmlTemplate);
  60650. var config = this._configuration.params || {};
  60651. this._rawHtml = compiledTemplate(config);
  60652. try {
  60653. this._fragment = document.createRange().createContextualFragment(this._rawHtml);
  60654. }
  60655. catch (e) {
  60656. var test = document.createElement(this.name);
  60657. test.innerHTML = this._rawHtml;
  60658. this._fragment = test;
  60659. }
  60660. if (this.parent) {
  60661. this.appendTo(this.parent, true);
  60662. }
  60663. };
  60664. Object.defineProperty(Template.prototype, "configuration", {
  60665. /**
  60666. * Get the template'S configuration
  60667. */
  60668. get: function () {
  60669. return this._configuration;
  60670. },
  60671. enumerable: true,
  60672. configurable: true
  60673. });
  60674. /**
  60675. * A template can be a parent element for other templates or HTML elements.
  60676. * This function will deliver all child HTML elements of this template.
  60677. */
  60678. Template.prototype.getChildElements = function () {
  60679. var childrenArray = [];
  60680. //Edge and IE don't support frage,ent.children
  60681. var children = this._fragment && this._fragment.children;
  60682. if (!this._fragment) {
  60683. var fragment = this.parent.querySelector(this.name);
  60684. if (fragment) {
  60685. children = fragment.querySelectorAll('*');
  60686. }
  60687. }
  60688. if (!children) {
  60689. // casting to HTMLCollection, as both NodeListOf and HTMLCollection have 'item()' and 'length'.
  60690. children = this._fragment.querySelectorAll('*');
  60691. }
  60692. for (var i = 0; i < children.length; ++i) {
  60693. childrenArray.push(helper_1.kebabToCamel(children.item(i).nodeName.toLowerCase()));
  60694. }
  60695. return childrenArray;
  60696. };
  60697. /**
  60698. * Appending the template to a parent HTML element.
  60699. * If a parent is already set and you wish to replace the old HTML with new one, forceRemove should be true.
  60700. * @param parent the parent to which the template is added
  60701. * @param forceRemove if the parent already exists, shoud the template be removed from it?
  60702. */
  60703. Template.prototype.appendTo = function (parent, forceRemove) {
  60704. var _this = this;
  60705. if (this.parent) {
  60706. if (forceRemove && this._addedFragment) {
  60707. /*let fragement = this.parent.querySelector(this.name)
  60708. if (fragement)
  60709. this.parent.removeChild(fragement);*/
  60710. this.parent.innerHTML = '';
  60711. }
  60712. else {
  60713. return;
  60714. }
  60715. }
  60716. this.parent = parent;
  60717. if (this._configuration.id) {
  60718. this.parent.id = this._configuration.id;
  60719. }
  60720. if (this._fragment) {
  60721. this.parent.appendChild(this._fragment);
  60722. this._addedFragment = this._fragment;
  60723. }
  60724. else {
  60725. this.parent.insertAdjacentHTML("beforeend", this._rawHtml);
  60726. }
  60727. // appended only one frame after.
  60728. setTimeout(function () {
  60729. _this._registerEvents();
  60730. _this.onAppended.notifyObservers(_this);
  60731. });
  60732. };
  60733. /**
  60734. * Show the template using the provided visibilityFunction, or natively using display: flex.
  60735. * The provided function returns a promise that should be fullfilled when the element is shown.
  60736. * Since it is a promise async operations are more than possible.
  60737. * See the default viewer for an opacity example.
  60738. * @param visibilityFunction The function to execute to show the template.
  60739. */
  60740. Template.prototype.show = function (visibilityFunction) {
  60741. var _this = this;
  60742. if (this._isHiding)
  60743. return Promise.resolve(this);
  60744. return Promise.resolve().then(function () {
  60745. _this._isShowing = true;
  60746. if (visibilityFunction) {
  60747. return visibilityFunction(_this);
  60748. }
  60749. else {
  60750. // flex? box? should this be configurable easier than the visibilityFunction?
  60751. _this.parent.style.display = 'flex';
  60752. // support old browsers with no flex:
  60753. if (_this.parent.style.display !== 'flex') {
  60754. _this.parent.style.display = '';
  60755. }
  60756. return _this;
  60757. }
  60758. }).then(function () {
  60759. _this.isShown = true;
  60760. _this._isShowing = false;
  60761. _this.onStateChange.notifyObservers(_this);
  60762. return _this;
  60763. });
  60764. };
  60765. /**
  60766. * Hide the template using the provided visibilityFunction, or natively using display: none.
  60767. * The provided function returns a promise that should be fullfilled when the element is hidden.
  60768. * Since it is a promise async operations are more than possible.
  60769. * See the default viewer for an opacity example.
  60770. * @param visibilityFunction The function to execute to show the template.
  60771. */
  60772. Template.prototype.hide = function (visibilityFunction) {
  60773. var _this = this;
  60774. if (this._isShowing)
  60775. return Promise.resolve(this);
  60776. return Promise.resolve().then(function () {
  60777. _this._isHiding = true;
  60778. if (visibilityFunction) {
  60779. return visibilityFunction(_this);
  60780. }
  60781. else {
  60782. // flex? box? should this be configurable easier than the visibilityFunction?
  60783. _this.parent.style.display = 'none';
  60784. return _this;
  60785. }
  60786. }).then(function () {
  60787. _this.isShown = false;
  60788. _this._isHiding = false;
  60789. _this.onStateChange.notifyObservers(_this);
  60790. return _this;
  60791. });
  60792. };
  60793. /**
  60794. * Dispose this template
  60795. */
  60796. Template.prototype.dispose = function () {
  60797. this.onAppended.clear();
  60798. this.onEventTriggered.clear();
  60799. this.onLoaded.clear();
  60800. this.onStateChange.clear();
  60801. this.isLoaded = false;
  60802. // remove from parent
  60803. try {
  60804. this.parent.removeChild(this._fragment);
  60805. }
  60806. catch (e) {
  60807. //noop
  60808. }
  60809. this.loadRequests.forEach(function (request) {
  60810. request.abort();
  60811. });
  60812. if (this._registeredEvents) {
  60813. this._registeredEvents.forEach(function (evt) {
  60814. evt.htmlElement.removeEventListener(evt.eventName, evt.function);
  60815. });
  60816. }
  60817. delete this._fragment;
  60818. };
  60819. Template.prototype._getTemplateAsHtml = function (templateConfig) {
  60820. var _this = this;
  60821. if (!templateConfig) {
  60822. return Promise.reject('No templateConfig provided');
  60823. }
  60824. else if (templateConfig.html !== undefined) {
  60825. return Promise.resolve(templateConfig.html);
  60826. }
  60827. else {
  60828. var location_1 = this._getTemplateLocation(templateConfig);
  60829. if (helper_1.isUrl(location_1)) {
  60830. return new Promise(function (resolve, reject) {
  60831. var fileRequest = babylonjs_1.Tools.LoadFile(location_1, function (data) {
  60832. resolve(data);
  60833. }, undefined, undefined, false, function (request, error) {
  60834. reject(error);
  60835. });
  60836. _this.loadRequests.push(fileRequest);
  60837. });
  60838. }
  60839. else {
  60840. location_1 = location_1.replace('#', '');
  60841. var element = document.getElementById(location_1);
  60842. if (element) {
  60843. return Promise.resolve(element.innerHTML);
  60844. }
  60845. else {
  60846. return Promise.reject('Template ID not found');
  60847. }
  60848. }
  60849. }
  60850. };
  60851. Template.prototype._registerEvents = function () {
  60852. var _this = this;
  60853. this._registeredEvents = this._registeredEvents || [];
  60854. if (this._registeredEvents.length) {
  60855. // first remove the registered events
  60856. this._registeredEvents.forEach(function (evt) {
  60857. evt.htmlElement.removeEventListener(evt.eventName, evt.function);
  60858. });
  60859. }
  60860. if (this._configuration.events) {
  60861. var _loop_1 = function (eventName) {
  60862. if (this_1._configuration.events && this_1._configuration.events[eventName]) {
  60863. var functionToFire_1 = function (selector, event) {
  60864. _this.onEventTriggered.notifyObservers({ event: event, template: _this, selector: selector });
  60865. };
  60866. // if boolean, set the parent as the event listener
  60867. if (typeof this_1._configuration.events[eventName] === 'boolean') {
  60868. var selector = this_1.parent.id;
  60869. if (selector) {
  60870. selector = '#' + selector;
  60871. }
  60872. else {
  60873. selector = this_1.parent.tagName;
  60874. }
  60875. var binding = functionToFire_1.bind(this_1, selector);
  60876. this_1.parent.addEventListener(eventName, functionToFire_1.bind(this_1, selector), false);
  60877. this_1._registeredEvents.push({
  60878. htmlElement: this_1.parent,
  60879. eventName: eventName,
  60880. function: binding
  60881. });
  60882. }
  60883. else if (typeof this_1._configuration.events[eventName] === 'object') {
  60884. var selectorsArray = Object.keys(this_1._configuration.events[eventName] || {});
  60885. // strict null checl is working incorrectly, must override:
  60886. var event_1 = this_1._configuration.events[eventName] || {};
  60887. selectorsArray.filter(function (selector) { return event_1[selector]; }).forEach(function (selector) {
  60888. if (selector && selector.indexOf('#') !== 0) {
  60889. selector = '#' + selector;
  60890. }
  60891. var htmlElement = _this.parent.querySelector(selector);
  60892. if (htmlElement) {
  60893. var binding = functionToFire_1.bind(_this, selector);
  60894. htmlElement.addEventListener(eventName, binding, false);
  60895. _this._registeredEvents.push({
  60896. htmlElement: htmlElement,
  60897. eventName: eventName,
  60898. function: binding
  60899. });
  60900. }
  60901. });
  60902. }
  60903. }
  60904. };
  60905. var this_1 = this;
  60906. for (var eventName in this._configuration.events) {
  60907. _loop_1(eventName);
  60908. }
  60909. }
  60910. };
  60911. Template.prototype._getTemplateLocation = function (templateConfig) {
  60912. if (!templateConfig || typeof templateConfig === 'string') {
  60913. return templateConfig;
  60914. }
  60915. else {
  60916. return templateConfig.location;
  60917. }
  60918. };
  60919. return Template;
  60920. }());
  60921. exports.Template = Template;
  60922. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVtcGxhdGVNYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RlbXBsYXRpbmcvdGVtcGxhdGVNYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsdUNBQTREO0FBQzVELG9DQUE4RDtBQUU5RCx1REFBeUQ7QUFDekQsK0NBQThDO0FBRTlDLCtCQUF1QztBQVl2Qzs7O0dBR0c7QUFDSDtJQThCSSx5QkFBbUIsZ0JBQTZCO1FBQTdCLHFCQUFnQixHQUFoQixnQkFBZ0IsQ0FBYTtRQUM1QyxJQUFJLENBQUMsU0FBUyxHQUFHLEVBQUUsQ0FBQztRQUVwQixJQUFJLENBQU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QUNKO1lBQ0wsQ0FBQzs7WUExQ0QsS0FBSyxJQUFJLFNBQVMsSUFBSSxJQUFJLENBQUMsY0FBYyxDQUFDLE1BQU07d0JBQXZDLFNBQVM7YUEwQ2pCO1NBQ0o7SUFDTCxDQUFDO0lBRU8sdUNBQW9CLEdBQTVCLFVBQTZCLGNBQWM7UUFDdkMsSUFBSSxDQUFDLGNBQWMsSUFBSSxPQUFPLGNBQWMsS0FBSyxRQUFRLEVBQUU7WUFDdkQsT0FBTyxjQUFjLENBQUM7U0FDekI7YUFBTTtZQUNILE9BQU8sY0FBYyxDQUFDLFFBQVEsQ0FBQztTQUNsQztJQUNMLENBQUM7SUFDTCxlQUFDO0FBQUQsQ0FBQyxBQS9XRCxJQStXQztBQS9XWSw0QkFBUSJ9
  60923. /***/ }),
  60924. /* 62 */
  60925. /***/ (function(module, exports, __webpack_require__) {
  60926. /**!
  60927. @license
  60928. handlebars v4.0.11
  60929. Copyright (C) 2011-2017 by Yehuda Katz
  60930. Permission is hereby granted, free of charge, to any person obtaining a copy
  60931. of this software and associated documentation files (the "Software"), to deal
  60932. in the Software without restriction, including without limitation the rights
  60933. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  60934. copies of the Software, and to permit persons to whom the Software is
  60935. furnished to do so, subject to the following conditions:
  60936. The above copyright notice and this permission notice shall be included in
  60937. all copies or substantial portions of the Software.
  60938. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  60939. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  60940. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  60941. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  60942. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  60943. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  60944. THE SOFTWARE.
  60945. */
  60946. (function webpackUniversalModuleDefinition(root, factory) {
  60947. if(true)
  60948. module.exports = factory();
  60949. else if(typeof define === 'function' && define.amd)
  60950. define([], factory);
  60951. else if(typeof exports === 'object')
  60952. exports["Handlebars"] = factory();
  60953. else
  60954. root["Handlebars"] = factory();
  60955. })(this, function() {
  60956. return /******/ (function(modules) { // webpackBootstrap
  60957. /******/ // The module cache
  60958. /******/ var installedModules = {};
  60959. /******/ // The require function
  60960. /******/ function __webpack_require__(moduleId) {
  60961. /******/ // Check if module is in cache
  60962. /******/ if(installedModules[moduleId])
  60963. /******/ return installedModules[moduleId].exports;
  60964. /******/ // Create a new module (and put it into the cache)
  60965. /******/ var module = installedModules[moduleId] = {
  60966. /******/ exports: {},
  60967. /******/ id: moduleId,
  60968. /******/ loaded: false
  60969. /******/ };
  60970. /******/ // Execute the module function
  60971. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  60972. /******/ // Flag the module as loaded
  60973. /******/ module.loaded = true;
  60974. /******/ // Return the exports of the module
  60975. /******/ return module.exports;
  60976. /******/ }
  60977. /******/ // expose the modules object (__webpack_modules__)
  60978. /******/ __webpack_require__.m = modules;
  60979. /******/ // expose the module cache
  60980. /******/ __webpack_require__.c = installedModules;
  60981. /******/ // __webpack_public_path__
  60982. /******/ __webpack_require__.p = "";
  60983. /******/ // Load entry module and return exports
  60984. /******/ return __webpack_require__(0);
  60985. /******/ })
  60986. /************************************************************************/
  60987. /******/ ([
  60988. /* 0 */
  60989. /***/ (function(module, exports, __webpack_require__) {
  60990. 'use strict';
  60991. var _interopRequireDefault = __webpack_require__(1)['default'];
  60992. exports.__esModule = true;
  60993. var _handlebarsRuntime = __webpack_require__(2);
  60994. var _handlebarsRuntime2 = _interopRequireDefault(_handlebarsRuntime);
  60995. // Compiler imports
  60996. var _handlebarsCompilerAst = __webpack_require__(35);
  60997. var _handlebarsCompilerAst2 = _interopRequireDefault(_handlebarsCompilerAst);
  60998. var _handlebarsCompilerBase = __webpack_require__(36);
  60999. var _handlebarsCompilerCompiler = __webpack_require__(41);
  61000. var _handlebarsCompilerJavascriptCompiler = __webpack_require__(42);
  61001. var _handlebarsCompilerJavascriptCompiler2 = _interopRequireDefault(_handlebarsCompilerJavascriptCompiler);
  61002. var _handlebarsCompilerVisitor = __webpack_require__(39);
  61003. var _handlebarsCompilerVisitor2 = _interopRequireDefault(_handlebarsCompilerVisitor);
  61004. var _handlebarsNoConflict = __webpack_require__(34);
  61005. var _handlebarsNoConflict2 = _interopRequireDefault(_handlebarsNoConflict);
  61006. var _create = _handlebarsRuntime2['default'].create;
  61007. function create() {
  61008. var hb = _create();
  61009. hb.compile = function (input, options) {
  61010. return _handlebarsCompilerCompiler.compile(input, options, hb);
  61011. };
  61012. hb.precompile = function (input, options) {
  61013. return _handlebarsCompilerCompiler.precompile(input, options, hb);
  61014. };
  61015. hb.AST = _handlebarsCompilerAst2['default'];
  61016. hb.Compiler = _handlebarsCompilerCompiler.Compiler;
  61017. hb.JavaScriptCompiler = _handlebarsCompilerJavascriptCompiler2['default'];
  61018. hb.Parser = _handlebarsCompilerBase.parser;
  61019. hb.parse = _handlebarsCompilerBase.parse;
  61020. return hb;
  61021. }
  61022. var inst = create();
  61023. inst.create = create;
  61024. _handlebarsNoConflict2['default'](inst);
  61025. inst.Visitor = _handlebarsCompilerVisitor2['default'];
  61026. inst['default'] = inst;
  61027. exports['default'] = inst;
  61028. module.exports = exports['default'];
  61029. /***/ }),
  61030. /* 1 */
  61031. /***/ (function(module, exports) {
  61032. "use strict";
  61033. exports["default"] = function (obj) {
  61034. return obj && obj.__esModule ? obj : {
  61035. "default": obj
  61036. };
  61037. };
  61038. exports.__esModule = true;
  61039. /***/ }),
  61040. /* 2 */
  61041. /***/ (function(module, exports, __webpack_require__) {
  61042. 'use strict';
  61043. var _interopRequireWildcard = __webpack_require__(3)['default'];
  61044. var _interopRequireDefault = __webpack_require__(1)['default'];
  61045. exports.__esModule = true;
  61046. var _handlebarsBase = __webpack_require__(4);
  61047. var base = _interopRequireWildcard(_handlebarsBase);
  61048. // Each of these augment the Handlebars object. No need to setup here.
  61049. // (This is done to easily share code between commonjs and browse envs)
  61050. var _handlebarsSafeString = __webpack_require__(21);
  61051. var _handlebarsSafeString2 = _interopRequireDefault(_handlebarsSafeString);
  61052. var _handlebarsException = __webpack_require__(6);
  61053. var _handlebarsException2 = _interopRequireDefault(_handlebarsException);
  61054. var _handlebarsUtils = __webpack_require__(5);
  61055. var Utils = _interopRequireWildcard(_handlebarsUtils);
  61056. var _handlebarsRuntime = __webpack_require__(22);
  61057. var runtime = _interopRequireWildcard(_handlebarsRuntime);
  61058. var _handlebarsNoConflict = __webpack_require__(34);
  61059. var _handlebarsNoConflict2 = _interopRequireDefault(_handlebarsNoConflict);
  61060. // For compatibility and usage outside of module systems, make the Handlebars object a namespace
  61061. function create() {
  61062. var hb = new base.HandlebarsEnvironment();
  61063. Utils.extend(hb, base);
  61064. hb.SafeString = _handlebarsSafeString2['default'];
  61065. hb.Exception = _handlebarsException2['default'];
  61066. hb.Utils = Utils;
  61067. hb.escapeExpression = Utils.escapeExpression;
  61068. hb.VM = runtime;
  61069. hb.template = function (spec) {
  61070. return runtime.template(spec, hb);
  61071. };
  61072. return hb;
  61073. }
  61074. var inst = create();
  61075. inst.create = create;
  61076. _handlebarsNoConflict2['default'](inst);
  61077. inst['default'] = inst;
  61078. exports['default'] = inst;
  61079. module.exports = exports['default'];
  61080. /***/ }),
  61081. /* 3 */
  61082. /***/ (function(module, exports) {
  61083. "use strict";
  61084. exports["default"] = function (obj) {
  61085. if (obj && obj.__esModule) {
  61086. return obj;
  61087. } else {
  61088. var newObj = {};
  61089. if (obj != null) {
  61090. for (var key in obj) {
  61091. if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
  61092. }
  61093. }
  61094. newObj["default"] = obj;
  61095. return newObj;
  61096. }
  61097. };
  61098. exports.__esModule = true;
  61099. /***/ }),
  61100. /* 4 */
  61101. /***/ (function(module, exports, __webpack_require__) {
  61102. 'use strict';
  61103. var _interopRequireDefault = __webpack_require__(1)['default'];
  61104. exports.__esModule = true;
  61105. exports.HandlebarsEnvironment = HandlebarsEnvironment;
  61106. var _utils = __webpack_require__(5);
  61107. var _exception = __webpack_require__(6);
  61108. var _exception2 = _interopRequireDefault(_exception);
  61109. var _helpers = __webpack_require__(10);
  61110. var _decorators = __webpack_require__(18);
  61111. var _logger = __webpack_require__(20);
  61112. var _logger2 = _interopRequireDefault(_logger);
  61113. var VERSION = '4.0.11';
  61114. exports.VERSION = VERSION;
  61115. var COMPILER_REVISION = 7;
  61116. exports.COMPILER_REVISION = COMPILER_REVISION;
  61117. var REVISION_CHANGES = {
  61118. 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
  61119. 2: '== 1.0.0-rc.3',
  61120. 3: '== 1.0.0-rc.4',
  61121. 4: '== 1.x.x',
  61122. 5: '== 2.0.0-alpha.x',
  61123. 6: '>= 2.0.0-beta.1',
  61124. 7: '>= 4.0.0'
  61125. };
  61126. exports.REVISION_CHANGES = REVISION_CHANGES;
  61127. var objectType = '[object Object]';
  61128. function HandlebarsEnvironment(helpers, partials, decorators) {
  61129. this.helpers = helpers || {};
  61130. this.partials = partials || {};
  61131. this.decorators = decorators || {};
  61132. _helpers.registerDefaultHelpers(this);
  61133. _decorators.registerDefaultDecorators(this);
  61134. }
  61135. HandlebarsEnvironment.prototype = {
  61136. constructor: HandlebarsEnvironment,
  61137. logger: _logger2['default'],
  61138. log: _logger2['default'].log,
  61139. registerHelper: function registerHelper(name, fn) {
  61140. if (_utils.toString.call(name) === objectType) {
  61141. if (fn) {
  61142. throw new _exception2['default']('Arg not supported with multiple helpers');
  61143. }
  61144. _utils.extend(this.helpers, name);
  61145. } else {
  61146. this.helpers[name] = fn;
  61147. }
  61148. },
  61149. unregisterHelper: function unregisterHelper(name) {
  61150. delete this.helpers[name];
  61151. },
  61152. registerPartial: function registerPartial(name, partial) {
  61153. if (_utils.toString.call(name) === objectType) {
  61154. _utils.extend(this.partials, name);
  61155. } else {
  61156. if (typeof partial === 'undefined') {
  61157. throw new _exception2['default']('Attempting to register a partial called "' + name + '" as undefined');
  61158. }
  61159. this.partials[name] = partial;
  61160. }
  61161. },
  61162. unregisterPartial: function unregisterPartial(name) {
  61163. delete this.partials[name];
  61164. },
  61165. registerDecorator: function registerDecorator(name, fn) {
  61166. if (_utils.toString.call(name) === objectType) {
  61167. if (fn) {
  61168. throw new _exception2['default']('Arg not supported with multiple decorators');
  61169. }
  61170. _utils.extend(this.decorators, name);
  61171. } else {
  61172. this.decorators[name] = fn;
  61173. }
  61174. },
  61175. unregisterDecorator: function unregisterDecorator(name) {
  61176. delete this.decorators[name];
  61177. }
  61178. };
  61179. var log = _logger2['default'].log;
  61180. exports.log = log;
  61181. exports.createFrame = _utils.createFrame;
  61182. exports.logger = _logger2['default'];
  61183. /***/ }),
  61184. /* 5 */
  61185. /***/ (function(module, exports) {
  61186. 'use strict';
  61187. exports.__esModule = true;
  61188. exports.extend = extend;
  61189. exports.indexOf = indexOf;
  61190. exports.escapeExpression = escapeExpression;
  61191. exports.isEmpty = isEmpty;
  61192. exports.createFrame = createFrame;
  61193. exports.blockParams = blockParams;
  61194. exports.appendContextPath = appendContextPath;
  61195. var escape = {
  61196. '&': '&amp;',
  61197. '<': '&lt;',
  61198. '>': '&gt;',
  61199. '"': '&quot;',
  61200. "'": '&#x27;',
  61201. '`': '&#x60;',
  61202. '=': '&#x3D;'
  61203. };
  61204. var badChars = /[&<>"'`=]/g,
  61205. possible = /[&<>"'`=]/;
  61206. function escapeChar(chr) {
  61207. return escape[chr];
  61208. }
  61209. function extend(obj /* , ...source */) {
  61210. for (var i = 1; i < arguments.length; i++) {
  61211. for (var key in arguments[i]) {
  61212. if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
  61213. obj[key] = arguments[i][key];
  61214. }
  61215. }
  61216. }
  61217. return obj;
  61218. }
  61219. var toString = Object.prototype.toString;
  61220. exports.toString = toString;
  61221. // Sourced from lodash
  61222. // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
  61223. /* eslint-disable func-style */
  61224. var isFunction = function isFunction(value) {
  61225. return typeof value === 'function';
  61226. };
  61227. // fallback for older versions of Chrome and Safari
  61228. /* istanbul ignore next */
  61229. if (isFunction(/x/)) {
  61230. exports.isFunction = isFunction = function (value) {
  61231. return typeof value === 'function' && toString.call(value) === '[object Function]';
  61232. };
  61233. }
  61234. exports.isFunction = isFunction;
  61235. /* eslint-enable func-style */
  61236. /* istanbul ignore next */
  61237. var isArray = Array.isArray || function (value) {
  61238. return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false;
  61239. };
  61240. exports.isArray = isArray;
  61241. // Older IE versions do not directly support indexOf so we must implement our own, sadly.
  61242. function indexOf(array, value) {
  61243. for (var i = 0, len = array.length; i < len; i++) {
  61244. if (array[i] === value) {
  61245. return i;
  61246. }
  61247. }
  61248. return -1;
  61249. }
  61250. function escapeExpression(string) {
  61251. if (typeof string !== 'string') {
  61252. // don't escape SafeStrings, since they're already safe
  61253. if (string && string.toHTML) {
  61254. return string.toHTML();
  61255. } else if (string == null) {
  61256. return '';
  61257. } else if (!string) {
  61258. return string + '';
  61259. }
  61260. // Force a string conversion as this will be done by the append regardless and
  61261. // the regex test will do this transparently behind the scenes, causing issues if
  61262. // an object's to string has escaped characters in it.
  61263. string = '' + string;
  61264. }
  61265. if (!possible.test(string)) {
  61266. return string;
  61267. }
  61268. return string.replace(badChars, escapeChar);
  61269. }
  61270. function isEmpty(value) {
  61271. if (!value && value !== 0) {
  61272. return true;
  61273. } else if (isArray(value) && value.length === 0) {
  61274. return true;
  61275. } else {
  61276. return false;
  61277. }
  61278. }
  61279. function createFrame(object) {
  61280. var frame = extend({}, object);
  61281. frame._parent = object;
  61282. return frame;
  61283. }
  61284. function blockParams(params, ids) {
  61285. params.path = ids;
  61286. return params;
  61287. }
  61288. function appendContextPath(contextPath, id) {
  61289. return (contextPath ? contextPath + '.' : '') + id;
  61290. }
  61291. /***/ }),
  61292. /* 6 */
  61293. /***/ (function(module, exports, __webpack_require__) {
  61294. 'use strict';
  61295. var _Object$defineProperty = __webpack_require__(7)['default'];
  61296. exports.__esModule = true;
  61297. var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
  61298. function Exception(message, node) {
  61299. var loc = node && node.loc,
  61300. line = undefined,
  61301. column = undefined;
  61302. if (loc) {
  61303. line = loc.start.line;
  61304. column = loc.start.column;
  61305. message += ' - ' + line + ':' + column;
  61306. }
  61307. var tmp = Error.prototype.constructor.call(this, message);
  61308. // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
  61309. for (var idx = 0; idx < errorProps.length; idx++) {
  61310. this[errorProps[idx]] = tmp[errorProps[idx]];
  61311. }
  61312. /* istanbul ignore else */
  61313. if (Error.captureStackTrace) {
  61314. Error.captureStackTrace(this, Exception);
  61315. }
  61316. try {
  61317. if (loc) {
  61318. this.lineNumber = line;
  61319. // Work around issue under safari where we can't directly set the column value
  61320. /* istanbul ignore next */
  61321. if (_Object$defineProperty) {
  61322. Object.defineProperty(this, 'column', {
  61323. value: column,
  61324. enumerable: true
  61325. });
  61326. } else {
  61327. this.column = column;
  61328. }
  61329. }
  61330. } catch (nop) {
  61331. /* Ignore if the browser is very particular */
  61332. }
  61333. }
  61334. Exception.prototype = new Error();
  61335. exports['default'] = Exception;
  61336. module.exports = exports['default'];
  61337. /***/ }),
  61338. /* 7 */
  61339. /***/ (function(module, exports, __webpack_require__) {
  61340. module.exports = { "default": __webpack_require__(8), __esModule: true };
  61341. /***/ }),
  61342. /* 8 */
  61343. /***/ (function(module, exports, __webpack_require__) {
  61344. var $ = __webpack_require__(9);
  61345. module.exports = function defineProperty(it, key, desc){
  61346. return $.setDesc(it, key, desc);
  61347. };
  61348. /***/ }),
  61349. /* 9 */
  61350. /***/ (function(module, exports) {
  61351. var $Object = Object;
  61352. module.exports = {
  61353. create: $Object.create,
  61354. getProto: $Object.getPrototypeOf,
  61355. isEnum: {}.propertyIsEnumerable,
  61356. getDesc: $Object.getOwnPropertyDescriptor,
  61357. setDesc: $Object.defineProperty,
  61358. setDescs: $Object.defineProperties,
  61359. getKeys: $Object.keys,
  61360. getNames: $Object.getOwnPropertyNames,
  61361. getSymbols: $Object.getOwnPropertySymbols,
  61362. each: [].forEach
  61363. };
  61364. /***/ }),
  61365. /* 10 */
  61366. /***/ (function(module, exports, __webpack_require__) {
  61367. 'use strict';
  61368. var _interopRequireDefault = __webpack_require__(1)['default'];
  61369. exports.__esModule = true;
  61370. exports.registerDefaultHelpers = registerDefaultHelpers;
  61371. var _helpersBlockHelperMissing = __webpack_require__(11);
  61372. var _helpersBlockHelperMissing2 = _interopRequireDefault(_helpersBlockHelperMissing);
  61373. var _helpersEach = __webpack_require__(12);
  61374. var _helpersEach2 = _interopRequireDefault(_helpersEach);
  61375. var _helpersHelperMissing = __webpack_require__(13);
  61376. var _helpersHelperMissing2 = _interopRequireDefault(_helpersHelperMissing);
  61377. var _helpersIf = __webpack_require__(14);
  61378. var _helpersIf2 = _interopRequireDefault(_helpersIf);
  61379. var _helpersLog = __webpack_require__(15);
  61380. var _helpersLog2 = _interopRequireDefault(_helpersLog);
  61381. var _helpersLookup = __webpack_require__(16);
  61382. var _helpersLookup2 = _interopRequireDefault(_helpersLookup);
  61383. var _helpersWith = __webpack_require__(17);
  61384. var _helpersWith2 = _interopRequireDefault(_helpersWith);
  61385. function registerDefaultHelpers(instance) {
  61386. _helpersBlockHelperMissing2['default'](instance);
  61387. _helpersEach2['default'](instance);
  61388. _helpersHelperMissing2['default'](instance);
  61389. _helpersIf2['default'](instance);
  61390. _helpersLog2['default'](instance);
  61391. _helpersLookup2['default'](instance);
  61392. _helpersWith2['default'](instance);
  61393. }
  61394. /***/ }),
  61395. /* 11 */
  61396. /***/ (function(module, exports, __webpack_require__) {
  61397. 'use strict';
  61398. exports.__esModule = true;
  61399. var _utils = __webpack_require__(5);
  61400. exports['default'] = function (instance) {
  61401. instance.registerHelper('blockHelperMissing', function (context, options) {
  61402. var inverse = options.inverse,
  61403. fn = options.fn;
  61404. if (context === true) {
  61405. return fn(this);
  61406. } else if (context === false || context == null) {
  61407. return inverse(this);
  61408. } else if (_utils.isArray(context)) {
  61409. if (context.length > 0) {
  61410. if (options.ids) {
  61411. options.ids = [options.name];
  61412. }
  61413. return instance.helpers.each(context, options);
  61414. } else {
  61415. return inverse(this);
  61416. }
  61417. } else {
  61418. if (options.data && options.ids) {
  61419. var data = _utils.createFrame(options.data);
  61420. data.contextPath = _utils.appendContextPath(options.data.contextPath, options.name);
  61421. options = { data: data };
  61422. }
  61423. return fn(context, options);
  61424. }
  61425. });
  61426. };
  61427. module.exports = exports['default'];
  61428. /***/ }),
  61429. /* 12 */
  61430. /***/ (function(module, exports, __webpack_require__) {
  61431. 'use strict';
  61432. var _interopRequireDefault = __webpack_require__(1)['default'];
  61433. exports.__esModule = true;
  61434. var _utils = __webpack_require__(5);
  61435. var _exception = __webpack_require__(6);
  61436. var _exception2 = _interopRequireDefault(_exception);
  61437. exports['default'] = function (instance) {
  61438. instance.registerHelper('each', function (context, options) {
  61439. if (!options) {
  61440. throw new _exception2['default']('Must pass iterator to #each');
  61441. }
  61442. var fn = options.fn,
  61443. inverse = options.inverse,
  61444. i = 0,
  61445. ret = '',
  61446. data = undefined,
  61447. contextPath = undefined;
  61448. if (options.data && options.ids) {
  61449. contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
  61450. }
  61451. if (_utils.isFunction(context)) {
  61452. context = context.call(this);
  61453. }
  61454. if (options.data) {
  61455. data = _utils.createFrame(options.data);
  61456. }
  61457. function execIteration(field, index, last) {
  61458. if (data) {
  61459. data.key = field;
  61460. data.index = index;
  61461. data.first = index === 0;
  61462. data.last = !!last;
  61463. if (contextPath) {
  61464. data.contextPath = contextPath + field;
  61465. }
  61466. }
  61467. ret = ret + fn(context[field], {
  61468. data: data,
  61469. blockParams: _utils.blockParams([context[field], field], [contextPath + field, null])
  61470. });
  61471. }
  61472. if (context && typeof context === 'object') {
  61473. if (_utils.isArray(context)) {
  61474. for (var j = context.length; i < j; i++) {
  61475. if (i in context) {
  61476. execIteration(i, i, i === context.length - 1);
  61477. }
  61478. }
  61479. } else {
  61480. var priorKey = undefined;
  61481. for (var key in context) {
  61482. if (context.hasOwnProperty(key)) {
  61483. // We're running the iterations one step out of sync so we can detect
  61484. // the last iteration without have to scan the object twice and create
  61485. // an itermediate keys array.
  61486. if (priorKey !== undefined) {
  61487. execIteration(priorKey, i - 1);
  61488. }
  61489. priorKey = key;
  61490. i++;
  61491. }
  61492. }
  61493. if (priorKey !== undefined) {
  61494. execIteration(priorKey, i - 1, true);
  61495. }
  61496. }
  61497. }
  61498. if (i === 0) {
  61499. ret = inverse(this);
  61500. }
  61501. return ret;
  61502. });
  61503. };
  61504. module.exports = exports['default'];
  61505. /***/ }),
  61506. /* 13 */
  61507. /***/ (function(module, exports, __webpack_require__) {
  61508. 'use strict';
  61509. var _interopRequireDefault = __webpack_require__(1)['default'];
  61510. exports.__esModule = true;
  61511. var _exception = __webpack_require__(6);
  61512. var _exception2 = _interopRequireDefault(_exception);
  61513. exports['default'] = function (instance) {
  61514. instance.registerHelper('helperMissing', function () /* [args, ]options */{
  61515. if (arguments.length === 1) {
  61516. // A missing field in a {{foo}} construct.
  61517. return undefined;
  61518. } else {
  61519. // Someone is actually trying to call something, blow up.
  61520. throw new _exception2['default']('Missing helper: "' + arguments[arguments.length - 1].name + '"');
  61521. }
  61522. });
  61523. };
  61524. module.exports = exports['default'];
  61525. /***/ }),
  61526. /* 14 */
  61527. /***/ (function(module, exports, __webpack_require__) {
  61528. 'use strict';
  61529. exports.__esModule = true;
  61530. var _utils = __webpack_require__(5);
  61531. exports['default'] = function (instance) {
  61532. instance.registerHelper('if', function (conditional, options) {
  61533. if (_utils.isFunction(conditional)) {
  61534. conditional = conditional.call(this);
  61535. }
  61536. // Default behavior is to render the positive path if the value is truthy and not empty.
  61537. // The `includeZero` option may be set to treat the condtional as purely not empty based on the
  61538. // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
  61539. if (!options.hash.includeZero && !conditional || _utils.isEmpty(conditional)) {
  61540. return options.inverse(this);
  61541. } else {
  61542. return options.fn(this);
  61543. }
  61544. });
  61545. instance.registerHelper('unless', function (conditional, options) {
  61546. return instance.helpers['if'].call(this, conditional, { fn: options.inverse, inverse: options.fn, hash: options.hash });
  61547. });
  61548. };
  61549. module.exports = exports['default'];
  61550. /***/ }),
  61551. /* 15 */
  61552. /***/ (function(module, exports) {
  61553. 'use strict';
  61554. exports.__esModule = true;
  61555. exports['default'] = function (instance) {
  61556. instance.registerHelper('log', function () /* message, options */{
  61557. var args = [undefined],
  61558. options = arguments[arguments.length - 1];
  61559. for (var i = 0; i < arguments.length - 1; i++) {
  61560. args.push(arguments[i]);
  61561. }
  61562. var level = 1;
  61563. if (options.hash.level != null) {
  61564. level = options.hash.level;
  61565. } else if (options.data && options.data.level != null) {
  61566. level = options.data.level;
  61567. }
  61568. args[0] = level;
  61569. instance.log.apply(instance, args);
  61570. });
  61571. };
  61572. module.exports = exports['default'];
  61573. /***/ }),
  61574. /* 16 */
  61575. /***/ (function(module, exports) {
  61576. 'use strict';
  61577. exports.__esModule = true;
  61578. exports['default'] = function (instance) {
  61579. instance.registerHelper('lookup', function (obj, field) {
  61580. return obj && obj[field];
  61581. });
  61582. };
  61583. module.exports = exports['default'];
  61584. /***/ }),
  61585. /* 17 */
  61586. /***/ (function(module, exports, __webpack_require__) {
  61587. 'use strict';
  61588. exports.__esModule = true;
  61589. var _utils = __webpack_require__(5);
  61590. exports['default'] = function (instance) {
  61591. instance.registerHelper('with', function (context, options) {
  61592. if (_utils.isFunction(context)) {
  61593. context = context.call(this);
  61594. }
  61595. var fn = options.fn;
  61596. if (!_utils.isEmpty(context)) {
  61597. var data = options.data;
  61598. if (options.data && options.ids) {
  61599. data = _utils.createFrame(options.data);
  61600. data.contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]);
  61601. }
  61602. return fn(context, {
  61603. data: data,
  61604. blockParams: _utils.blockParams([context], [data && data.contextPath])
  61605. });
  61606. } else {
  61607. return options.inverse(this);
  61608. }
  61609. });
  61610. };
  61611. module.exports = exports['default'];
  61612. /***/ }),
  61613. /* 18 */
  61614. /***/ (function(module, exports, __webpack_require__) {
  61615. 'use strict';
  61616. var _interopRequireDefault = __webpack_require__(1)['default'];
  61617. exports.__esModule = true;
  61618. exports.registerDefaultDecorators = registerDefaultDecorators;
  61619. var _decoratorsInline = __webpack_require__(19);
  61620. var _decoratorsInline2 = _interopRequireDefault(_decoratorsInline);
  61621. function registerDefaultDecorators(instance) {
  61622. _decoratorsInline2['default'](instance);
  61623. }
  61624. /***/ }),
  61625. /* 19 */
  61626. /***/ (function(module, exports, __webpack_require__) {
  61627. 'use strict';
  61628. exports.__esModule = true;
  61629. var _utils = __webpack_require__(5);
  61630. exports['default'] = function (instance) {
  61631. instance.registerDecorator('inline', function (fn, props, container, options) {
  61632. var ret = fn;
  61633. if (!props.partials) {
  61634. props.partials = {};
  61635. ret = function (context, options) {
  61636. // Create a new partials stack frame prior to exec.
  61637. var original = container.partials;
  61638. container.partials = _utils.extend({}, original, props.partials);
  61639. var ret = fn(context, options);
  61640. container.partials = original;
  61641. return ret;
  61642. };
  61643. }
  61644. props.partials[options.args[0]] = options.fn;
  61645. return ret;
  61646. });
  61647. };
  61648. module.exports = exports['default'];
  61649. /***/ }),
  61650. /* 20 */
  61651. /***/ (function(module, exports, __webpack_require__) {
  61652. 'use strict';
  61653. exports.__esModule = true;
  61654. var _utils = __webpack_require__(5);
  61655. var logger = {
  61656. methodMap: ['debug', 'info', 'warn', 'error'],
  61657. level: 'info',
  61658. // Maps a given level value to the `methodMap` indexes above.
  61659. lookupLevel: function lookupLevel(level) {
  61660. if (typeof level === 'string') {
  61661. var levelMap = _utils.indexOf(logger.methodMap, level.toLowerCase());
  61662. if (levelMap >= 0) {
  61663. level = levelMap;
  61664. } else {
  61665. level = parseInt(level, 10);
  61666. }
  61667. }
  61668. return level;
  61669. },
  61670. // Can be overridden in the host environment
  61671. log: function log(level) {
  61672. level = logger.lookupLevel(level);
  61673. if (typeof console !== 'undefined' && logger.lookupLevel(logger.level) <= level) {
  61674. var method = logger.methodMap[level];
  61675. if (!console[method]) {
  61676. // eslint-disable-line no-console
  61677. method = 'log';
  61678. }
  61679. for (var _len = arguments.length, message = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  61680. message[_key - 1] = arguments[_key];
  61681. }
  61682. console[method].apply(console, message); // eslint-disable-line no-console
  61683. }
  61684. }
  61685. };
  61686. exports['default'] = logger;
  61687. module.exports = exports['default'];
  61688. /***/ }),
  61689. /* 21 */
  61690. /***/ (function(module, exports) {
  61691. // Build out our basic SafeString type
  61692. 'use strict';
  61693. exports.__esModule = true;
  61694. function SafeString(string) {
  61695. this.string = string;
  61696. }
  61697. SafeString.prototype.toString = SafeString.prototype.toHTML = function () {
  61698. return '' + this.string;
  61699. };
  61700. exports['default'] = SafeString;
  61701. module.exports = exports['default'];
  61702. /***/ }),
  61703. /* 22 */
  61704. /***/ (function(module, exports, __webpack_require__) {
  61705. 'use strict';
  61706. var _Object$seal = __webpack_require__(23)['default'];
  61707. var _interopRequireWildcard = __webpack_require__(3)['default'];
  61708. var _interopRequireDefault = __webpack_require__(1)['default'];
  61709. exports.__esModule = true;
  61710. exports.checkRevision = checkRevision;
  61711. exports.template = template;
  61712. exports.wrapProgram = wrapProgram;
  61713. exports.resolvePartial = resolvePartial;
  61714. exports.invokePartial = invokePartial;
  61715. exports.noop = noop;
  61716. var _utils = __webpack_require__(5);
  61717. var Utils = _interopRequireWildcard(_utils);
  61718. var _exception = __webpack_require__(6);
  61719. var _exception2 = _interopRequireDefault(_exception);
  61720. var _base = __webpack_require__(4);
  61721. function checkRevision(compilerInfo) {
  61722. var compilerRevision = compilerInfo && compilerInfo[0] || 1,
  61723. currentRevision = _base.COMPILER_REVISION;
  61724. if (compilerRevision !== currentRevision) {
  61725. if (compilerRevision < currentRevision) {
  61726. var runtimeVersions = _base.REVISION_CHANGES[currentRevision],
  61727. compilerVersions = _base.REVISION_CHANGES[compilerRevision];
  61728. throw new _exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
  61729. } else {
  61730. // Use the embedded version info since the runtime doesn't know about this revision yet
  61731. throw new _exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
  61732. }
  61733. }
  61734. }
  61735. function template(templateSpec, env) {
  61736. /* istanbul ignore next */
  61737. if (!env) {
  61738. throw new _exception2['default']('No environment passed to template');
  61739. }
  61740. if (!templateSpec || !templateSpec.main) {
  61741. throw new _exception2['default']('Unknown template object: ' + typeof templateSpec);
  61742. }
  61743. templateSpec.main.decorator = templateSpec.main_d;
  61744. // Note: Using env.VM references rather than local var references throughout this section to allow
  61745. // for external users to override these as psuedo-supported APIs.
  61746. env.VM.checkRevision(templateSpec.compiler);
  61747. function invokePartialWrapper(partial, context, options) {
  61748. if (options.hash) {
  61749. context = Utils.extend({}, context, options.hash);
  61750. if (options.ids) {
  61751. options.ids[0] = true;
  61752. }
  61753. }
  61754. partial = env.VM.resolvePartial.call(this, partial, context, options);
  61755. var result = env.VM.invokePartial.call(this, partial, context, options);
  61756. if (result == null && env.compile) {
  61757. options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
  61758. result = options.partials[options.name](context, options);
  61759. }
  61760. if (result != null) {
  61761. if (options.indent) {
  61762. var lines = result.split('\n');
  61763. for (var i = 0, l = lines.length; i < l; i++) {
  61764. if (!lines[i] && i + 1 === l) {
  61765. break;
  61766. }
  61767. lines[i] = options.indent + lines[i];
  61768. }
  61769. result = lines.join('\n');
  61770. }
  61771. return result;
  61772. } else {
  61773. throw new _exception2['default']('The partial ' + options.name + ' could not be compiled when running in runtime-only mode');
  61774. }
  61775. }
  61776. // Just add water
  61777. var container = {
  61778. strict: function strict(obj, name) {
  61779. if (!(name in obj)) {
  61780. throw new _exception2['default']('"' + name + '" not defined in ' + obj);
  61781. }
  61782. return obj[name];
  61783. },
  61784. lookup: function lookup(depths, name) {
  61785. var len = depths.length;
  61786. for (var i = 0; i < len; i++) {
  61787. if (depths[i] && depths[i][name] != null) {
  61788. return depths[i][name];
  61789. }
  61790. }
  61791. },
  61792. lambda: function lambda(current, context) {
  61793. return typeof current === 'function' ? current.call(context) : current;
  61794. },
  61795. escapeExpression: Utils.escapeExpression,
  61796. invokePartial: invokePartialWrapper,
  61797. fn: function fn(i) {
  61798. var ret = templateSpec[i];
  61799. ret.decorator = templateSpec[i + '_d'];
  61800. return ret;
  61801. },
  61802. programs: [],
  61803. program: function program(i, data, declaredBlockParams, blockParams, depths) {
  61804. var programWrapper = this.programs[i],
  61805. fn = this.fn(i);
  61806. if (data || depths || blockParams || declaredBlockParams) {
  61807. programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
  61808. } else if (!programWrapper) {
  61809. programWrapper = this.programs[i] = wrapProgram(this, i, fn);
  61810. }
  61811. return programWrapper;
  61812. },
  61813. data: function data(value, depth) {
  61814. while (value && depth--) {
  61815. value = value._parent;
  61816. }
  61817. return value;
  61818. },
  61819. merge: function merge(param, common) {
  61820. var obj = param || common;
  61821. if (param && common && param !== common) {
  61822. obj = Utils.extend({}, common, param);
  61823. }
  61824. return obj;
  61825. },
  61826. // An empty object to use as replacement for null-contexts
  61827. nullContext: _Object$seal({}),
  61828. noop: env.VM.noop,
  61829. compilerInfo: templateSpec.compiler
  61830. };
  61831. function ret(context) {
  61832. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  61833. var data = options.data;
  61834. ret._setup(options);
  61835. if (!options.partial && templateSpec.useData) {
  61836. data = initData(context, data);
  61837. }
  61838. var depths = undefined,
  61839. blockParams = templateSpec.useBlockParams ? [] : undefined;
  61840. if (templateSpec.useDepths) {
  61841. if (options.depths) {
  61842. depths = context != options.depths[0] ? [context].concat(options.depths) : options.depths;
  61843. } else {
  61844. depths = [context];
  61845. }
  61846. }
  61847. function main(context /*, options*/) {
  61848. return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
  61849. }
  61850. main = executeDecorators(templateSpec.main, main, container, options.depths || [], data, blockParams);
  61851. return main(context, options);
  61852. }
  61853. ret.isTop = true;
  61854. ret._setup = function (options) {
  61855. if (!options.partial) {
  61856. container.helpers = container.merge(options.helpers, env.helpers);
  61857. if (templateSpec.usePartial) {
  61858. container.partials = container.merge(options.partials, env.partials);
  61859. }
  61860. if (templateSpec.usePartial || templateSpec.useDecorators) {
  61861. container.decorators = container.merge(options.decorators, env.decorators);
  61862. }
  61863. } else {
  61864. container.helpers = options.helpers;
  61865. container.partials = options.partials;
  61866. container.decorators = options.decorators;
  61867. }
  61868. };
  61869. ret._child = function (i, data, blockParams, depths) {
  61870. if (templateSpec.useBlockParams && !blockParams) {
  61871. throw new _exception2['default']('must pass block params');
  61872. }
  61873. if (templateSpec.useDepths && !depths) {
  61874. throw new _exception2['default']('must pass parent depths');
  61875. }
  61876. return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
  61877. };
  61878. return ret;
  61879. }
  61880. function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
  61881. function prog(context) {
  61882. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  61883. var currentDepths = depths;
  61884. if (depths && context != depths[0] && !(context === container.nullContext && depths[0] === null)) {
  61885. currentDepths = [context].concat(depths);
  61886. }
  61887. return fn(container, context, container.helpers, container.partials, options.data || data, blockParams && [options.blockParams].concat(blockParams), currentDepths);
  61888. }
  61889. prog = executeDecorators(fn, prog, container, depths, data, blockParams);
  61890. prog.program = i;
  61891. prog.depth = depths ? depths.length : 0;
  61892. prog.blockParams = declaredBlockParams || 0;
  61893. return prog;
  61894. }
  61895. function resolvePartial(partial, context, options) {
  61896. if (!partial) {
  61897. if (options.name === '@partial-block') {
  61898. partial = options.data['partial-block'];
  61899. } else {
  61900. partial = options.partials[options.name];
  61901. }
  61902. } else if (!partial.call && !options.name) {
  61903. // This is a dynamic partial that returned a string
  61904. options.name = partial;
  61905. partial = options.partials[partial];
  61906. }
  61907. return partial;
  61908. }
  61909. function invokePartial(partial, context, options) {
  61910. // Use the current closure context to save the partial-block if this partial
  61911. var currentPartialBlock = options.data && options.data['partial-block'];
  61912. options.partial = true;
  61913. if (options.ids) {
  61914. options.data.contextPath = options.ids[0] || options.data.contextPath;
  61915. }
  61916. var partialBlock = undefined;
  61917. if (options.fn && options.fn !== noop) {
  61918. (function () {
  61919. options.data = _base.createFrame(options.data);
  61920. // Wrapper function to get access to currentPartialBlock from the closure
  61921. var fn = options.fn;
  61922. partialBlock = options.data['partial-block'] = function partialBlockWrapper(context) {
  61923. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  61924. // Restore the partial-block from the closure for the execution of the block
  61925. // i.e. the part inside the block of the partial call.
  61926. options.data = _base.createFrame(options.data);
  61927. options.data['partial-block'] = currentPartialBlock;
  61928. return fn(context, options);
  61929. };
  61930. if (fn.partials) {
  61931. options.partials = Utils.extend({}, options.partials, fn.partials);
  61932. }
  61933. })();
  61934. }
  61935. if (partial === undefined && partialBlock) {
  61936. partial = partialBlock;
  61937. }
  61938. if (partial === undefined) {
  61939. throw new _exception2['default']('The partial ' + options.name + ' could not be found');
  61940. } else if (partial instanceof Function) {
  61941. return partial(context, options);
  61942. }
  61943. }
  61944. function noop() {
  61945. return '';
  61946. }
  61947. function initData(context, data) {
  61948. if (!data || !('root' in data)) {
  61949. data = data ? _base.createFrame(data) : {};
  61950. data.root = context;
  61951. }
  61952. return data;
  61953. }
  61954. function executeDecorators(fn, prog, container, depths, data, blockParams) {
  61955. if (fn.decorator) {
  61956. var props = {};
  61957. prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
  61958. Utils.extend(prog, props);
  61959. }
  61960. return prog;
  61961. }
  61962. /***/ }),
  61963. /* 23 */
  61964. /***/ (function(module, exports, __webpack_require__) {
  61965. module.exports = { "default": __webpack_require__(24), __esModule: true };
  61966. /***/ }),
  61967. /* 24 */
  61968. /***/ (function(module, exports, __webpack_require__) {
  61969. __webpack_require__(25);
  61970. module.exports = __webpack_require__(30).Object.seal;
  61971. /***/ }),
  61972. /* 25 */
  61973. /***/ (function(module, exports, __webpack_require__) {
  61974. // 19.1.2.17 Object.seal(O)
  61975. var isObject = __webpack_require__(26);
  61976. __webpack_require__(27)('seal', function($seal){
  61977. return function seal(it){
  61978. return $seal && isObject(it) ? $seal(it) : it;
  61979. };
  61980. });
  61981. /***/ }),
  61982. /* 26 */
  61983. /***/ (function(module, exports) {
  61984. module.exports = function(it){
  61985. return typeof it === 'object' ? it !== null : typeof it === 'function';
  61986. };
  61987. /***/ }),
  61988. /* 27 */
  61989. /***/ (function(module, exports, __webpack_require__) {
  61990. // most Object methods by ES6 should accept primitives
  61991. var $export = __webpack_require__(28)
  61992. , core = __webpack_require__(30)
  61993. , fails = __webpack_require__(33);
  61994. module.exports = function(KEY, exec){
  61995. var fn = (core.Object || {})[KEY] || Object[KEY]
  61996. , exp = {};
  61997. exp[KEY] = exec(fn);
  61998. $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);
  61999. };
  62000. /***/ }),
  62001. /* 28 */
  62002. /***/ (function(module, exports, __webpack_require__) {
  62003. var global = __webpack_require__(29)
  62004. , core = __webpack_require__(30)
  62005. , ctx = __webpack_require__(31)
  62006. , PROTOTYPE = 'prototype';
  62007. var $export = function(type, name, source){
  62008. var IS_FORCED = type & $export.F
  62009. , IS_GLOBAL = type & $export.G
  62010. , IS_STATIC = type & $export.S
  62011. , IS_PROTO = type & $export.P
  62012. , IS_BIND = type & $export.B
  62013. , IS_WRAP = type & $export.W
  62014. , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
  62015. , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
  62016. , key, own, out;
  62017. if(IS_GLOBAL)source = name;
  62018. for(key in source){
  62019. // contains in native
  62020. own = !IS_FORCED && target && key in target;
  62021. if(own && key in exports)continue;
  62022. // export native or passed
  62023. out = own ? target[key] : source[key];
  62024. // prevent global pollution for namespaces
  62025. exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
  62026. // bind timers to global for call from export context
  62027. : IS_BIND && own ? ctx(out, global)
  62028. // wrap global constructors for prevent change them in library
  62029. : IS_WRAP && target[key] == out ? (function(C){
  62030. var F = function(param){
  62031. return this instanceof C ? new C(param) : C(param);
  62032. };
  62033. F[PROTOTYPE] = C[PROTOTYPE];
  62034. return F;
  62035. // make static versions for prototype methods
  62036. })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  62037. if(IS_PROTO)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
  62038. }
  62039. };
  62040. // type bitmap
  62041. $export.F = 1; // forced
  62042. $export.G = 2; // global
  62043. $export.S = 4; // static
  62044. $export.P = 8; // proto
  62045. $export.B = 16; // bind
  62046. $export.W = 32; // wrap
  62047. module.exports = $export;
  62048. /***/ }),
  62049. /* 29 */
  62050. /***/ (function(module, exports) {
  62051. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  62052. var global = module.exports = typeof window != 'undefined' && window.Math == Math
  62053. ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
  62054. if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
  62055. /***/ }),
  62056. /* 30 */
  62057. /***/ (function(module, exports) {
  62058. var core = module.exports = {version: '1.2.6'};
  62059. if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
  62060. /***/ }),
  62061. /* 31 */
  62062. /***/ (function(module, exports, __webpack_require__) {
  62063. // optional / simple context binding
  62064. var aFunction = __webpack_require__(32);
  62065. module.exports = function(fn, that, length){
  62066. aFunction(fn);
  62067. if(that === undefined)return fn;
  62068. switch(length){
  62069. case 1: return function(a){
  62070. return fn.call(that, a);
  62071. };
  62072. case 2: return function(a, b){
  62073. return fn.call(that, a, b);
  62074. };
  62075. case 3: return function(a, b, c){
  62076. return fn.call(that, a, b, c);
  62077. };
  62078. }
  62079. return function(/* ...args */){
  62080. return fn.apply(that, arguments);
  62081. };
  62082. };
  62083. /***/ }),
  62084. /* 32 */
  62085. /***/ (function(module, exports) {
  62086. module.exports = function(it){
  62087. if(typeof it != 'function')throw TypeError(it + ' is not a function!');
  62088. return it;
  62089. };
  62090. /***/ }),
  62091. /* 33 */
  62092. /***/ (function(module, exports) {
  62093. module.exports = function(exec){
  62094. try {
  62095. return !!exec();
  62096. } catch(e){
  62097. return true;
  62098. }
  62099. };
  62100. /***/ }),
  62101. /* 34 */
  62102. /***/ (function(module, exports) {
  62103. /* WEBPACK VAR INJECTION */(function(global) {/* global window */
  62104. 'use strict';
  62105. exports.__esModule = true;
  62106. exports['default'] = function (Handlebars) {
  62107. /* istanbul ignore next */
  62108. var root = typeof global !== 'undefined' ? global : window,
  62109. $Handlebars = root.Handlebars;
  62110. /* istanbul ignore next */
  62111. Handlebars.noConflict = function () {
  62112. if (root.Handlebars === Handlebars) {
  62113. root.Handlebars = $Handlebars;
  62114. }
  62115. return Handlebars;
  62116. };
  62117. };
  62118. module.exports = exports['default'];
  62119. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  62120. /***/ }),
  62121. /* 35 */
  62122. /***/ (function(module, exports) {
  62123. 'use strict';
  62124. exports.__esModule = true;
  62125. var AST = {
  62126. // Public API used to evaluate derived attributes regarding AST nodes
  62127. helpers: {
  62128. // a mustache is definitely a helper if:
  62129. // * it is an eligible helper, and
  62130. // * it has at least one parameter or hash segment
  62131. helperExpression: function helperExpression(node) {
  62132. return node.type === 'SubExpression' || (node.type === 'MustacheStatement' || node.type === 'BlockStatement') && !!(node.params && node.params.length || node.hash);
  62133. },
  62134. scopedId: function scopedId(path) {
  62135. return (/^\.|this\b/.test(path.original)
  62136. );
  62137. },
  62138. // an ID is simple if it only has one part, and that part is not
  62139. // `..` or `this`.
  62140. simpleId: function simpleId(path) {
  62141. return path.parts.length === 1 && !AST.helpers.scopedId(path) && !path.depth;
  62142. }
  62143. }
  62144. };
  62145. // Must be exported as an object rather than the root of the module as the jison lexer
  62146. // must modify the object to operate properly.
  62147. exports['default'] = AST;
  62148. module.exports = exports['default'];
  62149. /***/ }),
  62150. /* 36 */
  62151. /***/ (function(module, exports, __webpack_require__) {
  62152. 'use strict';
  62153. var _interopRequireDefault = __webpack_require__(1)['default'];
  62154. var _interopRequireWildcard = __webpack_require__(3)['default'];
  62155. exports.__esModule = true;
  62156. exports.parse = parse;
  62157. var _parser = __webpack_require__(37);
  62158. var _parser2 = _interopRequireDefault(_parser);
  62159. var _whitespaceControl = __webpack_require__(38);
  62160. var _whitespaceControl2 = _interopRequireDefault(_whitespaceControl);
  62161. var _helpers = __webpack_require__(40);
  62162. var Helpers = _interopRequireWildcard(_helpers);
  62163. var _utils = __webpack_require__(5);
  62164. exports.parser = _parser2['default'];
  62165. var yy = {};
  62166. _utils.extend(yy, Helpers);
  62167. function parse(input, options) {
  62168. // Just return if an already-compiled AST was passed in.
  62169. if (input.type === 'Program') {
  62170. return input;
  62171. }
  62172. _parser2['default'].yy = yy;
  62173. // Altering the shared object here, but this is ok as parser is a sync operation
  62174. yy.locInfo = function (locInfo) {
  62175. return new yy.SourceLocation(options && options.srcName, locInfo);
  62176. };
  62177. var strip = new _whitespaceControl2['default'](options);
  62178. return strip.accept(_parser2['default'].parse(input));
  62179. }
  62180. /***/ }),
  62181. /* 37 */
  62182. /***/ (function(module, exports) {
  62183. // File ignored in coverage tests via setting in .istanbul.yml
  62184. /* Jison generated parser */
  62185. "use strict";
  62186. exports.__esModule = true;
  62187. var handlebars = (function () {
  62188. var parser = { trace: function trace() {},
  62189. yy: {},
  62190. symbols_: { "error": 2, "root": 3, "program": 4, "EOF": 5, "program_repetition0": 6, "statement": 7, "mustache": 8, "block": 9, "rawBlock": 10, "partial": 11, "partialBlock": 12, "content": 13, "COMMENT": 14, "CONTENT": 15, "openRawBlock": 16, "rawBlock_repetition_plus0": 17, "END_RAW_BLOCK": 18, "OPEN_RAW_BLOCK": 19, "helperName": 20, "openRawBlock_repetition0": 21, "openRawBlock_option0": 22, "CLOSE_RAW_BLOCK": 23, "openBlock": 24, "block_option0": 25, "closeBlock": 26, "openInverse": 27, "block_option1": 28, "OPEN_BLOCK": 29, "openBlock_repetition0": 30, "openBlock_option0": 31, "openBlock_option1": 32, "CLOSE": 33, "OPEN_INVERSE": 34, "openInverse_repetition0": 35, "openInverse_option0": 36, "openInverse_option1": 37, "openInverseChain": 38, "OPEN_INVERSE_CHAIN": 39, "openInverseChain_repetition0": 40, "openInverseChain_option0": 41, "openInverseChain_option1": 42, "inverseAndProgram": 43, "INVERSE": 44, "inverseChain": 45, "inverseChain_option0": 46, "OPEN_ENDBLOCK": 47, "OPEN": 48, "mustache_repetition0": 49, "mustache_option0": 50, "OPEN_UNESCAPED": 51, "mustache_repetition1": 52, "mustache_option1": 53, "CLOSE_UNESCAPED": 54, "OPEN_PARTIAL": 55, "partialName": 56, "partial_repetition0": 57, "partial_option0": 58, "openPartialBlock": 59, "OPEN_PARTIAL_BLOCK": 60, "openPartialBlock_repetition0": 61, "openPartialBlock_option0": 62, "param": 63, "sexpr": 64, "OPEN_SEXPR": 65, "sexpr_repetition0": 66, "sexpr_option0": 67, "CLOSE_SEXPR": 68, "hash": 69, "hash_repetition_plus0": 70, "hashSegment": 71, "ID": 72, "EQUALS": 73, "blockParams": 74, "OPEN_BLOCK_PARAMS": 75, "blockParams_repetition_plus0": 76, "CLOSE_BLOCK_PARAMS": 77, "path": 78, "dataName": 79, "STRING": 80, "NUMBER": 81, "BOOLEAN": 82, "UNDEFINED": 83, "NULL": 84, "DATA": 85, "pathSegments": 86, "SEP": 87, "$accept": 0, "$end": 1 },
  62191. terminals_: { 2: "error", 5: "EOF", 14: "COMMENT", 15: "CONTENT", 18: "END_RAW_BLOCK", 19: "OPEN_RAW_BLOCK", 23: "CLOSE_RAW_BLOCK", 29: "OPEN_BLOCK", 33: "CLOSE", 34: "OPEN_INVERSE", 39: "OPEN_INVERSE_CHAIN", 44: "INVERSE", 47: "OPEN_ENDBLOCK", 48: "OPEN", 51: "OPEN_UNESCAPED", 54: "CLOSE_UNESCAPED", 55: "OPEN_PARTIAL", 60: "OPEN_PARTIAL_BLOCK", 65: "OPEN_SEXPR", 68: "CLOSE_SEXPR", 72: "ID", 73: "EQUALS", 75: "OPEN_BLOCK_PARAMS", 77: "CLOSE_BLOCK_PARAMS", 80: "STRING", 81: "NUMBER", 82: "BOOLEAN", 83: "UNDEFINED", 84: "NULL", 85: "DATA", 87: "SEP" },
  62192. productions_: [0, [3, 2], [4, 1], [7, 1], [7, 1], [7, 1], [7, 1], [7, 1], [7, 1], [7, 1], [13, 1], [10, 3], [16, 5], [9, 4], [9, 4], [24, 6], [27, 6], [38, 6], [43, 2], [45, 3], [45, 1], [26, 3], [8, 5], [8, 5], [11, 5], [12, 3], [59, 5], [63, 1], [63, 1], [64, 5], [69, 1], [71, 3], [74, 3], [20, 1], [20, 1], [20, 1], [20, 1], [20, 1], [20, 1], [20, 1], [56, 1], [56, 1], [79, 2], [78, 1], [86, 3], [86, 1], [6, 0], [6, 2], [17, 1], [17, 2], [21, 0], [21, 2], [22, 0], [22, 1], [25, 0], [25, 1], [28, 0], [28, 1], [30, 0], [30, 2], [31, 0], [31, 1], [32, 0], [32, 1], [35, 0], [35, 2], [36, 0], [36, 1], [37, 0], [37, 1], [40, 0], [40, 2], [41, 0], [41, 1], [42, 0], [42, 1], [46, 0], [46, 1], [49, 0], [49, 2], [50, 0], [50, 1], [52, 0], [52, 2], [53, 0], [53, 1], [57, 0], [57, 2], [58, 0], [58, 1], [61, 0], [61, 2], [62, 0], [62, 1], [66, 0], [66, 2], [67, 0], [67, 1], [70, 1], [70, 2], [76, 1], [76, 2]],
  62193. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$
  62194. /**/) {
  62195. var $0 = $$.length - 1;
  62196. switch (yystate) {
  62197. case 1:
  62198. return $$[$0 - 1];
  62199. break;
  62200. case 2:
  62201. this.$ = yy.prepareProgram($$[$0]);
  62202. break;
  62203. case 3:
  62204. this.$ = $$[$0];
  62205. break;
  62206. case 4:
  62207. this.$ = $$[$0];
  62208. break;
  62209. case 5:
  62210. this.$ = $$[$0];
  62211. break;
  62212. case 6:
  62213. this.$ = $$[$0];
  62214. break;
  62215. case 7:
  62216. this.$ = $$[$0];
  62217. break;
  62218. case 8:
  62219. this.$ = $$[$0];
  62220. break;
  62221. case 9:
  62222. this.$ = {
  62223. type: 'CommentStatement',
  62224. value: yy.stripComment($$[$0]),
  62225. strip: yy.stripFlags($$[$0], $$[$0]),
  62226. loc: yy.locInfo(this._$)
  62227. };
  62228. break;
  62229. case 10:
  62230. this.$ = {
  62231. type: 'ContentStatement',
  62232. original: $$[$0],
  62233. value: $$[$0],
  62234. loc: yy.locInfo(this._$)
  62235. };
  62236. break;
  62237. case 11:
  62238. this.$ = yy.prepareRawBlock($$[$0 - 2], $$[$0 - 1], $$[$0], this._$);
  62239. break;
  62240. case 12:
  62241. this.$ = { path: $$[$0 - 3], params: $$[$0 - 2], hash: $$[$0 - 1] };
  62242. break;
  62243. case 13:
  62244. this.$ = yy.prepareBlock($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0], false, this._$);
  62245. break;
  62246. case 14:
  62247. this.$ = yy.prepareBlock($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0], true, this._$);
  62248. break;
  62249. case 15:
  62250. this.$ = { open: $$[$0 - 5], path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
  62251. break;
  62252. case 16:
  62253. this.$ = { path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
  62254. break;
  62255. case 17:
  62256. this.$ = { path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
  62257. break;
  62258. case 18:
  62259. this.$ = { strip: yy.stripFlags($$[$0 - 1], $$[$0 - 1]), program: $$[$0] };
  62260. break;
  62261. case 19:
  62262. var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$),
  62263. program = yy.prepareProgram([inverse], $$[$0 - 1].loc);
  62264. program.chained = true;
  62265. this.$ = { strip: $$[$0 - 2].strip, program: program, chain: true };
  62266. break;
  62267. case 20:
  62268. this.$ = $$[$0];
  62269. break;
  62270. case 21:
  62271. this.$ = { path: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 2], $$[$0]) };
  62272. break;
  62273. case 22:
  62274. this.$ = yy.prepareMustache($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0 - 4], yy.stripFlags($$[$0 - 4], $$[$0]), this._$);
  62275. break;
  62276. case 23:
  62277. this.$ = yy.prepareMustache($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0 - 4], yy.stripFlags($$[$0 - 4], $$[$0]), this._$);
  62278. break;
  62279. case 24:
  62280. this.$ = {
  62281. type: 'PartialStatement',
  62282. name: $$[$0 - 3],
  62283. params: $$[$0 - 2],
  62284. hash: $$[$0 - 1],
  62285. indent: '',
  62286. strip: yy.stripFlags($$[$0 - 4], $$[$0]),
  62287. loc: yy.locInfo(this._$)
  62288. };
  62289. break;
  62290. case 25:
  62291. this.$ = yy.preparePartialBlock($$[$0 - 2], $$[$0 - 1], $$[$0], this._$);
  62292. break;
  62293. case 26:
  62294. this.$ = { path: $$[$0 - 3], params: $$[$0 - 2], hash: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 4], $$[$0]) };
  62295. break;
  62296. case 27:
  62297. this.$ = $$[$0];
  62298. break;
  62299. case 28:
  62300. this.$ = $$[$0];
  62301. break;
  62302. case 29:
  62303. this.$ = {
  62304. type: 'SubExpression',
  62305. path: $$[$0 - 3],
  62306. params: $$[$0 - 2],
  62307. hash: $$[$0 - 1],
  62308. loc: yy.locInfo(this._$)
  62309. };
  62310. break;
  62311. case 30:
  62312. this.$ = { type: 'Hash', pairs: $$[$0], loc: yy.locInfo(this._$) };
  62313. break;
  62314. case 31:
  62315. this.$ = { type: 'HashPair', key: yy.id($$[$0 - 2]), value: $$[$0], loc: yy.locInfo(this._$) };
  62316. break;
  62317. case 32:
  62318. this.$ = yy.id($$[$0 - 1]);
  62319. break;
  62320. case 33:
  62321. this.$ = $$[$0];
  62322. break;
  62323. case 34:
  62324. this.$ = $$[$0];
  62325. break;
  62326. case 35:
  62327. this.$ = { type: 'StringLiteral', value: $$[$0], original: $$[$0], loc: yy.locInfo(this._$) };
  62328. break;
  62329. case 36:
  62330. this.$ = { type: 'NumberLiteral', value: Number($$[$0]), original: Number($$[$0]), loc: yy.locInfo(this._$) };
  62331. break;
  62332. case 37:
  62333. this.$ = { type: 'BooleanLiteral', value: $$[$0] === 'true', original: $$[$0] === 'true', loc: yy.locInfo(this._$) };
  62334. break;
  62335. case 38:
  62336. this.$ = { type: 'UndefinedLiteral', original: undefined, value: undefined, loc: yy.locInfo(this._$) };
  62337. break;
  62338. case 39:
  62339. this.$ = { type: 'NullLiteral', original: null, value: null, loc: yy.locInfo(this._$) };
  62340. break;
  62341. case 40:
  62342. this.$ = $$[$0];
  62343. break;
  62344. case 41:
  62345. this.$ = $$[$0];
  62346. break;
  62347. case 42:
  62348. this.$ = yy.preparePath(true, $$[$0], this._$);
  62349. break;
  62350. case 43:
  62351. this.$ = yy.preparePath(false, $$[$0], this._$);
  62352. break;
  62353. case 44:
  62354. $$[$0 - 2].push({ part: yy.id($$[$0]), original: $$[$0], separator: $$[$0 - 1] });this.$ = $$[$0 - 2];
  62355. break;
  62356. case 45:
  62357. this.$ = [{ part: yy.id($$[$0]), original: $$[$0] }];
  62358. break;
  62359. case 46:
  62360. this.$ = [];
  62361. break;
  62362. case 47:
  62363. $$[$0 - 1].push($$[$0]);
  62364. break;
  62365. case 48:
  62366. this.$ = [$$[$0]];
  62367. break;
  62368. case 49:
  62369. $$[$0 - 1].push($$[$0]);
  62370. break;
  62371. case 50:
  62372. this.$ = [];
  62373. break;
  62374. case 51:
  62375. $$[$0 - 1].push($$[$0]);
  62376. break;
  62377. case 58:
  62378. this.$ = [];
  62379. break;
  62380. case 59:
  62381. $$[$0 - 1].push($$[$0]);
  62382. break;
  62383. case 64:
  62384. this.$ = [];
  62385. break;
  62386. case 65:
  62387. $$[$0 - 1].push($$[$0]);
  62388. break;
  62389. case 70:
  62390. this.$ = [];
  62391. break;
  62392. case 71:
  62393. $$[$0 - 1].push($$[$0]);
  62394. break;
  62395. case 78:
  62396. this.$ = [];
  62397. break;
  62398. case 79:
  62399. $$[$0 - 1].push($$[$0]);
  62400. break;
  62401. case 82:
  62402. this.$ = [];
  62403. break;
  62404. case 83:
  62405. $$[$0 - 1].push($$[$0]);
  62406. break;
  62407. case 86:
  62408. this.$ = [];
  62409. break;
  62410. case 87:
  62411. $$[$0 - 1].push($$[$0]);
  62412. break;
  62413. case 90:
  62414. this.$ = [];
  62415. break;
  62416. case 91:
  62417. $$[$0 - 1].push($$[$0]);
  62418. break;
  62419. case 94:
  62420. this.$ = [];
  62421. break;
  62422. case 95:
  62423. $$[$0 - 1].push($$[$0]);
  62424. break;
  62425. case 98:
  62426. this.$ = [$$[$0]];
  62427. break;
  62428. case 99:
  62429. $$[$0 - 1].push($$[$0]);
  62430. break;
  62431. case 100:
  62432. this.$ = [$$[$0]];
  62433. break;
  62434. case 101:
  62435. $$[$0 - 1].push($$[$0]);
  62436. break;
  62437. }
  62438. },
  62439. table: [{ 3: 1, 4: 2, 5: [2, 46], 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 1: [3] }, { 5: [1, 4] }, { 5: [2, 2], 7: 5, 8: 6, 9: 7, 10: 8, 11: 9, 12: 10, 13: 11, 14: [1, 12], 15: [1, 20], 16: 17, 19: [1, 23], 24: 15, 27: 16, 29: [1, 21], 34: [1, 22], 39: [2, 2], 44: [2, 2], 47: [2, 2], 48: [1, 13], 51: [1, 14], 55: [1, 18], 59: 19, 60: [1, 24] }, { 1: [2, 1] }, { 5: [2, 47], 14: [2, 47], 15: [2, 47], 19: [2, 47], 29: [2, 47], 34: [2, 47], 39: [2, 47], 44: [2, 47], 47: [2, 47], 48: [2, 47], 51: [2, 47], 55: [2, 47], 60: [2, 47] }, { 5: [2, 3], 14: [2, 3], 15: [2, 3], 19: [2, 3], 29: [2, 3], 34: [2, 3], 39: [2, 3], 44: [2, 3], 47: [2, 3], 48: [2, 3], 51: [2, 3], 55: [2, 3], 60: [2, 3] }, { 5: [2, 4], 14: [2, 4], 15: [2, 4], 19: [2, 4], 29: [2, 4], 34: [2, 4], 39: [2, 4], 44: [2, 4], 47: [2, 4], 48: [2, 4], 51: [2, 4], 55: [2, 4], 60: [2, 4] }, { 5: [2, 5], 14: [2, 5], 15: [2, 5], 19: [2, 5], 29: [2, 5], 34: [2, 5], 39: [2, 5], 44: [2, 5], 47: [2, 5], 48: [2, 5], 51: [2, 5], 55: [2, 5], 60: [2, 5] }, { 5: [2, 6], 14: [2, 6], 15: [2, 6], 19: [2, 6], 29: [2, 6], 34: [2, 6], 39: [2, 6], 44: [2, 6], 47: [2, 6], 48: [2, 6], 51: [2, 6], 55: [2, 6], 60: [2, 6] }, { 5: [2, 7], 14: [2, 7], 15: [2, 7], 19: [2, 7], 29: [2, 7], 34: [2, 7], 39: [2, 7], 44: [2, 7], 47: [2, 7], 48: [2, 7], 51: [2, 7], 55: [2, 7], 60: [2, 7] }, { 5: [2, 8], 14: [2, 8], 15: [2, 8], 19: [2, 8], 29: [2, 8], 34: [2, 8], 39: [2, 8], 44: [2, 8], 47: [2, 8], 48: [2, 8], 51: [2, 8], 55: [2, 8], 60: [2, 8] }, { 5: [2, 9], 14: [2, 9], 15: [2, 9], 19: [2, 9], 29: [2, 9], 34: [2, 9], 39: [2, 9], 44: [2, 9], 47: [2, 9], 48: [2, 9], 51: [2, 9], 55: [2, 9], 60: [2, 9] }, { 20: 25, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 36, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 4: 37, 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 39: [2, 46], 44: [2, 46], 47: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 4: 38, 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 44: [2, 46], 47: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 13: 40, 15: [1, 20], 17: 39 }, { 20: 42, 56: 41, 64: 43, 65: [1, 44], 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 4: 45, 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 47: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 5: [2, 10], 14: [2, 10], 15: [2, 10], 18: [2, 10], 19: [2, 10], 29: [2, 10], 34: [2, 10], 39: [2, 10], 44: [2, 10], 47: [2, 10], 48: [2, 10], 51: [2, 10], 55: [2, 10], 60: [2, 10] }, { 20: 46, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 47, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 48, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 42, 56: 49, 64: 43, 65: [1, 44], 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 33: [2, 78], 49: 50, 65: [2, 78], 72: [2, 78], 80: [2, 78], 81: [2, 78], 82: [2, 78], 83: [2, 78], 84: [2, 78], 85: [2, 78] }, { 23: [2, 33], 33: [2, 33], 54: [2, 33], 65: [2, 33], 68: [2, 33], 72: [2, 33], 75: [2, 33], 80: [2, 33], 81: [2, 33], 82: [2, 33], 83: [2, 33], 84: [2, 33], 85: [2, 33] }, { 23: [2, 34], 33: [2, 34], 54: [2, 34], 65: [2, 34], 68: [2, 34], 72: [2, 34], 75: [2, 34], 80: [2, 34], 81: [2, 34], 82: [2, 34], 83: [2, 34], 84: [2, 34], 85: [2, 34] }, { 23: [2, 35], 33: [2, 35], 54: [2, 35], 65: [2, 35], 68: [2, 35], 72: [2, 35], 75: [2, 35], 80: [2, 35], 81: [2, 35], 82: [2, 35], 83: [2, 35], 84: [2, 35], 85: [2, 35] }, { 23: [2, 36], 33: [2, 36], 54: [2, 36], 65: [2, 36], 68: [2, 36], 72: [2, 36], 75: [2, 36], 80: [2, 36], 81: [2, 36], 82: [2, 36], 83: [2, 36], 84: [2, 36], 85: [2, 36] }, { 23: [2, 37], 33: [2, 37], 54: [2, 37], 65: [2, 37], 68: [2, 37], 72: [2, 37], 75: [2, 37], 80: [2, 37], 81: [2, 37], 82: [2, 37], 83: [2, 37], 84: [2, 37], 85: [2, 37] }, { 23: [2, 38], 33: [2, 38], 54: [2, 38], 65: [2, 38], 68: [2, 38], 72: [2, 38], 75: [2, 38], 80: [2, 38], 81: [2, 38], 82: [2, 38], 83: [2, 38], 84: [2, 38], 85: [2, 38] }, { 23: [2, 39], 33: [2, 39], 54: [2, 39], 65: [2, 39], 68: [2, 39], 72: [2, 39], 75: [2, 39], 80: [2, 39], 81: [2, 39], 82: [2, 39], 83: [2, 39], 84: [2, 39], 85: [2, 39] }, { 23: [2, 43], 33: [2, 43], 54: [2, 43], 65: [2, 43], 68: [2, 43], 72: [2, 43], 75: [2, 43], 80: [2, 43], 81: [2, 43], 82: [2, 43], 83: [2, 43], 84: [2, 43], 85: [2, 43], 87: [1, 51] }, { 72: [1, 35], 86: 52 }, { 23: [2, 45], 33: [2, 45], 54: [2, 45], 65: [2, 45], 68: [2, 45], 72: [2, 45], 75: [2, 45], 80: [2, 45], 81: [2, 45], 82: [2, 45], 83: [2, 45], 84: [2, 45], 85: [2, 45], 87: [2, 45] }, { 52: 53, 54: [2, 82], 65: [2, 82], 72: [2, 82], 80: [2, 82], 81: [2, 82], 82: [2, 82], 83: [2, 82], 84: [2, 82], 85: [2, 82] }, { 25: 54, 38: 56, 39: [1, 58], 43: 57, 44: [1, 59], 45: 55, 47: [2, 54] }, { 28: 60, 43: 61, 44: [1, 59], 47: [2, 56] }, { 13: 63, 15: [1, 20], 18: [1, 62] }, { 15: [2, 48], 18: [2, 48] }, { 33: [2, 86], 57: 64, 65: [2, 86], 72: [2, 86], 80: [2, 86], 81: [2, 86], 82: [2, 86], 83: [2, 86], 84: [2, 86], 85: [2, 86] }, { 33: [2, 40], 65: [2, 40], 72: [2, 40], 80: [2, 40], 81: [2, 40], 82: [2, 40], 83: [2, 40], 84: [2, 40], 85: [2, 40] }, { 33: [2, 41], 65: [2, 41], 72: [2, 41], 80: [2, 41], 81: [2, 41], 82: [2, 41], 83: [2, 41], 84: [2, 41], 85: [2, 41] }, { 20: 65, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 26: 66, 47: [1, 67] }, { 30: 68, 33: [2, 58], 65: [2, 58], 72: [2, 58], 75: [2, 58], 80: [2, 58], 81: [2, 58], 82: [2, 58], 83: [2, 58], 84: [2, 58], 85: [2, 58] }, { 33: [2, 64], 35: 69, 65: [2, 64], 72: [2, 64], 75: [2, 64], 80: [2, 64], 81: [2, 64], 82: [2, 64], 83: [2, 64], 84: [2, 64], 85: [2, 64] }, { 21: 70, 23: [2, 50], 65: [2, 50], 72: [2, 50], 80: [2, 50], 81: [2, 50], 82: [2, 50], 83: [2, 50], 84: [2, 50], 85: [2, 50] }, { 33: [2, 90], 61: 71, 65: [2, 90], 72: [2, 90], 80: [2, 90], 81: [2, 90], 82: [2, 90], 83: [2, 90], 84: [2, 90], 85: [2, 90] }, { 20: 75, 33: [2, 80], 50: 72, 63: 73, 64: 76, 65: [1, 44], 69: 74, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 72: [1, 80] }, { 23: [2, 42], 33: [2, 42], 54: [2, 42], 65: [2, 42], 68: [2, 42], 72: [2, 42], 75: [2, 42], 80: [2, 42], 81: [2, 42], 82: [2, 42], 83: [2, 42], 84: [2, 42], 85: [2, 42], 87: [1, 51] }, { 20: 75, 53: 81, 54: [2, 84], 63: 82, 64: 76, 65: [1, 44], 69: 83, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 26: 84, 47: [1, 67] }, { 47: [2, 55] }, { 4: 85, 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 39: [2, 46], 44: [2, 46], 47: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 47: [2, 20] }, { 20: 86, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 4: 87, 6: 3, 14: [2, 46], 15: [2, 46], 19: [2, 46], 29: [2, 46], 34: [2, 46], 47: [2, 46], 48: [2, 46], 51: [2, 46], 55: [2, 46], 60: [2, 46] }, { 26: 88, 47: [1, 67] }, { 47: [2, 57] }, { 5: [2, 11], 14: [2, 11], 15: [2, 11], 19: [2, 11], 29: [2, 11], 34: [2, 11], 39: [2, 11], 44: [2, 11], 47: [2, 11], 48: [2, 11], 51: [2, 11], 55: [2, 11], 60: [2, 11] }, { 15: [2, 49], 18: [2, 49] }, { 20: 75, 33: [2, 88], 58: 89, 63: 90, 64: 76, 65: [1, 44], 69: 91, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 65: [2, 94], 66: 92, 68: [2, 94], 72: [2, 94], 80: [2, 94], 81: [2, 94], 82: [2, 94], 83: [2, 94], 84: [2, 94], 85: [2, 94] }, { 5: [2, 25], 14: [2, 25], 15: [2, 25], 19: [2, 25], 29: [2, 25], 34: [2, 25], 39: [2, 25], 44: [2, 25], 47: [2, 25], 48: [2, 25], 51: [2, 25], 55: [2, 25], 60: [2, 25] }, { 20: 93, 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 75, 31: 94, 33: [2, 60], 63: 95, 64: 76, 65: [1, 44], 69: 96, 70: 77, 71: 78, 72: [1, 79], 75: [2, 60], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 75, 33: [2, 66], 36: 97, 63: 98, 64: 76, 65: [1, 44], 69: 99, 70: 77, 71: 78, 72: [1, 79], 75: [2, 66], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 75, 22: 100, 23: [2, 52], 63: 101, 64: 76, 65: [1, 44], 69: 102, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 20: 75, 33: [2, 92], 62: 103, 63: 104, 64: 76, 65: [1, 44], 69: 105, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 33: [1, 106] }, { 33: [2, 79], 65: [2, 79], 72: [2, 79], 80: [2, 79], 81: [2, 79], 82: [2, 79], 83: [2, 79], 84: [2, 79], 85: [2, 79] }, { 33: [2, 81] }, { 23: [2, 27], 33: [2, 27], 54: [2, 27], 65: [2, 27], 68: [2, 27], 72: [2, 27], 75: [2, 27], 80: [2, 27], 81: [2, 27], 82: [2, 27], 83: [2, 27], 84: [2, 27], 85: [2, 27] }, { 23: [2, 28], 33: [2, 28], 54: [2, 28], 65: [2, 28], 68: [2, 28], 72: [2, 28], 75: [2, 28], 80: [2, 28], 81: [2, 28], 82: [2, 28], 83: [2, 28], 84: [2, 28], 85: [2, 28] }, { 23: [2, 30], 33: [2, 30], 54: [2, 30], 68: [2, 30], 71: 107, 72: [1, 108], 75: [2, 30] }, { 23: [2, 98], 33: [2, 98], 54: [2, 98], 68: [2, 98], 72: [2, 98], 75: [2, 98] }, { 23: [2, 45], 33: [2, 45], 54: [2, 45], 65: [2, 45], 68: [2, 45], 72: [2, 45], 73: [1, 109], 75: [2, 45], 80: [2, 45], 81: [2, 45], 82: [2, 45], 83: [2, 45], 84: [2, 45], 85: [2, 45], 87: [2, 45] }, { 23: [2, 44], 33: [2, 44], 54: [2, 44], 65: [2, 44], 68: [2, 44], 72: [2, 44], 75: [2, 44], 80: [2, 44], 81: [2, 44], 82: [2, 44], 83: [2, 44], 84: [2, 44], 85: [2, 44], 87: [2, 44] }, { 54: [1, 110] }, { 54: [2, 83], 65: [2, 83], 72: [2, 83], 80: [2, 83], 81: [2, 83], 82: [2, 83], 83: [2, 83], 84: [2, 83], 85: [2, 83] }, { 54: [2, 85] }, { 5: [2, 13], 14: [2, 13], 15: [2, 13], 19: [2, 13], 29: [2, 13], 34: [2, 13], 39: [2, 13], 44: [2, 13], 47: [2, 13], 48: [2, 13], 51: [2, 13], 55: [2, 13], 60: [2, 13] }, { 38: 56, 39: [1, 58], 43: 57, 44: [1, 59], 45: 112, 46: 111, 47: [2, 76] }, { 33: [2, 70], 40: 113, 65: [2, 70], 72: [2, 70], 75: [2, 70], 80: [2, 70], 81: [2, 70], 82: [2, 70], 83: [2, 70], 84: [2, 70], 85: [2, 70] }, { 47: [2, 18] }, { 5: [2, 14], 14: [2, 14], 15: [2, 14], 19: [2, 14], 29: [2, 14], 34: [2, 14], 39: [2, 14], 44: [2, 14], 47: [2, 14], 48: [2, 14], 51: [2, 14], 55: [2, 14], 60: [2, 14] }, { 33: [1, 114] }, { 33: [2, 87], 65: [2, 87], 72: [2, 87], 80: [2, 87], 81: [2, 87], 82: [2, 87], 83: [2, 87], 84: [2, 87], 85: [2, 87] }, { 33: [2, 89] }, { 20: 75, 63: 116, 64: 76, 65: [1, 44], 67: 115, 68: [2, 96], 69: 117, 70: 77, 71: 78, 72: [1, 79], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 33: [1, 118] }, { 32: 119, 33: [2, 62], 74: 120, 75: [1, 121] }, { 33: [2, 59], 65: [2, 59], 72: [2, 59], 75: [2, 59], 80: [2, 59], 81: [2, 59], 82: [2, 59], 83: [2, 59], 84: [2, 59], 85: [2, 59] }, { 33: [2, 61], 75: [2, 61] }, { 33: [2, 68], 37: 122, 74: 123, 75: [1, 121] }, { 33: [2, 65], 65: [2, 65], 72: [2, 65], 75: [2, 65], 80: [2, 65], 81: [2, 65], 82: [2, 65], 83: [2, 65], 84: [2, 65], 85: [2, 65] }, { 33: [2, 67], 75: [2, 67] }, { 23: [1, 124] }, { 23: [2, 51], 65: [2, 51], 72: [2, 51], 80: [2, 51], 81: [2, 51], 82: [2, 51], 83: [2, 51], 84: [2, 51], 85: [2, 51] }, { 23: [2, 53] }, { 33: [1, 125] }, { 33: [2, 91], 65: [2, 91], 72: [2, 91], 80: [2, 91], 81: [2, 91], 82: [2, 91], 83: [2, 91], 84: [2, 91], 85: [2, 91] }, { 33: [2, 93] }, { 5: [2, 22], 14: [2, 22], 15: [2, 22], 19: [2, 22], 29: [2, 22], 34: [2, 22], 39: [2, 22], 44: [2, 22], 47: [2, 22], 48: [2, 22], 51: [2, 22], 55: [2, 22], 60: [2, 22] }, { 23: [2, 99], 33: [2, 99], 54: [2, 99], 68: [2, 99], 72: [2, 99], 75: [2, 99] }, { 73: [1, 109] }, { 20: 75, 63: 126, 64: 76, 65: [1, 44], 72: [1, 35], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 5: [2, 23], 14: [2, 23], 15: [2, 23], 19: [2, 23], 29: [2, 23], 34: [2, 23], 39: [2, 23], 44: [2, 23], 47: [2, 23], 48: [2, 23], 51: [2, 23], 55: [2, 23], 60: [2, 23] }, { 47: [2, 19] }, { 47: [2, 77] }, { 20: 75, 33: [2, 72], 41: 127, 63: 128, 64: 76, 65: [1, 44], 69: 129, 70: 77, 71: 78, 72: [1, 79], 75: [2, 72], 78: 26, 79: 27, 80: [1, 28], 81: [1, 29], 82: [1, 30], 83: [1, 31], 84: [1, 32], 85: [1, 34], 86: 33 }, { 5: [2, 24], 14: [2, 24], 15: [2, 24], 19: [2, 24], 29: [2, 24], 34: [2, 24], 39: [2, 24], 44: [2, 24], 47: [2, 24], 48: [2, 24], 51: [2, 24], 55: [2, 24], 60: [2, 24] }, { 68: [1, 130] }, { 65: [2, 95], 68: [2, 95], 72: [2, 95], 80: [2, 95], 81: [2, 95], 82: [2, 95], 83: [2, 95], 84: [2, 95], 85: [2, 95] }, { 68: [2, 97] }, { 5: [2, 21], 14: [2, 21], 15: [2, 21], 19: [2, 21], 29: [2, 21], 34: [2, 21], 39: [2, 21], 44: [2, 21], 47: [2, 21], 48: [2, 21], 51: [2, 21], 55: [2, 21], 60: [2, 21] }, { 33: [1, 131] }, { 33: [2, 63] }, { 72: [1, 133], 76: 132 }, { 33: [1, 134] }, { 33: [2, 69] }, { 15: [2, 12] }, { 14: [2, 26], 15: [2, 26], 19: [2, 26], 29: [2, 26], 34: [2, 26], 47: [2, 26], 48: [2, 26], 51: [2, 26], 55: [2, 26], 60: [2, 26] }, { 23: [2, 31], 33: [2, 31], 54: [2, 31], 68: [2, 31], 72: [2, 31], 75: [2, 31] }, { 33: [2, 74], 42: 135, 74: 136, 75: [1, 121] }, { 33: [2, 71], 65: [2, 71], 72: [2, 71], 75: [2, 71], 80: [2, 71], 81: [2, 71], 82: [2, 71], 83: [2, 71], 84: [2, 71], 85: [2, 71] }, { 33: [2, 73], 75: [2, 73] }, { 23: [2, 29], 33: [2, 29], 54: [2, 29], 65: [2, 29], 68: [2, 29], 72: [2, 29], 75: [2, 29], 80: [2, 29], 81: [2, 29], 82: [2, 29], 83: [2, 29], 84: [2, 29], 85: [2, 29] }, { 14: [2, 15], 15: [2, 15], 19: [2, 15], 29: [2, 15], 34: [2, 15], 39: [2, 15], 44: [2, 15], 47: [2, 15], 48: [2, 15], 51: [2, 15], 55: [2, 15], 60: [2, 15] }, { 72: [1, 138], 77: [1, 137] }, { 72: [2, 100], 77: [2, 100] }, { 14: [2, 16], 15: [2, 16], 19: [2, 16], 29: [2, 16], 34: [2, 16], 44: [2, 16], 47: [2, 16], 48: [2, 16], 51: [2, 16], 55: [2, 16], 60: [2, 16] }, { 33: [1, 139] }, { 33: [2, 75] }, { 33: [2, 32] }, { 72: [2, 101], 77: [2, 101] }, { 14: [2, 17], 15: [2, 17], 19: [2, 17], 29: [2, 17], 34: [2, 17], 39: [2, 17], 44: [2, 17], 47: [2, 17], 48: [2, 17], 51: [2, 17], 55: [2, 17], 60: [2, 17] }],
  62440. defaultActions: { 4: [2, 1], 55: [2, 55], 57: [2, 20], 61: [2, 57], 74: [2, 81], 83: [2, 85], 87: [2, 18], 91: [2, 89], 102: [2, 53], 105: [2, 93], 111: [2, 19], 112: [2, 77], 117: [2, 97], 120: [2, 63], 123: [2, 69], 124: [2, 12], 136: [2, 75], 137: [2, 32] },
  62441. parseError: function parseError(str, hash) {
  62442. throw new Error(str);
  62443. },
  62444. parse: function parse(input) {
  62445. var self = this,
  62446. stack = [0],
  62447. vstack = [null],
  62448. lstack = [],
  62449. table = this.table,
  62450. yytext = "",
  62451. yylineno = 0,
  62452. yyleng = 0,
  62453. recovering = 0,
  62454. TERROR = 2,
  62455. EOF = 1;
  62456. this.lexer.setInput(input);
  62457. this.lexer.yy = this.yy;
  62458. this.yy.lexer = this.lexer;
  62459. this.yy.parser = this;
  62460. if (typeof this.lexer.yylloc == "undefined") this.lexer.yylloc = {};
  62461. var yyloc = this.lexer.yylloc;
  62462. lstack.push(yyloc);
  62463. var ranges = this.lexer.options && this.lexer.options.ranges;
  62464. if (typeof this.yy.parseError === "function") this.parseError = this.yy.parseError;
  62465. function popStack(n) {
  62466. stack.length = stack.length - 2 * n;
  62467. vstack.length = vstack.length - n;
  62468. lstack.length = lstack.length - n;
  62469. }
  62470. function lex() {
  62471. var token;
  62472. token = self.lexer.lex() || 1;
  62473. if (typeof token !== "number") {
  62474. token = self.symbols_[token] || token;
  62475. }
  62476. return token;
  62477. }
  62478. var symbol,
  62479. preErrorSymbol,
  62480. state,
  62481. action,
  62482. a,
  62483. r,
  62484. yyval = {},
  62485. p,
  62486. len,
  62487. newState,
  62488. expected;
  62489. while (true) {
  62490. state = stack[stack.length - 1];
  62491. if (this.defaultActions[state]) {
  62492. action = this.defaultActions[state];
  62493. } else {
  62494. if (symbol === null || typeof symbol == "undefined") {
  62495. symbol = lex();
  62496. }
  62497. action = table[state] && table[state][symbol];
  62498. }
  62499. if (typeof action === "undefined" || !action.length || !action[0]) {
  62500. var errStr = "";
  62501. if (!recovering) {
  62502. expected = [];
  62503. for (p in table[state]) if (this.terminals_[p] && p > 2) {
  62504. expected.push("'" + this.terminals_[p] + "'");
  62505. }
  62506. if (this.lexer.showPosition) {
  62507. errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
  62508. } else {
  62509. errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1 ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
  62510. }
  62511. this.parseError(errStr, { text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected });
  62512. }
  62513. }
  62514. if (action[0] instanceof Array && action.length > 1) {
  62515. throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
  62516. }
  62517. switch (action[0]) {
  62518. case 1:
  62519. stack.push(symbol);
  62520. vstack.push(this.lexer.yytext);
  62521. lstack.push(this.lexer.yylloc);
  62522. stack.push(action[1]);
  62523. symbol = null;
  62524. if (!preErrorSymbol) {
  62525. yyleng = this.lexer.yyleng;
  62526. yytext = this.lexer.yytext;
  62527. yylineno = this.lexer.yylineno;
  62528. yyloc = this.lexer.yylloc;
  62529. if (recovering > 0) recovering--;
  62530. } else {
  62531. symbol = preErrorSymbol;
  62532. preErrorSymbol = null;
  62533. }
  62534. break;
  62535. case 2:
  62536. len = this.productions_[action[1]][1];
  62537. yyval.$ = vstack[vstack.length - len];
  62538. yyval._$ = { first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column };
  62539. if (ranges) {
  62540. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  62541. }
  62542. r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
  62543. if (typeof r !== "undefined") {
  62544. return r;
  62545. }
  62546. if (len) {
  62547. stack = stack.slice(0, -1 * len * 2);
  62548. vstack = vstack.slice(0, -1 * len);
  62549. lstack = lstack.slice(0, -1 * len);
  62550. }
  62551. stack.push(this.productions_[action[1]][0]);
  62552. vstack.push(yyval.$);
  62553. lstack.push(yyval._$);
  62554. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  62555. stack.push(newState);
  62556. break;
  62557. case 3:
  62558. return true;
  62559. }
  62560. }
  62561. return true;
  62562. }
  62563. };
  62564. /* Jison generated lexer */
  62565. var lexer = (function () {
  62566. var lexer = { EOF: 1,
  62567. parseError: function parseError(str, hash) {
  62568. if (this.yy.parser) {
  62569. this.yy.parser.parseError(str, hash);
  62570. } else {
  62571. throw new Error(str);
  62572. }
  62573. },
  62574. setInput: function setInput(input) {
  62575. this._input = input;
  62576. this._more = this._less = this.done = false;
  62577. this.yylineno = this.yyleng = 0;
  62578. this.yytext = this.matched = this.match = '';
  62579. this.conditionStack = ['INITIAL'];
  62580. this.yylloc = { first_line: 1, first_column: 0, last_line: 1, last_column: 0 };
  62581. if (this.options.ranges) this.yylloc.range = [0, 0];
  62582. this.offset = 0;
  62583. return this;
  62584. },
  62585. input: function input() {
  62586. var ch = this._input[0];
  62587. this.yytext += ch;
  62588. this.yyleng++;
  62589. this.offset++;
  62590. this.match += ch;
  62591. this.matched += ch;
  62592. var lines = ch.match(/(?:\r\n?|\n).*/g);
  62593. if (lines) {
  62594. this.yylineno++;
  62595. this.yylloc.last_line++;
  62596. } else {
  62597. this.yylloc.last_column++;
  62598. }
  62599. if (this.options.ranges) this.yylloc.range[1]++;
  62600. this._input = this._input.slice(1);
  62601. return ch;
  62602. },
  62603. unput: function unput(ch) {
  62604. var len = ch.length;
  62605. var lines = ch.split(/(?:\r\n?|\n)/g);
  62606. this._input = ch + this._input;
  62607. this.yytext = this.yytext.substr(0, this.yytext.length - len - 1);
  62608. //this.yyleng -= len;
  62609. this.offset -= len;
  62610. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  62611. this.match = this.match.substr(0, this.match.length - 1);
  62612. this.matched = this.matched.substr(0, this.matched.length - 1);
  62613. if (lines.length - 1) this.yylineno -= lines.length - 1;
  62614. var r = this.yylloc.range;
  62615. this.yylloc = { first_line: this.yylloc.first_line,
  62616. last_line: this.yylineno + 1,
  62617. first_column: this.yylloc.first_column,
  62618. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  62619. };
  62620. if (this.options.ranges) {
  62621. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  62622. }
  62623. return this;
  62624. },
  62625. more: function more() {
  62626. this._more = true;
  62627. return this;
  62628. },
  62629. less: function less(n) {
  62630. this.unput(this.match.slice(n));
  62631. },
  62632. pastInput: function pastInput() {
  62633. var past = this.matched.substr(0, this.matched.length - this.match.length);
  62634. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  62635. },
  62636. upcomingInput: function upcomingInput() {
  62637. var next = this.match;
  62638. if (next.length < 20) {
  62639. next += this._input.substr(0, 20 - next.length);
  62640. }
  62641. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  62642. },
  62643. showPosition: function showPosition() {
  62644. var pre = this.pastInput();
  62645. var c = new Array(pre.length + 1).join("-");
  62646. return pre + this.upcomingInput() + "\n" + c + "^";
  62647. },
  62648. next: function next() {
  62649. if (this.done) {
  62650. return this.EOF;
  62651. }
  62652. if (!this._input) this.done = true;
  62653. var token, match, tempMatch, index, col, lines;
  62654. if (!this._more) {
  62655. this.yytext = '';
  62656. this.match = '';
  62657. }
  62658. var rules = this._currentRules();
  62659. for (var i = 0; i < rules.length; i++) {
  62660. tempMatch = this._input.match(this.rules[rules[i]]);
  62661. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  62662. match = tempMatch;
  62663. index = i;
  62664. if (!this.options.flex) break;
  62665. }
  62666. }
  62667. if (match) {
  62668. lines = match[0].match(/(?:\r\n?|\n).*/g);
  62669. if (lines) this.yylineno += lines.length;
  62670. this.yylloc = { first_line: this.yylloc.last_line,
  62671. last_line: this.yylineno + 1,
  62672. first_column: this.yylloc.last_column,
  62673. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length };
  62674. this.yytext += match[0];
  62675. this.match += match[0];
  62676. this.matches = match;
  62677. this.yyleng = this.yytext.length;
  62678. if (this.options.ranges) {
  62679. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  62680. }
  62681. this._more = false;
  62682. this._input = this._input.slice(match[0].length);
  62683. this.matched += match[0];
  62684. token = this.performAction.call(this, this.yy, this, rules[index], this.conditionStack[this.conditionStack.length - 1]);
  62685. if (this.done && this._input) this.done = false;
  62686. if (token) return token;else return;
  62687. }
  62688. if (this._input === "") {
  62689. return this.EOF;
  62690. } else {
  62691. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), { text: "", token: null, line: this.yylineno });
  62692. }
  62693. },
  62694. lex: function lex() {
  62695. var r = this.next();
  62696. if (typeof r !== 'undefined') {
  62697. return r;
  62698. } else {
  62699. return this.lex();
  62700. }
  62701. },
  62702. begin: function begin(condition) {
  62703. this.conditionStack.push(condition);
  62704. },
  62705. popState: function popState() {
  62706. return this.conditionStack.pop();
  62707. },
  62708. _currentRules: function _currentRules() {
  62709. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  62710. },
  62711. topState: function topState() {
  62712. return this.conditionStack[this.conditionStack.length - 2];
  62713. },
  62714. pushState: function begin(condition) {
  62715. this.begin(condition);
  62716. } };
  62717. lexer.options = {};
  62718. lexer.performAction = function anonymous(yy, yy_, $avoiding_name_collisions, YY_START
  62719. /**/) {
  62720. function strip(start, end) {
  62721. return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng - end);
  62722. }
  62723. var YYSTATE = YY_START;
  62724. switch ($avoiding_name_collisions) {
  62725. case 0:
  62726. if (yy_.yytext.slice(-2) === "\\\\") {
  62727. strip(0, 1);
  62728. this.begin("mu");
  62729. } else if (yy_.yytext.slice(-1) === "\\") {
  62730. strip(0, 1);
  62731. this.begin("emu");
  62732. } else {
  62733. this.begin("mu");
  62734. }
  62735. if (yy_.yytext) return 15;
  62736. break;
  62737. case 1:
  62738. return 15;
  62739. break;
  62740. case 2:
  62741. this.popState();
  62742. return 15;
  62743. break;
  62744. case 3:
  62745. this.begin('raw');return 15;
  62746. break;
  62747. case 4:
  62748. this.popState();
  62749. // Should be using `this.topState()` below, but it currently
  62750. // returns the second top instead of the first top. Opened an
  62751. // issue about it at https://github.com/zaach/jison/issues/291
  62752. if (this.conditionStack[this.conditionStack.length - 1] === 'raw') {
  62753. return 15;
  62754. } else {
  62755. yy_.yytext = yy_.yytext.substr(5, yy_.yyleng - 9);
  62756. return 'END_RAW_BLOCK';
  62757. }
  62758. break;
  62759. case 5:
  62760. return 15;
  62761. break;
  62762. case 6:
  62763. this.popState();
  62764. return 14;
  62765. break;
  62766. case 7:
  62767. return 65;
  62768. break;
  62769. case 8:
  62770. return 68;
  62771. break;
  62772. case 9:
  62773. return 19;
  62774. break;
  62775. case 10:
  62776. this.popState();
  62777. this.begin('raw');
  62778. return 23;
  62779. break;
  62780. case 11:
  62781. return 55;
  62782. break;
  62783. case 12:
  62784. return 60;
  62785. break;
  62786. case 13:
  62787. return 29;
  62788. break;
  62789. case 14:
  62790. return 47;
  62791. break;
  62792. case 15:
  62793. this.popState();return 44;
  62794. break;
  62795. case 16:
  62796. this.popState();return 44;
  62797. break;
  62798. case 17:
  62799. return 34;
  62800. break;
  62801. case 18:
  62802. return 39;
  62803. break;
  62804. case 19:
  62805. return 51;
  62806. break;
  62807. case 20:
  62808. return 48;
  62809. break;
  62810. case 21:
  62811. this.unput(yy_.yytext);
  62812. this.popState();
  62813. this.begin('com');
  62814. break;
  62815. case 22:
  62816. this.popState();
  62817. return 14;
  62818. break;
  62819. case 23:
  62820. return 48;
  62821. break;
  62822. case 24:
  62823. return 73;
  62824. break;
  62825. case 25:
  62826. return 72;
  62827. break;
  62828. case 26:
  62829. return 72;
  62830. break;
  62831. case 27:
  62832. return 87;
  62833. break;
  62834. case 28:
  62835. // ignore whitespace
  62836. break;
  62837. case 29:
  62838. this.popState();return 54;
  62839. break;
  62840. case 30:
  62841. this.popState();return 33;
  62842. break;
  62843. case 31:
  62844. yy_.yytext = strip(1, 2).replace(/\\"/g, '"');return 80;
  62845. break;
  62846. case 32:
  62847. yy_.yytext = strip(1, 2).replace(/\\'/g, "'");return 80;
  62848. break;
  62849. case 33:
  62850. return 85;
  62851. break;
  62852. case 34:
  62853. return 82;
  62854. break;
  62855. case 35:
  62856. return 82;
  62857. break;
  62858. case 36:
  62859. return 83;
  62860. break;
  62861. case 37:
  62862. return 84;
  62863. break;
  62864. case 38:
  62865. return 81;
  62866. break;
  62867. case 39:
  62868. return 75;
  62869. break;
  62870. case 40:
  62871. return 77;
  62872. break;
  62873. case 41:
  62874. return 72;
  62875. break;
  62876. case 42:
  62877. yy_.yytext = yy_.yytext.replace(/\\([\\\]])/g, '$1');return 72;
  62878. break;
  62879. case 43:
  62880. return 'INVALID';
  62881. break;
  62882. case 44:
  62883. return 5;
  62884. break;
  62885. }
  62886. };
  62887. lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/, /^(?:[^\x00]+)/, /^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/, /^(?:\{\{\{\{(?=[^\/]))/, /^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/, /^(?:[^\x00]*?(?=(\{\{\{\{)))/, /^(?:[\s\S]*?--(~)?\}\})/, /^(?:\()/, /^(?:\))/, /^(?:\{\{\{\{)/, /^(?:\}\}\}\})/, /^(?:\{\{(~)?>)/, /^(?:\{\{(~)?#>)/, /^(?:\{\{(~)?#\*?)/, /^(?:\{\{(~)?\/)/, /^(?:\{\{(~)?\^\s*(~)?\}\})/, /^(?:\{\{(~)?\s*else\s*(~)?\}\})/, /^(?:\{\{(~)?\^)/, /^(?:\{\{(~)?\s*else\b)/, /^(?:\{\{(~)?\{)/, /^(?:\{\{(~)?&)/, /^(?:\{\{(~)?!--)/, /^(?:\{\{(~)?![\s\S]*?\}\})/, /^(?:\{\{(~)?\*?)/, /^(?:=)/, /^(?:\.\.)/, /^(?:\.(?=([=~}\s\/.)|])))/, /^(?:[\/.])/, /^(?:\s+)/, /^(?:\}(~)?\}\})/, /^(?:(~)?\}\})/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*')/, /^(?:@)/, /^(?:true(?=([~}\s)])))/, /^(?:false(?=([~}\s)])))/, /^(?:undefined(?=([~}\s)])))/, /^(?:null(?=([~}\s)])))/, /^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/, /^(?:as\s+\|)/, /^(?:\|)/, /^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)|]))))/, /^(?:\[(\\\]|[^\]])*\])/, /^(?:.)/, /^(?:$)/];
  62888. lexer.conditions = { "mu": { "rules": [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44], "inclusive": false }, "emu": { "rules": [2], "inclusive": false }, "com": { "rules": [6], "inclusive": false }, "raw": { "rules": [3, 4, 5], "inclusive": false }, "INITIAL": { "rules": [0, 1, 44], "inclusive": true } };
  62889. return lexer;
  62890. })();
  62891. parser.lexer = lexer;
  62892. function Parser() {
  62893. this.yy = {};
  62894. }Parser.prototype = parser;parser.Parser = Parser;
  62895. return new Parser();
  62896. })();exports["default"] = handlebars;
  62897. module.exports = exports["default"];
  62898. /***/ }),
  62899. /* 38 */
  62900. /***/ (function(module, exports, __webpack_require__) {
  62901. 'use strict';
  62902. var _interopRequireDefault = __webpack_require__(1)['default'];
  62903. exports.__esModule = true;
  62904. var _visitor = __webpack_require__(39);
  62905. var _visitor2 = _interopRequireDefault(_visitor);
  62906. function WhitespaceControl() {
  62907. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  62908. this.options = options;
  62909. }
  62910. WhitespaceControl.prototype = new _visitor2['default']();
  62911. WhitespaceControl.prototype.Program = function (program) {
  62912. var doStandalone = !this.options.ignoreStandalone;
  62913. var isRoot = !this.isRootSeen;
  62914. this.isRootSeen = true;
  62915. var body = program.body;
  62916. for (var i = 0, l = body.length; i < l; i++) {
  62917. var current = body[i],
  62918. strip = this.accept(current);
  62919. if (!strip) {
  62920. continue;
  62921. }
  62922. var _isPrevWhitespace = isPrevWhitespace(body, i, isRoot),
  62923. _isNextWhitespace = isNextWhitespace(body, i, isRoot),
  62924. openStandalone = strip.openStandalone && _isPrevWhitespace,
  62925. closeStandalone = strip.closeStandalone && _isNextWhitespace,
  62926. inlineStandalone = strip.inlineStandalone && _isPrevWhitespace && _isNextWhitespace;
  62927. if (strip.close) {
  62928. omitRight(body, i, true);
  62929. }
  62930. if (strip.open) {
  62931. omitLeft(body, i, true);
  62932. }
  62933. if (doStandalone && inlineStandalone) {
  62934. omitRight(body, i);
  62935. if (omitLeft(body, i)) {
  62936. // If we are on a standalone node, save the indent info for partials
  62937. if (current.type === 'PartialStatement') {
  62938. // Pull out the whitespace from the final line
  62939. current.indent = /([ \t]+$)/.exec(body[i - 1].original)[1];
  62940. }
  62941. }
  62942. }
  62943. if (doStandalone && openStandalone) {
  62944. omitRight((current.program || current.inverse).body);
  62945. // Strip out the previous content node if it's whitespace only
  62946. omitLeft(body, i);
  62947. }
  62948. if (doStandalone && closeStandalone) {
  62949. // Always strip the next node
  62950. omitRight(body, i);
  62951. omitLeft((current.inverse || current.program).body);
  62952. }
  62953. }
  62954. return program;
  62955. };
  62956. WhitespaceControl.prototype.BlockStatement = WhitespaceControl.prototype.DecoratorBlock = WhitespaceControl.prototype.PartialBlockStatement = function (block) {
  62957. this.accept(block.program);
  62958. this.accept(block.inverse);
  62959. // Find the inverse program that is involed with whitespace stripping.
  62960. var program = block.program || block.inverse,
  62961. inverse = block.program && block.inverse,
  62962. firstInverse = inverse,
  62963. lastInverse = inverse;
  62964. if (inverse && inverse.chained) {
  62965. firstInverse = inverse.body[0].program;
  62966. // Walk the inverse chain to find the last inverse that is actually in the chain.
  62967. while (lastInverse.chained) {
  62968. lastInverse = lastInverse.body[lastInverse.body.length - 1].program;
  62969. }
  62970. }
  62971. var strip = {
  62972. open: block.openStrip.open,
  62973. close: block.closeStrip.close,
  62974. // Determine the standalone candiacy. Basically flag our content as being possibly standalone
  62975. // so our parent can determine if we actually are standalone
  62976. openStandalone: isNextWhitespace(program.body),
  62977. closeStandalone: isPrevWhitespace((firstInverse || program).body)
  62978. };
  62979. if (block.openStrip.close) {
  62980. omitRight(program.body, null, true);
  62981. }
  62982. if (inverse) {
  62983. var inverseStrip = block.inverseStrip;
  62984. if (inverseStrip.open) {
  62985. omitLeft(program.body, null, true);
  62986. }
  62987. if (inverseStrip.close) {
  62988. omitRight(firstInverse.body, null, true);
  62989. }
  62990. if (block.closeStrip.open) {
  62991. omitLeft(lastInverse.body, null, true);
  62992. }
  62993. // Find standalone else statments
  62994. if (!this.options.ignoreStandalone && isPrevWhitespace(program.body) && isNextWhitespace(firstInverse.body)) {
  62995. omitLeft(program.body);
  62996. omitRight(firstInverse.body);
  62997. }
  62998. } else if (block.closeStrip.open) {
  62999. omitLeft(program.body, null, true);
  63000. }
  63001. return strip;
  63002. };
  63003. WhitespaceControl.prototype.Decorator = WhitespaceControl.prototype.MustacheStatement = function (mustache) {
  63004. return mustache.strip;
  63005. };
  63006. WhitespaceControl.prototype.PartialStatement = WhitespaceControl.prototype.CommentStatement = function (node) {
  63007. /* istanbul ignore next */
  63008. var strip = node.strip || {};
  63009. return {
  63010. inlineStandalone: true,
  63011. open: strip.open,
  63012. close: strip.close
  63013. };
  63014. };
  63015. function isPrevWhitespace(body, i, isRoot) {
  63016. if (i === undefined) {
  63017. i = body.length;
  63018. }
  63019. // Nodes that end with newlines are considered whitespace (but are special
  63020. // cased for strip operations)
  63021. var prev = body[i - 1],
  63022. sibling = body[i - 2];
  63023. if (!prev) {
  63024. return isRoot;
  63025. }
  63026. if (prev.type === 'ContentStatement') {
  63027. return (sibling || !isRoot ? /\r?\n\s*?$/ : /(^|\r?\n)\s*?$/).test(prev.original);
  63028. }
  63029. }
  63030. function isNextWhitespace(body, i, isRoot) {
  63031. if (i === undefined) {
  63032. i = -1;
  63033. }
  63034. var next = body[i + 1],
  63035. sibling = body[i + 2];
  63036. if (!next) {
  63037. return isRoot;
  63038. }
  63039. if (next.type === 'ContentStatement') {
  63040. return (sibling || !isRoot ? /^\s*?\r?\n/ : /^\s*?(\r?\n|$)/).test(next.original);
  63041. }
  63042. }
  63043. // Marks the node to the right of the position as omitted.
  63044. // I.e. {{foo}}' ' will mark the ' ' node as omitted.
  63045. //
  63046. // If i is undefined, then the first child will be marked as such.
  63047. //
  63048. // If mulitple is truthy then all whitespace will be stripped out until non-whitespace
  63049. // content is met.
  63050. function omitRight(body, i, multiple) {
  63051. var current = body[i == null ? 0 : i + 1];
  63052. if (!current || current.type !== 'ContentStatement' || !multiple && current.rightStripped) {
  63053. return;
  63054. }
  63055. var original = current.value;
  63056. current.value = current.value.replace(multiple ? /^\s+/ : /^[ \t]*\r?\n?/, '');
  63057. current.rightStripped = current.value !== original;
  63058. }
  63059. // Marks the node to the left of the position as omitted.
  63060. // I.e. ' '{{foo}} will mark the ' ' node as omitted.
  63061. //
  63062. // If i is undefined then the last child will be marked as such.
  63063. //
  63064. // If mulitple is truthy then all whitespace will be stripped out until non-whitespace
  63065. // content is met.
  63066. function omitLeft(body, i, multiple) {
  63067. var current = body[i == null ? body.length - 1 : i - 1];
  63068. if (!current || current.type !== 'ContentStatement' || !multiple && current.leftStripped) {
  63069. return;
  63070. }
  63071. // We omit the last node if it's whitespace only and not preceeded by a non-content node.
  63072. var original = current.value;
  63073. current.value = current.value.replace(multiple ? /\s+$/ : /[ \t]+$/, '');
  63074. current.leftStripped = current.value !== original;
  63075. return current.leftStripped;
  63076. }
  63077. exports['default'] = WhitespaceControl;
  63078. module.exports = exports['default'];
  63079. /***/ }),
  63080. /* 39 */
  63081. /***/ (function(module, exports, __webpack_require__) {
  63082. 'use strict';
  63083. var _interopRequireDefault = __webpack_require__(1)['default'];
  63084. exports.__esModule = true;
  63085. var _exception = __webpack_require__(6);
  63086. var _exception2 = _interopRequireDefault(_exception);
  63087. function Visitor() {
  63088. this.parents = [];
  63089. }
  63090. Visitor.prototype = {
  63091. constructor: Visitor,
  63092. mutating: false,
  63093. // Visits a given value. If mutating, will replace the value if necessary.
  63094. acceptKey: function acceptKey(node, name) {
  63095. var value = this.accept(node[name]);
  63096. if (this.mutating) {
  63097. // Hacky sanity check: This may have a few false positives for type for the helper
  63098. // methods but will generally do the right thing without a lot of overhead.
  63099. if (value && !Visitor.prototype[value.type]) {
  63100. throw new _exception2['default']('Unexpected node type "' + value.type + '" found when accepting ' + name + ' on ' + node.type);
  63101. }
  63102. node[name] = value;
  63103. }
  63104. },
  63105. // Performs an accept operation with added sanity check to ensure
  63106. // required keys are not removed.
  63107. acceptRequired: function acceptRequired(node, name) {
  63108. this.acceptKey(node, name);
  63109. if (!node[name]) {
  63110. throw new _exception2['default'](node.type + ' requires ' + name);
  63111. }
  63112. },
  63113. // Traverses a given array. If mutating, empty respnses will be removed
  63114. // for child elements.
  63115. acceptArray: function acceptArray(array) {
  63116. for (var i = 0, l = array.length; i < l; i++) {
  63117. this.acceptKey(array, i);
  63118. if (!array[i]) {
  63119. array.splice(i, 1);
  63120. i--;
  63121. l--;
  63122. }
  63123. }
  63124. },
  63125. accept: function accept(object) {
  63126. if (!object) {
  63127. return;
  63128. }
  63129. /* istanbul ignore next: Sanity code */
  63130. if (!this[object.type]) {
  63131. throw new _exception2['default']('Unknown type: ' + object.type, object);
  63132. }
  63133. if (this.current) {
  63134. this.parents.unshift(this.current);
  63135. }
  63136. this.current = object;
  63137. var ret = this[object.type](object);
  63138. this.current = this.parents.shift();
  63139. if (!this.mutating || ret) {
  63140. return ret;
  63141. } else if (ret !== false) {
  63142. return object;
  63143. }
  63144. },
  63145. Program: function Program(program) {
  63146. this.acceptArray(program.body);
  63147. },
  63148. MustacheStatement: visitSubExpression,
  63149. Decorator: visitSubExpression,
  63150. BlockStatement: visitBlock,
  63151. DecoratorBlock: visitBlock,
  63152. PartialStatement: visitPartial,
  63153. PartialBlockStatement: function PartialBlockStatement(partial) {
  63154. visitPartial.call(this, partial);
  63155. this.acceptKey(partial, 'program');
  63156. },
  63157. ContentStatement: function ContentStatement() /* content */{},
  63158. CommentStatement: function CommentStatement() /* comment */{},
  63159. SubExpression: visitSubExpression,
  63160. PathExpression: function PathExpression() /* path */{},
  63161. StringLiteral: function StringLiteral() /* string */{},
  63162. NumberLiteral: function NumberLiteral() /* number */{},
  63163. BooleanLiteral: function BooleanLiteral() /* bool */{},
  63164. UndefinedLiteral: function UndefinedLiteral() /* literal */{},
  63165. NullLiteral: function NullLiteral() /* literal */{},
  63166. Hash: function Hash(hash) {
  63167. this.acceptArray(hash.pairs);
  63168. },
  63169. HashPair: function HashPair(pair) {
  63170. this.acceptRequired(pair, 'value');
  63171. }
  63172. };
  63173. function visitSubExpression(mustache) {
  63174. this.acceptRequired(mustache, 'path');
  63175. this.acceptArray(mustache.params);
  63176. this.acceptKey(mustache, 'hash');
  63177. }
  63178. function visitBlock(block) {
  63179. visitSubExpression.call(this, block);
  63180. this.acceptKey(block, 'program');
  63181. this.acceptKey(block, 'inverse');
  63182. }
  63183. function visitPartial(partial) {
  63184. this.acceptRequired(partial, 'name');
  63185. this.acceptArray(partial.params);
  63186. this.acceptKey(partial, 'hash');
  63187. }
  63188. exports['default'] = Visitor;
  63189. module.exports = exports['default'];
  63190. /***/ }),
  63191. /* 40 */
  63192. /***/ (function(module, exports, __webpack_require__) {
  63193. 'use strict';
  63194. var _interopRequireDefault = __webpack_require__(1)['default'];
  63195. exports.__esModule = true;
  63196. exports.SourceLocation = SourceLocation;
  63197. exports.id = id;
  63198. exports.stripFlags = stripFlags;
  63199. exports.stripComment = stripComment;
  63200. exports.preparePath = preparePath;
  63201. exports.prepareMustache = prepareMustache;
  63202. exports.prepareRawBlock = prepareRawBlock;
  63203. exports.prepareBlock = prepareBlock;
  63204. exports.prepareProgram = prepareProgram;
  63205. exports.preparePartialBlock = preparePartialBlock;
  63206. var _exception = __webpack_require__(6);
  63207. var _exception2 = _interopRequireDefault(_exception);
  63208. function validateClose(open, close) {
  63209. close = close.path ? close.path.original : close;
  63210. if (open.path.original !== close) {
  63211. var errorNode = { loc: open.path.loc };
  63212. throw new _exception2['default'](open.path.original + " doesn't match " + close, errorNode);
  63213. }
  63214. }
  63215. function SourceLocation(source, locInfo) {
  63216. this.source = source;
  63217. this.start = {
  63218. line: locInfo.first_line,
  63219. column: locInfo.first_column
  63220. };
  63221. this.end = {
  63222. line: locInfo.last_line,
  63223. column: locInfo.last_column
  63224. };
  63225. }
  63226. function id(token) {
  63227. if (/^\[.*\]$/.test(token)) {
  63228. return token.substr(1, token.length - 2);
  63229. } else {
  63230. return token;
  63231. }
  63232. }
  63233. function stripFlags(open, close) {
  63234. return {
  63235. open: open.charAt(2) === '~',
  63236. close: close.charAt(close.length - 3) === '~'
  63237. };
  63238. }
  63239. function stripComment(comment) {
  63240. return comment.replace(/^\{\{~?\!-?-?/, '').replace(/-?-?~?\}\}$/, '');
  63241. }
  63242. function preparePath(data, parts, loc) {
  63243. loc = this.locInfo(loc);
  63244. var original = data ? '@' : '',
  63245. dig = [],
  63246. depth = 0,
  63247. depthString = '';
  63248. for (var i = 0, l = parts.length; i < l; i++) {
  63249. var part = parts[i].part,
  63250. // If we have [] syntax then we do not treat path references as operators,
  63251. // i.e. foo.[this] resolves to approximately context.foo['this']
  63252. isLiteral = parts[i].original !== part;
  63253. original += (parts[i].separator || '') + part;
  63254. if (!isLiteral && (part === '..' || part === '.' || part === 'this')) {
  63255. if (dig.length > 0) {
  63256. throw new _exception2['default']('Invalid path: ' + original, { loc: loc });
  63257. } else if (part === '..') {
  63258. depth++;
  63259. depthString += '../';
  63260. }
  63261. } else {
  63262. dig.push(part);
  63263. }
  63264. }
  63265. return {
  63266. type: 'PathExpression',
  63267. data: data,
  63268. depth: depth,
  63269. parts: dig,
  63270. original: original,
  63271. loc: loc
  63272. };
  63273. }
  63274. function prepareMustache(path, params, hash, open, strip, locInfo) {
  63275. // Must use charAt to support IE pre-10
  63276. var escapeFlag = open.charAt(3) || open.charAt(2),
  63277. escaped = escapeFlag !== '{' && escapeFlag !== '&';
  63278. var decorator = /\*/.test(open);
  63279. return {
  63280. type: decorator ? 'Decorator' : 'MustacheStatement',
  63281. path: path,
  63282. params: params,
  63283. hash: hash,
  63284. escaped: escaped,
  63285. strip: strip,
  63286. loc: this.locInfo(locInfo)
  63287. };
  63288. }
  63289. function prepareRawBlock(openRawBlock, contents, close, locInfo) {
  63290. validateClose(openRawBlock, close);
  63291. locInfo = this.locInfo(locInfo);
  63292. var program = {
  63293. type: 'Program',
  63294. body: contents,
  63295. strip: {},
  63296. loc: locInfo
  63297. };
  63298. return {
  63299. type: 'BlockStatement',
  63300. path: openRawBlock.path,
  63301. params: openRawBlock.params,
  63302. hash: openRawBlock.hash,
  63303. program: program,
  63304. openStrip: {},
  63305. inverseStrip: {},
  63306. closeStrip: {},
  63307. loc: locInfo
  63308. };
  63309. }
  63310. function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {
  63311. if (close && close.path) {
  63312. validateClose(openBlock, close);
  63313. }
  63314. var decorator = /\*/.test(openBlock.open);
  63315. program.blockParams = openBlock.blockParams;
  63316. var inverse = undefined,
  63317. inverseStrip = undefined;
  63318. if (inverseAndProgram) {
  63319. if (decorator) {
  63320. throw new _exception2['default']('Unexpected inverse block on decorator', inverseAndProgram);
  63321. }
  63322. if (inverseAndProgram.chain) {
  63323. inverseAndProgram.program.body[0].closeStrip = close.strip;
  63324. }
  63325. inverseStrip = inverseAndProgram.strip;
  63326. inverse = inverseAndProgram.program;
  63327. }
  63328. if (inverted) {
  63329. inverted = inverse;
  63330. inverse = program;
  63331. program = inverted;
  63332. }
  63333. return {
  63334. type: decorator ? 'DecoratorBlock' : 'BlockStatement',
  63335. path: openBlock.path,
  63336. params: openBlock.params,
  63337. hash: openBlock.hash,
  63338. program: program,
  63339. inverse: inverse,
  63340. openStrip: openBlock.strip,
  63341. inverseStrip: inverseStrip,
  63342. closeStrip: close && close.strip,
  63343. loc: this.locInfo(locInfo)
  63344. };
  63345. }
  63346. function prepareProgram(statements, loc) {
  63347. if (!loc && statements.length) {
  63348. var firstLoc = statements[0].loc,
  63349. lastLoc = statements[statements.length - 1].loc;
  63350. /* istanbul ignore else */
  63351. if (firstLoc && lastLoc) {
  63352. loc = {
  63353. source: firstLoc.source,
  63354. start: {
  63355. line: firstLoc.start.line,
  63356. column: firstLoc.start.column
  63357. },
  63358. end: {
  63359. line: lastLoc.end.line,
  63360. column: lastLoc.end.column
  63361. }
  63362. };
  63363. }
  63364. }
  63365. return {
  63366. type: 'Program',
  63367. body: statements,
  63368. strip: {},
  63369. loc: loc
  63370. };
  63371. }
  63372. function preparePartialBlock(open, program, close, locInfo) {
  63373. validateClose(open, close);
  63374. return {
  63375. type: 'PartialBlockStatement',
  63376. name: open.path,
  63377. params: open.params,
  63378. hash: open.hash,
  63379. program: program,
  63380. openStrip: open.strip,
  63381. closeStrip: close && close.strip,
  63382. loc: this.locInfo(locInfo)
  63383. };
  63384. }
  63385. /***/ }),
  63386. /* 41 */
  63387. /***/ (function(module, exports, __webpack_require__) {
  63388. /* eslint-disable new-cap */
  63389. 'use strict';
  63390. var _interopRequireDefault = __webpack_require__(1)['default'];
  63391. exports.__esModule = true;
  63392. exports.Compiler = Compiler;
  63393. exports.precompile = precompile;
  63394. exports.compile = compile;
  63395. var _exception = __webpack_require__(6);
  63396. var _exception2 = _interopRequireDefault(_exception);
  63397. var _utils = __webpack_require__(5);
  63398. var _ast = __webpack_require__(35);
  63399. var _ast2 = _interopRequireDefault(_ast);
  63400. var slice = [].slice;
  63401. function Compiler() {}
  63402. // the foundHelper register will disambiguate helper lookup from finding a
  63403. // function in a context. This is necessary for mustache compatibility, which
  63404. // requires that context functions in blocks are evaluated by blockHelperMissing,
  63405. // and then proceed as if the resulting value was provided to blockHelperMissing.
  63406. Compiler.prototype = {
  63407. compiler: Compiler,
  63408. equals: function equals(other) {
  63409. var len = this.opcodes.length;
  63410. if (other.opcodes.length !== len) {
  63411. return false;
  63412. }
  63413. for (var i = 0; i < len; i++) {
  63414. var opcode = this.opcodes[i],
  63415. otherOpcode = other.opcodes[i];
  63416. if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) {
  63417. return false;
  63418. }
  63419. }
  63420. // We know that length is the same between the two arrays because they are directly tied
  63421. // to the opcode behavior above.
  63422. len = this.children.length;
  63423. for (var i = 0; i < len; i++) {
  63424. if (!this.children[i].equals(other.children[i])) {
  63425. return false;
  63426. }
  63427. }
  63428. return true;
  63429. },
  63430. guid: 0,
  63431. compile: function compile(program, options) {
  63432. this.sourceNode = [];
  63433. this.opcodes = [];
  63434. this.children = [];
  63435. this.options = options;
  63436. this.stringParams = options.stringParams;
  63437. this.trackIds = options.trackIds;
  63438. options.blockParams = options.blockParams || [];
  63439. // These changes will propagate to the other compiler components
  63440. var knownHelpers = options.knownHelpers;
  63441. options.knownHelpers = {
  63442. 'helperMissing': true,
  63443. 'blockHelperMissing': true,
  63444. 'each': true,
  63445. 'if': true,
  63446. 'unless': true,
  63447. 'with': true,
  63448. 'log': true,
  63449. 'lookup': true
  63450. };
  63451. if (knownHelpers) {
  63452. for (var _name in knownHelpers) {
  63453. /* istanbul ignore else */
  63454. if (_name in knownHelpers) {
  63455. this.options.knownHelpers[_name] = knownHelpers[_name];
  63456. }
  63457. }
  63458. }
  63459. return this.accept(program);
  63460. },
  63461. compileProgram: function compileProgram(program) {
  63462. var childCompiler = new this.compiler(),
  63463. // eslint-disable-line new-cap
  63464. result = childCompiler.compile(program, this.options),
  63465. guid = this.guid++;
  63466. this.usePartial = this.usePartial || result.usePartial;
  63467. this.children[guid] = result;
  63468. this.useDepths = this.useDepths || result.useDepths;
  63469. return guid;
  63470. },
  63471. accept: function accept(node) {
  63472. /* istanbul ignore next: Sanity code */
  63473. if (!this[node.type]) {
  63474. throw new _exception2['default']('Unknown type: ' + node.type, node);
  63475. }
  63476. this.sourceNode.unshift(node);
  63477. var ret = this[node.type](node);
  63478. this.sourceNode.shift();
  63479. return ret;
  63480. },
  63481. Program: function Program(program) {
  63482. this.options.blockParams.unshift(program.blockParams);
  63483. var body = program.body,
  63484. bodyLength = body.length;
  63485. for (var i = 0; i < bodyLength; i++) {
  63486. this.accept(body[i]);
  63487. }
  63488. this.options.blockParams.shift();
  63489. this.isSimple = bodyLength === 1;
  63490. this.blockParams = program.blockParams ? program.blockParams.length : 0;
  63491. return this;
  63492. },
  63493. BlockStatement: function BlockStatement(block) {
  63494. transformLiteralToPath(block);
  63495. var program = block.program,
  63496. inverse = block.inverse;
  63497. program = program && this.compileProgram(program);
  63498. inverse = inverse && this.compileProgram(inverse);
  63499. var type = this.classifySexpr(block);
  63500. if (type === 'helper') {
  63501. this.helperSexpr(block, program, inverse);
  63502. } else if (type === 'simple') {
  63503. this.simpleSexpr(block);
  63504. // now that the simple mustache is resolved, we need to
  63505. // evaluate it by executing `blockHelperMissing`
  63506. this.opcode('pushProgram', program);
  63507. this.opcode('pushProgram', inverse);
  63508. this.opcode('emptyHash');
  63509. this.opcode('blockValue', block.path.original);
  63510. } else {
  63511. this.ambiguousSexpr(block, program, inverse);
  63512. // now that the simple mustache is resolved, we need to
  63513. // evaluate it by executing `blockHelperMissing`
  63514. this.opcode('pushProgram', program);
  63515. this.opcode('pushProgram', inverse);
  63516. this.opcode('emptyHash');
  63517. this.opcode('ambiguousBlockValue');
  63518. }
  63519. this.opcode('append');
  63520. },
  63521. DecoratorBlock: function DecoratorBlock(decorator) {
  63522. var program = decorator.program && this.compileProgram(decorator.program);
  63523. var params = this.setupFullMustacheParams(decorator, program, undefined),
  63524. path = decorator.path;
  63525. this.useDecorators = true;
  63526. this.opcode('registerDecorator', params.length, path.original);
  63527. },
  63528. PartialStatement: function PartialStatement(partial) {
  63529. this.usePartial = true;
  63530. var program = partial.program;
  63531. if (program) {
  63532. program = this.compileProgram(partial.program);
  63533. }
  63534. var params = partial.params;
  63535. if (params.length > 1) {
  63536. throw new _exception2['default']('Unsupported number of partial arguments: ' + params.length, partial);
  63537. } else if (!params.length) {
  63538. if (this.options.explicitPartialContext) {
  63539. this.opcode('pushLiteral', 'undefined');
  63540. } else {
  63541. params.push({ type: 'PathExpression', parts: [], depth: 0 });
  63542. }
  63543. }
  63544. var partialName = partial.name.original,
  63545. isDynamic = partial.name.type === 'SubExpression';
  63546. if (isDynamic) {
  63547. this.accept(partial.name);
  63548. }
  63549. this.setupFullMustacheParams(partial, program, undefined, true);
  63550. var indent = partial.indent || '';
  63551. if (this.options.preventIndent && indent) {
  63552. this.opcode('appendContent', indent);
  63553. indent = '';
  63554. }
  63555. this.opcode('invokePartial', isDynamic, partialName, indent);
  63556. this.opcode('append');
  63557. },
  63558. PartialBlockStatement: function PartialBlockStatement(partialBlock) {
  63559. this.PartialStatement(partialBlock);
  63560. },
  63561. MustacheStatement: function MustacheStatement(mustache) {
  63562. this.SubExpression(mustache);
  63563. if (mustache.escaped && !this.options.noEscape) {
  63564. this.opcode('appendEscaped');
  63565. } else {
  63566. this.opcode('append');
  63567. }
  63568. },
  63569. Decorator: function Decorator(decorator) {
  63570. this.DecoratorBlock(decorator);
  63571. },
  63572. ContentStatement: function ContentStatement(content) {
  63573. if (content.value) {
  63574. this.opcode('appendContent', content.value);
  63575. }
  63576. },
  63577. CommentStatement: function CommentStatement() {},
  63578. SubExpression: function SubExpression(sexpr) {
  63579. transformLiteralToPath(sexpr);
  63580. var type = this.classifySexpr(sexpr);
  63581. if (type === 'simple') {
  63582. this.simpleSexpr(sexpr);
  63583. } else if (type === 'helper') {
  63584. this.helperSexpr(sexpr);
  63585. } else {
  63586. this.ambiguousSexpr(sexpr);
  63587. }
  63588. },
  63589. ambiguousSexpr: function ambiguousSexpr(sexpr, program, inverse) {
  63590. var path = sexpr.path,
  63591. name = path.parts[0],
  63592. isBlock = program != null || inverse != null;
  63593. this.opcode('getContext', path.depth);
  63594. this.opcode('pushProgram', program);
  63595. this.opcode('pushProgram', inverse);
  63596. path.strict = true;
  63597. this.accept(path);
  63598. this.opcode('invokeAmbiguous', name, isBlock);
  63599. },
  63600. simpleSexpr: function simpleSexpr(sexpr) {
  63601. var path = sexpr.path;
  63602. path.strict = true;
  63603. this.accept(path);
  63604. this.opcode('resolvePossibleLambda');
  63605. },
  63606. helperSexpr: function helperSexpr(sexpr, program, inverse) {
  63607. var params = this.setupFullMustacheParams(sexpr, program, inverse),
  63608. path = sexpr.path,
  63609. name = path.parts[0];
  63610. if (this.options.knownHelpers[name]) {
  63611. this.opcode('invokeKnownHelper', params.length, name);
  63612. } else if (this.options.knownHelpersOnly) {
  63613. throw new _exception2['default']('You specified knownHelpersOnly, but used the unknown helper ' + name, sexpr);
  63614. } else {
  63615. path.strict = true;
  63616. path.falsy = true;
  63617. this.accept(path);
  63618. this.opcode('invokeHelper', params.length, path.original, _ast2['default'].helpers.simpleId(path));
  63619. }
  63620. },
  63621. PathExpression: function PathExpression(path) {
  63622. this.addDepth(path.depth);
  63623. this.opcode('getContext', path.depth);
  63624. var name = path.parts[0],
  63625. scoped = _ast2['default'].helpers.scopedId(path),
  63626. blockParamId = !path.depth && !scoped && this.blockParamIndex(name);
  63627. if (blockParamId) {
  63628. this.opcode('lookupBlockParam', blockParamId, path.parts);
  63629. } else if (!name) {
  63630. // Context reference, i.e. `{{foo .}}` or `{{foo ..}}`
  63631. this.opcode('pushContext');
  63632. } else if (path.data) {
  63633. this.options.data = true;
  63634. this.opcode('lookupData', path.depth, path.parts, path.strict);
  63635. } else {
  63636. this.opcode('lookupOnContext', path.parts, path.falsy, path.strict, scoped);
  63637. }
  63638. },
  63639. StringLiteral: function StringLiteral(string) {
  63640. this.opcode('pushString', string.value);
  63641. },
  63642. NumberLiteral: function NumberLiteral(number) {
  63643. this.opcode('pushLiteral', number.value);
  63644. },
  63645. BooleanLiteral: function BooleanLiteral(bool) {
  63646. this.opcode('pushLiteral', bool.value);
  63647. },
  63648. UndefinedLiteral: function UndefinedLiteral() {
  63649. this.opcode('pushLiteral', 'undefined');
  63650. },
  63651. NullLiteral: function NullLiteral() {
  63652. this.opcode('pushLiteral', 'null');
  63653. },
  63654. Hash: function Hash(hash) {
  63655. var pairs = hash.pairs,
  63656. i = 0,
  63657. l = pairs.length;
  63658. this.opcode('pushHash');
  63659. for (; i < l; i++) {
  63660. this.pushParam(pairs[i].value);
  63661. }
  63662. while (i--) {
  63663. this.opcode('assignToHash', pairs[i].key);
  63664. }
  63665. this.opcode('popHash');
  63666. },
  63667. // HELPERS
  63668. opcode: function opcode(name) {
  63669. this.opcodes.push({ opcode: name, args: slice.call(arguments, 1), loc: this.sourceNode[0].loc });
  63670. },
  63671. addDepth: function addDepth(depth) {
  63672. if (!depth) {
  63673. return;
  63674. }
  63675. this.useDepths = true;
  63676. },
  63677. classifySexpr: function classifySexpr(sexpr) {
  63678. var isSimple = _ast2['default'].helpers.simpleId(sexpr.path);
  63679. var isBlockParam = isSimple && !!this.blockParamIndex(sexpr.path.parts[0]);
  63680. // a mustache is an eligible helper if:
  63681. // * its id is simple (a single part, not `this` or `..`)
  63682. var isHelper = !isBlockParam && _ast2['default'].helpers.helperExpression(sexpr);
  63683. // if a mustache is an eligible helper but not a definite
  63684. // helper, it is ambiguous, and will be resolved in a later
  63685. // pass or at runtime.
  63686. var isEligible = !isBlockParam && (isHelper || isSimple);
  63687. // if ambiguous, we can possibly resolve the ambiguity now
  63688. // An eligible helper is one that does not have a complex path, i.e. `this.foo`, `../foo` etc.
  63689. if (isEligible && !isHelper) {
  63690. var _name2 = sexpr.path.parts[0],
  63691. options = this.options;
  63692. if (options.knownHelpers[_name2]) {
  63693. isHelper = true;
  63694. } else if (options.knownHelpersOnly) {
  63695. isEligible = false;
  63696. }
  63697. }
  63698. if (isHelper) {
  63699. return 'helper';
  63700. } else if (isEligible) {
  63701. return 'ambiguous';
  63702. } else {
  63703. return 'simple';
  63704. }
  63705. },
  63706. pushParams: function pushParams(params) {
  63707. for (var i = 0, l = params.length; i < l; i++) {
  63708. this.pushParam(params[i]);
  63709. }
  63710. },
  63711. pushParam: function pushParam(val) {
  63712. var value = val.value != null ? val.value : val.original || '';
  63713. if (this.stringParams) {
  63714. if (value.replace) {
  63715. value = value.replace(/^(\.?\.\/)*/g, '').replace(/\//g, '.');
  63716. }
  63717. if (val.depth) {
  63718. this.addDepth(val.depth);
  63719. }
  63720. this.opcode('getContext', val.depth || 0);
  63721. this.opcode('pushStringParam', value, val.type);
  63722. if (val.type === 'SubExpression') {
  63723. // SubExpressions get evaluated and passed in
  63724. // in string params mode.
  63725. this.accept(val);
  63726. }
  63727. } else {
  63728. if (this.trackIds) {
  63729. var blockParamIndex = undefined;
  63730. if (val.parts && !_ast2['default'].helpers.scopedId(val) && !val.depth) {
  63731. blockParamIndex = this.blockParamIndex(val.parts[0]);
  63732. }
  63733. if (blockParamIndex) {
  63734. var blockParamChild = val.parts.slice(1).join('.');
  63735. this.opcode('pushId', 'BlockParam', blockParamIndex, blockParamChild);
  63736. } else {
  63737. value = val.original || value;
  63738. if (value.replace) {
  63739. value = value.replace(/^this(?:\.|$)/, '').replace(/^\.\//, '').replace(/^\.$/, '');
  63740. }
  63741. this.opcode('pushId', val.type, value);
  63742. }
  63743. }
  63744. this.accept(val);
  63745. }
  63746. },
  63747. setupFullMustacheParams: function setupFullMustacheParams(sexpr, program, inverse, omitEmpty) {
  63748. var params = sexpr.params;
  63749. this.pushParams(params);
  63750. this.opcode('pushProgram', program);
  63751. this.opcode('pushProgram', inverse);
  63752. if (sexpr.hash) {
  63753. this.accept(sexpr.hash);
  63754. } else {
  63755. this.opcode('emptyHash', omitEmpty);
  63756. }
  63757. return params;
  63758. },
  63759. blockParamIndex: function blockParamIndex(name) {
  63760. for (var depth = 0, len = this.options.blockParams.length; depth < len; depth++) {
  63761. var blockParams = this.options.blockParams[depth],
  63762. param = blockParams && _utils.indexOf(blockParams, name);
  63763. if (blockParams && param >= 0) {
  63764. return [depth, param];
  63765. }
  63766. }
  63767. }
  63768. };
  63769. function precompile(input, options, env) {
  63770. if (input == null || typeof input !== 'string' && input.type !== 'Program') {
  63771. throw new _exception2['default']('You must pass a string or Handlebars AST to Handlebars.precompile. You passed ' + input);
  63772. }
  63773. options = options || {};
  63774. if (!('data' in options)) {
  63775. options.data = true;
  63776. }
  63777. if (options.compat) {
  63778. options.useDepths = true;
  63779. }
  63780. var ast = env.parse(input, options),
  63781. environment = new env.Compiler().compile(ast, options);
  63782. return new env.JavaScriptCompiler().compile(environment, options);
  63783. }
  63784. function compile(input, options, env) {
  63785. if (options === undefined) options = {};
  63786. if (input == null || typeof input !== 'string' && input.type !== 'Program') {
  63787. throw new _exception2['default']('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input);
  63788. }
  63789. options = _utils.extend({}, options);
  63790. if (!('data' in options)) {
  63791. options.data = true;
  63792. }
  63793. if (options.compat) {
  63794. options.useDepths = true;
  63795. }
  63796. var compiled = undefined;
  63797. function compileInput() {
  63798. var ast = env.parse(input, options),
  63799. environment = new env.Compiler().compile(ast, options),
  63800. templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true);
  63801. return env.template(templateSpec);
  63802. }
  63803. // Template is only compiled on first use and cached after that point.
  63804. function ret(context, execOptions) {
  63805. if (!compiled) {
  63806. compiled = compileInput();
  63807. }
  63808. return compiled.call(this, context, execOptions);
  63809. }
  63810. ret._setup = function (setupOptions) {
  63811. if (!compiled) {
  63812. compiled = compileInput();
  63813. }
  63814. return compiled._setup(setupOptions);
  63815. };
  63816. ret._child = function (i, data, blockParams, depths) {
  63817. if (!compiled) {
  63818. compiled = compileInput();
  63819. }
  63820. return compiled._child(i, data, blockParams, depths);
  63821. };
  63822. return ret;
  63823. }
  63824. function argEquals(a, b) {
  63825. if (a === b) {
  63826. return true;
  63827. }
  63828. if (_utils.isArray(a) && _utils.isArray(b) && a.length === b.length) {
  63829. for (var i = 0; i < a.length; i++) {
  63830. if (!argEquals(a[i], b[i])) {
  63831. return false;
  63832. }
  63833. }
  63834. return true;
  63835. }
  63836. }
  63837. function transformLiteralToPath(sexpr) {
  63838. if (!sexpr.path.parts) {
  63839. var literal = sexpr.path;
  63840. // Casting to string here to make false and 0 literal values play nicely with the rest
  63841. // of the system.
  63842. sexpr.path = {
  63843. type: 'PathExpression',
  63844. data: false,
  63845. depth: 0,
  63846. parts: [literal.original + ''],
  63847. original: literal.original + '',
  63848. loc: literal.loc
  63849. };
  63850. }
  63851. }
  63852. /***/ }),
  63853. /* 42 */
  63854. /***/ (function(module, exports, __webpack_require__) {
  63855. 'use strict';
  63856. var _interopRequireDefault = __webpack_require__(1)['default'];
  63857. exports.__esModule = true;
  63858. var _base = __webpack_require__(4);
  63859. var _exception = __webpack_require__(6);
  63860. var _exception2 = _interopRequireDefault(_exception);
  63861. var _utils = __webpack_require__(5);
  63862. var _codeGen = __webpack_require__(43);
  63863. var _codeGen2 = _interopRequireDefault(_codeGen);
  63864. function Literal(value) {
  63865. this.value = value;
  63866. }
  63867. function JavaScriptCompiler() {}
  63868. JavaScriptCompiler.prototype = {
  63869. // PUBLIC API: You can override these methods in a subclass to provide
  63870. // alternative compiled forms for name lookup and buffering semantics
  63871. nameLookup: function nameLookup(parent, name /* , type*/) {
  63872. if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
  63873. return [parent, '.', name];
  63874. } else {
  63875. return [parent, '[', JSON.stringify(name), ']'];
  63876. }
  63877. },
  63878. depthedLookup: function depthedLookup(name) {
  63879. return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
  63880. },
  63881. compilerInfo: function compilerInfo() {
  63882. var revision = _base.COMPILER_REVISION,
  63883. versions = _base.REVISION_CHANGES[revision];
  63884. return [revision, versions];
  63885. },
  63886. appendToBuffer: function appendToBuffer(source, location, explicit) {
  63887. // Force a source as this simplifies the merge logic.
  63888. if (!_utils.isArray(source)) {
  63889. source = [source];
  63890. }
  63891. source = this.source.wrap(source, location);
  63892. if (this.environment.isSimple) {
  63893. return ['return ', source, ';'];
  63894. } else if (explicit) {
  63895. // This is a case where the buffer operation occurs as a child of another
  63896. // construct, generally braces. We have to explicitly output these buffer
  63897. // operations to ensure that the emitted code goes in the correct location.
  63898. return ['buffer += ', source, ';'];
  63899. } else {
  63900. source.appendToBuffer = true;
  63901. return source;
  63902. }
  63903. },
  63904. initializeBuffer: function initializeBuffer() {
  63905. return this.quotedString('');
  63906. },
  63907. // END PUBLIC API
  63908. compile: function compile(environment, options, context, asObject) {
  63909. this.environment = environment;
  63910. this.options = options;
  63911. this.stringParams = this.options.stringParams;
  63912. this.trackIds = this.options.trackIds;
  63913. this.precompile = !asObject;
  63914. this.name = this.environment.name;
  63915. this.isChild = !!context;
  63916. this.context = context || {
  63917. decorators: [],
  63918. programs: [],
  63919. environments: []
  63920. };
  63921. this.preamble();
  63922. this.stackSlot = 0;
  63923. this.stackVars = [];
  63924. this.aliases = {};
  63925. this.registers = { list: [] };
  63926. this.hashes = [];
  63927. this.compileStack = [];
  63928. this.inlineStack = [];
  63929. this.blockParams = [];
  63930. this.compileChildren(environment, options);
  63931. this.useDepths = this.useDepths || environment.useDepths || environment.useDecorators || this.options.compat;
  63932. this.useBlockParams = this.useBlockParams || environment.useBlockParams;
  63933. var opcodes = environment.opcodes,
  63934. opcode = undefined,
  63935. firstLoc = undefined,
  63936. i = undefined,
  63937. l = undefined;
  63938. for (i = 0, l = opcodes.length; i < l; i++) {
  63939. opcode = opcodes[i];
  63940. this.source.currentLocation = opcode.loc;
  63941. firstLoc = firstLoc || opcode.loc;
  63942. this[opcode.opcode].apply(this, opcode.args);
  63943. }
  63944. // Flush any trailing content that might be pending.
  63945. this.source.currentLocation = firstLoc;
  63946. this.pushSource('');
  63947. /* istanbul ignore next */
  63948. if (this.stackSlot || this.inlineStack.length || this.compileStack.length) {
  63949. throw new _exception2['default']('Compile completed with content left on stack');
  63950. }
  63951. if (!this.decorators.isEmpty()) {
  63952. this.useDecorators = true;
  63953. this.decorators.prepend('var decorators = container.decorators;\n');
  63954. this.decorators.push('return fn;');
  63955. if (asObject) {
  63956. this.decorators = Function.apply(this, ['fn', 'props', 'container', 'depth0', 'data', 'blockParams', 'depths', this.decorators.merge()]);
  63957. } else {
  63958. this.decorators.prepend('function(fn, props, container, depth0, data, blockParams, depths) {\n');
  63959. this.decorators.push('}\n');
  63960. this.decorators = this.decorators.merge();
  63961. }
  63962. } else {
  63963. this.decorators = undefined;
  63964. }
  63965. var fn = this.createFunctionContext(asObject);
  63966. if (!this.isChild) {
  63967. var ret = {
  63968. compiler: this.compilerInfo(),
  63969. main: fn
  63970. };
  63971. if (this.decorators) {
  63972. ret.main_d = this.decorators; // eslint-disable-line camelcase
  63973. ret.useDecorators = true;
  63974. }
  63975. var _context = this.context;
  63976. var programs = _context.programs;
  63977. var decorators = _context.decorators;
  63978. for (i = 0, l = programs.length; i < l; i++) {
  63979. if (programs[i]) {
  63980. ret[i] = programs[i];
  63981. if (decorators[i]) {
  63982. ret[i + '_d'] = decorators[i];
  63983. ret.useDecorators = true;
  63984. }
  63985. }
  63986. }
  63987. if (this.environment.usePartial) {
  63988. ret.usePartial = true;
  63989. }
  63990. if (this.options.data) {
  63991. ret.useData = true;
  63992. }
  63993. if (this.useDepths) {
  63994. ret.useDepths = true;
  63995. }
  63996. if (this.useBlockParams) {
  63997. ret.useBlockParams = true;
  63998. }
  63999. if (this.options.compat) {
  64000. ret.compat = true;
  64001. }
  64002. if (!asObject) {
  64003. ret.compiler = JSON.stringify(ret.compiler);
  64004. this.source.currentLocation = { start: { line: 1, column: 0 } };
  64005. ret = this.objectLiteral(ret);
  64006. if (options.srcName) {
  64007. ret = ret.toStringWithSourceMap({ file: options.destName });
  64008. ret.map = ret.map && ret.map.toString();
  64009. } else {
  64010. ret = ret.toString();
  64011. }
  64012. } else {
  64013. ret.compilerOptions = this.options;
  64014. }
  64015. return ret;
  64016. } else {
  64017. return fn;
  64018. }
  64019. },
  64020. preamble: function preamble() {
  64021. // track the last context pushed into place to allow skipping the
  64022. // getContext opcode when it would be a noop
  64023. this.lastContext = 0;
  64024. this.source = new _codeGen2['default'](this.options.srcName);
  64025. this.decorators = new _codeGen2['default'](this.options.srcName);
  64026. },
  64027. createFunctionContext: function createFunctionContext(asObject) {
  64028. var varDeclarations = '';
  64029. var locals = this.stackVars.concat(this.registers.list);
  64030. if (locals.length > 0) {
  64031. varDeclarations += ', ' + locals.join(', ');
  64032. }
  64033. // Generate minimizer alias mappings
  64034. //
  64035. // When using true SourceNodes, this will update all references to the given alias
  64036. // as the source nodes are reused in situ. For the non-source node compilation mode,
  64037. // aliases will not be used, but this case is already being run on the client and
  64038. // we aren't concern about minimizing the template size.
  64039. var aliasCount = 0;
  64040. for (var alias in this.aliases) {
  64041. // eslint-disable-line guard-for-in
  64042. var node = this.aliases[alias];
  64043. if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
  64044. varDeclarations += ', alias' + ++aliasCount + '=' + alias;
  64045. node.children[0] = 'alias' + aliasCount;
  64046. }
  64047. }
  64048. var params = ['container', 'depth0', 'helpers', 'partials', 'data'];
  64049. if (this.useBlockParams || this.useDepths) {
  64050. params.push('blockParams');
  64051. }
  64052. if (this.useDepths) {
  64053. params.push('depths');
  64054. }
  64055. // Perform a second pass over the output to merge content when possible
  64056. var source = this.mergeSource(varDeclarations);
  64057. if (asObject) {
  64058. params.push(source);
  64059. return Function.apply(this, params);
  64060. } else {
  64061. return this.source.wrap(['function(', params.join(','), ') {\n ', source, '}']);
  64062. }
  64063. },
  64064. mergeSource: function mergeSource(varDeclarations) {
  64065. var isSimple = this.environment.isSimple,
  64066. appendOnly = !this.forceBuffer,
  64067. appendFirst = undefined,
  64068. sourceSeen = undefined,
  64069. bufferStart = undefined,
  64070. bufferEnd = undefined;
  64071. this.source.each(function (line) {
  64072. if (line.appendToBuffer) {
  64073. if (bufferStart) {
  64074. line.prepend(' + ');
  64075. } else {
  64076. bufferStart = line;
  64077. }
  64078. bufferEnd = line;
  64079. } else {
  64080. if (bufferStart) {
  64081. if (!sourceSeen) {
  64082. appendFirst = true;
  64083. } else {
  64084. bufferStart.prepend('buffer += ');
  64085. }
  64086. bufferEnd.add(';');
  64087. bufferStart = bufferEnd = undefined;
  64088. }
  64089. sourceSeen = true;
  64090. if (!isSimple) {
  64091. appendOnly = false;
  64092. }
  64093. }
  64094. });
  64095. if (appendOnly) {
  64096. if (bufferStart) {
  64097. bufferStart.prepend('return ');
  64098. bufferEnd.add(';');
  64099. } else if (!sourceSeen) {
  64100. this.source.push('return "";');
  64101. }
  64102. } else {
  64103. varDeclarations += ', buffer = ' + (appendFirst ? '' : this.initializeBuffer());
  64104. if (bufferStart) {
  64105. bufferStart.prepend('return buffer + ');
  64106. bufferEnd.add(';');
  64107. } else {
  64108. this.source.push('return buffer;');
  64109. }
  64110. }
  64111. if (varDeclarations) {
  64112. this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n'));
  64113. }
  64114. return this.source.merge();
  64115. },
  64116. // [blockValue]
  64117. //
  64118. // On stack, before: hash, inverse, program, value
  64119. // On stack, after: return value of blockHelperMissing
  64120. //
  64121. // The purpose of this opcode is to take a block of the form
  64122. // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and
  64123. // replace it on the stack with the result of properly
  64124. // invoking blockHelperMissing.
  64125. blockValue: function blockValue(name) {
  64126. var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
  64127. params = [this.contextName(0)];
  64128. this.setupHelperArgs(name, 0, params);
  64129. var blockName = this.popStack();
  64130. params.splice(1, 0, blockName);
  64131. this.push(this.source.functionCall(blockHelperMissing, 'call', params));
  64132. },
  64133. // [ambiguousBlockValue]
  64134. //
  64135. // On stack, before: hash, inverse, program, value
  64136. // Compiler value, before: lastHelper=value of last found helper, if any
  64137. // On stack, after, if no lastHelper: same as [blockValue]
  64138. // On stack, after, if lastHelper: value
  64139. ambiguousBlockValue: function ambiguousBlockValue() {
  64140. // We're being a bit cheeky and reusing the options value from the prior exec
  64141. var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
  64142. params = [this.contextName(0)];
  64143. this.setupHelperArgs('', 0, params, true);
  64144. this.flushInline();
  64145. var current = this.topStack();
  64146. params.splice(1, 0, current);
  64147. this.pushSource(['if (!', this.lastHelper, ') { ', current, ' = ', this.source.functionCall(blockHelperMissing, 'call', params), '}']);
  64148. },
  64149. // [appendContent]
  64150. //
  64151. // On stack, before: ...
  64152. // On stack, after: ...
  64153. //
  64154. // Appends the string value of `content` to the current buffer
  64155. appendContent: function appendContent(content) {
  64156. if (this.pendingContent) {
  64157. content = this.pendingContent + content;
  64158. } else {
  64159. this.pendingLocation = this.source.currentLocation;
  64160. }
  64161. this.pendingContent = content;
  64162. },
  64163. // [append]
  64164. //
  64165. // On stack, before: value, ...
  64166. // On stack, after: ...
  64167. //
  64168. // Coerces `value` to a String and appends it to the current buffer.
  64169. //
  64170. // If `value` is truthy, or 0, it is coerced into a string and appended
  64171. // Otherwise, the empty string is appended
  64172. append: function append() {
  64173. if (this.isInline()) {
  64174. this.replaceStack(function (current) {
  64175. return [' != null ? ', current, ' : ""'];
  64176. });
  64177. this.pushSource(this.appendToBuffer(this.popStack()));
  64178. } else {
  64179. var local = this.popStack();
  64180. this.pushSource(['if (', local, ' != null) { ', this.appendToBuffer(local, undefined, true), ' }']);
  64181. if (this.environment.isSimple) {
  64182. this.pushSource(['else { ', this.appendToBuffer("''", undefined, true), ' }']);
  64183. }
  64184. }
  64185. },
  64186. // [appendEscaped]
  64187. //
  64188. // On stack, before: value, ...
  64189. // On stack, after: ...
  64190. //
  64191. // Escape `value` and append it to the buffer
  64192. appendEscaped: function appendEscaped() {
  64193. this.pushSource(this.appendToBuffer([this.aliasable('container.escapeExpression'), '(', this.popStack(), ')']));
  64194. },
  64195. // [getContext]
  64196. //
  64197. // On stack, before: ...
  64198. // On stack, after: ...
  64199. // Compiler value, after: lastContext=depth
  64200. //
  64201. // Set the value of the `lastContext` compiler value to the depth
  64202. getContext: function getContext(depth) {
  64203. this.lastContext = depth;
  64204. },
  64205. // [pushContext]
  64206. //
  64207. // On stack, before: ...
  64208. // On stack, after: currentContext, ...
  64209. //
  64210. // Pushes the value of the current context onto the stack.
  64211. pushContext: function pushContext() {
  64212. this.pushStackLiteral(this.contextName(this.lastContext));
  64213. },
  64214. // [lookupOnContext]
  64215. //
  64216. // On stack, before: ...
  64217. // On stack, after: currentContext[name], ...
  64218. //
  64219. // Looks up the value of `name` on the current context and pushes
  64220. // it onto the stack.
  64221. lookupOnContext: function lookupOnContext(parts, falsy, strict, scoped) {
  64222. var i = 0;
  64223. if (!scoped && this.options.compat && !this.lastContext) {
  64224. // The depthed query is expected to handle the undefined logic for the root level that
  64225. // is implemented below, so we evaluate that directly in compat mode
  64226. this.push(this.depthedLookup(parts[i++]));
  64227. } else {
  64228. this.pushContext();
  64229. }
  64230. this.resolvePath('context', parts, i, falsy, strict);
  64231. },
  64232. // [lookupBlockParam]
  64233. //
  64234. // On stack, before: ...
  64235. // On stack, after: blockParam[name], ...
  64236. //
  64237. // Looks up the value of `parts` on the given block param and pushes
  64238. // it onto the stack.
  64239. lookupBlockParam: function lookupBlockParam(blockParamId, parts) {
  64240. this.useBlockParams = true;
  64241. this.push(['blockParams[', blockParamId[0], '][', blockParamId[1], ']']);
  64242. this.resolvePath('context', parts, 1);
  64243. },
  64244. // [lookupData]
  64245. //
  64246. // On stack, before: ...
  64247. // On stack, after: data, ...
  64248. //
  64249. // Push the data lookup operator
  64250. lookupData: function lookupData(depth, parts, strict) {
  64251. if (!depth) {
  64252. this.pushStackLiteral('data');
  64253. } else {
  64254. this.pushStackLiteral('container.data(data, ' + depth + ')');
  64255. }
  64256. this.resolvePath('data', parts, 0, true, strict);
  64257. },
  64258. resolvePath: function resolvePath(type, parts, i, falsy, strict) {
  64259. // istanbul ignore next
  64260. var _this = this;
  64261. if (this.options.strict || this.options.assumeObjects) {
  64262. this.push(strictLookup(this.options.strict && strict, this, parts, type));
  64263. return;
  64264. }
  64265. var len = parts.length;
  64266. for (; i < len; i++) {
  64267. /* eslint-disable no-loop-func */
  64268. this.replaceStack(function (current) {
  64269. var lookup = _this.nameLookup(current, parts[i], type);
  64270. // We want to ensure that zero and false are handled properly if the context (falsy flag)
  64271. // needs to have the special handling for these values.
  64272. if (!falsy) {
  64273. return [' != null ? ', lookup, ' : ', current];
  64274. } else {
  64275. // Otherwise we can use generic falsy handling
  64276. return [' && ', lookup];
  64277. }
  64278. });
  64279. /* eslint-enable no-loop-func */
  64280. }
  64281. },
  64282. // [resolvePossibleLambda]
  64283. //
  64284. // On stack, before: value, ...
  64285. // On stack, after: resolved value, ...
  64286. //
  64287. // If the `value` is a lambda, replace it on the stack by
  64288. // the return value of the lambda
  64289. resolvePossibleLambda: function resolvePossibleLambda() {
  64290. this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
  64291. },
  64292. // [pushStringParam]
  64293. //
  64294. // On stack, before: ...
  64295. // On stack, after: string, currentContext, ...
  64296. //
  64297. // This opcode is designed for use in string mode, which
  64298. // provides the string value of a parameter along with its
  64299. // depth rather than resolving it immediately.
  64300. pushStringParam: function pushStringParam(string, type) {
  64301. this.pushContext();
  64302. this.pushString(type);
  64303. // If it's a subexpression, the string result
  64304. // will be pushed after this opcode.
  64305. if (type !== 'SubExpression') {
  64306. if (typeof string === 'string') {
  64307. this.pushString(string);
  64308. } else {
  64309. this.pushStackLiteral(string);
  64310. }
  64311. }
  64312. },
  64313. emptyHash: function emptyHash(omitEmpty) {
  64314. if (this.trackIds) {
  64315. this.push('{}'); // hashIds
  64316. }
  64317. if (this.stringParams) {
  64318. this.push('{}'); // hashContexts
  64319. this.push('{}'); // hashTypes
  64320. }
  64321. this.pushStackLiteral(omitEmpty ? 'undefined' : '{}');
  64322. },
  64323. pushHash: function pushHash() {
  64324. if (this.hash) {
  64325. this.hashes.push(this.hash);
  64326. }
  64327. this.hash = { values: [], types: [], contexts: [], ids: [] };
  64328. },
  64329. popHash: function popHash() {
  64330. var hash = this.hash;
  64331. this.hash = this.hashes.pop();
  64332. if (this.trackIds) {
  64333. this.push(this.objectLiteral(hash.ids));
  64334. }
  64335. if (this.stringParams) {
  64336. this.push(this.objectLiteral(hash.contexts));
  64337. this.push(this.objectLiteral(hash.types));
  64338. }
  64339. this.push(this.objectLiteral(hash.values));
  64340. },
  64341. // [pushString]
  64342. //
  64343. // On stack, before: ...
  64344. // On stack, after: quotedString(string), ...
  64345. //
  64346. // Push a quoted version of `string` onto the stack
  64347. pushString: function pushString(string) {
  64348. this.pushStackLiteral(this.quotedString(string));
  64349. },
  64350. // [pushLiteral]
  64351. //
  64352. // On stack, before: ...
  64353. // On stack, after: value, ...
  64354. //
  64355. // Pushes a value onto the stack. This operation prevents
  64356. // the compiler from creating a temporary variable to hold
  64357. // it.
  64358. pushLiteral: function pushLiteral(value) {
  64359. this.pushStackLiteral(value);
  64360. },
  64361. // [pushProgram]
  64362. //
  64363. // On stack, before: ...
  64364. // On stack, after: program(guid), ...
  64365. //
  64366. // Push a program expression onto the stack. This takes
  64367. // a compile-time guid and converts it into a runtime-accessible
  64368. // expression.
  64369. pushProgram: function pushProgram(guid) {
  64370. if (guid != null) {
  64371. this.pushStackLiteral(this.programExpression(guid));
  64372. } else {
  64373. this.pushStackLiteral(null);
  64374. }
  64375. },
  64376. // [registerDecorator]
  64377. //
  64378. // On stack, before: hash, program, params..., ...
  64379. // On stack, after: ...
  64380. //
  64381. // Pops off the decorator's parameters, invokes the decorator,
  64382. // and inserts the decorator into the decorators list.
  64383. registerDecorator: function registerDecorator(paramSize, name) {
  64384. var foundDecorator = this.nameLookup('decorators', name, 'decorator'),
  64385. options = this.setupHelperArgs(name, paramSize);
  64386. this.decorators.push(['fn = ', this.decorators.functionCall(foundDecorator, '', ['fn', 'props', 'container', options]), ' || fn;']);
  64387. },
  64388. // [invokeHelper]
  64389. //
  64390. // On stack, before: hash, inverse, program, params..., ...
  64391. // On stack, after: result of helper invocation
  64392. //
  64393. // Pops off the helper's parameters, invokes the helper,
  64394. // and pushes the helper's return value onto the stack.
  64395. //
  64396. // If the helper is not found, `helperMissing` is called.
  64397. invokeHelper: function invokeHelper(paramSize, name, isSimple) {
  64398. var nonHelper = this.popStack(),
  64399. helper = this.setupHelper(paramSize, name),
  64400. simple = isSimple ? [helper.name, ' || '] : '';
  64401. var lookup = ['('].concat(simple, nonHelper);
  64402. if (!this.options.strict) {
  64403. lookup.push(' || ', this.aliasable('helpers.helperMissing'));
  64404. }
  64405. lookup.push(')');
  64406. this.push(this.source.functionCall(lookup, 'call', helper.callParams));
  64407. },
  64408. // [invokeKnownHelper]
  64409. //
  64410. // On stack, before: hash, inverse, program, params..., ...
  64411. // On stack, after: result of helper invocation
  64412. //
  64413. // This operation is used when the helper is known to exist,
  64414. // so a `helperMissing` fallback is not required.
  64415. invokeKnownHelper: function invokeKnownHelper(paramSize, name) {
  64416. var helper = this.setupHelper(paramSize, name);
  64417. this.push(this.source.functionCall(helper.name, 'call', helper.callParams));
  64418. },
  64419. // [invokeAmbiguous]
  64420. //
  64421. // On stack, before: hash, inverse, program, params..., ...
  64422. // On stack, after: result of disambiguation
  64423. //
  64424. // This operation is used when an expression like `{{foo}}`
  64425. // is provided, but we don't know at compile-time whether it
  64426. // is a helper or a path.
  64427. //
  64428. // This operation emits more code than the other options,
  64429. // and can be avoided by passing the `knownHelpers` and
  64430. // `knownHelpersOnly` flags at compile-time.
  64431. invokeAmbiguous: function invokeAmbiguous(name, helperCall) {
  64432. this.useRegister('helper');
  64433. var nonHelper = this.popStack();
  64434. this.emptyHash();
  64435. var helper = this.setupHelper(0, name, helperCall);
  64436. var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
  64437. var lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
  64438. if (!this.options.strict) {
  64439. lookup[0] = '(helper = ';
  64440. lookup.push(' != null ? helper : ', this.aliasable('helpers.helperMissing'));
  64441. }
  64442. this.push(['(', lookup, helper.paramsInit ? ['),(', helper.paramsInit] : [], '),', '(typeof helper === ', this.aliasable('"function"'), ' ? ', this.source.functionCall('helper', 'call', helper.callParams), ' : helper))']);
  64443. },
  64444. // [invokePartial]
  64445. //
  64446. // On stack, before: context, ...
  64447. // On stack after: result of partial invocation
  64448. //
  64449. // This operation pops off a context, invokes a partial with that context,
  64450. // and pushes the result of the invocation back.
  64451. invokePartial: function invokePartial(isDynamic, name, indent) {
  64452. var params = [],
  64453. options = this.setupParams(name, 1, params);
  64454. if (isDynamic) {
  64455. name = this.popStack();
  64456. delete options.name;
  64457. }
  64458. if (indent) {
  64459. options.indent = JSON.stringify(indent);
  64460. }
  64461. options.helpers = 'helpers';
  64462. options.partials = 'partials';
  64463. options.decorators = 'container.decorators';
  64464. if (!isDynamic) {
  64465. params.unshift(this.nameLookup('partials', name, 'partial'));
  64466. } else {
  64467. params.unshift(name);
  64468. }
  64469. if (this.options.compat) {
  64470. options.depths = 'depths';
  64471. }
  64472. options = this.objectLiteral(options);
  64473. params.push(options);
  64474. this.push(this.source.functionCall('container.invokePartial', '', params));
  64475. },
  64476. // [assignToHash]
  64477. //
  64478. // On stack, before: value, ..., hash, ...
  64479. // On stack, after: ..., hash, ...
  64480. //
  64481. // Pops a value off the stack and assigns it to the current hash
  64482. assignToHash: function assignToHash(key) {
  64483. var value = this.popStack(),
  64484. context = undefined,
  64485. type = undefined,
  64486. id = undefined;
  64487. if (this.trackIds) {
  64488. id = this.popStack();
  64489. }
  64490. if (this.stringParams) {
  64491. type = this.popStack();
  64492. context = this.popStack();
  64493. }
  64494. var hash = this.hash;
  64495. if (context) {
  64496. hash.contexts[key] = context;
  64497. }
  64498. if (type) {
  64499. hash.types[key] = type;
  64500. }
  64501. if (id) {
  64502. hash.ids[key] = id;
  64503. }
  64504. hash.values[key] = value;
  64505. },
  64506. pushId: function pushId(type, name, child) {
  64507. if (type === 'BlockParam') {
  64508. this.pushStackLiteral('blockParams[' + name[0] + '].path[' + name[1] + ']' + (child ? ' + ' + JSON.stringify('.' + child) : ''));
  64509. } else if (type === 'PathExpression') {
  64510. this.pushString(name);
  64511. } else if (type === 'SubExpression') {
  64512. this.pushStackLiteral('true');
  64513. } else {
  64514. this.pushStackLiteral('null');
  64515. }
  64516. },
  64517. // HELPERS
  64518. compiler: JavaScriptCompiler,
  64519. compileChildren: function compileChildren(environment, options) {
  64520. var children = environment.children,
  64521. child = undefined,
  64522. compiler = undefined;
  64523. for (var i = 0, l = children.length; i < l; i++) {
  64524. child = children[i];
  64525. compiler = new this.compiler(); // eslint-disable-line new-cap
  64526. var existing = this.matchExistingProgram(child);
  64527. if (existing == null) {
  64528. this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
  64529. var index = this.context.programs.length;
  64530. child.index = index;
  64531. child.name = 'program' + index;
  64532. this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
  64533. this.context.decorators[index] = compiler.decorators;
  64534. this.context.environments[index] = child;
  64535. this.useDepths = this.useDepths || compiler.useDepths;
  64536. this.useBlockParams = this.useBlockParams || compiler.useBlockParams;
  64537. child.useDepths = this.useDepths;
  64538. child.useBlockParams = this.useBlockParams;
  64539. } else {
  64540. child.index = existing.index;
  64541. child.name = 'program' + existing.index;
  64542. this.useDepths = this.useDepths || existing.useDepths;
  64543. this.useBlockParams = this.useBlockParams || existing.useBlockParams;
  64544. }
  64545. }
  64546. },
  64547. matchExistingProgram: function matchExistingProgram(child) {
  64548. for (var i = 0, len = this.context.environments.length; i < len; i++) {
  64549. var environment = this.context.environments[i];
  64550. if (environment && environment.equals(child)) {
  64551. return environment;
  64552. }
  64553. }
  64554. },
  64555. programExpression: function programExpression(guid) {
  64556. var child = this.environment.children[guid],
  64557. programParams = [child.index, 'data', child.blockParams];
  64558. if (this.useBlockParams || this.useDepths) {
  64559. programParams.push('blockParams');
  64560. }
  64561. if (this.useDepths) {
  64562. programParams.push('depths');
  64563. }
  64564. return 'container.program(' + programParams.join(', ') + ')';
  64565. },
  64566. useRegister: function useRegister(name) {
  64567. if (!this.registers[name]) {
  64568. this.registers[name] = true;
  64569. this.registers.list.push(name);
  64570. }
  64571. },
  64572. push: function push(expr) {
  64573. if (!(expr instanceof Literal)) {
  64574. expr = this.source.wrap(expr);
  64575. }
  64576. this.inlineStack.push(expr);
  64577. return expr;
  64578. },
  64579. pushStackLiteral: function pushStackLiteral(item) {
  64580. this.push(new Literal(item));
  64581. },
  64582. pushSource: function pushSource(source) {
  64583. if (this.pendingContent) {
  64584. this.source.push(this.appendToBuffer(this.source.quotedString(this.pendingContent), this.pendingLocation));
  64585. this.pendingContent = undefined;
  64586. }
  64587. if (source) {
  64588. this.source.push(source);
  64589. }
  64590. },
  64591. replaceStack: function replaceStack(callback) {
  64592. var prefix = ['('],
  64593. stack = undefined,
  64594. createdStack = undefined,
  64595. usedLiteral = undefined;
  64596. /* istanbul ignore next */
  64597. if (!this.isInline()) {
  64598. throw new _exception2['default']('replaceStack on non-inline');
  64599. }
  64600. // We want to merge the inline statement into the replacement statement via ','
  64601. var top = this.popStack(true);
  64602. if (top instanceof Literal) {
  64603. // Literals do not need to be inlined
  64604. stack = [top.value];
  64605. prefix = ['(', stack];
  64606. usedLiteral = true;
  64607. } else {
  64608. // Get or create the current stack name for use by the inline
  64609. createdStack = true;
  64610. var _name = this.incrStack();
  64611. prefix = ['((', this.push(_name), ' = ', top, ')'];
  64612. stack = this.topStack();
  64613. }
  64614. var item = callback.call(this, stack);
  64615. if (!usedLiteral) {
  64616. this.popStack();
  64617. }
  64618. if (createdStack) {
  64619. this.stackSlot--;
  64620. }
  64621. this.push(prefix.concat(item, ')'));
  64622. },
  64623. incrStack: function incrStack() {
  64624. this.stackSlot++;
  64625. if (this.stackSlot > this.stackVars.length) {
  64626. this.stackVars.push('stack' + this.stackSlot);
  64627. }
  64628. return this.topStackName();
  64629. },
  64630. topStackName: function topStackName() {
  64631. return 'stack' + this.stackSlot;
  64632. },
  64633. flushInline: function flushInline() {
  64634. var inlineStack = this.inlineStack;
  64635. this.inlineStack = [];
  64636. for (var i = 0, len = inlineStack.length; i < len; i++) {
  64637. var entry = inlineStack[i];
  64638. /* istanbul ignore if */
  64639. if (entry instanceof Literal) {
  64640. this.compileStack.push(entry);
  64641. } else {
  64642. var stack = this.incrStack();
  64643. this.pushSource([stack, ' = ', entry, ';']);
  64644. this.compileStack.push(stack);
  64645. }
  64646. }
  64647. },
  64648. isInline: function isInline() {
  64649. return this.inlineStack.length;
  64650. },
  64651. popStack: function popStack(wrapped) {
  64652. var inline = this.isInline(),
  64653. item = (inline ? this.inlineStack : this.compileStack).pop();
  64654. if (!wrapped && item instanceof Literal) {
  64655. return item.value;
  64656. } else {
  64657. if (!inline) {
  64658. /* istanbul ignore next */
  64659. if (!this.stackSlot) {
  64660. throw new _exception2['default']('Invalid stack pop');
  64661. }
  64662. this.stackSlot--;
  64663. }
  64664. return item;
  64665. }
  64666. },
  64667. topStack: function topStack() {
  64668. var stack = this.isInline() ? this.inlineStack : this.compileStack,
  64669. item = stack[stack.length - 1];
  64670. /* istanbul ignore if */
  64671. if (item instanceof Literal) {
  64672. return item.value;
  64673. } else {
  64674. return item;
  64675. }
  64676. },
  64677. contextName: function contextName(context) {
  64678. if (this.useDepths && context) {
  64679. return 'depths[' + context + ']';
  64680. } else {
  64681. return 'depth' + context;
  64682. }
  64683. },
  64684. quotedString: function quotedString(str) {
  64685. return this.source.quotedString(str);
  64686. },
  64687. objectLiteral: function objectLiteral(obj) {
  64688. return this.source.objectLiteral(obj);
  64689. },
  64690. aliasable: function aliasable(name) {
  64691. var ret = this.aliases[name];
  64692. if (ret) {
  64693. ret.referenceCount++;
  64694. return ret;
  64695. }
  64696. ret = this.aliases[name] = this.source.wrap(name);
  64697. ret.aliasable = true;
  64698. ret.referenceCount = 1;
  64699. return ret;
  64700. },
  64701. setupHelper: function setupHelper(paramSize, name, blockHelper) {
  64702. var params = [],
  64703. paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
  64704. var foundHelper = this.nameLookup('helpers', name, 'helper'),
  64705. callContext = this.aliasable(this.contextName(0) + ' != null ? ' + this.contextName(0) + ' : (container.nullContext || {})');
  64706. return {
  64707. params: params,
  64708. paramsInit: paramsInit,
  64709. name: foundHelper,
  64710. callParams: [callContext].concat(params)
  64711. };
  64712. },
  64713. setupParams: function setupParams(helper, paramSize, params) {
  64714. var options = {},
  64715. contexts = [],
  64716. types = [],
  64717. ids = [],
  64718. objectArgs = !params,
  64719. param = undefined;
  64720. if (objectArgs) {
  64721. params = [];
  64722. }
  64723. options.name = this.quotedString(helper);
  64724. options.hash = this.popStack();
  64725. if (this.trackIds) {
  64726. options.hashIds = this.popStack();
  64727. }
  64728. if (this.stringParams) {
  64729. options.hashTypes = this.popStack();
  64730. options.hashContexts = this.popStack();
  64731. }
  64732. var inverse = this.popStack(),
  64733. program = this.popStack();
  64734. // Avoid setting fn and inverse if neither are set. This allows
  64735. // helpers to do a check for `if (options.fn)`
  64736. if (program || inverse) {
  64737. options.fn = program || 'container.noop';
  64738. options.inverse = inverse || 'container.noop';
  64739. }
  64740. // The parameters go on to the stack in order (making sure that they are evaluated in order)
  64741. // so we need to pop them off the stack in reverse order
  64742. var i = paramSize;
  64743. while (i--) {
  64744. param = this.popStack();
  64745. params[i] = param;
  64746. if (this.trackIds) {
  64747. ids[i] = this.popStack();
  64748. }
  64749. if (this.stringParams) {
  64750. types[i] = this.popStack();
  64751. contexts[i] = this.popStack();
  64752. }
  64753. }
  64754. if (objectArgs) {
  64755. options.args = this.source.generateArray(params);
  64756. }
  64757. if (this.trackIds) {
  64758. options.ids = this.source.generateArray(ids);
  64759. }
  64760. if (this.stringParams) {
  64761. options.types = this.source.generateArray(types);
  64762. options.contexts = this.source.generateArray(contexts);
  64763. }
  64764. if (this.options.data) {
  64765. options.data = 'data';
  64766. }
  64767. if (this.useBlockParams) {
  64768. options.blockParams = 'blockParams';
  64769. }
  64770. return options;
  64771. },
  64772. setupHelperArgs: function setupHelperArgs(helper, paramSize, params, useRegister) {
  64773. var options = this.setupParams(helper, paramSize, params);
  64774. options = this.objectLiteral(options);
  64775. if (useRegister) {
  64776. this.useRegister('options');
  64777. params.push('options');
  64778. return ['options=', options];
  64779. } else if (params) {
  64780. params.push(options);
  64781. return '';
  64782. } else {
  64783. return options;
  64784. }
  64785. }
  64786. };
  64787. (function () {
  64788. var reservedWords = ('break else new var' + ' case finally return void' + ' catch for switch while' + ' continue function this with' + ' default if throw' + ' delete in try' + ' do instanceof typeof' + ' abstract enum int short' + ' boolean export interface static' + ' byte extends long super' + ' char final native synchronized' + ' class float package throws' + ' const goto private transient' + ' debugger implements protected volatile' + ' double import public let yield await' + ' null true false').split(' ');
  64789. var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
  64790. for (var i = 0, l = reservedWords.length; i < l; i++) {
  64791. compilerWords[reservedWords[i]] = true;
  64792. }
  64793. })();
  64794. JavaScriptCompiler.isValidJavaScriptVariableName = function (name) {
  64795. return !JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name);
  64796. };
  64797. function strictLookup(requireTerminal, compiler, parts, type) {
  64798. var stack = compiler.popStack(),
  64799. i = 0,
  64800. len = parts.length;
  64801. if (requireTerminal) {
  64802. len--;
  64803. }
  64804. for (; i < len; i++) {
  64805. stack = compiler.nameLookup(stack, parts[i], type);
  64806. }
  64807. if (requireTerminal) {
  64808. return [compiler.aliasable('container.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
  64809. } else {
  64810. return stack;
  64811. }
  64812. }
  64813. exports['default'] = JavaScriptCompiler;
  64814. module.exports = exports['default'];
  64815. /***/ }),
  64816. /* 43 */
  64817. /***/ (function(module, exports, __webpack_require__) {
  64818. /* global define */
  64819. 'use strict';
  64820. exports.__esModule = true;
  64821. var _utils = __webpack_require__(5);
  64822. var SourceNode = undefined;
  64823. try {
  64824. /* istanbul ignore next */
  64825. if (false) {
  64826. // We don't support this in AMD environments. For these environments, we asusme that
  64827. // they are running on the browser and thus have no need for the source-map library.
  64828. var SourceMap = require('source-map');
  64829. SourceNode = SourceMap.SourceNode;
  64830. }
  64831. } catch (err) {}
  64832. /* NOP */
  64833. /* istanbul ignore if: tested but not covered in istanbul due to dist build */
  64834. if (!SourceNode) {
  64835. SourceNode = function (line, column, srcFile, chunks) {
  64836. this.src = '';
  64837. if (chunks) {
  64838. this.add(chunks);
  64839. }
  64840. };
  64841. /* istanbul ignore next */
  64842. SourceNode.prototype = {
  64843. add: function add(chunks) {
  64844. if (_utils.isArray(chunks)) {
  64845. chunks = chunks.join('');
  64846. }
  64847. this.src += chunks;
  64848. },
  64849. prepend: function prepend(chunks) {
  64850. if (_utils.isArray(chunks)) {
  64851. chunks = chunks.join('');
  64852. }
  64853. this.src = chunks + this.src;
  64854. },
  64855. toStringWithSourceMap: function toStringWithSourceMap() {
  64856. return { code: this.toString() };
  64857. },
  64858. toString: function toString() {
  64859. return this.src;
  64860. }
  64861. };
  64862. }
  64863. function castChunk(chunk, codeGen, loc) {
  64864. if (_utils.isArray(chunk)) {
  64865. var ret = [];
  64866. for (var i = 0, len = chunk.length; i < len; i++) {
  64867. ret.push(codeGen.wrap(chunk[i], loc));
  64868. }
  64869. return ret;
  64870. } else if (typeof chunk === 'boolean' || typeof chunk === 'number') {
  64871. // Handle primitives that the SourceNode will throw up on
  64872. return chunk + '';
  64873. }
  64874. return chunk;
  64875. }
  64876. function CodeGen(srcFile) {
  64877. this.srcFile = srcFile;
  64878. this.source = [];
  64879. }
  64880. CodeGen.prototype = {
  64881. isEmpty: function isEmpty() {
  64882. return !this.source.length;
  64883. },
  64884. prepend: function prepend(source, loc) {
  64885. this.source.unshift(this.wrap(source, loc));
  64886. },
  64887. push: function push(source, loc) {
  64888. this.source.push(this.wrap(source, loc));
  64889. },
  64890. merge: function merge() {
  64891. var source = this.empty();
  64892. this.each(function (line) {
  64893. source.add([' ', line, '\n']);
  64894. });
  64895. return source;
  64896. },
  64897. each: function each(iter) {
  64898. for (var i = 0, len = this.source.length; i < len; i++) {
  64899. iter(this.source[i]);
  64900. }
  64901. },
  64902. empty: function empty() {
  64903. var loc = this.currentLocation || { start: {} };
  64904. return new SourceNode(loc.start.line, loc.start.column, this.srcFile);
  64905. },
  64906. wrap: function wrap(chunk) {
  64907. var loc = arguments.length <= 1 || arguments[1] === undefined ? this.currentLocation || { start: {} } : arguments[1];
  64908. if (chunk instanceof SourceNode) {
  64909. return chunk;
  64910. }
  64911. chunk = castChunk(chunk, this, loc);
  64912. return new SourceNode(loc.start.line, loc.start.column, this.srcFile, chunk);
  64913. },
  64914. functionCall: function functionCall(fn, type, params) {
  64915. params = this.generateList(params);
  64916. return this.wrap([fn, type ? '.' + type + '(' : '(', params, ')']);
  64917. },
  64918. quotedString: function quotedString(str) {
  64919. return '"' + (str + '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
  64920. .replace(/\u2029/g, '\\u2029') + '"';
  64921. },
  64922. objectLiteral: function objectLiteral(obj) {
  64923. var pairs = [];
  64924. for (var key in obj) {
  64925. if (obj.hasOwnProperty(key)) {
  64926. var value = castChunk(obj[key], this);
  64927. if (value !== 'undefined') {
  64928. pairs.push([this.quotedString(key), ':', value]);
  64929. }
  64930. }
  64931. }
  64932. var ret = this.generateList(pairs);
  64933. ret.prepend('{');
  64934. ret.add('}');
  64935. return ret;
  64936. },
  64937. generateList: function generateList(entries) {
  64938. var ret = this.empty();
  64939. for (var i = 0, len = entries.length; i < len; i++) {
  64940. if (i) {
  64941. ret.add(',');
  64942. }
  64943. ret.add(castChunk(entries[i], this));
  64944. }
  64945. return ret;
  64946. },
  64947. generateArray: function generateArray(entries) {
  64948. var ret = this.generateList(entries);
  64949. ret.prepend('[');
  64950. ret.add(']');
  64951. return ret;
  64952. }
  64953. };
  64954. exports['default'] = CodeGen;
  64955. module.exports = exports['default'];
  64956. /***/ })
  64957. /******/ ])
  64958. });
  64959. ;
  64960. /***/ }),
  64961. /* 63 */
  64962. /***/ (function(module, exports, __webpack_require__) {
  64963. "use strict";
  64964. Object.defineProperty(exports, "__esModule", { value: true });
  64965. /**
  64966. * The EventManager is in charge of registering user interctions with the viewer.
  64967. * It is used in the TemplateManager
  64968. */
  64969. var EventManager = /** @class */ (function () {
  64970. function EventManager(_templateManager) {
  64971. var _this = this;
  64972. this._templateManager = _templateManager;
  64973. this._callbacksContainer = {};
  64974. this._templateManager.onEventTriggered.add(function (eventData) {
  64975. _this._eventTriggered(eventData);
  64976. });
  64977. }
  64978. /**
  64979. * Register a new callback to a specific template.
  64980. * The best example for the usage can be found in the DefaultViewer
  64981. *
  64982. * @param templateName the templateName to register the event to
  64983. * @param callback The callback to be executed
  64984. * @param eventType the type of event to register
  64985. * @param selector an optional selector. if not defined the parent object in the template will be selected
  64986. */
  64987. EventManager.prototype.registerCallback = function (templateName, callback, eventType, selector) {
  64988. if (!this._callbacksContainer[templateName]) {
  64989. this._callbacksContainer[templateName] = [];
  64990. }
  64991. this._callbacksContainer[templateName].push({
  64992. eventType: eventType,
  64993. callback: callback,
  64994. selector: selector
  64995. });
  64996. };
  64997. /**
  64998. * This will remove a registered event from the defined template.
  64999. * Each one of the variables apart from the template name are optional, but one must be provided.
  65000. *
  65001. * @param templateName the templateName
  65002. * @param callback the callback to remove (optional)
  65003. * @param eventType the event type to remove (optional)
  65004. * @param selector the selector from which to remove the event (optional)
  65005. */
  65006. EventManager.prototype.unregisterCallback = function (templateName, callback, eventType, selector) {
  65007. var callbackDefs = this._callbacksContainer[templateName] || [];
  65008. this._callbacksContainer[templateName] = callbackDefs.filter(function (callbackDef) { return (!callbackDef.eventType || callbackDef.eventType === eventType) && (!callbackDef.selector || callbackDef.selector === selector); });
  65009. };
  65010. EventManager.prototype._eventTriggered = function (data) {
  65011. var templateName = data.template.name;
  65012. var eventType = data.event.type;
  65013. var selector = data.selector;
  65014. var callbackDefs = this._callbacksContainer[templateName] || [];
  65015. callbackDefs.filter(function (callbackDef) { return (!callbackDef.eventType || callbackDef.eventType === eventType) && (!callbackDef.selector || callbackDef.selector === selector); }).forEach(function (callbackDef) {
  65016. callbackDef.callback(data);
  65017. });
  65018. };
  65019. /**
  65020. * Dispose the event manager
  65021. */
  65022. EventManager.prototype.dispose = function () {
  65023. this._callbacksContainer = {};
  65024. };
  65025. return EventManager;
  65026. }());
  65027. exports.EventManager = EventManager;
  65028. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRNYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RlbXBsYXRpbmcvZXZlbnRNYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBR0E7OztHQUdHO0FBQ0g7SUFJSSxzQkFBb0IsZ0JBQWlDO1FBQXJELGlCQUtDO1FBTG1CLHFCQUFnQixHQUFoQixnQkFBZ0IsQ0FBaUI7UUFDakQsSUFBSSxDQUFDLG1CQUFtQixHQUFHLEVBQUUsQ0FBQztRQUM5QixJQUF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tBQUssUUFBUSxDQUFDLEVBQS9ILENBQStILENBQUMsQ0FBQztJQUNqTixDQUFDO0lBRU8sc0NBQWUsR0FBdkIsVUFBd0IsSUFBbUI7UUFDdkMsSUFBSSxZQUFZLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUM7UUFDdEMsSUFBSSxTQUFTLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUM7UUFDaEMsSUFBSSxRQUFRLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQztRQUU3QixJQUFJLFlBQVksR0FBRyxJQUFJLENBQUMsbUJBQW1CLENBQUMsWUFBWSxDQUFDLElBQUksRUFBRSxDQUFDO1FBQ2hFLFlBQVksQ0FBQyxNQUFNLENBQUMsVUFBQSxXQUFXLElBQUksT0FBQSxDQUFDLENBQUMsV0FBVyxDQUFDLFNBQVMsSUFBSSxXQUFXLENBQUMsU0FBUyxLQUFLLFNBQVMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxXQUFXLENBQUMsUUFBUSxJQUFJLFdBQVcsQ0FBQyxRQUFRLEtBQUssUUFBUSxDQUFDLEVBQS9ILENBQStILENBQUMsQ0FBQyxPQUFPLENBQUMsVUFBQSxXQUFXO1lBQ25MLFdBQVcsQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDL0IsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDO0lBRUQ7O09BRUc7SUFDSSw4QkFBTyxHQUFkO1FBQ0ksSUFBSSxDQUFDLG1CQUFtQixHQUFHLEVBQUUsQ0FBQztJQUNsQyxDQUFDO0lBQ0wsbUJBQUM7QUFBRCxDQUFDLEFBOURELElBOERDO0FBOURZLG9DQUFZIn0=
  65029. /***/ }),
  65030. /* 64 */
  65031. /***/ (function(module, exports, __webpack_require__) {
  65032. /*!
  65033. * PEP v0.4.3 | https://github.com/jquery/PEP
  65034. * Copyright jQuery Foundation and other contributors | http://jquery.org/license
  65035. */
  65036. (function (global, factory) {
  65037. true ? module.exports = factory() :
  65038. typeof define === 'function' && define.amd ? define(factory) :
  65039. (global.PointerEventsPolyfill = factory());
  65040. }(this, function () { 'use strict';
  65041. /**
  65042. * This is the constructor for new PointerEvents.
  65043. *
  65044. * New Pointer Events must be given a type, and an optional dictionary of
  65045. * initialization properties.
  65046. *
  65047. * Due to certain platform requirements, events returned from the constructor
  65048. * identify as MouseEvents.
  65049. *
  65050. * @constructor
  65051. * @param {String} inType The type of the event to create.
  65052. * @param {Object} [inDict] An optional dictionary of initial event properties.
  65053. * @return {Event} A new PointerEvent of type `inType`, initialized with properties from `inDict`.
  65054. */
  65055. var MOUSE_PROPS = [
  65056. 'bubbles',
  65057. 'cancelable',
  65058. 'view',
  65059. 'detail',
  65060. 'screenX',
  65061. 'screenY',
  65062. 'clientX',
  65063. 'clientY',
  65064. 'ctrlKey',
  65065. 'altKey',
  65066. 'shiftKey',
  65067. 'metaKey',
  65068. 'button',
  65069. 'relatedTarget',
  65070. 'pageX',
  65071. 'pageY'
  65072. ];
  65073. var MOUSE_DEFAULTS = [
  65074. false,
  65075. false,
  65076. null,
  65077. null,
  65078. 0,
  65079. 0,
  65080. 0,
  65081. 0,
  65082. false,
  65083. false,
  65084. false,
  65085. false,
  65086. 0,
  65087. null,
  65088. 0,
  65089. 0
  65090. ];
  65091. function PointerEvent(inType, inDict) {
  65092. inDict = inDict || Object.create(null);
  65093. var e = document.createEvent('Event');
  65094. e.initEvent(inType, inDict.bubbles || false, inDict.cancelable || false);
  65095. // define inherited MouseEvent properties
  65096. // skip bubbles and cancelable since they're set above in initEvent()
  65097. for (var i = 2, p; i < MOUSE_PROPS.length; i++) {
  65098. p = MOUSE_PROPS[i];
  65099. e[p] = inDict[p] || MOUSE_DEFAULTS[i];
  65100. }
  65101. e.buttons = inDict.buttons || 0;
  65102. // Spec requires that pointers without pressure specified use 0.5 for down
  65103. // state and 0 for up state.
  65104. var pressure = 0;
  65105. if (inDict.pressure && e.buttons) {
  65106. pressure = inDict.pressure;
  65107. } else {
  65108. pressure = e.buttons ? 0.5 : 0;
  65109. }
  65110. // add x/y properties aliased to clientX/Y
  65111. e.x = e.clientX;
  65112. e.y = e.clientY;
  65113. // define the properties of the PointerEvent interface
  65114. e.pointerId = inDict.pointerId || 0;
  65115. e.width = inDict.width || 0;
  65116. e.height = inDict.height || 0;
  65117. e.pressure = pressure;
  65118. e.tiltX = inDict.tiltX || 0;
  65119. e.tiltY = inDict.tiltY || 0;
  65120. e.twist = inDict.twist || 0;
  65121. e.tangentialPressure = inDict.tangentialPressure || 0;
  65122. e.pointerType = inDict.pointerType || '';
  65123. e.hwTimestamp = inDict.hwTimestamp || 0;
  65124. e.isPrimary = inDict.isPrimary || false;
  65125. return e;
  65126. }
  65127. /**
  65128. * This module implements a map of pointer states
  65129. */
  65130. var USE_MAP = window.Map && window.Map.prototype.forEach;
  65131. var PointerMap = USE_MAP ? Map : SparseArrayMap;
  65132. function SparseArrayMap() {
  65133. this.array = [];
  65134. this.size = 0;
  65135. }
  65136. SparseArrayMap.prototype = {
  65137. set: function(k, v) {
  65138. if (v === undefined) {
  65139. return this.delete(k);
  65140. }
  65141. if (!this.has(k)) {
  65142. this.size++;
  65143. }
  65144. this.array[k] = v;
  65145. },
  65146. has: function(k) {
  65147. return this.array[k] !== undefined;
  65148. },
  65149. delete: function(k) {
  65150. if (this.has(k)) {
  65151. delete this.array[k];
  65152. this.size--;
  65153. }
  65154. },
  65155. get: function(k) {
  65156. return this.array[k];
  65157. },
  65158. clear: function() {
  65159. this.array.length = 0;
  65160. this.size = 0;
  65161. },
  65162. // return value, key, map
  65163. forEach: function(callback, thisArg) {
  65164. return this.array.forEach(function(v, k) {
  65165. callback.call(thisArg, v, k, this);
  65166. }, this);
  65167. }
  65168. };
  65169. var CLONE_PROPS = [
  65170. // MouseEvent
  65171. 'bubbles',
  65172. 'cancelable',
  65173. 'view',
  65174. 'detail',
  65175. 'screenX',
  65176. 'screenY',
  65177. 'clientX',
  65178. 'clientY',
  65179. 'ctrlKey',
  65180. 'altKey',
  65181. 'shiftKey',
  65182. 'metaKey',
  65183. 'button',
  65184. 'relatedTarget',
  65185. // DOM Level 3
  65186. 'buttons',
  65187. // PointerEvent
  65188. 'pointerId',
  65189. 'width',
  65190. 'height',
  65191. 'pressure',
  65192. 'tiltX',
  65193. 'tiltY',
  65194. 'pointerType',
  65195. 'hwTimestamp',
  65196. 'isPrimary',
  65197. // event instance
  65198. 'type',
  65199. 'target',
  65200. 'currentTarget',
  65201. 'which',
  65202. 'pageX',
  65203. 'pageY',
  65204. 'timeStamp'
  65205. ];
  65206. var CLONE_DEFAULTS = [
  65207. // MouseEvent
  65208. false,
  65209. false,
  65210. null,
  65211. null,
  65212. 0,
  65213. 0,
  65214. 0,
  65215. 0,
  65216. false,
  65217. false,
  65218. false,
  65219. false,
  65220. 0,
  65221. null,
  65222. // DOM Level 3
  65223. 0,
  65224. // PointerEvent
  65225. 0,
  65226. 0,
  65227. 0,
  65228. 0,
  65229. 0,
  65230. 0,
  65231. '',
  65232. 0,
  65233. false,
  65234. // event instance
  65235. '',
  65236. null,
  65237. null,
  65238. 0,
  65239. 0,
  65240. 0,
  65241. 0
  65242. ];
  65243. var BOUNDARY_EVENTS = {
  65244. 'pointerover': 1,
  65245. 'pointerout': 1,
  65246. 'pointerenter': 1,
  65247. 'pointerleave': 1
  65248. };
  65249. var HAS_SVG_INSTANCE = (typeof SVGElementInstance !== 'undefined');
  65250. /**
  65251. * This module is for normalizing events. Mouse and Touch events will be
  65252. * collected here, and fire PointerEvents that have the same semantics, no
  65253. * matter the source.
  65254. * Events fired:
  65255. * - pointerdown: a pointing is added
  65256. * - pointerup: a pointer is removed
  65257. * - pointermove: a pointer is moved
  65258. * - pointerover: a pointer crosses into an element
  65259. * - pointerout: a pointer leaves an element
  65260. * - pointercancel: a pointer will no longer generate events
  65261. */
  65262. var dispatcher = {
  65263. pointermap: new PointerMap(),
  65264. eventMap: Object.create(null),
  65265. captureInfo: Object.create(null),
  65266. // Scope objects for native events.
  65267. // This exists for ease of testing.
  65268. eventSources: Object.create(null),
  65269. eventSourceList: [],
  65270. /**
  65271. * Add a new event source that will generate pointer events.
  65272. *
  65273. * `inSource` must contain an array of event names named `events`, and
  65274. * functions with the names specified in the `events` array.
  65275. * @param {string} name A name for the event source
  65276. * @param {Object} source A new source of platform events.
  65277. */
  65278. registerSource: function(name, source) {
  65279. var s = source;
  65280. var newEvents = s.events;
  65281. if (newEvents) {
  65282. newEvents.forEach(function(e) {
  65283. if (s[e]) {
  65284. this.eventMap[e] = s[e].bind(s);
  65285. }
  65286. }, this);
  65287. this.eventSources[name] = s;
  65288. this.eventSourceList.push(s);
  65289. }
  65290. },
  65291. register: function(element) {
  65292. var l = this.eventSourceList.length;
  65293. for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) {
  65294. // call eventsource register
  65295. es.register.call(es, element);
  65296. }
  65297. },
  65298. unregister: function(element) {
  65299. var l = this.eventSourceList.length;
  65300. for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) {
  65301. // call eventsource register
  65302. es.unregister.call(es, element);
  65303. }
  65304. },
  65305. contains: /*scope.external.contains || */function(container, contained) {
  65306. try {
  65307. return container.contains(contained);
  65308. } catch (ex) {
  65309. // most likely: https://bugzilla.mozilla.org/show_bug.cgi?id=208427
  65310. return false;
  65311. }
  65312. },
  65313. // EVENTS
  65314. down: function(inEvent) {
  65315. inEvent.bubbles = true;
  65316. this.fireEvent('pointerdown', inEvent);
  65317. },
  65318. move: function(inEvent) {
  65319. inEvent.bubbles = true;
  65320. this.fireEvent('pointermove', inEvent);
  65321. },
  65322. up: function(inEvent) {
  65323. inEvent.bubbles = true;
  65324. this.fireEvent('pointerup', inEvent);
  65325. },
  65326. enter: function(inEvent) {
  65327. inEvent.bubbles = false;
  65328. this.fireEvent('pointerenter', inEvent);
  65329. },
  65330. leave: function(inEvent) {
  65331. inEvent.bubbles = false;
  65332. this.fireEvent('pointerleave', inEvent);
  65333. },
  65334. over: function(inEvent) {
  65335. inEvent.bubbles = true;
  65336. this.fireEvent('pointerover', inEvent);
  65337. },
  65338. out: function(inEvent) {
  65339. inEvent.bubbles = true;
  65340. this.fireEvent('pointerout', inEvent);
  65341. },
  65342. cancel: function(inEvent) {
  65343. inEvent.bubbles = true;
  65344. this.fireEvent('pointercancel', inEvent);
  65345. },
  65346. leaveOut: function(event) {
  65347. this.out(event);
  65348. this.propagate(event, this.leave, false);
  65349. },
  65350. enterOver: function(event) {
  65351. this.over(event);
  65352. this.propagate(event, this.enter, true);
  65353. },
  65354. // LISTENER LOGIC
  65355. eventHandler: function(inEvent) {
  65356. // This is used to prevent multiple dispatch of pointerevents from
  65357. // platform events. This can happen when two elements in different scopes
  65358. // are set up to create pointer events, which is relevant to Shadow DOM.
  65359. if (inEvent._handledByPE) {
  65360. return;
  65361. }
  65362. var type = inEvent.type;
  65363. var fn = this.eventMap && this.eventMap[type];
  65364. if (fn) {
  65365. fn(inEvent);
  65366. }
  65367. inEvent._handledByPE = true;
  65368. },
  65369. // set up event listeners
  65370. listen: function(target, events) {
  65371. events.forEach(function(e) {
  65372. this.addEvent(target, e);
  65373. }, this);
  65374. },
  65375. // remove event listeners
  65376. unlisten: function(target, events) {
  65377. events.forEach(function(e) {
  65378. this.removeEvent(target, e);
  65379. }, this);
  65380. },
  65381. addEvent: /*scope.external.addEvent || */function(target, eventName) {
  65382. target.addEventListener(eventName, this.boundHandler);
  65383. },
  65384. removeEvent: /*scope.external.removeEvent || */function(target, eventName) {
  65385. target.removeEventListener(eventName, this.boundHandler);
  65386. },
  65387. // EVENT CREATION AND TRACKING
  65388. /**
  65389. * Creates a new Event of type `inType`, based on the information in
  65390. * `inEvent`.
  65391. *
  65392. * @param {string} inType A string representing the type of event to create
  65393. * @param {Event} inEvent A platform event with a target
  65394. * @return {Event} A PointerEvent of type `inType`
  65395. */
  65396. makeEvent: function(inType, inEvent) {
  65397. // relatedTarget must be null if pointer is captured
  65398. if (this.captureInfo[inEvent.pointerId]) {
  65399. inEvent.relatedTarget = null;
  65400. }
  65401. var e = new PointerEvent(inType, inEvent);
  65402. if (inEvent.preventDefault) {
  65403. e.preventDefault = inEvent.preventDefault;
  65404. }
  65405. e._target = e._target || inEvent.target;
  65406. return e;
  65407. },
  65408. // make and dispatch an event in one call
  65409. fireEvent: function(inType, inEvent) {
  65410. var e = this.makeEvent(inType, inEvent);
  65411. return this.dispatchEvent(e);
  65412. },
  65413. /**
  65414. * Returns a snapshot of inEvent, with writable properties.
  65415. *
  65416. * @param {Event} inEvent An event that contains properties to copy.
  65417. * @return {Object} An object containing shallow copies of `inEvent`'s
  65418. * properties.
  65419. */
  65420. cloneEvent: function(inEvent) {
  65421. var eventCopy = Object.create(null);
  65422. var p;
  65423. for (var i = 0; i < CLONE_PROPS.length; i++) {
  65424. p = CLONE_PROPS[i];
  65425. eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
  65426. // Work around SVGInstanceElement shadow tree
  65427. // Return the <use> element that is represented by the instance for Safari, Chrome, IE.
  65428. // This is the behavior implemented by Firefox.
  65429. if (HAS_SVG_INSTANCE && (p === 'target' || p === 'relatedTarget')) {
  65430. if (eventCopy[p] instanceof SVGElementInstance) {
  65431. eventCopy[p] = eventCopy[p].correspondingUseElement;
  65432. }
  65433. }
  65434. }
  65435. // keep the semantics of preventDefault
  65436. if (inEvent.preventDefault) {
  65437. eventCopy.preventDefault = function() {
  65438. inEvent.preventDefault();
  65439. };
  65440. }
  65441. return eventCopy;
  65442. },
  65443. getTarget: function(inEvent) {
  65444. var capture = this.captureInfo[inEvent.pointerId];
  65445. if (!capture) {
  65446. return inEvent._target;
  65447. }
  65448. if (inEvent._target === capture || !(inEvent.type in BOUNDARY_EVENTS)) {
  65449. return capture;
  65450. }
  65451. },
  65452. propagate: function(event, fn, propagateDown) {
  65453. var target = event.target;
  65454. var targets = [];
  65455. // Order of conditions due to document.contains() missing in IE.
  65456. while (target !== document && !target.contains(event.relatedTarget)) {
  65457. targets.push(target);
  65458. target = target.parentNode;
  65459. // Touch: Do not propagate if node is detached.
  65460. if (!target) {
  65461. return;
  65462. }
  65463. }
  65464. if (propagateDown) {
  65465. targets.reverse();
  65466. }
  65467. targets.forEach(function(target) {
  65468. event.target = target;
  65469. fn.call(this, event);
  65470. }, this);
  65471. },
  65472. setCapture: function(inPointerId, inTarget, skipDispatch) {
  65473. if (this.captureInfo[inPointerId]) {
  65474. this.releaseCapture(inPointerId, skipDispatch);
  65475. }
  65476. this.captureInfo[inPointerId] = inTarget;
  65477. this.implicitRelease = this.releaseCapture.bind(this, inPointerId, skipDispatch);
  65478. document.addEventListener('pointerup', this.implicitRelease);
  65479. document.addEventListener('pointercancel', this.implicitRelease);
  65480. var e = new PointerEvent('gotpointercapture');
  65481. e.pointerId = inPointerId;
  65482. e._target = inTarget;
  65483. if (!skipDispatch) {
  65484. this.asyncDispatchEvent(e);
  65485. }
  65486. },
  65487. releaseCapture: function(inPointerId, skipDispatch) {
  65488. var t = this.captureInfo[inPointerId];
  65489. if (!t) {
  65490. return;
  65491. }
  65492. this.captureInfo[inPointerId] = undefined;
  65493. document.removeEventListener('pointerup', this.implicitRelease);
  65494. document.removeEventListener('pointercancel', this.implicitRelease);
  65495. var e = new PointerEvent('lostpointercapture');
  65496. e.pointerId = inPointerId;
  65497. e._target = t;
  65498. if (!skipDispatch) {
  65499. this.asyncDispatchEvent(e);
  65500. }
  65501. },
  65502. /**
  65503. * Dispatches the event to its target.
  65504. *
  65505. * @param {Event} inEvent The event to be dispatched.
  65506. * @return {Boolean} True if an event handler returns true, false otherwise.
  65507. */
  65508. dispatchEvent: /*scope.external.dispatchEvent || */function(inEvent) {
  65509. var t = this.getTarget(inEvent);
  65510. if (t) {
  65511. return t.dispatchEvent(inEvent);
  65512. }
  65513. },
  65514. asyncDispatchEvent: function(inEvent) {
  65515. requestAnimationFrame(this.dispatchEvent.bind(this, inEvent));
  65516. }
  65517. };
  65518. dispatcher.boundHandler = dispatcher.eventHandler.bind(dispatcher);
  65519. var targeting = {
  65520. shadow: function(inEl) {
  65521. if (inEl) {
  65522. return inEl.shadowRoot || inEl.webkitShadowRoot;
  65523. }
  65524. },
  65525. canTarget: function(shadow) {
  65526. return shadow && Boolean(shadow.elementFromPoint);
  65527. },
  65528. targetingShadow: function(inEl) {
  65529. var s = this.shadow(inEl);
  65530. if (this.canTarget(s)) {
  65531. return s;
  65532. }
  65533. },
  65534. olderShadow: function(shadow) {
  65535. var os = shadow.olderShadowRoot;
  65536. if (!os) {
  65537. var se = shadow.querySelector('shadow');
  65538. if (se) {
  65539. os = se.olderShadowRoot;
  65540. }
  65541. }
  65542. return os;
  65543. },
  65544. allShadows: function(element) {
  65545. var shadows = [];
  65546. var s = this.shadow(element);
  65547. while (s) {
  65548. shadows.push(s);
  65549. s = this.olderShadow(s);
  65550. }
  65551. return shadows;
  65552. },
  65553. searchRoot: function(inRoot, x, y) {
  65554. if (inRoot) {
  65555. var t = inRoot.elementFromPoint(x, y);
  65556. var st, sr;
  65557. // is element a shadow host?
  65558. sr = this.targetingShadow(t);
  65559. while (sr) {
  65560. // find the the element inside the shadow root
  65561. st = sr.elementFromPoint(x, y);
  65562. if (!st) {
  65563. // check for older shadows
  65564. sr = this.olderShadow(sr);
  65565. } else {
  65566. // shadowed element may contain a shadow root
  65567. var ssr = this.targetingShadow(st);
  65568. return this.searchRoot(ssr, x, y) || st;
  65569. }
  65570. }
  65571. // light dom element is the target
  65572. return t;
  65573. }
  65574. },
  65575. owner: function(element) {
  65576. var s = element;
  65577. // walk up until you hit the shadow root or document
  65578. while (s.parentNode) {
  65579. s = s.parentNode;
  65580. }
  65581. // the owner element is expected to be a Document or ShadowRoot
  65582. if (s.nodeType !== Node.DOCUMENT_NODE && s.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
  65583. s = document;
  65584. }
  65585. return s;
  65586. },
  65587. findTarget: function(inEvent) {
  65588. var x = inEvent.clientX;
  65589. var y = inEvent.clientY;
  65590. // if the listener is in the shadow root, it is much faster to start there
  65591. var s = this.owner(inEvent.target);
  65592. // if x, y is not in this root, fall back to document search
  65593. if (!s.elementFromPoint(x, y)) {
  65594. s = document;
  65595. }
  65596. return this.searchRoot(s, x, y);
  65597. }
  65598. };
  65599. var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
  65600. var map = Array.prototype.map.call.bind(Array.prototype.map);
  65601. var toArray = Array.prototype.slice.call.bind(Array.prototype.slice);
  65602. var filter = Array.prototype.filter.call.bind(Array.prototype.filter);
  65603. var MO = window.MutationObserver || window.WebKitMutationObserver;
  65604. var SELECTOR = '[touch-action]';
  65605. var OBSERVER_INIT = {
  65606. subtree: true,
  65607. childList: true,
  65608. attributes: true,
  65609. attributeOldValue: true,
  65610. attributeFilter: ['touch-action']
  65611. };
  65612. function Installer(add, remove, changed, binder) {
  65613. this.addCallback = add.bind(binder);
  65614. this.removeCallback = remove.bind(binder);
  65615. this.changedCallback = changed.bind(binder);
  65616. if (MO) {
  65617. this.observer = new MO(this.mutationWatcher.bind(this));
  65618. }
  65619. }
  65620. Installer.prototype = {
  65621. watchSubtree: function(target) {
  65622. // Only watch scopes that can target find, as these are top-level.
  65623. // Otherwise we can see duplicate additions and removals that add noise.
  65624. //
  65625. // TODO(dfreedman): For some instances with ShadowDOMPolyfill, we can see
  65626. // a removal without an insertion when a node is redistributed among
  65627. // shadows. Since it all ends up correct in the document, watching only
  65628. // the document will yield the correct mutations to watch.
  65629. if (this.observer && targeting.canTarget(target)) {
  65630. this.observer.observe(target, OBSERVER_INIT);
  65631. }
  65632. },
  65633. enableOnSubtree: function(target) {
  65634. this.watchSubtree(target);
  65635. if (target === document && document.readyState !== 'complete') {
  65636. this.installOnLoad();
  65637. } else {
  65638. this.installNewSubtree(target);
  65639. }
  65640. },
  65641. installNewSubtree: function(target) {
  65642. forEach(this.findElements(target), this.addElement, this);
  65643. },
  65644. findElements: function(target) {
  65645. if (target.querySelectorAll) {
  65646. return target.querySelectorAll(SELECTOR);
  65647. }
  65648. return [];
  65649. },
  65650. removeElement: function(el) {
  65651. this.removeCallback(el);
  65652. },
  65653. addElement: function(el) {
  65654. this.addCallback(el);
  65655. },
  65656. elementChanged: function(el, oldValue) {
  65657. this.changedCallback(el, oldValue);
  65658. },
  65659. concatLists: function(accum, list) {
  65660. return accum.concat(toArray(list));
  65661. },
  65662. // register all touch-action = none nodes on document load
  65663. installOnLoad: function() {
  65664. document.addEventListener('readystatechange', function() {
  65665. if (document.readyState === 'complete') {
  65666. this.installNewSubtree(document);
  65667. }
  65668. }.bind(this));
  65669. },
  65670. isElement: function(n) {
  65671. return n.nodeType === Node.ELEMENT_NODE;
  65672. },
  65673. flattenMutationTree: function(inNodes) {
  65674. // find children with touch-action
  65675. var tree = map(inNodes, this.findElements, this);
  65676. // make sure the added nodes are accounted for
  65677. tree.push(filter(inNodes, this.isElement));
  65678. // flatten the list
  65679. return tree.reduce(this.concatLists, []);
  65680. },
  65681. mutationWatcher: function(mutations) {
  65682. mutations.forEach(this.mutationHandler, this);
  65683. },
  65684. mutationHandler: function(m) {
  65685. if (m.type === 'childList') {
  65686. var added = this.flattenMutationTree(m.addedNodes);
  65687. added.forEach(this.addElement, this);
  65688. var removed = this.flattenMutationTree(m.removedNodes);
  65689. removed.forEach(this.removeElement, this);
  65690. } else if (m.type === 'attributes') {
  65691. this.elementChanged(m.target, m.oldValue);
  65692. }
  65693. }
  65694. };
  65695. function shadowSelector(v) {
  65696. return 'body /shadow-deep/ ' + selector(v);
  65697. }
  65698. function selector(v) {
  65699. return '[touch-action="' + v + '"]';
  65700. }
  65701. function rule(v) {
  65702. return '{ -ms-touch-action: ' + v + '; touch-action: ' + v + '; }';
  65703. }
  65704. var attrib2css = [
  65705. 'none',
  65706. 'auto',
  65707. 'pan-x',
  65708. 'pan-y',
  65709. {
  65710. rule: 'pan-x pan-y',
  65711. selectors: [
  65712. 'pan-x pan-y',
  65713. 'pan-y pan-x'
  65714. ]
  65715. }
  65716. ];
  65717. var styles = '';
  65718. // only install stylesheet if the browser has touch action support
  65719. var hasNativePE = window.PointerEvent || window.MSPointerEvent;
  65720. // only add shadow selectors if shadowdom is supported
  65721. var hasShadowRoot = !window.ShadowDOMPolyfill && document.head.createShadowRoot;
  65722. function applyAttributeStyles() {
  65723. if (hasNativePE) {
  65724. attrib2css.forEach(function(r) {
  65725. if (String(r) === r) {
  65726. styles += selector(r) + rule(r) + '\n';
  65727. if (hasShadowRoot) {
  65728. styles += shadowSelector(r) + rule(r) + '\n';
  65729. }
  65730. } else {
  65731. styles += r.selectors.map(selector) + rule(r.rule) + '\n';
  65732. if (hasShadowRoot) {
  65733. styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
  65734. }
  65735. }
  65736. });
  65737. var el = document.createElement('style');
  65738. el.textContent = styles;
  65739. document.head.appendChild(el);
  65740. }
  65741. }
  65742. var pointermap = dispatcher.pointermap;
  65743. // radius around touchend that swallows mouse events
  65744. var DEDUP_DIST = 25;
  65745. // left, middle, right, back, forward
  65746. var BUTTON_TO_BUTTONS = [1, 4, 2, 8, 16];
  65747. var HAS_BUTTONS = false;
  65748. try {
  65749. HAS_BUTTONS = new MouseEvent('test', { buttons: 1 }).buttons === 1;
  65750. } catch (e) {}
  65751. // handler block for native mouse events
  65752. var mouseEvents = {
  65753. POINTER_ID: 1,
  65754. POINTER_TYPE: 'mouse',
  65755. events: [
  65756. 'mousedown',
  65757. 'mousemove',
  65758. 'mouseup',
  65759. 'mouseover',
  65760. 'mouseout'
  65761. ],
  65762. register: function(target) {
  65763. dispatcher.listen(target, this.events);
  65764. },
  65765. unregister: function(target) {
  65766. dispatcher.unlisten(target, this.events);
  65767. },
  65768. lastTouches: [],
  65769. // collide with the global mouse listener
  65770. isEventSimulatedFromTouch: function(inEvent) {
  65771. var lts = this.lastTouches;
  65772. var x = inEvent.clientX;
  65773. var y = inEvent.clientY;
  65774. for (var i = 0, l = lts.length, t; i < l && (t = lts[i]); i++) {
  65775. // simulated mouse events will be swallowed near a primary touchend
  65776. var dx = Math.abs(x - t.x);
  65777. var dy = Math.abs(y - t.y);
  65778. if (dx <= DEDUP_DIST && dy <= DEDUP_DIST) {
  65779. return true;
  65780. }
  65781. }
  65782. },
  65783. prepareEvent: function(inEvent) {
  65784. var e = dispatcher.cloneEvent(inEvent);
  65785. // forward mouse preventDefault
  65786. var pd = e.preventDefault;
  65787. e.preventDefault = function() {
  65788. inEvent.preventDefault();
  65789. pd();
  65790. };
  65791. e.pointerId = this.POINTER_ID;
  65792. e.isPrimary = true;
  65793. e.pointerType = this.POINTER_TYPE;
  65794. return e;
  65795. },
  65796. prepareButtonsForMove: function(e, inEvent) {
  65797. var p = pointermap.get(this.POINTER_ID);
  65798. // Update buttons state after possible out-of-document mouseup.
  65799. if (inEvent.which === 0 || !p) {
  65800. e.buttons = 0;
  65801. } else {
  65802. e.buttons = p.buttons;
  65803. }
  65804. inEvent.buttons = e.buttons;
  65805. },
  65806. mousedown: function(inEvent) {
  65807. if (!this.isEventSimulatedFromTouch(inEvent)) {
  65808. var p = pointermap.get(this.POINTER_ID);
  65809. var e = this.prepareEvent(inEvent);
  65810. if (!HAS_BUTTONS) {
  65811. e.buttons = BUTTON_TO_BUTTONS[e.button];
  65812. if (p) { e.buttons |= p.buttons; }
  65813. inEvent.buttons = e.buttons;
  65814. }
  65815. pointermap.set(this.POINTER_ID, inEvent);
  65816. if (!p || p.buttons === 0) {
  65817. dispatcher.down(e);
  65818. } else {
  65819. dispatcher.move(e);
  65820. }
  65821. }
  65822. },
  65823. mousemove: function(inEvent) {
  65824. if (!this.isEventSimulatedFromTouch(inEvent)) {
  65825. var e = this.prepareEvent(inEvent);
  65826. if (!HAS_BUTTONS) { this.prepareButtonsForMove(e, inEvent); }
  65827. e.button = -1;
  65828. pointermap.set(this.POINTER_ID, inEvent);
  65829. dispatcher.move(e);
  65830. }
  65831. },
  65832. mouseup: function(inEvent) {
  65833. if (!this.isEventSimulatedFromTouch(inEvent)) {
  65834. var p = pointermap.get(this.POINTER_ID);
  65835. var e = this.prepareEvent(inEvent);
  65836. if (!HAS_BUTTONS) {
  65837. var up = BUTTON_TO_BUTTONS[e.button];
  65838. // Produces wrong state of buttons in Browsers without `buttons` support
  65839. // when a mouse button that was pressed outside the document is released
  65840. // inside and other buttons are still pressed down.
  65841. e.buttons = p ? p.buttons & ~up : 0;
  65842. inEvent.buttons = e.buttons;
  65843. }
  65844. pointermap.set(this.POINTER_ID, inEvent);
  65845. // Support: Firefox <=44 only
  65846. // FF Ubuntu includes the lifted button in the `buttons` property on
  65847. // mouseup.
  65848. // https://bugzilla.mozilla.org/show_bug.cgi?id=1223366
  65849. e.buttons &= ~BUTTON_TO_BUTTONS[e.button];
  65850. if (e.buttons === 0) {
  65851. dispatcher.up(e);
  65852. } else {
  65853. dispatcher.move(e);
  65854. }
  65855. }
  65856. },
  65857. mouseover: function(inEvent) {
  65858. if (!this.isEventSimulatedFromTouch(inEvent)) {
  65859. var e = this.prepareEvent(inEvent);
  65860. if (!HAS_BUTTONS) { this.prepareButtonsForMove(e, inEvent); }
  65861. e.button = -1;
  65862. pointermap.set(this.POINTER_ID, inEvent);
  65863. dispatcher.enterOver(e);
  65864. }
  65865. },
  65866. mouseout: function(inEvent) {
  65867. if (!this.isEventSimulatedFromTouch(inEvent)) {
  65868. var e = this.prepareEvent(inEvent);
  65869. if (!HAS_BUTTONS) { this.prepareButtonsForMove(e, inEvent); }
  65870. e.button = -1;
  65871. dispatcher.leaveOut(e);
  65872. }
  65873. },
  65874. cancel: function(inEvent) {
  65875. var e = this.prepareEvent(inEvent);
  65876. dispatcher.cancel(e);
  65877. this.deactivateMouse();
  65878. },
  65879. deactivateMouse: function() {
  65880. pointermap.delete(this.POINTER_ID);
  65881. }
  65882. };
  65883. var captureInfo = dispatcher.captureInfo;
  65884. var findTarget = targeting.findTarget.bind(targeting);
  65885. var allShadows = targeting.allShadows.bind(targeting);
  65886. var pointermap$1 = dispatcher.pointermap;
  65887. // This should be long enough to ignore compat mouse events made by touch
  65888. var DEDUP_TIMEOUT = 2500;
  65889. var CLICK_COUNT_TIMEOUT = 200;
  65890. var ATTRIB = 'touch-action';
  65891. var INSTALLER;
  65892. // handler block for native touch events
  65893. var touchEvents = {
  65894. events: [
  65895. 'touchstart',
  65896. 'touchmove',
  65897. 'touchend',
  65898. 'touchcancel'
  65899. ],
  65900. register: function(target) {
  65901. INSTALLER.enableOnSubtree(target);
  65902. },
  65903. unregister: function() {
  65904. // TODO(dfreedman): is it worth it to disconnect the MO?
  65905. },
  65906. elementAdded: function(el) {
  65907. var a = el.getAttribute(ATTRIB);
  65908. var st = this.touchActionToScrollType(a);
  65909. if (st) {
  65910. el._scrollType = st;
  65911. dispatcher.listen(el, this.events);
  65912. // set touch-action on shadows as well
  65913. allShadows(el).forEach(function(s) {
  65914. s._scrollType = st;
  65915. dispatcher.listen(s, this.events);
  65916. }, this);
  65917. }
  65918. },
  65919. elementRemoved: function(el) {
  65920. el._scrollType = undefined;
  65921. dispatcher.unlisten(el, this.events);
  65922. // remove touch-action from shadow
  65923. allShadows(el).forEach(function(s) {
  65924. s._scrollType = undefined;
  65925. dispatcher.unlisten(s, this.events);
  65926. }, this);
  65927. },
  65928. elementChanged: function(el, oldValue) {
  65929. var a = el.getAttribute(ATTRIB);
  65930. var st = this.touchActionToScrollType(a);
  65931. var oldSt = this.touchActionToScrollType(oldValue);
  65932. // simply update scrollType if listeners are already established
  65933. if (st && oldSt) {
  65934. el._scrollType = st;
  65935. allShadows(el).forEach(function(s) {
  65936. s._scrollType = st;
  65937. }, this);
  65938. } else if (oldSt) {
  65939. this.elementRemoved(el);
  65940. } else if (st) {
  65941. this.elementAdded(el);
  65942. }
  65943. },
  65944. scrollTypes: {
  65945. EMITTER: 'none',
  65946. XSCROLLER: 'pan-x',
  65947. YSCROLLER: 'pan-y',
  65948. SCROLLER: /^(?:pan-x pan-y)|(?:pan-y pan-x)|auto$/
  65949. },
  65950. touchActionToScrollType: function(touchAction) {
  65951. var t = touchAction;
  65952. var st = this.scrollTypes;
  65953. if (t === 'none') {
  65954. return 'none';
  65955. } else if (t === st.XSCROLLER) {
  65956. return 'X';
  65957. } else if (t === st.YSCROLLER) {
  65958. return 'Y';
  65959. } else if (st.SCROLLER.exec(t)) {
  65960. return 'XY';
  65961. }
  65962. },
  65963. POINTER_TYPE: 'touch',
  65964. firstTouch: null,
  65965. isPrimaryTouch: function(inTouch) {
  65966. return this.firstTouch === inTouch.identifier;
  65967. },
  65968. setPrimaryTouch: function(inTouch) {
  65969. // set primary touch if there no pointers, or the only pointer is the mouse
  65970. if (pointermap$1.size === 0 || (pointermap$1.size === 1 && pointermap$1.has(1))) {
  65971. this.firstTouch = inTouch.identifier;
  65972. this.firstXY = { X: inTouch.clientX, Y: inTouch.clientY };
  65973. this.scrolling = false;
  65974. this.cancelResetClickCount();
  65975. }
  65976. },
  65977. removePrimaryPointer: function(inPointer) {
  65978. if (inPointer.isPrimary) {
  65979. this.firstTouch = null;
  65980. this.firstXY = null;
  65981. this.resetClickCount();
  65982. }
  65983. },
  65984. clickCount: 0,
  65985. resetId: null,
  65986. resetClickCount: function() {
  65987. var fn = function() {
  65988. this.clickCount = 0;
  65989. this.resetId = null;
  65990. }.bind(this);
  65991. this.resetId = setTimeout(fn, CLICK_COUNT_TIMEOUT);
  65992. },
  65993. cancelResetClickCount: function() {
  65994. if (this.resetId) {
  65995. clearTimeout(this.resetId);
  65996. }
  65997. },
  65998. typeToButtons: function(type) {
  65999. var ret = 0;
  66000. if (type === 'touchstart' || type === 'touchmove') {
  66001. ret = 1;
  66002. }
  66003. return ret;
  66004. },
  66005. touchToPointer: function(inTouch) {
  66006. var cte = this.currentTouchEvent;
  66007. var e = dispatcher.cloneEvent(inTouch);
  66008. // We reserve pointerId 1 for Mouse.
  66009. // Touch identifiers can start at 0.
  66010. // Add 2 to the touch identifier for compatibility.
  66011. var id = e.pointerId = inTouch.identifier + 2;
  66012. e.target = captureInfo[id] || findTarget(e);
  66013. e.bubbles = true;
  66014. e.cancelable = true;
  66015. e.detail = this.clickCount;
  66016. e.button = 0;
  66017. e.buttons = this.typeToButtons(cte.type);
  66018. e.width = (inTouch.radiusX || inTouch.webkitRadiusX || 0) * 2;
  66019. e.height = (inTouch.radiusY || inTouch.webkitRadiusY || 0) * 2;
  66020. e.pressure = inTouch.force || inTouch.webkitForce || 0.5;
  66021. e.isPrimary = this.isPrimaryTouch(inTouch);
  66022. e.pointerType = this.POINTER_TYPE;
  66023. // forward modifier keys
  66024. e.altKey = cte.altKey;
  66025. e.ctrlKey = cte.ctrlKey;
  66026. e.metaKey = cte.metaKey;
  66027. e.shiftKey = cte.shiftKey;
  66028. // forward touch preventDefaults
  66029. var self = this;
  66030. e.preventDefault = function() {
  66031. self.scrolling = false;
  66032. self.firstXY = null;
  66033. cte.preventDefault();
  66034. };
  66035. return e;
  66036. },
  66037. processTouches: function(inEvent, inFunction) {
  66038. var tl = inEvent.changedTouches;
  66039. this.currentTouchEvent = inEvent;
  66040. for (var i = 0, t; i < tl.length; i++) {
  66041. t = tl[i];
  66042. inFunction.call(this, this.touchToPointer(t));
  66043. }
  66044. },
  66045. // For single axis scrollers, determines whether the element should emit
  66046. // pointer events or behave as a scroller
  66047. shouldScroll: function(inEvent) {
  66048. if (this.firstXY) {
  66049. var ret;
  66050. var scrollAxis = inEvent.currentTarget._scrollType;
  66051. if (scrollAxis === 'none') {
  66052. // this element is a touch-action: none, should never scroll
  66053. ret = false;
  66054. } else if (scrollAxis === 'XY') {
  66055. // this element should always scroll
  66056. ret = true;
  66057. } else {
  66058. var t = inEvent.changedTouches[0];
  66059. // check the intended scroll axis, and other axis
  66060. var a = scrollAxis;
  66061. var oa = scrollAxis === 'Y' ? 'X' : 'Y';
  66062. var da = Math.abs(t['client' + a] - this.firstXY[a]);
  66063. var doa = Math.abs(t['client' + oa] - this.firstXY[oa]);
  66064. // if delta in the scroll axis > delta other axis, scroll instead of
  66065. // making events
  66066. ret = da >= doa;
  66067. }
  66068. this.firstXY = null;
  66069. return ret;
  66070. }
  66071. },
  66072. findTouch: function(inTL, inId) {
  66073. for (var i = 0, l = inTL.length, t; i < l && (t = inTL[i]); i++) {
  66074. if (t.identifier === inId) {
  66075. return true;
  66076. }
  66077. }
  66078. },
  66079. // In some instances, a touchstart can happen without a touchend. This
  66080. // leaves the pointermap in a broken state.
  66081. // Therefore, on every touchstart, we remove the touches that did not fire a
  66082. // touchend event.
  66083. // To keep state globally consistent, we fire a
  66084. // pointercancel for this "abandoned" touch
  66085. vacuumTouches: function(inEvent) {
  66086. var tl = inEvent.touches;
  66087. // pointermap.size should be < tl.length here, as the touchstart has not
  66088. // been processed yet.
  66089. if (pointermap$1.size >= tl.length) {
  66090. var d = [];
  66091. pointermap$1.forEach(function(value, key) {
  66092. // Never remove pointerId == 1, which is mouse.
  66093. // Touch identifiers are 2 smaller than their pointerId, which is the
  66094. // index in pointermap.
  66095. if (key !== 1 && !this.findTouch(tl, key - 2)) {
  66096. var p = value.out;
  66097. d.push(p);
  66098. }
  66099. }, this);
  66100. d.forEach(this.cancelOut, this);
  66101. }
  66102. },
  66103. touchstart: function(inEvent) {
  66104. this.vacuumTouches(inEvent);
  66105. this.setPrimaryTouch(inEvent.changedTouches[0]);
  66106. this.dedupSynthMouse(inEvent);
  66107. if (!this.scrolling) {
  66108. this.clickCount++;
  66109. this.processTouches(inEvent, this.overDown);
  66110. }
  66111. },
  66112. overDown: function(inPointer) {
  66113. pointermap$1.set(inPointer.pointerId, {
  66114. target: inPointer.target,
  66115. out: inPointer,
  66116. outTarget: inPointer.target
  66117. });
  66118. dispatcher.enterOver(inPointer);
  66119. dispatcher.down(inPointer);
  66120. },
  66121. touchmove: function(inEvent) {
  66122. if (!this.scrolling) {
  66123. if (this.shouldScroll(inEvent)) {
  66124. this.scrolling = true;
  66125. this.touchcancel(inEvent);
  66126. } else {
  66127. inEvent.preventDefault();
  66128. this.processTouches(inEvent, this.moveOverOut);
  66129. }
  66130. }
  66131. },
  66132. moveOverOut: function(inPointer) {
  66133. var event = inPointer;
  66134. var pointer = pointermap$1.get(event.pointerId);
  66135. // a finger drifted off the screen, ignore it
  66136. if (!pointer) {
  66137. return;
  66138. }
  66139. var outEvent = pointer.out;
  66140. var outTarget = pointer.outTarget;
  66141. dispatcher.move(event);
  66142. if (outEvent && outTarget !== event.target) {
  66143. outEvent.relatedTarget = event.target;
  66144. event.relatedTarget = outTarget;
  66145. // recover from retargeting by shadow
  66146. outEvent.target = outTarget;
  66147. if (event.target) {
  66148. dispatcher.leaveOut(outEvent);
  66149. dispatcher.enterOver(event);
  66150. } else {
  66151. // clean up case when finger leaves the screen
  66152. event.target = outTarget;
  66153. event.relatedTarget = null;
  66154. this.cancelOut(event);
  66155. }
  66156. }
  66157. pointer.out = event;
  66158. pointer.outTarget = event.target;
  66159. },
  66160. touchend: function(inEvent) {
  66161. this.dedupSynthMouse(inEvent);
  66162. this.processTouches(inEvent, this.upOut);
  66163. },
  66164. upOut: function(inPointer) {
  66165. if (!this.scrolling) {
  66166. dispatcher.up(inPointer);
  66167. dispatcher.leaveOut(inPointer);
  66168. }
  66169. this.cleanUpPointer(inPointer);
  66170. },
  66171. touchcancel: function(inEvent) {
  66172. this.processTouches(inEvent, this.cancelOut);
  66173. },
  66174. cancelOut: function(inPointer) {
  66175. dispatcher.cancel(inPointer);
  66176. dispatcher.leaveOut(inPointer);
  66177. this.cleanUpPointer(inPointer);
  66178. },
  66179. cleanUpPointer: function(inPointer) {
  66180. pointermap$1.delete(inPointer.pointerId);
  66181. this.removePrimaryPointer(inPointer);
  66182. },
  66183. // prevent synth mouse events from creating pointer events
  66184. dedupSynthMouse: function(inEvent) {
  66185. var lts = mouseEvents.lastTouches;
  66186. var t = inEvent.changedTouches[0];
  66187. // only the primary finger will synth mouse events
  66188. if (this.isPrimaryTouch(t)) {
  66189. // remember x/y of last touch
  66190. var lt = { x: t.clientX, y: t.clientY };
  66191. lts.push(lt);
  66192. var fn = (function(lts, lt) {
  66193. var i = lts.indexOf(lt);
  66194. if (i > -1) {
  66195. lts.splice(i, 1);
  66196. }
  66197. }).bind(null, lts, lt);
  66198. setTimeout(fn, DEDUP_TIMEOUT);
  66199. }
  66200. }
  66201. };
  66202. INSTALLER = new Installer(touchEvents.elementAdded, touchEvents.elementRemoved,
  66203. touchEvents.elementChanged, touchEvents);
  66204. var pointermap$2 = dispatcher.pointermap;
  66205. var HAS_BITMAP_TYPE = window.MSPointerEvent &&
  66206. typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE === 'number';
  66207. var msEvents = {
  66208. events: [
  66209. 'MSPointerDown',
  66210. 'MSPointerMove',
  66211. 'MSPointerUp',
  66212. 'MSPointerOut',
  66213. 'MSPointerOver',
  66214. 'MSPointerCancel',
  66215. 'MSGotPointerCapture',
  66216. 'MSLostPointerCapture'
  66217. ],
  66218. register: function(target) {
  66219. dispatcher.listen(target, this.events);
  66220. },
  66221. unregister: function(target) {
  66222. dispatcher.unlisten(target, this.events);
  66223. },
  66224. POINTER_TYPES: [
  66225. '',
  66226. 'unavailable',
  66227. 'touch',
  66228. 'pen',
  66229. 'mouse'
  66230. ],
  66231. prepareEvent: function(inEvent) {
  66232. var e = inEvent;
  66233. if (HAS_BITMAP_TYPE) {
  66234. e = dispatcher.cloneEvent(inEvent);
  66235. e.pointerType = this.POINTER_TYPES[inEvent.pointerType];
  66236. }
  66237. return e;
  66238. },
  66239. cleanup: function(id) {
  66240. pointermap$2.delete(id);
  66241. },
  66242. MSPointerDown: function(inEvent) {
  66243. pointermap$2.set(inEvent.pointerId, inEvent);
  66244. var e = this.prepareEvent(inEvent);
  66245. dispatcher.down(e);
  66246. },
  66247. MSPointerMove: function(inEvent) {
  66248. var e = this.prepareEvent(inEvent);
  66249. dispatcher.move(e);
  66250. },
  66251. MSPointerUp: function(inEvent) {
  66252. var e = this.prepareEvent(inEvent);
  66253. dispatcher.up(e);
  66254. this.cleanup(inEvent.pointerId);
  66255. },
  66256. MSPointerOut: function(inEvent) {
  66257. var e = this.prepareEvent(inEvent);
  66258. dispatcher.leaveOut(e);
  66259. },
  66260. MSPointerOver: function(inEvent) {
  66261. var e = this.prepareEvent(inEvent);
  66262. dispatcher.enterOver(e);
  66263. },
  66264. MSPointerCancel: function(inEvent) {
  66265. var e = this.prepareEvent(inEvent);
  66266. dispatcher.cancel(e);
  66267. this.cleanup(inEvent.pointerId);
  66268. },
  66269. MSLostPointerCapture: function(inEvent) {
  66270. var e = dispatcher.makeEvent('lostpointercapture', inEvent);
  66271. dispatcher.dispatchEvent(e);
  66272. },
  66273. MSGotPointerCapture: function(inEvent) {
  66274. var e = dispatcher.makeEvent('gotpointercapture', inEvent);
  66275. dispatcher.dispatchEvent(e);
  66276. }
  66277. };
  66278. function applyPolyfill() {
  66279. // only activate if this platform does not have pointer events
  66280. if (!window.PointerEvent) {
  66281. window.PointerEvent = PointerEvent;
  66282. if (window.navigator.msPointerEnabled) {
  66283. var tp = window.navigator.msMaxTouchPoints;
  66284. Object.defineProperty(window.navigator, 'maxTouchPoints', {
  66285. value: tp,
  66286. enumerable: true
  66287. });
  66288. dispatcher.registerSource('ms', msEvents);
  66289. } else {
  66290. Object.defineProperty(window.navigator, 'maxTouchPoints', {
  66291. value: 0,
  66292. enumerable: true
  66293. });
  66294. dispatcher.registerSource('mouse', mouseEvents);
  66295. if (window.ontouchstart !== undefined) {
  66296. dispatcher.registerSource('touch', touchEvents);
  66297. }
  66298. }
  66299. dispatcher.register(document);
  66300. }
  66301. }
  66302. var n = window.navigator;
  66303. var s;
  66304. var r;
  66305. var h;
  66306. function assertActive(id) {
  66307. if (!dispatcher.pointermap.has(id)) {
  66308. var error = new Error('InvalidPointerId');
  66309. error.name = 'InvalidPointerId';
  66310. throw error;
  66311. }
  66312. }
  66313. function assertConnected(elem) {
  66314. var parent = elem.parentNode;
  66315. while (parent && parent !== elem.ownerDocument) {
  66316. parent = parent.parentNode;
  66317. }
  66318. if (!parent) {
  66319. var error = new Error('InvalidStateError');
  66320. error.name = 'InvalidStateError';
  66321. throw error;
  66322. }
  66323. }
  66324. function inActiveButtonState(id) {
  66325. var p = dispatcher.pointermap.get(id);
  66326. return p.buttons !== 0;
  66327. }
  66328. if (n.msPointerEnabled) {
  66329. s = function(pointerId) {
  66330. assertActive(pointerId);
  66331. assertConnected(this);
  66332. if (inActiveButtonState(pointerId)) {
  66333. dispatcher.setCapture(pointerId, this, true);
  66334. this.msSetPointerCapture(pointerId);
  66335. }
  66336. };
  66337. r = function(pointerId) {
  66338. assertActive(pointerId);
  66339. dispatcher.releaseCapture(pointerId, true);
  66340. this.msReleasePointerCapture(pointerId);
  66341. };
  66342. } else {
  66343. s = function setPointerCapture(pointerId) {
  66344. assertActive(pointerId);
  66345. assertConnected(this);
  66346. if (inActiveButtonState(pointerId)) {
  66347. dispatcher.setCapture(pointerId, this);
  66348. }
  66349. };
  66350. r = function releasePointerCapture(pointerId) {
  66351. assertActive(pointerId);
  66352. dispatcher.releaseCapture(pointerId);
  66353. };
  66354. }
  66355. h = function hasPointerCapture(pointerId) {
  66356. return !!dispatcher.captureInfo[pointerId];
  66357. };
  66358. function applyPolyfill$1() {
  66359. if (window.Element && !Element.prototype.setPointerCapture) {
  66360. Object.defineProperties(Element.prototype, {
  66361. 'setPointerCapture': {
  66362. value: s
  66363. },
  66364. 'releasePointerCapture': {
  66365. value: r
  66366. },
  66367. 'hasPointerCapture': {
  66368. value: h
  66369. }
  66370. });
  66371. }
  66372. }
  66373. applyAttributeStyles();
  66374. applyPolyfill();
  66375. applyPolyfill$1();
  66376. var pointerevents = {
  66377. dispatcher: dispatcher,
  66378. Installer: Installer,
  66379. PointerEvent: PointerEvent,
  66380. PointerMap: PointerMap,
  66381. targetFinding: targeting
  66382. };
  66383. return pointerevents;
  66384. }));
  66385. /***/ }),
  66386. /* 65 */
  66387. /***/ (function(module, exports, __webpack_require__) {
  66388. "use strict";
  66389. Object.defineProperty(exports, "__esModule", { value: true });
  66390. var defaultViewer_1 = __webpack_require__(8);
  66391. var mappers_1 = __webpack_require__(3);
  66392. var globals_1 = __webpack_require__(4);
  66393. /**
  66394. * Will attach an init function the the DOMContentLoaded event.
  66395. * The init function will be removed automatically after the event was triggered.
  66396. */
  66397. function initListeners() {
  66398. document.addEventListener("DOMContentLoaded", init);
  66399. function init(event) {
  66400. document.removeEventListener("DOMContentLoaded", init);
  66401. if (globals_1.viewerGlobals.disableInit)
  66402. return;
  66403. InitTags();
  66404. }
  66405. }
  66406. exports.initListeners = initListeners;
  66407. /**
  66408. * Select all HTML tags on the page that match the selector and initialize a viewer
  66409. *
  66410. * @param selector the selector to initialize the viewer on (default is 'babylon')
  66411. */
  66412. function InitTags(selector) {
  66413. if (selector === void 0) { selector = 'babylon'; }
  66414. var elements = document.querySelectorAll(selector);
  66415. for (var i = 0; i < elements.length; ++i) {
  66416. var element = elements.item(i);
  66417. // get the html configuration
  66418. var configMapper = mappers_1.mapperManager.getMapper('dom');
  66419. var config = configMapper.map(element);
  66420. var viewer = new defaultViewer_1.DefaultViewer(element, config);
  66421. }
  66422. }
  66423. exports.InitTags = InitTags;
  66424. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5pdGlhbGl6ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW5pdGlhbGl6ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3REFBdUQ7QUFDdkQsbURBQXdEO0FBQ3hELG1EQUF3RDtBQUd4RDs7O0dBR0c7QUFDSDtJQUNJLFFBQVEsQ0FBQyxnQkFBZ0IsQ0FBQyxrQkFBa0IsRUFBRSxJQUFJLENBQUMsQ0FBQztJQUNwRCxjQUFjLEtBQUs7UUFDZixRQUFRLENBQUMsbUJBQW1CLENBQUMsa0JBQWtCLEVBQUUsSUFBSSxDQUFDLENBQUM7UUFDdkQsSUFBSSx1QkFBYSxDQUFDLFdBQVc7WUFBRSxPQUFPO1FBQ3RDLFFBQVEsRUFBRSxDQUFDO0lBQ2YsQ0FBQztBQUNMLENBQUM7QUFQRCxzQ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