babylon.canvas2d.max.js 692 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var __extends = (this && this.__extends) || function (d, b) {
  8. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  9. function __() { this.constructor = d; }
  10. __.prototype = b.prototype;
  11. d.prototype = new __();
  12. };
  13. var BABYLON;
  14. (function (BABYLON) {
  15. /**
  16. * Class for the ObservableStringDictionary.onDictionaryChanged observable
  17. */
  18. var DictionaryChanged = (function () {
  19. function DictionaryChanged() {
  20. }
  21. Object.defineProperty(DictionaryChanged, "clearAction", {
  22. /**
  23. * The content of the dictionary was totally cleared
  24. */
  25. get: function () {
  26. return DictionaryChanged._clearAction;
  27. },
  28. enumerable: true,
  29. configurable: true
  30. });
  31. Object.defineProperty(DictionaryChanged, "newItemAction", {
  32. /**
  33. * A new item was added, the newItem field contains the key/value pair
  34. */
  35. get: function () {
  36. return DictionaryChanged._newItemAction;
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. Object.defineProperty(DictionaryChanged, "removedItemAction", {
  42. /**
  43. * An existing item was removed, the removedKey field contains its key
  44. */
  45. get: function () {
  46. return DictionaryChanged._removedItemAction;
  47. },
  48. enumerable: true,
  49. configurable: true
  50. });
  51. Object.defineProperty(DictionaryChanged, "itemValueChangedAction", {
  52. /**
  53. * An existing item had a value change, the changedItem field contains the key/value
  54. */
  55. get: function () {
  56. return DictionaryChanged._itemValueChangedAction;
  57. },
  58. enumerable: true,
  59. configurable: true
  60. });
  61. Object.defineProperty(DictionaryChanged, "replacedAction", {
  62. /**
  63. * The dictionary's content was reset and replaced by the content of another dictionary.
  64. * DictionaryChanged<T> contains no further information about this action
  65. */
  66. get: function () {
  67. return DictionaryChanged._replacedAction;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. DictionaryChanged._clearAction = 0x1;
  73. DictionaryChanged._newItemAction = 0x2;
  74. DictionaryChanged._removedItemAction = 0x4;
  75. DictionaryChanged._itemValueChangedAction = 0x8;
  76. DictionaryChanged._replacedAction = 0x10;
  77. return DictionaryChanged;
  78. }());
  79. BABYLON.DictionaryChanged = DictionaryChanged;
  80. var OSDWatchedObjectChangedInfo = (function () {
  81. function OSDWatchedObjectChangedInfo() {
  82. }
  83. return OSDWatchedObjectChangedInfo;
  84. }());
  85. BABYLON.OSDWatchedObjectChangedInfo = OSDWatchedObjectChangedInfo;
  86. var ObservableStringDictionary = (function (_super) {
  87. __extends(ObservableStringDictionary, _super);
  88. function ObservableStringDictionary(watchObjectsPropertyChange) {
  89. _super.call(this);
  90. this._propertyChanged = null;
  91. this._dictionaryChanged = null;
  92. this.dci = new DictionaryChanged();
  93. this._callingDicChanged = false;
  94. this._watchedObjectChanged = null;
  95. this._callingWatchedObjectChanged = false;
  96. this._woci = new OSDWatchedObjectChangedInfo();
  97. this._watchObjectsPropertyChange = watchObjectsPropertyChange;
  98. this._watchedObjectList = this._watchObjectsPropertyChange ? new BABYLON.StringDictionary() : null;
  99. }
  100. /**
  101. * This will clear this dictionary and copy the content from the 'source' one.
  102. * If the T value is a custom object, it won't be copied/cloned, the same object will be used
  103. * @param source the dictionary to take the content from and copy to this dictionary
  104. */
  105. ObservableStringDictionary.prototype.copyFrom = function (source) {
  106. var _this = this;
  107. var oldCount = this.count;
  108. // Don't rely on this class' implementation for clear/add otherwise tons of notification will be thrown
  109. _super.prototype.clear.call(this);
  110. source.forEach(function (t, v) { return _this._add(t, v, false, _this._watchObjectsPropertyChange); });
  111. this.onDictionaryChanged(DictionaryChanged.replacedAction, null, null, null);
  112. this.onPropertyChanged("count", oldCount, this.count);
  113. };
  114. /**
  115. * Get a value from its key or add it if it doesn't exist.
  116. * This method will ensure you that a given key/data will be present in the dictionary.
  117. * @param key the given key to get the matching value from
  118. * @param factory the factory that will create the value if the key is not present in the dictionary.
  119. * The factory will only be invoked if there's no data for the given key.
  120. * @return the value corresponding to the key.
  121. */
  122. ObservableStringDictionary.prototype.getOrAddWithFactory = function (key, factory) {
  123. var _this = this;
  124. var val = _super.prototype.getOrAddWithFactory.call(this, key, function (k) {
  125. var v = factory(key);
  126. _this._add(key, v, true, _this._watchObjectsPropertyChange);
  127. return v;
  128. });
  129. return val;
  130. };
  131. /**
  132. * Add a new key and its corresponding value
  133. * @param key the key to add
  134. * @param value the value corresponding to the key
  135. * @return true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary
  136. */
  137. ObservableStringDictionary.prototype.add = function (key, value) {
  138. return this._add(key, value, true, true);
  139. };
  140. ObservableStringDictionary.prototype.getAndRemove = function (key) {
  141. var val = _super.prototype.get.call(this, key);
  142. this._remove(key, true, val);
  143. return val;
  144. };
  145. ObservableStringDictionary.prototype._add = function (key, value, fireNotif, registerWatcher) {
  146. if (_super.prototype.add.call(this, key, value)) {
  147. if (fireNotif) {
  148. this.onDictionaryChanged(DictionaryChanged.newItemAction, { key: key, value: value }, null, null);
  149. this.onPropertyChanged("count", this.count - 1, this.count);
  150. }
  151. if (registerWatcher) {
  152. this._addWatchedElement(key, value);
  153. }
  154. return true;
  155. }
  156. return false;
  157. };
  158. ObservableStringDictionary.prototype._addWatchedElement = function (key, el) {
  159. var _this = this;
  160. if (el["propertyChanged"]) {
  161. this._watchedObjectList.add(key, el.propertyChanged.add(function (e, d) {
  162. _this.onWatchedObjectChanged(key, el, e);
  163. }));
  164. }
  165. };
  166. ObservableStringDictionary.prototype._removeWatchedElement = function (key, el) {
  167. var observer = this._watchedObjectList.getAndRemove(key);
  168. el.propertyChanged.remove(observer);
  169. };
  170. ObservableStringDictionary.prototype.set = function (key, value) {
  171. var oldValue = this.get(key);
  172. if (this._watchObjectsPropertyChange) {
  173. this._removeWatchedElement(key, oldValue);
  174. }
  175. if (_super.prototype.set.call(this, key, value)) {
  176. this.onDictionaryChanged(DictionaryChanged.itemValueChangedAction, null, null, { key: key, oldValue: oldValue, newValue: value });
  177. this._addWatchedElement(key, value);
  178. return true;
  179. }
  180. return false;
  181. };
  182. /**
  183. * Remove a key/value from the dictionary.
  184. * @param key the key to remove
  185. * @return true if the item was successfully deleted, false if no item with such key exist in the dictionary
  186. */
  187. ObservableStringDictionary.prototype.remove = function (key) {
  188. return this._remove(key, true);
  189. };
  190. ObservableStringDictionary.prototype._remove = function (key, fireNotif, element) {
  191. if (!element) {
  192. element = this.get(key);
  193. }
  194. if (!element) {
  195. return false;
  196. }
  197. if (_super.prototype.remove.call(this, key) === undefined) {
  198. return false;
  199. }
  200. this.onDictionaryChanged(DictionaryChanged.removedItemAction, null, key, null);
  201. this.onPropertyChanged("count", this.count + 1, this.count);
  202. if (this._watchObjectsPropertyChange) {
  203. this._removeWatchedElement(key, element);
  204. }
  205. return true;
  206. };
  207. /**
  208. * Clear the whole content of the dictionary
  209. */
  210. ObservableStringDictionary.prototype.clear = function () {
  211. var _this = this;
  212. this._watchedObjectList.forEach(function (k, v) {
  213. var el = _this.get(k);
  214. _this._removeWatchedElement(k, el);
  215. });
  216. this._watchedObjectList.clear();
  217. var oldCount = this.count;
  218. _super.prototype.clear.call(this);
  219. this.onDictionaryChanged(DictionaryChanged.clearAction, null, null, null);
  220. this.onPropertyChanged("count", oldCount, 0);
  221. };
  222. Object.defineProperty(ObservableStringDictionary.prototype, "propertyChanged", {
  223. get: function () {
  224. if (!this._propertyChanged) {
  225. this._propertyChanged = new BABYLON.Observable();
  226. }
  227. return this._propertyChanged;
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. ObservableStringDictionary.prototype.onPropertyChanged = function (propName, oldValue, newValue, mask) {
  233. if (this._propertyChanged && this._propertyChanged.hasObservers()) {
  234. var pci = ObservableStringDictionary.callingPropChanged ? new BABYLON.PropertyChangedInfo() : ObservableStringDictionary.pci;
  235. pci.oldValue = oldValue;
  236. pci.newValue = newValue;
  237. pci.propertyName = propName;
  238. try {
  239. ObservableStringDictionary.callingPropChanged = true;
  240. this.propertyChanged.notifyObservers(pci, mask);
  241. }
  242. finally {
  243. ObservableStringDictionary.callingPropChanged = false;
  244. }
  245. }
  246. };
  247. Object.defineProperty(ObservableStringDictionary.prototype, "dictionaryChanged", {
  248. get: function () {
  249. if (!this._dictionaryChanged) {
  250. this._dictionaryChanged = new BABYLON.Observable();
  251. }
  252. return this._dictionaryChanged;
  253. },
  254. enumerable: true,
  255. configurable: true
  256. });
  257. ObservableStringDictionary.prototype.onDictionaryChanged = function (action, newItem, removedKey, changedItem) {
  258. if (this._dictionaryChanged && this._dictionaryChanged.hasObservers()) {
  259. var dci = this._callingDicChanged ? new DictionaryChanged() : this.dci;
  260. dci.action = action;
  261. dci.newItem = newItem;
  262. dci.removedKey = removedKey;
  263. dci.changedItem = changedItem;
  264. try {
  265. this._callingDicChanged = true;
  266. this.dictionaryChanged.notifyObservers(dci, action);
  267. }
  268. finally {
  269. this._callingDicChanged = false;
  270. }
  271. }
  272. };
  273. Object.defineProperty(ObservableStringDictionary.prototype, "watchedObjectChanged", {
  274. get: function () {
  275. if (!this._watchedObjectChanged) {
  276. this._watchedObjectChanged = new BABYLON.Observable();
  277. }
  278. return this._watchedObjectChanged;
  279. },
  280. enumerable: true,
  281. configurable: true
  282. });
  283. ObservableStringDictionary.prototype.onWatchedObjectChanged = function (key, object, propChanged) {
  284. if (this._watchedObjectChanged && this._watchedObjectChanged.hasObservers()) {
  285. var woci = this._callingWatchedObjectChanged ? new OSDWatchedObjectChangedInfo() : this._woci;
  286. woci.key = key;
  287. woci.object = object;
  288. woci.propertyChanged = propChanged;
  289. try {
  290. this._callingWatchedObjectChanged = true;
  291. this.watchedObjectChanged.notifyObservers(woci);
  292. }
  293. finally {
  294. this._callingWatchedObjectChanged = false;
  295. }
  296. }
  297. };
  298. ObservableStringDictionary.pci = new BABYLON.PropertyChangedInfo();
  299. ObservableStringDictionary.callingPropChanged = false;
  300. return ObservableStringDictionary;
  301. }(BABYLON.StringDictionary));
  302. BABYLON.ObservableStringDictionary = ObservableStringDictionary;
  303. })(BABYLON || (BABYLON = {}));
  304. var BABYLON;
  305. (function (BABYLON) {
  306. /**
  307. * Custom type of the propertyChanged observable
  308. */
  309. var PropertyChangedInfo = (function () {
  310. function PropertyChangedInfo() {
  311. }
  312. return PropertyChangedInfo;
  313. }());
  314. BABYLON.PropertyChangedInfo = PropertyChangedInfo;
  315. /**
  316. * The purpose of this class is to provide a base implementation of the IPropertyChanged interface for the user to avoid rewriting a code needlessly.
  317. * Typical use of this class is to check for equality in a property set(), then call the onPropertyChanged method if values are different after the new value is set. The protected method will notify observers of the change.
  318. * Remark: onPropertyChanged detects reentrant code and acts in a way to make sure everything is fine, fast and allocation friendly (when there no reentrant code which should be 99% of the time)
  319. */
  320. var PropertyChangedBase = (function () {
  321. function PropertyChangedBase() {
  322. this._propertyChanged = null;
  323. }
  324. /**
  325. * Protected method to call when there's a change of value in a property set
  326. * @param propName the name of the concerned property
  327. * @param oldValue its old value
  328. * @param newValue its new value
  329. * @param mask an optional observable mask
  330. */
  331. PropertyChangedBase.prototype.onPropertyChanged = function (propName, oldValue, newValue, mask) {
  332. if (this.propertyChanged.hasObservers()) {
  333. var pci = PropertyChangedBase.calling ? new PropertyChangedInfo() : PropertyChangedBase.pci;
  334. pci.oldValue = oldValue;
  335. pci.newValue = newValue;
  336. pci.propertyName = propName;
  337. try {
  338. PropertyChangedBase.calling = true;
  339. this.propertyChanged.notifyObservers(pci, mask);
  340. }
  341. finally {
  342. PropertyChangedBase.calling = false;
  343. }
  344. }
  345. };
  346. Object.defineProperty(PropertyChangedBase.prototype, "propertyChanged", {
  347. /**
  348. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  349. * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
  350. */
  351. get: function () {
  352. if (!this._propertyChanged) {
  353. this._propertyChanged = new BABYLON.Observable();
  354. }
  355. return this._propertyChanged;
  356. },
  357. enumerable: true,
  358. configurable: true
  359. });
  360. PropertyChangedBase.pci = new PropertyChangedInfo();
  361. PropertyChangedBase.calling = false;
  362. return PropertyChangedBase;
  363. }());
  364. BABYLON.PropertyChangedBase = PropertyChangedBase;
  365. /**
  366. * Class for the ObservableArray.onArrayChanged observable
  367. */
  368. var ArrayChanged = (function () {
  369. function ArrayChanged() {
  370. this.action = 0;
  371. this.newItems = new Array();
  372. this.removedItems = new Array();
  373. this.changedItems = new Array();
  374. this.newStartingIndex = -1;
  375. this.removedStartingIndex = -1;
  376. }
  377. Object.defineProperty(ArrayChanged, "clearAction", {
  378. /**
  379. * The content of the array was totally cleared
  380. */
  381. get: function () {
  382. return ArrayChanged._clearAction;
  383. },
  384. enumerable: true,
  385. configurable: true
  386. });
  387. Object.defineProperty(ArrayChanged, "newItemsAction", {
  388. /**
  389. * A new item was added, the newItems field contains the key/value pairs
  390. */
  391. get: function () {
  392. return ArrayChanged._newItemsAction;
  393. },
  394. enumerable: true,
  395. configurable: true
  396. });
  397. Object.defineProperty(ArrayChanged, "removedItemsAction", {
  398. /**
  399. * An existing item was removed, the removedKey field contains its key
  400. */
  401. get: function () {
  402. return ArrayChanged._removedItemsAction;
  403. },
  404. enumerable: true,
  405. configurable: true
  406. });
  407. Object.defineProperty(ArrayChanged, "changedItemAction", {
  408. /**
  409. * One or many items in the array were changed, the
  410. */
  411. get: function () {
  412. return ArrayChanged._changedItemAction;
  413. },
  414. enumerable: true,
  415. configurable: true
  416. });
  417. Object.defineProperty(ArrayChanged, "replacedArrayAction", {
  418. /**
  419. * The array's content was totally changed
  420. * Depending on the method that used this mode the ChangedArray object may contains more information
  421. */
  422. get: function () {
  423. return ArrayChanged._replacedArrayAction;
  424. },
  425. enumerable: true,
  426. configurable: true
  427. });
  428. Object.defineProperty(ArrayChanged, "lengthChangedAction", {
  429. /**
  430. * The length of the array changed
  431. */
  432. get: function () {
  433. return ArrayChanged._lengthChangedAction;
  434. },
  435. enumerable: true,
  436. configurable: true
  437. });
  438. ArrayChanged.prototype.clear = function () {
  439. this.action = 0;
  440. this.newItems.splice(0);
  441. this.removedItems.splice(0);
  442. this.changedItems.splice(0);
  443. this.removedStartingIndex = this.removedStartingIndex = this.changedStartingIndex = 0;
  444. };
  445. ArrayChanged._clearAction = 0x1;
  446. ArrayChanged._newItemsAction = 0x2;
  447. ArrayChanged._removedItemsAction = 0x4;
  448. ArrayChanged._replacedArrayAction = 0x8;
  449. ArrayChanged._lengthChangedAction = 0x10;
  450. ArrayChanged._changedItemAction = 0x20;
  451. return ArrayChanged;
  452. }());
  453. BABYLON.ArrayChanged = ArrayChanged;
  454. var OAWatchedObjectChangedInfo = (function () {
  455. function OAWatchedObjectChangedInfo() {
  456. }
  457. return OAWatchedObjectChangedInfo;
  458. }());
  459. BABYLON.OAWatchedObjectChangedInfo = OAWatchedObjectChangedInfo;
  460. /**
  461. * This class mimics the Javascript Array and TypeScript Array<T> classes, adding new features concerning the Observable pattern.
  462. *
  463. */
  464. var ObservableArray = (function (_super) {
  465. __extends(ObservableArray, _super);
  466. /**
  467. * Create an Observable Array.
  468. * @param watchObjectsPropertyChange
  469. * @param array and optional array that will be encapsulated by this ObservableArray instance. That's right, it's NOT a copy!
  470. */
  471. function ObservableArray(watchObjectsPropertyChange, array) {
  472. _super.call(this);
  473. this.dci = new ArrayChanged();
  474. this._callingArrayChanged = false;
  475. this._array = (array != null) ? array : new Array();
  476. this.dci = new ArrayChanged();
  477. this._callingArrayChanged = false;
  478. this._arrayChanged = null;
  479. this._callingWatchedObjectChanged = false;
  480. this._watchObjectsPropertyChange = watchObjectsPropertyChange;
  481. this._watchedObjectList = this._watchObjectsPropertyChange ? new BABYLON.StringDictionary() : null;
  482. this._woci = new OAWatchedObjectChangedInfo();
  483. }
  484. Object.defineProperty(ObservableArray.prototype, "length", {
  485. /**
  486. * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
  487. */
  488. get: function () {
  489. return this._array.length;
  490. },
  491. set: function (value) {
  492. if (value === this._array.length) {
  493. return;
  494. }
  495. var oldLength = this._array.length;
  496. this._array.length = value;
  497. this.onPropertyChanged("length", oldLength, this._array.length);
  498. },
  499. enumerable: true,
  500. configurable: true
  501. });
  502. ObservableArray.prototype.getAt = function (index) {
  503. return this._array[index];
  504. };
  505. ObservableArray.prototype.setAt = function (index, value) {
  506. if (index < 0) {
  507. return false;
  508. }
  509. var insertion = (index >= this._array.length) || this._array[index] === undefined;
  510. var oldLength = 0;
  511. if (insertion) {
  512. oldLength = this._array.length;
  513. }
  514. else if (this._watchObjectsPropertyChange) {
  515. this._removeWatchedElement(this._array[index]);
  516. }
  517. this._array[index] = value;
  518. if (this._watchObjectsPropertyChange) {
  519. this._addWatchedElement(value);
  520. }
  521. if (insertion) {
  522. this.onPropertyChanged("length", oldLength, this._array.length);
  523. }
  524. var ac = this.getArrayChangedObject();
  525. if (ac) {
  526. ac.action = insertion ? ArrayChanged.newItemsAction : ArrayChanged.changedItemAction;
  527. if (insertion) {
  528. ac.newItems.splice(0, ac.newItems.length, { index: index, value: value });
  529. ac.newStartingIndex = index;
  530. ac.changedItems.splice(0);
  531. }
  532. else {
  533. ac.newItems.splice(0);
  534. ac.changedStartingIndex = index;
  535. ac.changedItems.splice(0, ac.changedItems.length, { index: index, value: value });
  536. }
  537. ac.removedItems.splice(0);
  538. ac.removedStartingIndex = -1;
  539. this.callArrayChanged(ac);
  540. }
  541. };
  542. /**
  543. * Returns a string representation of an array.
  544. */
  545. ObservableArray.prototype.toString = function () {
  546. return this._array.toString();
  547. };
  548. ObservableArray.prototype.toLocaleString = function () {
  549. return this._array.toLocaleString();
  550. };
  551. /**
  552. * Appends new elements to an array, and returns the new length of the array.
  553. * @param items New elements of the Array.
  554. */
  555. ObservableArray.prototype.push = function () {
  556. var items = [];
  557. for (var _i = 0; _i < arguments.length; _i++) {
  558. items[_i - 0] = arguments[_i];
  559. }
  560. var oldLength = this._array.length;
  561. var n = (_a = this._array).push.apply(_a, items);
  562. if (this._watchObjectsPropertyChange) {
  563. this._addWatchedElement.apply(this, items);
  564. }
  565. this.onPropertyChanged("length", oldLength, this._array.length);
  566. var ac = this.getArrayChangedObject();
  567. if (ac) {
  568. ac.action = ArrayChanged.newItemsAction;
  569. ac.newStartingIndex = oldLength;
  570. this.feedNotifArray.apply(this, [ac.newItems, oldLength].concat(items));
  571. this.callArrayChanged(ac);
  572. }
  573. return n;
  574. var _a;
  575. };
  576. /**
  577. * Removes the last element from an array and returns it.
  578. */
  579. ObservableArray.prototype.pop = function () {
  580. var firstRemove = this._array.length - 1;
  581. var res = this._array.pop();
  582. if (res && this._watchObjectsPropertyChange) {
  583. this._removeWatchedElement(res);
  584. }
  585. if (firstRemove !== -1) {
  586. this.onPropertyChanged("length", this._array.length + 1, this._array.length);
  587. var ac = this.getArrayChangedObject();
  588. if (ac) {
  589. ac.action = ArrayChanged.removedItemsAction;
  590. ac.removedStartingIndex = firstRemove;
  591. this.feedNotifArray(ac.removedItems, firstRemove, res);
  592. }
  593. }
  594. return res;
  595. };
  596. /**
  597. * Combines two or more arrays.
  598. * @param items Additional items to add to the end of array1.
  599. */
  600. ObservableArray.prototype.concat = function () {
  601. var items = [];
  602. for (var _i = 0; _i < arguments.length; _i++) {
  603. items[_i - 0] = arguments[_i];
  604. }
  605. return new ObservableArray(this._watchObjectsPropertyChange, (_a = this._array).concat.apply(_a, items));
  606. var _a;
  607. };
  608. /**
  609. * Adds all the elements of an array separated by the specified separator string.
  610. * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
  611. */
  612. ObservableArray.prototype.join = function (separator) {
  613. return this._array.join(separator);
  614. };
  615. /**
  616. * Reverses the elements in an Array.
  617. * The arrayChanged action is
  618. */
  619. ObservableArray.prototype.reverse = function () {
  620. var res = this._array.reverse();
  621. var ac = this.getArrayChangedObject();
  622. ac.action = ArrayChanged.replacedArrayAction;
  623. return res;
  624. };
  625. /**
  626. * Removes the first element from an array and returns it, shift all subsequents element one element before.
  627. * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
  628. *
  629. */
  630. ObservableArray.prototype.shift = function () {
  631. var oldLength = this._array.length;
  632. var res = this._array.shift();
  633. if (this._watchedObjectChanged && res != null) {
  634. this._removeWatchedElement(res);
  635. }
  636. if (oldLength !== 0) {
  637. this.onPropertyChanged("length", oldLength, this._array.length);
  638. var ac = this.getArrayChangedObject();
  639. if (ac) {
  640. ac.action = ArrayChanged.replacedArrayAction;
  641. ac.removedItems.splice(0, ac.removedItems.length, { index: 0, value: res });
  642. ac.newItems.splice(0);
  643. ac.changedItems.splice(0);
  644. ac.removedStartingIndex = 0;
  645. this.callArrayChanged(ac);
  646. }
  647. }
  648. return res;
  649. };
  650. /**
  651. * Returns a section of an array.
  652. * @param start The beginning of the specified portion of the array.
  653. * @param end The end of the specified portion of the array.
  654. */
  655. ObservableArray.prototype.slice = function (start, end) {
  656. return new ObservableArray(this._watchObjectsPropertyChange, this._array.slice(start, end));
  657. };
  658. /**
  659. * Sorts an array.
  660. * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
  661. * On the contrary of the Javascript Array's implementation, this method returns nothing
  662. */
  663. ObservableArray.prototype.sort = function (compareFn) {
  664. var oldLength = this._array.length;
  665. this._array.sort(compareFn);
  666. if (oldLength !== 0) {
  667. var ac = this.getArrayChangedObject();
  668. if (ac) {
  669. ac.clear();
  670. ac.action = ArrayChanged.replacedArrayAction;
  671. this.callArrayChanged(ac);
  672. }
  673. }
  674. };
  675. /**
  676. * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
  677. * @param start The zero-based location in the array from which to start removing elements.
  678. * @param deleteCount The number of elements to remove.
  679. * @param items Elements to insert into the array in place of the deleted elements.
  680. */
  681. ObservableArray.prototype.splice = function (start, deleteCount) {
  682. var items = [];
  683. for (var _i = 2; _i < arguments.length; _i++) {
  684. items[_i - 2] = arguments[_i];
  685. }
  686. var oldLength = this._array.length;
  687. if (this._watchObjectsPropertyChange) {
  688. for (var i = start; i < start + deleteCount; i++) {
  689. var val = this._array[i];
  690. if (this._watchObjectsPropertyChange && val != null) {
  691. this._removeWatchedElement(val);
  692. }
  693. }
  694. }
  695. var res = (_a = this._array).splice.apply(_a, [start, deleteCount].concat(items));
  696. if (this._watchObjectsPropertyChange) {
  697. this._addWatchedElement.apply(this, items);
  698. }
  699. if (oldLength !== this._array.length) {
  700. this.onPropertyChanged("length", oldLength, this._array.length);
  701. }
  702. var ac = this.getArrayChangedObject();
  703. if (ac) {
  704. ac.clear();
  705. ac.action = ArrayChanged.replacedArrayAction;
  706. this.callArrayChanged(ac);
  707. }
  708. return res;
  709. var _a;
  710. };
  711. /**
  712. * Inserts new elements at the start of an array.
  713. * @param items Elements to insert at the start of the Array.
  714. * The ChangedArray action is replacedArrayAction, newItems contains the list of the added items
  715. */
  716. ObservableArray.prototype.unshift = function () {
  717. var items = [];
  718. for (var _i = 0; _i < arguments.length; _i++) {
  719. items[_i - 0] = arguments[_i];
  720. }
  721. var oldLength = this._array.length;
  722. var res = (_a = this._array).unshift.apply(_a, items);
  723. if (this._watchObjectsPropertyChange) {
  724. this._addWatchedElement.apply(this, items);
  725. }
  726. this.onPropertyChanged("length", oldLength, this._array.length);
  727. var ac = this.getArrayChangedObject();
  728. if (ac) {
  729. ac.clear();
  730. ac.action = ArrayChanged.replacedArrayAction;
  731. ac.newStartingIndex = 0,
  732. this.feedNotifArray.apply(this, [ac.newItems, 0].concat(items));
  733. this.callArrayChanged(ac);
  734. }
  735. return res;
  736. var _a;
  737. };
  738. /**
  739. * Returns the index of the first occurrence of a value in an array.
  740. * @param searchElement The value to locate in the array.
  741. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
  742. */
  743. ObservableArray.prototype.indexOf = function (searchElement, fromIndex) {
  744. return this._array.indexOf(searchElement, fromIndex);
  745. };
  746. /**
  747. * Returns the index of the last occurrence of a specified value in an array.
  748. * @param searchElement The value to locate in the array.
  749. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
  750. */
  751. ObservableArray.prototype.lastIndexOf = function (searchElement, fromIndex) {
  752. return this._array.lastIndexOf(searchElement, fromIndex);
  753. };
  754. /**
  755. * Determines whether all the members of an array satisfy the specified test.
  756. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
  757. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  758. */
  759. ObservableArray.prototype.every = function (callbackfn, thisArg) {
  760. return this._array.every(callbackfn, thisArg);
  761. };
  762. /**
  763. * Determines whether the specified callback function returns true for any element of an array.
  764. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
  765. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  766. */
  767. ObservableArray.prototype.some = function (callbackfn, thisArg) {
  768. return this._array.some(callbackfn, thisArg);
  769. };
  770. /**
  771. * Performs the specified action for each element in an array.
  772. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
  773. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  774. */
  775. ObservableArray.prototype.forEach = function (callbackfn, thisArg) {
  776. return this._array.forEach(callbackfn, thisArg);
  777. };
  778. /**
  779. * Calls a defined callback function on each element of an array, and returns an array that contains the results.
  780. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
  781. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  782. */
  783. ObservableArray.prototype.map = function (callbackfn, thisArg) {
  784. return this._array.map(callbackfn, thisArg);
  785. };
  786. /**
  787. * Returns the elements of an array that meet the condition specified in a callback function.
  788. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
  789. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
  790. */
  791. ObservableArray.prototype.filter = function (callbackfn, thisArg) {
  792. return this._array.filter(callbackfn, thisArg);
  793. };
  794. /**
  795. * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  796. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
  797. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  798. */
  799. ObservableArray.prototype.reduce = function (callbackfn, initialValue) {
  800. return this._array.reduce(callbackfn);
  801. };
  802. /**
  803. * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
  804. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
  805. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
  806. */
  807. ObservableArray.prototype.reduceRight = function (callbackfn, initialValue) {
  808. return this._array.reduceRight(callbackfn);
  809. };
  810. Object.defineProperty(ObservableArray.prototype, "arrayChanged", {
  811. get: function () {
  812. if (!this._arrayChanged) {
  813. this._arrayChanged = new BABYLON.Observable();
  814. }
  815. return this._arrayChanged;
  816. },
  817. enumerable: true,
  818. configurable: true
  819. });
  820. ObservableArray.prototype.getArrayChangedObject = function () {
  821. if (this._arrayChanged && this._arrayChanged.hasObservers()) {
  822. var ac = this._callingArrayChanged ? new ArrayChanged() : this.dci;
  823. return ac;
  824. }
  825. return null;
  826. };
  827. ObservableArray.prototype.feedNotifArray = function (array, startindIndex) {
  828. var items = [];
  829. for (var _i = 2; _i < arguments.length; _i++) {
  830. items[_i - 2] = arguments[_i];
  831. }
  832. array.splice(0);
  833. for (var i = 0; i < items.length; i++) {
  834. var value = this._array[i + startindIndex];
  835. if (value !== undefined) {
  836. array.push({ index: i + startindIndex, value: value });
  837. }
  838. }
  839. };
  840. ObservableArray.prototype.callArrayChanged = function (ac) {
  841. try {
  842. this._callingArrayChanged = true;
  843. this.arrayChanged.notifyObservers(ac, ac.action);
  844. }
  845. finally {
  846. this._callingArrayChanged = false;
  847. }
  848. };
  849. Object.defineProperty(ObservableArray.prototype, "watchedObjectChanged", {
  850. get: function () {
  851. if (!this._watchedObjectChanged) {
  852. this._watchedObjectChanged = new BABYLON.Observable();
  853. }
  854. return this._watchedObjectChanged;
  855. },
  856. enumerable: true,
  857. configurable: true
  858. });
  859. ObservableArray.prototype._addWatchedElement = function () {
  860. var _this = this;
  861. var items = [];
  862. for (var _i = 0; _i < arguments.length; _i++) {
  863. items[_i - 0] = arguments[_i];
  864. }
  865. var _loop_1 = function(curItem) {
  866. if (curItem["propertyChanged"]) {
  867. var key_1 = curItem["__ObsArrayObjID__"];
  868. // The object may already be part of another ObsArray, so there already be a valid ID
  869. if (!key_1) {
  870. key_1 = BABYLON.Tools.RandomId();
  871. curItem["__ObsArrayObjID__"] = key_1;
  872. }
  873. this_1._watchedObjectList.add(key_1, curItem.propertyChanged.add(function (e, d) {
  874. _this.onWatchedObjectChanged(key_1, curItem, e);
  875. }));
  876. }
  877. };
  878. var this_1 = this;
  879. for (var _a = 0, items_1 = items; _a < items_1.length; _a++) {
  880. var curItem = items_1[_a];
  881. _loop_1(curItem);
  882. }
  883. };
  884. ObservableArray.prototype._removeWatchedElement = function () {
  885. var items = [];
  886. for (var _i = 0; _i < arguments.length; _i++) {
  887. items[_i - 0] = arguments[_i];
  888. }
  889. for (var _a = 0, items_2 = items; _a < items_2.length; _a++) {
  890. var curItem = items_2[_a];
  891. var key = curItem["__ObsArrayObjID__"];
  892. if (key != null) {
  893. var observer = this._watchedObjectList.getAndRemove(key);
  894. curItem.propertyChanged.remove(observer);
  895. }
  896. }
  897. };
  898. ObservableArray.prototype.onWatchedObjectChanged = function (key, object, propChanged) {
  899. if (this._watchedObjectChanged && this._watchedObjectChanged.hasObservers()) {
  900. var woci = this._callingWatchedObjectChanged ? new OAWatchedObjectChangedInfo() : this._woci;
  901. woci.object = object;
  902. woci.propertyChanged = propChanged;
  903. try {
  904. this._callingWatchedObjectChanged = true;
  905. this.watchedObjectChanged.notifyObservers(woci);
  906. }
  907. finally {
  908. this._callingWatchedObjectChanged = false;
  909. }
  910. }
  911. };
  912. return ObservableArray;
  913. }(PropertyChangedBase));
  914. BABYLON.ObservableArray = ObservableArray;
  915. })(BABYLON || (BABYLON = {}));
  916. var BABYLON;
  917. (function (BABYLON) {
  918. /**
  919. * Stores 2D Bounding Information.
  920. * This class handles a circle area and a bounding rectangle one.
  921. */
  922. var BoundingInfo2D = (function () {
  923. function BoundingInfo2D() {
  924. this.radius = 0;
  925. this.center = BABYLON.Vector2.Zero();
  926. this.extent = BABYLON.Vector2.Zero();
  927. }
  928. /**
  929. * Create a BoundingInfo2D object from a given size
  930. * @param size the size that will be used to set the extend, radius will be computed from it.
  931. */
  932. BoundingInfo2D.CreateFromSize = function (size) {
  933. var r = new BoundingInfo2D();
  934. BoundingInfo2D.CreateFromSizeToRef(size, r);
  935. return r;
  936. };
  937. /**
  938. * Create a BoundingInfo2D object from a given radius
  939. * @param radius the radius to use, the extent will be computed from it.
  940. */
  941. BoundingInfo2D.CreateFromRadius = function (radius) {
  942. var r = new BoundingInfo2D();
  943. BoundingInfo2D.CreateFromRadiusToRef(radius, r);
  944. return r;
  945. };
  946. /**
  947. * Create a BoundingInfo2D object from a list of points.
  948. * The resulted object will be the smallest bounding area that includes all the given points.
  949. * @param points an array of points to compute the bounding object from.
  950. */
  951. BoundingInfo2D.CreateFromPoints = function (points) {
  952. var r = new BoundingInfo2D();
  953. BoundingInfo2D.CreateFromPointsToRef(points, r);
  954. return r;
  955. };
  956. /**
  957. * Update a BoundingInfo2D object using the given Size as input
  958. * @param size the bounding data will be computed from this size.
  959. * @param b must be a valid/allocated object, it will contain the result of the operation
  960. */
  961. BoundingInfo2D.CreateFromSizeToRef = function (size, b) {
  962. if (!size) {
  963. size = BABYLON.Size.Zero();
  964. }
  965. b.center.x = +size.width / 2;
  966. b.center.y = +size.height / 2;
  967. b.extent.x = b.center.x;
  968. b.extent.y = b.center.y;
  969. b.radius = b.extent.length();
  970. };
  971. /**
  972. * Update a BoundingInfo2D object using the given radius as input
  973. * @param radius the bounding data will be computed from this radius
  974. * @param b must be a valid/allocated object, it will contain the result of the operation
  975. */
  976. BoundingInfo2D.CreateFromRadiusToRef = function (radius, b) {
  977. b.center.x = b.center.y = 0;
  978. var r = +radius;
  979. b.extent.x = r;
  980. b.extent.y = r;
  981. b.radius = r;
  982. };
  983. /**
  984. * Update a BoundingInfo2D object using the given points array as input
  985. * @param points the point array to use to update the bounding data
  986. * @param b must be a valid/allocated object, it will contain the result of the operation
  987. */
  988. BoundingInfo2D.CreateFromPointsToRef = function (points, b) {
  989. var xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
  990. for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
  991. var p = points_1[_i];
  992. xmin = Math.min(p.x, xmin);
  993. xmax = Math.max(p.x, xmax);
  994. ymin = Math.min(p.y, ymin);
  995. ymax = Math.max(p.y, ymax);
  996. }
  997. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, b);
  998. };
  999. /**
  1000. * Update a BoundingInfo2D object using the given min/max values as input
  1001. * @param xmin the smallest x coordinate
  1002. * @param xmax the biggest x coordinate
  1003. * @param ymin the smallest y coordinate
  1004. * @param ymax the buggest y coordinate
  1005. * @param b must be a valid/allocated object, it will contain the result of the operation
  1006. */
  1007. BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
  1008. var w = xmax - xmin;
  1009. var h = ymax - ymin;
  1010. b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
  1011. b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
  1012. b.radius = b.extent.length();
  1013. };
  1014. /**
  1015. * Duplicate this instance and return a new one
  1016. * @return the duplicated instance
  1017. */
  1018. BoundingInfo2D.prototype.clone = function () {
  1019. var r = new BoundingInfo2D();
  1020. r.center = this.center.clone();
  1021. r.radius = this.radius;
  1022. r.extent = this.extent.clone();
  1023. return r;
  1024. };
  1025. BoundingInfo2D.prototype.clear = function () {
  1026. this.center.copyFromFloats(0, 0);
  1027. this.radius = 0;
  1028. this.extent.copyFromFloats(0, 0);
  1029. };
  1030. BoundingInfo2D.prototype.copyFrom = function (src) {
  1031. this.center.copyFrom(src.center);
  1032. this.radius = src.radius;
  1033. this.extent.copyFrom(src.extent);
  1034. };
  1035. /**
  1036. * return the max extend of the bounding info
  1037. */
  1038. BoundingInfo2D.prototype.max = function () {
  1039. var r = BABYLON.Vector2.Zero();
  1040. this.maxToRef(r);
  1041. return r;
  1042. };
  1043. /**
  1044. * Update a vector2 with the max extend of the bounding info
  1045. * @param result must be a valid/allocated vector2 that will contain the result of the operation
  1046. */
  1047. BoundingInfo2D.prototype.maxToRef = function (result) {
  1048. result.x = this.center.x + this.extent.x;
  1049. result.y = this.center.y + this.extent.y;
  1050. };
  1051. /**
  1052. * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
  1053. * @param matrix the transformation matrix to apply
  1054. * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
  1055. */
  1056. BoundingInfo2D.prototype.transform = function (matrix) {
  1057. var r = new BoundingInfo2D();
  1058. this.transformToRef(matrix, r);
  1059. return r;
  1060. };
  1061. /**
  1062. * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
  1063. * @param other the second BoundingInfo2D to compute the union with this one
  1064. * @return a new instance containing the result of the union
  1065. */
  1066. BoundingInfo2D.prototype.union = function (other) {
  1067. var r = new BoundingInfo2D();
  1068. this.unionToRef(other, r);
  1069. return r;
  1070. };
  1071. /**
  1072. * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
  1073. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  1074. * @param matrix The matrix to use to compute the transformation
  1075. * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
  1076. */
  1077. BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
  1078. // Construct a bounding box based on the extent values
  1079. var p = BoundingInfo2D._transform;
  1080. p[0].x = this.center.x + this.extent.x;
  1081. p[0].y = this.center.y + this.extent.y;
  1082. p[1].x = this.center.x + this.extent.x;
  1083. p[1].y = this.center.y - this.extent.y;
  1084. p[2].x = this.center.x - this.extent.x;
  1085. p[2].y = this.center.y - this.extent.y;
  1086. p[3].x = this.center.x - this.extent.x;
  1087. p[3].y = this.center.y + this.extent.y;
  1088. // Transform the four points of the bounding box with the matrix
  1089. for (var i = 0; i < 4; i++) {
  1090. BABYLON.Vector2.TransformToRef(p[i], matrix, p[i]);
  1091. }
  1092. BoundingInfo2D.CreateFromPointsToRef(p, result);
  1093. };
  1094. /**
  1095. * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
  1096. * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
  1097. * @param other the second object used to compute the union
  1098. * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
  1099. */
  1100. BoundingInfo2D.prototype.unionToRef = function (other, result) {
  1101. var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
  1102. var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
  1103. var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
  1104. var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
  1105. BoundingInfo2D.CreateFromMinMaxToRef(xmin, xmax, ymin, ymax, result);
  1106. };
  1107. /**
  1108. * Check if the given point is inside the BoundingInfo.
  1109. * The test is first made on the radius, then inside the rectangle described by the extent
  1110. * @param pickPosition the position to test
  1111. * @return true if the point is inside, false otherwise
  1112. */
  1113. BoundingInfo2D.prototype.doesIntersect = function (pickPosition) {
  1114. // is it inside the radius?
  1115. var pickLocal = pickPosition.subtract(this.center);
  1116. if (pickLocal.lengthSquared() <= (this.radius * this.radius)) {
  1117. // is it inside the rectangle?
  1118. return ((Math.abs(pickLocal.x) <= this.extent.x) && (Math.abs(pickLocal.y) <= this.extent.y));
  1119. }
  1120. return false;
  1121. };
  1122. BoundingInfo2D._transform = new Array(BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero(), BABYLON.Vector2.Zero());
  1123. return BoundingInfo2D;
  1124. }());
  1125. BABYLON.BoundingInfo2D = BoundingInfo2D;
  1126. })(BABYLON || (BABYLON = {}));
  1127. var BABYLON;
  1128. (function (BABYLON) {
  1129. var LayoutEngineBase = (function () {
  1130. function LayoutEngineBase() {
  1131. this.layoutDirtyOnPropertyChangedMask = 0;
  1132. }
  1133. LayoutEngineBase.prototype.updateLayout = function (prim) {
  1134. };
  1135. Object.defineProperty(LayoutEngineBase.prototype, "isChildPositionAllowed", {
  1136. get: function () {
  1137. return false;
  1138. },
  1139. enumerable: true,
  1140. configurable: true
  1141. });
  1142. LayoutEngineBase.prototype.isLocked = function () {
  1143. return this._isLocked;
  1144. };
  1145. LayoutEngineBase.prototype.lock = function () {
  1146. if (this._isLocked) {
  1147. return false;
  1148. }
  1149. this._isLocked = true;
  1150. return true;
  1151. };
  1152. LayoutEngineBase = __decorate([
  1153. BABYLON.className("LayoutEngineBase", "BABYLON")
  1154. ], LayoutEngineBase);
  1155. return LayoutEngineBase;
  1156. }());
  1157. BABYLON.LayoutEngineBase = LayoutEngineBase;
  1158. var CanvasLayoutEngine = (function (_super) {
  1159. __extends(CanvasLayoutEngine, _super);
  1160. function CanvasLayoutEngine() {
  1161. _super.apply(this, arguments);
  1162. }
  1163. // A very simple (no) layout computing...
  1164. // The Canvas and its direct children gets the Canvas' size as Layout Area
  1165. // Indirect children have their Layout Area to the actualSize (margin area) of their parent
  1166. CanvasLayoutEngine.prototype.updateLayout = function (prim) {
  1167. // If this prim is layoutDiry we update its layoutArea and also the one of its direct children
  1168. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1169. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1170. var child = _a[_i];
  1171. this._doUpdate(child);
  1172. }
  1173. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1174. }
  1175. };
  1176. CanvasLayoutEngine.prototype._doUpdate = function (prim) {
  1177. // Canvas ?
  1178. if (prim instanceof BABYLON.Canvas2D) {
  1179. prim.layoutArea = prim.actualSize;
  1180. }
  1181. else if (prim.parent instanceof BABYLON.Canvas2D) {
  1182. prim.layoutArea = prim.owner.actualSize;
  1183. }
  1184. else {
  1185. prim.layoutArea = prim.parent.contentArea;
  1186. }
  1187. };
  1188. Object.defineProperty(CanvasLayoutEngine.prototype, "isChildPositionAllowed", {
  1189. get: function () {
  1190. return true;
  1191. },
  1192. enumerable: true,
  1193. configurable: true
  1194. });
  1195. CanvasLayoutEngine.Singleton = new CanvasLayoutEngine();
  1196. CanvasLayoutEngine = __decorate([
  1197. BABYLON.className("CanvasLayoutEngine", "BABYLON")
  1198. ], CanvasLayoutEngine);
  1199. return CanvasLayoutEngine;
  1200. }(LayoutEngineBase));
  1201. BABYLON.CanvasLayoutEngine = CanvasLayoutEngine;
  1202. var StackPanelLayoutEngine = (function (_super) {
  1203. __extends(StackPanelLayoutEngine, _super);
  1204. function StackPanelLayoutEngine() {
  1205. _super.call(this);
  1206. this._isHorizontal = true;
  1207. this.layoutDirtyOnPropertyChangedMask = BABYLON.Prim2DBase.sizeProperty.flagId;
  1208. }
  1209. Object.defineProperty(StackPanelLayoutEngine, "Horizontal", {
  1210. get: function () {
  1211. if (!StackPanelLayoutEngine._horizontal) {
  1212. StackPanelLayoutEngine._horizontal = new StackPanelLayoutEngine();
  1213. StackPanelLayoutEngine._horizontal.isHorizontal = true;
  1214. StackPanelLayoutEngine._horizontal.lock();
  1215. }
  1216. return StackPanelLayoutEngine._horizontal;
  1217. },
  1218. enumerable: true,
  1219. configurable: true
  1220. });
  1221. Object.defineProperty(StackPanelLayoutEngine, "Vertical", {
  1222. get: function () {
  1223. if (!StackPanelLayoutEngine._vertical) {
  1224. StackPanelLayoutEngine._vertical = new StackPanelLayoutEngine();
  1225. StackPanelLayoutEngine._vertical.isHorizontal = false;
  1226. StackPanelLayoutEngine._vertical.lock();
  1227. }
  1228. return StackPanelLayoutEngine._vertical;
  1229. },
  1230. enumerable: true,
  1231. configurable: true
  1232. });
  1233. Object.defineProperty(StackPanelLayoutEngine.prototype, "isHorizontal", {
  1234. get: function () {
  1235. return this._isHorizontal;
  1236. },
  1237. set: function (val) {
  1238. if (this.isLocked()) {
  1239. return;
  1240. }
  1241. this._isHorizontal = val;
  1242. },
  1243. enumerable: true,
  1244. configurable: true
  1245. });
  1246. StackPanelLayoutEngine.prototype.updateLayout = function (prim) {
  1247. if (prim._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  1248. var x = 0;
  1249. var y = 0;
  1250. var h = this.isHorizontal;
  1251. var max = 0;
  1252. for (var _i = 0, _a = prim.children; _i < _a.length; _i++) {
  1253. var child = _a[_i];
  1254. var layoutArea = void 0;
  1255. if (child._hasMargin) {
  1256. child.margin.computeWithAlignment(prim.layoutArea, child.actualSize, child.marginAlignment, StackPanelLayoutEngine.dstOffset, StackPanelLayoutEngine.dstArea, true);
  1257. layoutArea = StackPanelLayoutEngine.dstArea.clone();
  1258. child.layoutArea = layoutArea;
  1259. }
  1260. else {
  1261. layoutArea = child.layoutArea;
  1262. child.margin.computeArea(child.actualSize, layoutArea);
  1263. }
  1264. max = Math.max(max, h ? layoutArea.height : layoutArea.width);
  1265. }
  1266. for (var _b = 0, _c = prim.children; _b < _c.length; _b++) {
  1267. var child = _c[_b];
  1268. child.layoutAreaPos = new BABYLON.Vector2(x, y);
  1269. var layoutArea = child.layoutArea;
  1270. if (h) {
  1271. x += layoutArea.width;
  1272. child.layoutArea = new BABYLON.Size(layoutArea.width, max);
  1273. }
  1274. else {
  1275. y += layoutArea.height;
  1276. child.layoutArea = new BABYLON.Size(max, layoutArea.height);
  1277. }
  1278. }
  1279. prim._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  1280. }
  1281. };
  1282. Object.defineProperty(StackPanelLayoutEngine.prototype, "isChildPositionAllowed", {
  1283. get: function () {
  1284. return false;
  1285. },
  1286. enumerable: true,
  1287. configurable: true
  1288. });
  1289. StackPanelLayoutEngine._horizontal = null;
  1290. StackPanelLayoutEngine._vertical = null;
  1291. StackPanelLayoutEngine.dstOffset = BABYLON.Vector2.Zero();
  1292. StackPanelLayoutEngine.dstArea = BABYLON.Size.Zero();
  1293. StackPanelLayoutEngine = __decorate([
  1294. BABYLON.className("StackPanelLayoutEngine", "BABYLON")
  1295. ], StackPanelLayoutEngine);
  1296. return StackPanelLayoutEngine;
  1297. }(LayoutEngineBase));
  1298. BABYLON.StackPanelLayoutEngine = StackPanelLayoutEngine;
  1299. })(BABYLON || (BABYLON = {}));
  1300. var BABYLON;
  1301. (function (BABYLON) {
  1302. /**
  1303. * Base class implementing the ILocable interface.
  1304. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  1305. */
  1306. var LockableBase = (function () {
  1307. function LockableBase() {
  1308. }
  1309. LockableBase.prototype.isLocked = function () {
  1310. return this._isLocked;
  1311. };
  1312. LockableBase.prototype.lock = function () {
  1313. if (this._isLocked) {
  1314. return true;
  1315. }
  1316. this.onLock();
  1317. this._isLocked = true;
  1318. return false;
  1319. };
  1320. /**
  1321. * Protected handler that will be called when the instance is about to be locked.
  1322. */
  1323. LockableBase.prototype.onLock = function () {
  1324. };
  1325. return LockableBase;
  1326. }());
  1327. BABYLON.LockableBase = LockableBase;
  1328. var SolidColorBrush2D = (function (_super) {
  1329. __extends(SolidColorBrush2D, _super);
  1330. function SolidColorBrush2D(color, lock) {
  1331. if (lock === void 0) { lock = false; }
  1332. _super.call(this);
  1333. this._color = color;
  1334. if (lock) {
  1335. {
  1336. this.lock();
  1337. }
  1338. }
  1339. }
  1340. /**
  1341. * Return true if the brush is transparent, false if it's totally opaque
  1342. */
  1343. SolidColorBrush2D.prototype.isTransparent = function () {
  1344. return this._color && this._color.a < 1.0;
  1345. };
  1346. Object.defineProperty(SolidColorBrush2D.prototype, "color", {
  1347. /**
  1348. * The color used by this instance to render
  1349. * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
  1350. */
  1351. get: function () {
  1352. return this._color;
  1353. },
  1354. set: function (value) {
  1355. if (this.isLocked()) {
  1356. return;
  1357. }
  1358. this._color = value;
  1359. },
  1360. enumerable: true,
  1361. configurable: true
  1362. });
  1363. /**
  1364. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  1365. */
  1366. SolidColorBrush2D.prototype.toString = function () {
  1367. return this._color.toHexString();
  1368. };
  1369. SolidColorBrush2D = __decorate([
  1370. BABYLON.className("SolidColorBrush2D", "BABYLON")
  1371. ], SolidColorBrush2D);
  1372. return SolidColorBrush2D;
  1373. }(LockableBase));
  1374. BABYLON.SolidColorBrush2D = SolidColorBrush2D;
  1375. var GradientColorBrush2D = (function (_super) {
  1376. __extends(GradientColorBrush2D, _super);
  1377. function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
  1378. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  1379. if (rotation === void 0) { rotation = 0; }
  1380. if (scale === void 0) { scale = 1; }
  1381. if (lock === void 0) { lock = false; }
  1382. _super.call(this);
  1383. this._color1 = color1;
  1384. this._color2 = color2;
  1385. this._translation = translation;
  1386. this._rotation = rotation;
  1387. this._scale = scale;
  1388. if (lock) {
  1389. this.lock();
  1390. }
  1391. }
  1392. /**
  1393. * Return true if the brush is transparent, false if it's totally opaque
  1394. */
  1395. GradientColorBrush2D.prototype.isTransparent = function () {
  1396. return (this._color1 && this._color1.a < 1.0) || (this._color2 && this._color2.a < 1.0);
  1397. };
  1398. Object.defineProperty(GradientColorBrush2D.prototype, "color1", {
  1399. /**
  1400. * First color, the blend will start from this color
  1401. */
  1402. get: function () {
  1403. return this._color1;
  1404. },
  1405. set: function (value) {
  1406. if (this.isLocked()) {
  1407. return;
  1408. }
  1409. this._color1 = value;
  1410. },
  1411. enumerable: true,
  1412. configurable: true
  1413. });
  1414. Object.defineProperty(GradientColorBrush2D.prototype, "color2", {
  1415. /**
  1416. * Second color, the blend will end to this color
  1417. */
  1418. get: function () {
  1419. return this._color2;
  1420. },
  1421. set: function (value) {
  1422. if (this.isLocked()) {
  1423. return;
  1424. }
  1425. this._color2 = value;
  1426. },
  1427. enumerable: true,
  1428. configurable: true
  1429. });
  1430. Object.defineProperty(GradientColorBrush2D.prototype, "translation", {
  1431. /**
  1432. * Translation vector to apply on the blend
  1433. * Default is [0;0]
  1434. */
  1435. get: function () {
  1436. return this._translation;
  1437. },
  1438. set: function (value) {
  1439. if (this.isLocked()) {
  1440. return;
  1441. }
  1442. this._translation = value;
  1443. },
  1444. enumerable: true,
  1445. configurable: true
  1446. });
  1447. Object.defineProperty(GradientColorBrush2D.prototype, "rotation", {
  1448. /**
  1449. * Rotation in radian to apply to the brush
  1450. * Default direction of the brush is vertical, you can change this using this property.
  1451. * Default is 0.
  1452. */
  1453. get: function () {
  1454. return this._rotation;
  1455. },
  1456. set: function (value) {
  1457. if (this.isLocked()) {
  1458. return;
  1459. }
  1460. this._rotation = value;
  1461. },
  1462. enumerable: true,
  1463. configurable: true
  1464. });
  1465. Object.defineProperty(GradientColorBrush2D.prototype, "scale", {
  1466. /**
  1467. * Scale factor to apply to the gradient.
  1468. * Default is 1: no scale.
  1469. */
  1470. get: function () {
  1471. return this._scale;
  1472. },
  1473. set: function (value) {
  1474. if (this.isLocked()) {
  1475. return;
  1476. }
  1477. this._scale = value;
  1478. },
  1479. enumerable: true,
  1480. configurable: true
  1481. });
  1482. /**
  1483. * Return a string describing the brush
  1484. */
  1485. GradientColorBrush2D.prototype.toString = function () {
  1486. return "C1:" + this._color1 + ";C2:" + this._color2 + ";T:" + this._translation.toString() + ";R:" + this._rotation + ";S:" + this._scale + ";";
  1487. };
  1488. /**
  1489. * Build a unique key string for the given parameters
  1490. */
  1491. GradientColorBrush2D.BuildKey = function (color1, color2, translation, rotation, scale) {
  1492. return "C1:" + color1 + ";C2:" + color2 + ";T:" + translation.toString() + ";R:" + rotation + ";S:" + scale + ";";
  1493. };
  1494. GradientColorBrush2D = __decorate([
  1495. BABYLON.className("GradientColorBrush2D", "BABYLON")
  1496. ], GradientColorBrush2D);
  1497. return GradientColorBrush2D;
  1498. }(LockableBase));
  1499. BABYLON.GradientColorBrush2D = GradientColorBrush2D;
  1500. })(BABYLON || (BABYLON = {}));
  1501. var BABYLON;
  1502. (function (BABYLON) {
  1503. var Prim2DClassInfo = (function () {
  1504. function Prim2DClassInfo() {
  1505. }
  1506. return Prim2DClassInfo;
  1507. }());
  1508. BABYLON.Prim2DClassInfo = Prim2DClassInfo;
  1509. var Prim2DPropInfo = (function () {
  1510. function Prim2DPropInfo() {
  1511. }
  1512. Prim2DPropInfo.PROPKIND_MODEL = 1;
  1513. Prim2DPropInfo.PROPKIND_INSTANCE = 2;
  1514. Prim2DPropInfo.PROPKIND_DYNAMIC = 3;
  1515. return Prim2DPropInfo;
  1516. }());
  1517. BABYLON.Prim2DPropInfo = Prim2DPropInfo;
  1518. var ClassTreeInfo = (function () {
  1519. function ClassTreeInfo(baseClass, type, classContentFactory) {
  1520. this._baseClass = baseClass;
  1521. this._type = type;
  1522. this._subClasses = new Array();
  1523. this._levelContent = new BABYLON.StringDictionary();
  1524. this._classContentFactory = classContentFactory;
  1525. }
  1526. Object.defineProperty(ClassTreeInfo.prototype, "classContent", {
  1527. get: function () {
  1528. if (!this._classContent) {
  1529. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  1530. }
  1531. return this._classContent;
  1532. },
  1533. enumerable: true,
  1534. configurable: true
  1535. });
  1536. Object.defineProperty(ClassTreeInfo.prototype, "type", {
  1537. get: function () {
  1538. return this._type;
  1539. },
  1540. enumerable: true,
  1541. configurable: true
  1542. });
  1543. Object.defineProperty(ClassTreeInfo.prototype, "levelContent", {
  1544. get: function () {
  1545. return this._levelContent;
  1546. },
  1547. enumerable: true,
  1548. configurable: true
  1549. });
  1550. Object.defineProperty(ClassTreeInfo.prototype, "fullContent", {
  1551. get: function () {
  1552. if (!this._fullContent) {
  1553. var dic_1 = new BABYLON.StringDictionary();
  1554. var curLevel = this;
  1555. while (curLevel) {
  1556. curLevel.levelContent.forEach(function (k, v) { return dic_1.add(k, v); });
  1557. curLevel = curLevel._baseClass;
  1558. }
  1559. this._fullContent = dic_1;
  1560. }
  1561. return this._fullContent;
  1562. },
  1563. enumerable: true,
  1564. configurable: true
  1565. });
  1566. ClassTreeInfo.prototype.getLevelOf = function (type) {
  1567. // Are we already there?
  1568. if (type === this._type) {
  1569. return this;
  1570. }
  1571. var baseProto = Object.getPrototypeOf(type);
  1572. var curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  1573. if (!curProtoContent) {
  1574. this.getLevelOf(baseProto);
  1575. }
  1576. return this.getOrAddType(baseProto, type);
  1577. };
  1578. ClassTreeInfo.prototype.getOrAddType = function (baseType, type) {
  1579. // Are we at the level corresponding to the baseType?
  1580. // If so, get or add the level we're looking for
  1581. if (baseType === this._type) {
  1582. for (var _i = 0, _a = this._subClasses; _i < _a.length; _i++) {
  1583. var subType = _a[_i];
  1584. if (subType.type === type) {
  1585. return subType.node;
  1586. }
  1587. }
  1588. var node = new ClassTreeInfo(this, type, this._classContentFactory);
  1589. var info = { type: type, node: node };
  1590. this._subClasses.push(info);
  1591. return info.node;
  1592. }
  1593. // Recurse down to keep looking for the node corresponding to the baseTypeName
  1594. for (var _b = 0, _c = this._subClasses; _b < _c.length; _b++) {
  1595. var subType = _c[_b];
  1596. var info = subType.node.getOrAddType(baseType, type);
  1597. if (info) {
  1598. return info;
  1599. }
  1600. }
  1601. return null;
  1602. };
  1603. ClassTreeInfo.get = function (type) {
  1604. var dic = type["__classTreeInfo"];
  1605. if (!dic) {
  1606. return null;
  1607. }
  1608. return dic.getLevelOf(type);
  1609. };
  1610. ClassTreeInfo.getOrRegister = function (type, classContentFactory) {
  1611. var dic = type["__classTreeInfo"];
  1612. if (!dic) {
  1613. dic = new ClassTreeInfo(null, type, classContentFactory);
  1614. type["__classTreeInfo"] = dic;
  1615. }
  1616. return dic;
  1617. };
  1618. return ClassTreeInfo;
  1619. }());
  1620. BABYLON.ClassTreeInfo = ClassTreeInfo;
  1621. var DataBinding = (function () {
  1622. function DataBinding() {
  1623. this._converter = null;
  1624. this._mode = DataBinding.MODE_DEFAULT;
  1625. this._uiElementId = null;
  1626. this._dataSource = null;
  1627. this._currentDataSource = null;
  1628. this._propertyPathName = null;
  1629. this._stringFormat = null;
  1630. this._updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  1631. this._boundTo = null;
  1632. this._owner = null;
  1633. this._updateCounter = 0;
  1634. }
  1635. Object.defineProperty(DataBinding.prototype, "converter", {
  1636. /**
  1637. * Provide a callback that will convert the value obtained by the Data Binding to the type of the SmartProperty it's bound to.
  1638. * If no value are set, then it's assumed that the sourceValue is of the same type as the SmartProperty's one.
  1639. * If the SmartProperty type is a basic data type (string, boolean or number) and no converter is specified but the sourceValue is of a different type, the conversion will be implicitly made, if possible.
  1640. * @param sourceValue the source object retrieve by the Data Binding mechanism
  1641. * @returns the object of a compatible type with the SmartProperty it's bound to
  1642. */
  1643. get: function () {
  1644. return this._converter;
  1645. },
  1646. set: function (value) {
  1647. if (this._converter === value) {
  1648. return;
  1649. }
  1650. this._converter = value;
  1651. },
  1652. enumerable: true,
  1653. configurable: true
  1654. });
  1655. Object.defineProperty(DataBinding.prototype, "mode", {
  1656. /**
  1657. * Set the mode to use for the data flow in the binding. Set one of the MODE_xxx static member of this class. If not specified then MODE_DEFAULT will be used
  1658. */
  1659. get: function () {
  1660. if (this._mode === DataBinding.MODE_DEFAULT) {
  1661. return this._boundTo.bindingMode;
  1662. }
  1663. return this._mode;
  1664. },
  1665. set: function (value) {
  1666. if (this._mode === value) {
  1667. return;
  1668. }
  1669. this._mode = value;
  1670. },
  1671. enumerable: true,
  1672. configurable: true
  1673. });
  1674. Object.defineProperty(DataBinding.prototype, "uiElementId", {
  1675. /**
  1676. * You can override the Data Source object with this member which is the Id of a uiElement existing in the UI Logical tree.
  1677. * If not set and source no set too, then the dataSource property will be used.
  1678. */
  1679. get: function () {
  1680. return this._uiElementId;
  1681. },
  1682. set: function (value) {
  1683. if (this._uiElementId === value) {
  1684. return;
  1685. }
  1686. this._uiElementId = value;
  1687. },
  1688. enumerable: true,
  1689. configurable: true
  1690. });
  1691. Object.defineProperty(DataBinding.prototype, "dataSource", {
  1692. /**
  1693. * You can override the Data Source object with this member which is the source object to use directly.
  1694. * If not set and uiElement no set too, then the dataSource property of the SmartPropertyBase object will be used.
  1695. */
  1696. get: function () {
  1697. return this._dataSource;
  1698. },
  1699. set: function (value) {
  1700. if (this._dataSource === value) {
  1701. return;
  1702. }
  1703. this._dataSource = value;
  1704. },
  1705. enumerable: true,
  1706. configurable: true
  1707. });
  1708. Object.defineProperty(DataBinding.prototype, "propertyPathName", {
  1709. /**
  1710. * The path & name of the property to get from the source object.
  1711. * Once the Source object is evaluated (it's either the one got from uiElementId, source or dataSource) you can specify which property of this object is the value to bind to the smartProperty.
  1712. * If nothing is set then the source object will be used.
  1713. * You can specify an indirect property using the format "firstProperty.indirectProperty" like "address.postalCode" if the source is a Customer object which contains an address property and the Address class contains a postalCode property.
  1714. * If the property is an Array and you want to address a particular element then use the 'arrayProperty[index]' notation. For example "phoneNumbers[0]" to get the first element of the phoneNumber property which is an array.
  1715. */
  1716. get: function () {
  1717. return this._propertyPathName;
  1718. },
  1719. set: function (value) {
  1720. if (this._propertyPathName === value) {
  1721. return;
  1722. }
  1723. if (this._owner) {
  1724. }
  1725. this._propertyPathName = value;
  1726. if (this._owner) {
  1727. }
  1728. },
  1729. enumerable: true,
  1730. configurable: true
  1731. });
  1732. Object.defineProperty(DataBinding.prototype, "stringFormat", {
  1733. /**
  1734. * If the Smart Property is of the string type, you can use the string interpolation notation to provide how the sourceValue will be formatted, reference to the source value must be made via the token: ${value}. For instance `Customer Name: ${value}`
  1735. */
  1736. get: function () {
  1737. return this._stringFormat;
  1738. },
  1739. set: function (value) {
  1740. if (this._stringFormat === value) {
  1741. return;
  1742. }
  1743. this._stringFormat = value;
  1744. },
  1745. enumerable: true,
  1746. configurable: true
  1747. });
  1748. Object.defineProperty(DataBinding.prototype, "updateSourceTrigger", {
  1749. /**
  1750. * Specify how the source should be updated, use one of the UPDATESOURCETRIGGER_xxx member of this class, if not specified then UPDATESOURCETRIGGER_DEFAULT will be used.
  1751. */
  1752. get: function () {
  1753. return this._updateSourceTrigger;
  1754. },
  1755. set: function (value) {
  1756. if (this._updateSourceTrigger === value) {
  1757. return;
  1758. }
  1759. this._updateSourceTrigger = value;
  1760. },
  1761. enumerable: true,
  1762. configurable: true
  1763. });
  1764. DataBinding.prototype.canUpdateTarget = function (resetUpdateCounter) {
  1765. if (resetUpdateCounter) {
  1766. this._updateCounter = 0;
  1767. }
  1768. var mode = this.mode;
  1769. if (mode === DataBinding.MODE_ONETIME) {
  1770. return this._updateCounter === 0;
  1771. }
  1772. if (mode === DataBinding.MODE_ONEWAYTOSOURCE) {
  1773. return false;
  1774. }
  1775. return true;
  1776. };
  1777. DataBinding.prototype.updateTarget = function () {
  1778. var value = this._getActualDataSource();
  1779. var properties = this.propertyPathName.split(".");
  1780. for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
  1781. var propertyName = properties_1[_i];
  1782. value = value[propertyName];
  1783. }
  1784. this._storeBoundValue(this._owner, value);
  1785. };
  1786. DataBinding.prototype._storeBoundValue = function (watcher, value) {
  1787. if ((++this._updateCounter > 1) && (this.mode === DataBinding.MODE_ONETIME)) {
  1788. return;
  1789. }
  1790. var newValue = value;
  1791. if (this._converter) {
  1792. newValue = this._converter(value);
  1793. }
  1794. if (this._stringFormat) {
  1795. newValue = this._stringFormat(newValue);
  1796. }
  1797. watcher[this._boundTo.name] = newValue;
  1798. };
  1799. DataBinding.prototype._getActualDataSource = function () {
  1800. if (this.dataSource) {
  1801. return this.dataSource;
  1802. }
  1803. if (this.uiElementId) {
  1804. // TODO Find UIElement
  1805. return null;
  1806. }
  1807. return this._owner.dataSource;
  1808. };
  1809. DataBinding.prototype._registerDataSource = function (updateTarget) {
  1810. var ds = this._getActualDataSource();
  1811. if (ds === this._currentDataSource) {
  1812. return;
  1813. }
  1814. if (this._currentDataSource) {
  1815. BindingHelper.unregisterDataSource(this._currentDataSource, this, 0);
  1816. }
  1817. if (ds) {
  1818. BindingHelper.registerDataSource(ds, this);
  1819. if (updateTarget && this.canUpdateTarget(true)) {
  1820. this.updateTarget();
  1821. }
  1822. }
  1823. this._currentDataSource = ds;
  1824. };
  1825. DataBinding.prototype._unregisterDataSource = function () {
  1826. var ds = this._getActualDataSource();
  1827. if (ds) {
  1828. BindingHelper.unregisterDataSource(ds, this, 0);
  1829. }
  1830. };
  1831. /**
  1832. * Use the mode specified in the SmartProperty declaration
  1833. */
  1834. DataBinding.MODE_DEFAULT = 1;
  1835. /**
  1836. * Update the binding target only once when the Smart Property's value is first accessed
  1837. */
  1838. DataBinding.MODE_ONETIME = 2;
  1839. /**
  1840. * Update the smart property when the source changes.
  1841. * The source won't be updated if the smart property value is set.
  1842. */
  1843. DataBinding.MODE_ONEWAY = 3;
  1844. /**
  1845. * Only update the source when the target's data is changing.
  1846. */
  1847. DataBinding.MODE_ONEWAYTOSOURCE = 4;
  1848. /**
  1849. * Update the bind target when the source changes and update the source when the Smart Property value is set.
  1850. */
  1851. DataBinding.MODE_TWOWAY = 5;
  1852. /**
  1853. * Use the Update Source Trigger defined in the SmartProperty declaration
  1854. */
  1855. DataBinding.UPDATESOURCETRIGGER_DEFAULT = 1;
  1856. /**
  1857. * Update the source as soon as the Smart Property has a value change
  1858. */
  1859. DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED = 2;
  1860. /**
  1861. * Update the source when the binding target loses focus
  1862. */
  1863. DataBinding.UPDATESOURCETRIGGER_LOSTFOCUS = 3;
  1864. /**
  1865. * Update the source will be made by explicitly calling the UpdateFromDataSource method
  1866. */
  1867. DataBinding.UPDATESOURCETRIGGER_EXPLICIT = 4;
  1868. DataBinding = __decorate([
  1869. BABYLON.className("DataBinding", "BABYLON")
  1870. ], DataBinding);
  1871. return DataBinding;
  1872. }());
  1873. BABYLON.DataBinding = DataBinding;
  1874. var SmartPropertyBase = (function (_super) {
  1875. __extends(SmartPropertyBase, _super);
  1876. function SmartPropertyBase() {
  1877. _super.call(this);
  1878. this._dataSource = null;
  1879. this._dataSourceObserver = null;
  1880. this._instanceDirtyFlags = 0;
  1881. this._isDisposed = false;
  1882. this._bindings = null;
  1883. this._hasBinding = 0;
  1884. this._bindingSourceChanged = 0;
  1885. this._disposeObservable = null;
  1886. }
  1887. Object.defineProperty(SmartPropertyBase.prototype, "disposeObservable", {
  1888. get: function () {
  1889. if (!this._disposeObservable) {
  1890. this._disposeObservable = new BABYLON.Observable();
  1891. }
  1892. return this._disposeObservable;
  1893. },
  1894. enumerable: true,
  1895. configurable: true
  1896. });
  1897. Object.defineProperty(SmartPropertyBase.prototype, "isDisposed", {
  1898. /**
  1899. * Check if the object is disposed or not.
  1900. * @returns true if the object is dispose, false otherwise.
  1901. */
  1902. get: function () {
  1903. return this._isDisposed;
  1904. },
  1905. enumerable: true,
  1906. configurable: true
  1907. });
  1908. /**
  1909. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  1910. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  1911. */
  1912. SmartPropertyBase.prototype.dispose = function () {
  1913. if (this.isDisposed) {
  1914. return false;
  1915. }
  1916. if (this._disposeObservable && this._disposeObservable.hasObservers()) {
  1917. this._disposeObservable.notifyObservers(this);
  1918. }
  1919. this._isDisposed = true;
  1920. return true;
  1921. };
  1922. /**
  1923. * Check if a given set of properties are dirty or not.
  1924. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1925. * @return true if at least one property is dirty, false if none of them are.
  1926. */
  1927. SmartPropertyBase.prototype.checkPropertiesDirty = function (flags) {
  1928. return (this._instanceDirtyFlags & flags) !== 0;
  1929. };
  1930. /**
  1931. * Clear a given set of properties.
  1932. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  1933. * @return the new set of property still marked as dirty
  1934. */
  1935. SmartPropertyBase.prototype.clearPropertiesDirty = function (flags) {
  1936. this._instanceDirtyFlags &= ~flags;
  1937. return this._instanceDirtyFlags;
  1938. };
  1939. SmartPropertyBase.prototype._resetPropertiesDirty = function () {
  1940. this._instanceDirtyFlags = 0;
  1941. };
  1942. /**
  1943. * Add an externally attached data from its key.
  1944. * This method call will fail and return false, if such key already exists.
  1945. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  1946. * @param key the unique key that identifies the data
  1947. * @param data the data object to associate to the key for this Engine instance
  1948. * @return true if no such key were already present and the data was added successfully, false otherwise
  1949. */
  1950. SmartPropertyBase.prototype.addExternalData = function (key, data) {
  1951. if (!this._externalData) {
  1952. this._externalData = new BABYLON.StringDictionary();
  1953. }
  1954. return this._externalData.add(key, data);
  1955. };
  1956. /**
  1957. * Get an externally attached data from its key
  1958. * @param key the unique key that identifies the data
  1959. * @return the associated data, if present (can be null), or undefined if not present
  1960. */
  1961. SmartPropertyBase.prototype.getExternalData = function (key) {
  1962. if (!this._externalData) {
  1963. return null;
  1964. }
  1965. return this._externalData.get(key);
  1966. };
  1967. /**
  1968. * Get an externally attached data from its key, create it using a factory if it's not already present
  1969. * @param key the unique key that identifies the data
  1970. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  1971. * @return the associated data, can be null if the factory returned null.
  1972. */
  1973. SmartPropertyBase.prototype.getOrAddExternalDataWithFactory = function (key, factory) {
  1974. if (!this._externalData) {
  1975. this._externalData = new BABYLON.StringDictionary();
  1976. }
  1977. return this._externalData.getOrAddWithFactory(key, factory);
  1978. };
  1979. /**
  1980. * Remove an externally attached data from the Engine instance
  1981. * @param key the unique key that identifies the data
  1982. * @return true if the data was successfully removed, false if it doesn't exist
  1983. */
  1984. SmartPropertyBase.prototype.removeExternalData = function (key) {
  1985. if (!this._externalData) {
  1986. return false;
  1987. }
  1988. return this._externalData.remove(key);
  1989. };
  1990. SmartPropertyBase._hookProperty = function (propId, piStore, kind, settings) {
  1991. return function (target, propName, descriptor) {
  1992. if (!settings) {
  1993. settings = {};
  1994. }
  1995. var propInfo = SmartPropertyBase._createPropInfo(target, propName, propId, kind, settings);
  1996. if (piStore) {
  1997. piStore(propInfo);
  1998. }
  1999. var getter = descriptor.get, setter = descriptor.set;
  2000. var typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2001. // Overload the property setter implementation to add our own logic
  2002. descriptor.set = function (val) {
  2003. if (!setter) {
  2004. throw Error("Property '" + propInfo.name + "' of type '" + BABYLON.Tools.getFullClassName(this) + "' has no setter defined but was invoked as if it had one.");
  2005. }
  2006. // check for disposed first, do nothing
  2007. if (this.isDisposed) {
  2008. return;
  2009. }
  2010. var curVal = getter.call(this);
  2011. if (SmartPropertyBase._checkUnchanged(curVal, val)) {
  2012. return;
  2013. }
  2014. // Cast the object we're working one
  2015. var prim = this;
  2016. // Change the value
  2017. setter.call(this, val);
  2018. // Notify change, dirty flags update
  2019. prim._handlePropChanged(curVal, val, propName, propInfo, typeLevelCompare);
  2020. };
  2021. };
  2022. };
  2023. SmartPropertyBase._createPropInfo = function (target, propName, propId, kind, settings) {
  2024. var dic = ClassTreeInfo.getOrRegister(target, function () { return new Prim2DClassInfo(); });
  2025. var node = dic.getLevelOf(target);
  2026. var propInfo = node.levelContent.get(propId.toString());
  2027. if (propInfo) {
  2028. throw new Error("The ID " + propId + " is already taken by another property declaration named: " + propInfo.name);
  2029. }
  2030. // Create, setup and add the PropInfo object to our prop dictionary
  2031. propInfo = new Prim2DPropInfo();
  2032. propInfo.id = propId;
  2033. propInfo.flagId = Math.pow(2, propId);
  2034. propInfo.kind = kind;
  2035. propInfo.name = propName;
  2036. propInfo.bindingMode = (settings.bindingMode !== undefined) ? settings.bindingMode : DataBinding.MODE_TWOWAY;
  2037. propInfo.bindingUpdateSourceTrigger = (settings.bindingUpdateSourceTrigger !== undefined) ? settings.bindingUpdateSourceTrigger : DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED;
  2038. propInfo.dirtyBoundingInfo = (settings.dirtyBoundingInfo !== undefined) ? settings.dirtyBoundingInfo : false;
  2039. propInfo.dirtyParentBoundingInfo = (settings.dirtyParentBoundingBox !== undefined) ? settings.dirtyParentBoundingBox : false;
  2040. propInfo.typeLevelCompare = (settings.typeLevelCompare !== undefined) ? settings.typeLevelCompare : false;
  2041. node.levelContent.add(propName, propInfo);
  2042. return propInfo;
  2043. };
  2044. Object.defineProperty(SmartPropertyBase.prototype, "propDic", {
  2045. /**
  2046. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  2047. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  2048. */
  2049. get: function () {
  2050. if (!this._propInfo) {
  2051. var cti = ClassTreeInfo.get(Object.getPrototypeOf(this));
  2052. if (!cti) {
  2053. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  2054. }
  2055. this._propInfo = cti.fullContent;
  2056. }
  2057. return this._propInfo;
  2058. },
  2059. enumerable: true,
  2060. configurable: true
  2061. });
  2062. SmartPropertyBase._checkUnchanged = function (curValue, newValue) {
  2063. // Nothing to nothing: nothing to do!
  2064. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  2065. return true;
  2066. }
  2067. // Check value unchanged
  2068. if ((curValue != null) && (newValue != null)) {
  2069. if (typeof (curValue.equals) == "function") {
  2070. if (curValue.equals(newValue)) {
  2071. return true;
  2072. }
  2073. }
  2074. else {
  2075. if (curValue === newValue) {
  2076. return true;
  2077. }
  2078. }
  2079. }
  2080. return false;
  2081. };
  2082. SmartPropertyBase.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2083. // Trigger property changed
  2084. var info = SmartPropertyBase.propChangeGuarding ? new BABYLON.PropertyChangedInfo() : SmartPropertyPrim.propChangedInfo;
  2085. info.oldValue = curValue;
  2086. info.newValue = newValue;
  2087. info.propertyName = propName;
  2088. var propMask = propInfo ? propInfo.flagId : -1;
  2089. try {
  2090. SmartPropertyBase.propChangeGuarding = true;
  2091. this.propertyChanged.notifyObservers(info, propMask);
  2092. }
  2093. finally {
  2094. SmartPropertyBase.propChangeGuarding = false;
  2095. }
  2096. };
  2097. SmartPropertyBase.prototype._triggerPropertyChanged = function (propInfo, newValue) {
  2098. if (this.isDisposed) {
  2099. return;
  2100. }
  2101. if (!propInfo) {
  2102. return;
  2103. }
  2104. this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
  2105. };
  2106. Object.defineProperty(SmartPropertyBase.prototype, "dataSource", {
  2107. /**
  2108. * Set the object from which Smart Properties using Binding will take/update their data from/to.
  2109. * When the object is part of a graph (with parent/children relationship) if the dataSource of a given instance is not specified, then the parent's one is used.
  2110. */
  2111. get: function () {
  2112. // Don't access to _dataSource directly but via a call to the _getDataSource method which can be overloaded in inherited classes
  2113. return this._getDataSource();
  2114. },
  2115. set: function (value) {
  2116. if (this._dataSource === value) {
  2117. return;
  2118. }
  2119. var oldValue = this._dataSource;
  2120. this._dataSource = value;
  2121. if (this._bindings && value != null) {
  2122. // Register the bindings
  2123. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2124. var binding = _a[_i];
  2125. if (binding != null) {
  2126. binding._registerDataSource(true);
  2127. }
  2128. }
  2129. }
  2130. this.onPropertyChanged("dataSource", oldValue, value);
  2131. },
  2132. enumerable: true,
  2133. configurable: true
  2134. });
  2135. // Inheriting classes can overload this method to provides additional logic for dataSource access
  2136. SmartPropertyBase.prototype._getDataSource = function () {
  2137. return this._dataSource;
  2138. };
  2139. SmartPropertyBase.prototype.createSimpleDataBinding = function (propInfo, propertyPathName, mode) {
  2140. if (mode === void 0) { mode = DataBinding.MODE_DEFAULT; }
  2141. var binding = new DataBinding();
  2142. binding.propertyPathName = propertyPathName;
  2143. binding.mode = mode;
  2144. return this.createDataBinding(propInfo, binding);
  2145. };
  2146. SmartPropertyBase.prototype.createDataBinding = function (propInfo, binding) {
  2147. if (!this._bindings) {
  2148. this._bindings = new Array();
  2149. }
  2150. if (!binding || binding._owner != null) {
  2151. throw Error("A valid/unused Binding must be passed.");
  2152. }
  2153. // Unregister a potentially existing binding for this property
  2154. this.removeDataBinding(propInfo);
  2155. // register the binding
  2156. binding._owner = this;
  2157. binding._boundTo = propInfo;
  2158. this._bindings[propInfo.id] = binding;
  2159. this._hasBinding |= propInfo.flagId;
  2160. binding._registerDataSource(true);
  2161. return binding;
  2162. };
  2163. SmartPropertyBase.prototype.removeDataBinding = function (propInfo) {
  2164. if ((this._hasBinding & propInfo.flagId) === 0) {
  2165. return false;
  2166. }
  2167. var curBinding = this._bindings[propInfo.id];
  2168. curBinding._unregisterDataSource();
  2169. this._bindings[propInfo.id] = null;
  2170. this._hasBinding &= ~propInfo.flagId;
  2171. return true;
  2172. };
  2173. SmartPropertyBase.prototype.updateFromDataSource = function () {
  2174. for (var _i = 0, _a = this._bindings; _i < _a.length; _i++) {
  2175. var binding = _a[_i];
  2176. if (binding) {
  2177. }
  2178. }
  2179. };
  2180. SmartPropertyBase.propChangedInfo = new BABYLON.PropertyChangedInfo();
  2181. SmartPropertyBase.propChangeGuarding = false;
  2182. SmartPropertyBase = __decorate([
  2183. BABYLON.className("SmartPropertyBase", "BABYLON")
  2184. ], SmartPropertyBase);
  2185. return SmartPropertyBase;
  2186. }(BABYLON.PropertyChangedBase));
  2187. BABYLON.SmartPropertyBase = SmartPropertyBase;
  2188. var BindingInfo = (function () {
  2189. function BindingInfo(binding, level, isLast) {
  2190. this.binding = binding;
  2191. this.level = level;
  2192. this.isLast = isLast;
  2193. }
  2194. return BindingInfo;
  2195. }());
  2196. var MonitoredObjectData = (function () {
  2197. function MonitoredObjectData(monitoredObject) {
  2198. var _this = this;
  2199. this.monitoredObject = monitoredObject;
  2200. this.monitoredIntermediateProperties = new BABYLON.StringDictionary();
  2201. this.observer = this.monitoredObject.propertyChanged.add(function (e, s) { _this.propertyChangedHandler(e.propertyName, e.oldValue, e.newValue); });
  2202. this.boundProperties = new BABYLON.StringDictionary();
  2203. this.monitoredIntermediateMask = 0;
  2204. this.boundPropertiesMask = 0;
  2205. }
  2206. MonitoredObjectData.prototype.propertyChangedHandler = function (propName, oldValue, newValue) {
  2207. var propId = BindingHelper._getPropertyID(this.monitoredObject, propName);
  2208. var propIdStr = propId.toString();
  2209. // Loop through all the registered bindings for this property that had a value change
  2210. if ((this.boundPropertiesMask & propId) !== 0) {
  2211. var bindingInfos = this.boundProperties.get(propIdStr);
  2212. for (var _i = 0, bindingInfos_1 = bindingInfos; _i < bindingInfos_1.length; _i++) {
  2213. var bi = bindingInfos_1[_i];
  2214. if (!bi.isLast) {
  2215. BindingHelper.unregisterDataSource(this.monitoredObject, bi.binding, bi.level);
  2216. BindingHelper.registerDataSource(bi.binding._currentDataSource, bi.binding);
  2217. }
  2218. if (bi.binding.canUpdateTarget(false)) {
  2219. bi.binding.updateTarget();
  2220. }
  2221. }
  2222. }
  2223. };
  2224. return MonitoredObjectData;
  2225. }());
  2226. var BindingHelper = (function () {
  2227. function BindingHelper() {
  2228. }
  2229. BindingHelper.registerDataSource = function (dataSource, binding) {
  2230. var properties = binding.propertyPathName.split(".");
  2231. var ownerMod = null;
  2232. var ownerInterPropId = 0;
  2233. var propertyOwner = dataSource;
  2234. var _loop_1 = function(i) {
  2235. var propName = properties[i];
  2236. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2237. var propIdStr = propId.toString();
  2238. var mod = void 0;
  2239. if (ownerMod) {
  2240. var o_1 = ownerMod;
  2241. var po_1 = propertyOwner;
  2242. var oii_1 = ownerInterPropId;
  2243. mod = ownerMod.monitoredIntermediateProperties.getOrAddWithFactory(oii_1.toString(), function (k) {
  2244. o_1.monitoredIntermediateMask |= oii_1;
  2245. return BindingHelper._getMonitoredObjectData(po_1);
  2246. });
  2247. }
  2248. else {
  2249. mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2250. }
  2251. var m = mod;
  2252. var bindingInfos = mod.boundProperties.getOrAddWithFactory(propIdStr, function (k) {
  2253. m.boundPropertiesMask |= propId;
  2254. return new Array();
  2255. });
  2256. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2257. if (!bi) {
  2258. bindingInfos.push(new BindingInfo(binding, i, (i + 1) === properties.length));
  2259. }
  2260. ownerMod = mod;
  2261. ownerInterPropId = propId;
  2262. propertyOwner = propertyOwner[propName];
  2263. };
  2264. for (var i = 0; i < properties.length; i++) {
  2265. _loop_1(i);
  2266. }
  2267. };
  2268. BindingHelper.unregisterDataSource = function (dataSource, binding, level) {
  2269. var properties = binding.propertyPathName.split(".");
  2270. var propertyOwner = dataSource;
  2271. var mod = BindingHelper._getMonitoredObjectData(propertyOwner);
  2272. for (var i = 0; i < properties.length; i++) {
  2273. var propName = properties[i];
  2274. var propId = BindingHelper._getPropertyID(propertyOwner, propName);
  2275. var propIdStr = propId.toString();
  2276. if (i >= level) {
  2277. mod = BindingHelper._unregisterBinding(mod, propId, binding);
  2278. }
  2279. else {
  2280. mod = mod.monitoredIntermediateProperties.get(propIdStr);
  2281. }
  2282. propertyOwner = propertyOwner[propName];
  2283. }
  2284. };
  2285. BindingHelper._unregisterBinding = function (mod, propertyID, binding) {
  2286. var propertyIDStr = propertyID.toString();
  2287. var res = null;
  2288. // Check if the property is registered as an intermediate and remove it
  2289. if ((mod.monitoredIntermediateMask & propertyID) !== 0) {
  2290. res = mod.monitoredIntermediateProperties.get(propertyIDStr);
  2291. mod.monitoredIntermediateProperties.remove(propertyIDStr);
  2292. // Update the mask
  2293. mod.monitoredIntermediateMask &= ~propertyID;
  2294. }
  2295. // Check if the property is registered as a final property and remove it
  2296. if ((mod.boundPropertiesMask & propertyID) !== 0) {
  2297. var bindingInfos = mod.boundProperties.get(propertyIDStr);
  2298. // Find the binding and remove it
  2299. var bi = BABYLON.Tools.first(bindingInfos, function (cbi) { return cbi.binding === binding; });
  2300. if (bi) {
  2301. var bii = bindingInfos.indexOf(bi);
  2302. bindingInfos.splice(bii, 1);
  2303. }
  2304. // If the array is empty, update the mask
  2305. if (bindingInfos.length === 0) {
  2306. mod.boundPropertiesMask &= ~propertyID;
  2307. }
  2308. }
  2309. // Check if the MOD is empty and unregister the observer and remove it from the list of MODs
  2310. if (mod.boundPropertiesMask === 0 && mod.monitoredIntermediateMask === 0) {
  2311. // Unregister the observer on Property Change
  2312. mod.monitoredObject.propertyChanged.remove(mod.observer);
  2313. // Remove the MOD from the dic
  2314. var objectId = BindingHelper._getObjectId(mod.monitoredObject);
  2315. BindingHelper._monitoredObjects.remove(objectId);
  2316. }
  2317. return res;
  2318. };
  2319. BindingHelper._getMonitoredObjectData = function (object) {
  2320. var objectId = BindingHelper._getObjectId(object);
  2321. var mod = BindingHelper._monitoredObjects.getOrAddWithFactory(objectId, function (k) { return new MonitoredObjectData(object); });
  2322. return mod;
  2323. };
  2324. BindingHelper._getObjectId = function (obj) {
  2325. var id = obj["__bindingHelperObjectId__"];
  2326. if (id == null) {
  2327. id = BABYLON.Tools.RandomId();
  2328. obj["__bindingHelperObjectId__"] = id;
  2329. return id;
  2330. }
  2331. return id;
  2332. };
  2333. BindingHelper._getObjectTypePropertyIDs = function (obj) {
  2334. var fullName = BABYLON.Tools.getFullClassName(obj);
  2335. if (!fullName) {
  2336. throw Error("Types involved in Data Binding must be decorated with the @className decorator");
  2337. }
  2338. var d = BindingHelper._propertiesID.getOrAddWithFactory(fullName, function () { return new BABYLON.StringDictionary(); });
  2339. return d;
  2340. };
  2341. BindingHelper._getPropertyID = function (object, propName) {
  2342. var otd = BindingHelper._getObjectTypePropertyIDs(object);
  2343. // Make sure we have a WatchedPropertyData for this property of this object type. This will contains the flagIg of the watched property.
  2344. // We use this flagId to flag for each watched instance which properties are watched, as final or intermediate and which directions are used
  2345. var propData = otd.getOrAddWithFactory(propName, function (k) { return 1 << otd.count; });
  2346. return propData;
  2347. };
  2348. BindingHelper._propertiesID = new BABYLON.StringDictionary();
  2349. BindingHelper._monitoredObjects = new BABYLON.StringDictionary();
  2350. return BindingHelper;
  2351. }());
  2352. var SmartPropertyPrim = (function (_super) {
  2353. __extends(SmartPropertyPrim, _super);
  2354. function SmartPropertyPrim() {
  2355. _super.call(this);
  2356. this._flags = 0;
  2357. this._modelKey = null;
  2358. this._levelBoundingInfo = new BABYLON.BoundingInfo2D();
  2359. this._boundingInfo = new BABYLON.BoundingInfo2D();
  2360. this.animations = new Array();
  2361. }
  2362. /**
  2363. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  2364. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  2365. */
  2366. SmartPropertyPrim.prototype.dispose = function () {
  2367. if (this.isDisposed) {
  2368. return false;
  2369. }
  2370. _super.prototype.dispose.call(this);
  2371. // Don't set to null, it may upset somebody...
  2372. this.animations.splice(0);
  2373. return true;
  2374. };
  2375. /**
  2376. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  2377. * Look at Sprite2D for more information
  2378. */
  2379. SmartPropertyPrim.prototype.getAnimatables = function () {
  2380. return new Array();
  2381. };
  2382. Object.defineProperty(SmartPropertyPrim.prototype, "modelKey", {
  2383. /**
  2384. * Property giving the Model Key associated to the property.
  2385. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  2386. * @returns the model key string.
  2387. */
  2388. get: function () {
  2389. var _this = this;
  2390. // No need to compute it?
  2391. if (!this._isFlagSet(SmartPropertyPrim.flagModelDirty) && this._modelKey) {
  2392. return this._modelKey;
  2393. }
  2394. var modelKey = "Class:" + BABYLON.Tools.getClassName(this) + ";";
  2395. var propDic = this.propDic;
  2396. propDic.forEach(function (k, v) {
  2397. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  2398. var propVal = _this[v.name];
  2399. // Special case, array, this WON'T WORK IN ALL CASES, all entries have to be of the same type and it must be a BJS well known one
  2400. if (propVal && propVal.constructor === Array) {
  2401. var firstVal = propVal[0];
  2402. if (!firstVal) {
  2403. propVal = 0;
  2404. }
  2405. else {
  2406. propVal = BABYLON.Tools.hashCodeFromStream(BABYLON.Tools.arrayOrStringFeeder(propVal));
  2407. }
  2408. }
  2409. modelKey += v.name + ":" + ((propVal != null) ? ((v.typeLevelCompare) ? BABYLON.Tools.getClassName(propVal) : propVal.toString()) : "[null]") + ";";
  2410. }
  2411. });
  2412. this._clearFlags(SmartPropertyPrim.flagModelDirty);
  2413. this._modelKey = modelKey;
  2414. return modelKey;
  2415. },
  2416. enumerable: true,
  2417. configurable: true
  2418. });
  2419. Object.defineProperty(SmartPropertyPrim.prototype, "isDirty", {
  2420. /**
  2421. * States if the Primitive is dirty and should be rendered again next time.
  2422. * @returns true is dirty, false otherwise
  2423. */
  2424. get: function () {
  2425. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim.flagModelDirty | SmartPropertyPrim.flagPositioningDirty | SmartPropertyPrim.flagLayoutDirty);
  2426. },
  2427. enumerable: true,
  2428. configurable: true
  2429. });
  2430. SmartPropertyPrim.prototype._boundingBoxDirty = function () {
  2431. this._setFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  2432. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  2433. if (this instanceof BABYLON.Prim2DBase) {
  2434. var curprim = this;
  2435. while (curprim) {
  2436. curprim._setFlags(SmartPropertyPrim.flagBoundingInfoDirty);
  2437. if (curprim.isSizeAuto) {
  2438. curprim.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  2439. curprim._setFlags(SmartPropertyPrim.flagPositioningDirty);
  2440. }
  2441. if (curprim instanceof BABYLON.Group2D) {
  2442. if (curprim.isRenderableGroup) {
  2443. break;
  2444. }
  2445. }
  2446. curprim = curprim.parent;
  2447. }
  2448. }
  2449. };
  2450. SmartPropertyPrim.prototype._handlePropChanged = function (curValue, newValue, propName, propInfo, typeLevelCompare) {
  2451. _super.prototype._handlePropChanged.call(this, curValue, newValue, propName, propInfo, typeLevelCompare);
  2452. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  2453. if (propInfo.dirtyBoundingInfo) {
  2454. this._boundingBoxDirty();
  2455. }
  2456. else if (propInfo.dirtyParentBoundingInfo) {
  2457. var p = this._parent;
  2458. if (p != null) {
  2459. p._boundingBoxDirty();
  2460. }
  2461. }
  2462. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  2463. if (this instanceof BABYLON.Group2D) {
  2464. this.handleGroupChanged(propInfo);
  2465. }
  2466. // Check for parent layout dirty
  2467. if (this instanceof BABYLON.Prim2DBase) {
  2468. var p = this._parent;
  2469. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  2470. p._setLayoutDirty();
  2471. }
  2472. }
  2473. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  2474. var instanceDirty = false;
  2475. if (typeLevelCompare && curValue != null && newValue != null) {
  2476. var cvProto = curValue.__proto__;
  2477. var nvProto = newValue.__proto__;
  2478. instanceDirty = (cvProto === nvProto);
  2479. }
  2480. // Set the dirty flags
  2481. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  2482. if (!this.isDirty) {
  2483. this._setFlags(SmartPropertyPrim.flagModelDirty);
  2484. }
  2485. }
  2486. else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  2487. var propMask = propInfo.flagId;
  2488. this.onPrimitivePropertyDirty(propMask);
  2489. }
  2490. };
  2491. SmartPropertyPrim.prototype.onPrimitivePropertyDirty = function (propFlagId) {
  2492. this.onPrimBecomesDirty();
  2493. this._instanceDirtyFlags |= propFlagId;
  2494. };
  2495. SmartPropertyPrim.prototype.handleGroupChanged = function (prop) {
  2496. };
  2497. SmartPropertyPrim.prototype._resetPropertiesDirty = function () {
  2498. _super.prototype._resetPropertiesDirty.call(this);
  2499. this._clearFlags(SmartPropertyPrim.flagPrimInDirtyList | SmartPropertyPrim.flagNeedRefresh);
  2500. };
  2501. Object.defineProperty(SmartPropertyPrim.prototype, "levelBoundingInfo", {
  2502. /**
  2503. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  2504. */
  2505. get: function () {
  2506. if (this._isFlagSet(SmartPropertyPrim.flagLevelBoundingInfoDirty)) {
  2507. this.updateLevelBoundingInfo();
  2508. this._clearFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  2509. }
  2510. return this._levelBoundingInfo;
  2511. },
  2512. enumerable: true,
  2513. configurable: true
  2514. });
  2515. /**
  2516. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  2517. */
  2518. SmartPropertyPrim.prototype.updateLevelBoundingInfo = function () {
  2519. };
  2520. /**
  2521. * Property method called when the Primitive becomes dirty
  2522. */
  2523. SmartPropertyPrim.prototype.onPrimBecomesDirty = function () {
  2524. };
  2525. /**
  2526. * Check if a given flag is set
  2527. * @param flag the flag value
  2528. * @return true if set, false otherwise
  2529. */
  2530. SmartPropertyPrim.prototype._isFlagSet = function (flag) {
  2531. return (this._flags & flag) !== 0;
  2532. };
  2533. /**
  2534. * Check if all given flags are set
  2535. * @param flags the flags ORed
  2536. * @return true if all the flags are set, false otherwise
  2537. */
  2538. SmartPropertyPrim.prototype._areAllFlagsSet = function (flags) {
  2539. return (this._flags & flags) === flags;
  2540. };
  2541. /**
  2542. * Check if at least one flag of the given flags is set
  2543. * @param flags the flags ORed
  2544. * @return true if at least one flag is set, false otherwise
  2545. */
  2546. SmartPropertyPrim.prototype._areSomeFlagsSet = function (flags) {
  2547. return (this._flags & flags) !== 0;
  2548. };
  2549. /**
  2550. * Clear the given flags
  2551. * @param flags the flags to clear
  2552. */
  2553. SmartPropertyPrim.prototype._clearFlags = function (flags) {
  2554. this._flags &= ~flags;
  2555. };
  2556. /**
  2557. * Set the given flags to true state
  2558. * @param flags the flags ORed to set
  2559. * @return the flags state before this call
  2560. */
  2561. SmartPropertyPrim.prototype._setFlags = function (flags) {
  2562. var cur = this._flags;
  2563. this._flags |= flags;
  2564. return cur;
  2565. };
  2566. /**
  2567. * Change the state of the given flags
  2568. * @param flags the flags ORed to change
  2569. * @param state true to set them, false to clear them
  2570. */
  2571. SmartPropertyPrim.prototype._changeFlags = function (flags, state) {
  2572. if (state) {
  2573. this._flags |= flags;
  2574. }
  2575. else {
  2576. this._flags &= ~flags;
  2577. }
  2578. };
  2579. SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT = 0;
  2580. SmartPropertyPrim.flagFREE001 = 0x0000001; // set if the object is already disposed
  2581. SmartPropertyPrim.flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  2582. SmartPropertyPrim.flagModelDirty = 0x0000004; // set if the model must be changed
  2583. SmartPropertyPrim.flagLayoutDirty = 0x0000008; // set if the layout must be computed
  2584. SmartPropertyPrim.flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  2585. SmartPropertyPrim.flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  2586. SmartPropertyPrim.flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  2587. SmartPropertyPrim.flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  2588. SmartPropertyPrim.flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  2589. SmartPropertyPrim.flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  2590. SmartPropertyPrim.flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  2591. SmartPropertyPrim.flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  2592. SmartPropertyPrim.flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  2593. SmartPropertyPrim.flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  2594. SmartPropertyPrim.flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  2595. SmartPropertyPrim.flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  2596. SmartPropertyPrim.flagIsContainer = 0x0010000; // set if the primitive is a container
  2597. SmartPropertyPrim.flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  2598. SmartPropertyPrim.flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  2599. SmartPropertyPrim.flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  2600. SmartPropertyPrim.flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  2601. SmartPropertyPrim.flagLayoutBoundingInfoDirty = 0x0100000; // set if the layout bounding info is dirty
  2602. SmartPropertyPrim = __decorate([
  2603. BABYLON.className("SmartPropertyPrim", "BABYLON")
  2604. ], SmartPropertyPrim);
  2605. return SmartPropertyPrim;
  2606. }(SmartPropertyBase));
  2607. BABYLON.SmartPropertyPrim = SmartPropertyPrim;
  2608. function dependencyProperty(propId, piStore, mode, updateSourceTrigger) {
  2609. if (mode === void 0) { mode = DataBinding.MODE_TWOWAY; }
  2610. if (updateSourceTrigger === void 0) { updateSourceTrigger = DataBinding.UPDATESOURCETRIGGER_PROPERTYCHANGED; }
  2611. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { bindingMode: mode, bindingUpdateSourceTrigger: updateSourceTrigger });
  2612. }
  2613. BABYLON.dependencyProperty = dependencyProperty;
  2614. function modelLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2615. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2616. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2617. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2618. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_MODEL, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2619. }
  2620. BABYLON.modelLevelProperty = modelLevelProperty;
  2621. function instanceLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2622. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2623. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2624. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2625. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_INSTANCE, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2626. }
  2627. BABYLON.instanceLevelProperty = instanceLevelProperty;
  2628. function dynamicLevelProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox) {
  2629. if (typeLevelCompare === void 0) { typeLevelCompare = false; }
  2630. if (dirtyBoundingInfo === void 0) { dirtyBoundingInfo = false; }
  2631. if (dirtyParentBoundingBox === void 0) { dirtyParentBoundingBox = false; }
  2632. return SmartPropertyBase._hookProperty(propId, piStore, Prim2DPropInfo.PROPKIND_DYNAMIC, { typeLevelCompare: typeLevelCompare, dirtyBoundingInfo: dirtyBoundingInfo, dirtyParentBoundingBox: dirtyParentBoundingBox });
  2633. }
  2634. BABYLON.dynamicLevelProperty = dynamicLevelProperty;
  2635. })(BABYLON || (BABYLON = {}));
  2636. var BABYLON;
  2637. (function (BABYLON) {
  2638. var PrepareRender2DContext = (function () {
  2639. function PrepareRender2DContext() {
  2640. this.forceRefreshPrimitive = false;
  2641. }
  2642. return PrepareRender2DContext;
  2643. }());
  2644. BABYLON.PrepareRender2DContext = PrepareRender2DContext;
  2645. var Render2DContext = (function () {
  2646. function Render2DContext(renderMode) {
  2647. this._renderMode = renderMode;
  2648. this.useInstancing = false;
  2649. this.groupInfoPartData = null;
  2650. this.partDataStartIndex = this.partDataEndIndex = null;
  2651. this.instancedBuffers = null;
  2652. }
  2653. Object.defineProperty(Render2DContext.prototype, "renderMode", {
  2654. /**
  2655. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  2656. */
  2657. get: function () {
  2658. return this._renderMode;
  2659. },
  2660. enumerable: true,
  2661. configurable: true
  2662. });
  2663. Object.defineProperty(Render2DContext, "RenderModeOpaque", {
  2664. /**
  2665. * The set of primitives to render is opaque.
  2666. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  2667. */
  2668. get: function () {
  2669. return Render2DContext._renderModeOpaque;
  2670. },
  2671. enumerable: true,
  2672. configurable: true
  2673. });
  2674. Object.defineProperty(Render2DContext, "RenderModeAlphaTest", {
  2675. /**
  2676. * The set of primitives to render is using Alpha Test (aka masking).
  2677. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeOpaque and is depth independent (i.e. primitives are not sorted by depth). Depth Compare and Write are both enabled.
  2678. */
  2679. get: function () {
  2680. return Render2DContext._renderModeAlphaTest;
  2681. },
  2682. enumerable: true,
  2683. configurable: true
  2684. });
  2685. Object.defineProperty(Render2DContext, "RenderModeTransparent", {
  2686. /**
  2687. * The set of primitives to render is transparent.
  2688. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeAlphaTest and is depth dependent (i.e. primitives are stored by depth and rendered back to front). Depth Compare is on, but Depth write is Off.
  2689. */
  2690. get: function () {
  2691. return Render2DContext._renderModeTransparent;
  2692. },
  2693. enumerable: true,
  2694. configurable: true
  2695. });
  2696. Render2DContext._renderModeOpaque = 1;
  2697. Render2DContext._renderModeAlphaTest = 2;
  2698. Render2DContext._renderModeTransparent = 3;
  2699. return Render2DContext;
  2700. }());
  2701. BABYLON.Render2DContext = Render2DContext;
  2702. /**
  2703. * This class store information for the pointerEventObservable Observable.
  2704. * The Observable is divided into many sub events (using the Mask feature of the Observable pattern): PointerOver, PointerEnter, PointerDown, PointerMouseWheel, PointerMove, PointerUp, PointerDown, PointerLeave, PointerGotCapture and PointerLostCapture.
  2705. */
  2706. var PrimitivePointerInfo = (function () {
  2707. function PrimitivePointerInfo() {
  2708. this.primitivePointerPos = BABYLON.Vector2.Zero();
  2709. this.tilt = BABYLON.Vector2.Zero();
  2710. this.cancelBubble = false;
  2711. }
  2712. Object.defineProperty(PrimitivePointerInfo, "PointerOver", {
  2713. // The behavior is based on the HTML specifications of the Pointer Events (https://www.w3.org/TR/pointerevents/#list-of-pointer-events). This is not 100% compliant and not meant to be, but still, it's based on these specs for most use cases to be programmed the same way (as closest as possible) as it would have been in HTML.
  2714. /**
  2715. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  2716. * Bubbles: yes
  2717. */
  2718. get: function () {
  2719. return PrimitivePointerInfo._pointerOver;
  2720. },
  2721. enumerable: true,
  2722. configurable: true
  2723. });
  2724. Object.defineProperty(PrimitivePointerInfo, "PointerEnter", {
  2725. /**
  2726. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  2727. * Bubbles: no
  2728. */
  2729. get: function () {
  2730. return PrimitivePointerInfo._pointerEnter;
  2731. },
  2732. enumerable: true,
  2733. configurable: true
  2734. });
  2735. Object.defineProperty(PrimitivePointerInfo, "PointerDown", {
  2736. /**
  2737. * This event type is raised when a pointer enters the active button state (non-zero value in the buttons property). For mouse it's when the device transitions from no buttons depressed to at least one button depressed. For touch/pen this is when a physical contact is made.
  2738. * Bubbles: yes
  2739. */
  2740. get: function () {
  2741. return PrimitivePointerInfo._pointerDown;
  2742. },
  2743. enumerable: true,
  2744. configurable: true
  2745. });
  2746. Object.defineProperty(PrimitivePointerInfo, "PointerMouseWheel", {
  2747. /**
  2748. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  2749. * Bubbles: yes
  2750. */
  2751. get: function () {
  2752. return PrimitivePointerInfo._pointerMouseWheel;
  2753. },
  2754. enumerable: true,
  2755. configurable: true
  2756. });
  2757. Object.defineProperty(PrimitivePointerInfo, "PointerMove", {
  2758. /**
  2759. * This event type is raised when a pointer change coordinates or when a pointer changes button state, pressure, tilt, or contact geometry and the circumstances produce no other pointers events.
  2760. * Bubbles: yes
  2761. */
  2762. get: function () {
  2763. return PrimitivePointerInfo._pointerMove;
  2764. },
  2765. enumerable: true,
  2766. configurable: true
  2767. });
  2768. Object.defineProperty(PrimitivePointerInfo, "PointerUp", {
  2769. /**
  2770. * This event type is raised when the pointer leaves the active buttons states (zero value in the buttons property). For mouse, this is when the device transitions from at least one button depressed to no buttons depressed. For touch/pen, this is when physical contact is removed.
  2771. * Bubbles: yes
  2772. */
  2773. get: function () {
  2774. return PrimitivePointerInfo._pointerUp;
  2775. },
  2776. enumerable: true,
  2777. configurable: true
  2778. });
  2779. Object.defineProperty(PrimitivePointerInfo, "PointerOut", {
  2780. /**
  2781. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  2782. * Bubbles: yes
  2783. */
  2784. get: function () {
  2785. return PrimitivePointerInfo._pointerOut;
  2786. },
  2787. enumerable: true,
  2788. configurable: true
  2789. });
  2790. Object.defineProperty(PrimitivePointerInfo, "PointerLeave", {
  2791. /**
  2792. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  2793. * Bubbles: no
  2794. */
  2795. get: function () {
  2796. return PrimitivePointerInfo._pointerLeave;
  2797. },
  2798. enumerable: true,
  2799. configurable: true
  2800. });
  2801. Object.defineProperty(PrimitivePointerInfo, "PointerGotCapture", {
  2802. /**
  2803. * This event type is raised when a primitive receives the pointer capture. This event is fired at the element that is receiving pointer capture. Subsequent events for that pointer will be fired at this element.
  2804. * Bubbles: yes
  2805. */
  2806. get: function () {
  2807. return PrimitivePointerInfo._pointerGotCapture;
  2808. },
  2809. enumerable: true,
  2810. configurable: true
  2811. });
  2812. Object.defineProperty(PrimitivePointerInfo, "PointerLostCapture", {
  2813. /**
  2814. * This event type is raised after pointer capture is released for a pointer.
  2815. * Bubbles: yes
  2816. */
  2817. get: function () {
  2818. return PrimitivePointerInfo._pointerLostCapture;
  2819. },
  2820. enumerable: true,
  2821. configurable: true
  2822. });
  2823. Object.defineProperty(PrimitivePointerInfo, "MouseWheelPrecision", {
  2824. get: function () {
  2825. return PrimitivePointerInfo._mouseWheelPrecision;
  2826. },
  2827. enumerable: true,
  2828. configurable: true
  2829. });
  2830. PrimitivePointerInfo.prototype.updateRelatedTarget = function (prim, primPointerPos) {
  2831. this.relatedTarget = prim;
  2832. this.relatedTargetPointerPos = primPointerPos;
  2833. };
  2834. PrimitivePointerInfo.getEventTypeName = function (mask) {
  2835. switch (mask) {
  2836. case PrimitivePointerInfo.PointerOver: return "PointerOver";
  2837. case PrimitivePointerInfo.PointerEnter: return "PointerEnter";
  2838. case PrimitivePointerInfo.PointerDown: return "PointerDown";
  2839. case PrimitivePointerInfo.PointerMouseWheel: return "PointerMouseWheel";
  2840. case PrimitivePointerInfo.PointerMove: return "PointerMove";
  2841. case PrimitivePointerInfo.PointerUp: return "PointerUp";
  2842. case PrimitivePointerInfo.PointerOut: return "PointerOut";
  2843. case PrimitivePointerInfo.PointerLeave: return "PointerLeave";
  2844. case PrimitivePointerInfo.PointerGotCapture: return "PointerGotCapture";
  2845. case PrimitivePointerInfo.PointerLostCapture: return "PointerLostCapture";
  2846. }
  2847. };
  2848. PrimitivePointerInfo._pointerOver = 0x0001;
  2849. PrimitivePointerInfo._pointerEnter = 0x0002;
  2850. PrimitivePointerInfo._pointerDown = 0x0004;
  2851. PrimitivePointerInfo._pointerMouseWheel = 0x0008;
  2852. PrimitivePointerInfo._pointerMove = 0x0010;
  2853. PrimitivePointerInfo._pointerUp = 0x0020;
  2854. PrimitivePointerInfo._pointerOut = 0x0040;
  2855. PrimitivePointerInfo._pointerLeave = 0x0080;
  2856. PrimitivePointerInfo._pointerGotCapture = 0x0100;
  2857. PrimitivePointerInfo._pointerLostCapture = 0x0200;
  2858. PrimitivePointerInfo._mouseWheelPrecision = 3.0;
  2859. return PrimitivePointerInfo;
  2860. }());
  2861. BABYLON.PrimitivePointerInfo = PrimitivePointerInfo;
  2862. /**
  2863. * Defines the horizontal and vertical alignment information for a Primitive.
  2864. */
  2865. var PrimitiveAlignment = (function () {
  2866. function PrimitiveAlignment(changeCallback) {
  2867. this._changedCallback = changeCallback;
  2868. this._horizontal = PrimitiveAlignment.AlignLeft;
  2869. this._vertical = PrimitiveAlignment.AlignBottom;
  2870. }
  2871. Object.defineProperty(PrimitiveAlignment, "AlignLeft", {
  2872. /**
  2873. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  2874. */
  2875. get: function () { return PrimitiveAlignment._AlignLeft; },
  2876. enumerable: true,
  2877. configurable: true
  2878. });
  2879. Object.defineProperty(PrimitiveAlignment, "AlignTop", {
  2880. /**
  2881. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  2882. */
  2883. get: function () { return PrimitiveAlignment._AlignTop; },
  2884. enumerable: true,
  2885. configurable: true
  2886. });
  2887. Object.defineProperty(PrimitiveAlignment, "AlignRight", {
  2888. /**
  2889. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  2890. */
  2891. get: function () { return PrimitiveAlignment._AlignRight; },
  2892. enumerable: true,
  2893. configurable: true
  2894. });
  2895. Object.defineProperty(PrimitiveAlignment, "AlignBottom", {
  2896. /**
  2897. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  2898. */
  2899. get: function () { return PrimitiveAlignment._AlignBottom; },
  2900. enumerable: true,
  2901. configurable: true
  2902. });
  2903. Object.defineProperty(PrimitiveAlignment, "AlignCenter", {
  2904. /**
  2905. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  2906. */
  2907. get: function () { return PrimitiveAlignment._AlignCenter; },
  2908. enumerable: true,
  2909. configurable: true
  2910. });
  2911. Object.defineProperty(PrimitiveAlignment, "AlignStretch", {
  2912. /**
  2913. * The content is stretched toward the opposite edges of the Primitive
  2914. */
  2915. get: function () { return PrimitiveAlignment._AlignStretch; },
  2916. enumerable: true,
  2917. configurable: true
  2918. });
  2919. Object.defineProperty(PrimitiveAlignment.prototype, "horizontal", {
  2920. /**
  2921. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  2922. */
  2923. get: function () {
  2924. return this._horizontal;
  2925. },
  2926. set: function (value) {
  2927. if (this._horizontal === value) {
  2928. return;
  2929. }
  2930. this._horizontal = value;
  2931. this.onChangeCallback();
  2932. },
  2933. enumerable: true,
  2934. configurable: true
  2935. });
  2936. Object.defineProperty(PrimitiveAlignment.prototype, "vertical", {
  2937. /**
  2938. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  2939. */
  2940. get: function () {
  2941. return this._vertical;
  2942. },
  2943. set: function (value) {
  2944. if (this._vertical === value) {
  2945. return;
  2946. }
  2947. this._vertical = value;
  2948. this.onChangeCallback();
  2949. },
  2950. enumerable: true,
  2951. configurable: true
  2952. });
  2953. PrimitiveAlignment.prototype.onChangeCallback = function () {
  2954. if (this._changedCallback) {
  2955. this._changedCallback();
  2956. }
  2957. };
  2958. /**
  2959. * Set the horizontal alignment from a string value.
  2960. * @param text can be either: 'left','right','center','stretch'
  2961. */
  2962. PrimitiveAlignment.prototype.setHorizontal = function (text) {
  2963. var v = text.trim().toLocaleLowerCase();
  2964. switch (v) {
  2965. case "left":
  2966. this.horizontal = PrimitiveAlignment.AlignLeft;
  2967. return;
  2968. case "right":
  2969. this.horizontal = PrimitiveAlignment.AlignRight;
  2970. return;
  2971. case "center":
  2972. this.horizontal = PrimitiveAlignment.AlignCenter;
  2973. return;
  2974. case "stretch":
  2975. this.horizontal = PrimitiveAlignment.AlignStretch;
  2976. return;
  2977. }
  2978. };
  2979. /**
  2980. * Set the vertical alignment from a string value.
  2981. * @param text can be either: 'top','bottom','center','stretch'
  2982. */
  2983. PrimitiveAlignment.prototype.setVertical = function (text) {
  2984. var v = text.trim().toLocaleLowerCase();
  2985. switch (v) {
  2986. case "top":
  2987. this.vertical = PrimitiveAlignment.AlignTop;
  2988. return;
  2989. case "bottom":
  2990. this.vertical = PrimitiveAlignment.AlignBottom;
  2991. return;
  2992. case "center":
  2993. this.vertical = PrimitiveAlignment.AlignCenter;
  2994. return;
  2995. case "stretch":
  2996. this.vertical = PrimitiveAlignment.AlignStretch;
  2997. return;
  2998. }
  2999. };
  3000. /**
  3001. * Set the horizontal and or vertical alignments from a string value.
  3002. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  3003. */
  3004. PrimitiveAlignment.prototype.fromString = function (value) {
  3005. var m = value.trim().split(",");
  3006. if (m.length === 1) {
  3007. this.setHorizontal(m[0]);
  3008. this.setVertical(m[0]);
  3009. }
  3010. else {
  3011. for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
  3012. var v = m_1[_i];
  3013. v = v.toLocaleLowerCase().trim();
  3014. // Horizontal
  3015. var i = v.indexOf("h:");
  3016. if (i === -1) {
  3017. i = v.indexOf("horizontal:");
  3018. }
  3019. if (i !== -1) {
  3020. v = v.substr(v.indexOf(":") + 1);
  3021. this.setHorizontal(v);
  3022. continue;
  3023. }
  3024. // Vertical
  3025. i = v.indexOf("v:");
  3026. if (i === -1) {
  3027. i = v.indexOf("vertical:");
  3028. }
  3029. if (i !== -1) {
  3030. v = v.substr(v.indexOf(":") + 1);
  3031. this.setVertical(v);
  3032. continue;
  3033. }
  3034. }
  3035. }
  3036. };
  3037. PrimitiveAlignment.prototype.copyFrom = function (pa) {
  3038. this._horizontal = pa._horizontal;
  3039. this._vertical = pa._vertical;
  3040. this.onChangeCallback();
  3041. };
  3042. Object.defineProperty(PrimitiveAlignment.prototype, "isDefault", {
  3043. get: function () {
  3044. return this.horizontal === PrimitiveAlignment.AlignLeft && this.vertical === PrimitiveAlignment.AlignBottom;
  3045. },
  3046. enumerable: true,
  3047. configurable: true
  3048. });
  3049. PrimitiveAlignment._AlignLeft = 1;
  3050. PrimitiveAlignment._AlignTop = 1; // Same as left
  3051. PrimitiveAlignment._AlignRight = 2;
  3052. PrimitiveAlignment._AlignBottom = 2; // Same as right
  3053. PrimitiveAlignment._AlignCenter = 3;
  3054. PrimitiveAlignment._AlignStretch = 4;
  3055. PrimitiveAlignment = __decorate([
  3056. BABYLON.className("PrimitiveAlignment", "BABYLON")
  3057. ], PrimitiveAlignment);
  3058. return PrimitiveAlignment;
  3059. }());
  3060. BABYLON.PrimitiveAlignment = PrimitiveAlignment;
  3061. /**
  3062. * Stores information about a Primitive that was intersected
  3063. */
  3064. var PrimitiveIntersectedInfo = (function () {
  3065. function PrimitiveIntersectedInfo(prim, intersectionLocation) {
  3066. this.prim = prim;
  3067. this.intersectionLocation = intersectionLocation;
  3068. }
  3069. return PrimitiveIntersectedInfo;
  3070. }());
  3071. BABYLON.PrimitiveIntersectedInfo = PrimitiveIntersectedInfo;
  3072. /**
  3073. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  3074. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  3075. */
  3076. var PrimitiveThickness = (function () {
  3077. function PrimitiveThickness(parentAccess, changedCallback) {
  3078. this._parentAccess = parentAccess;
  3079. this._changedCallback = changedCallback;
  3080. this._pixels = new Array(4);
  3081. this._percentages = new Array(4);
  3082. this._setType(0, PrimitiveThickness.Auto);
  3083. this._setType(1, PrimitiveThickness.Auto);
  3084. this._setType(2, PrimitiveThickness.Auto);
  3085. this._setType(3, PrimitiveThickness.Auto);
  3086. this._pixels[0] = 0;
  3087. this._pixels[1] = 0;
  3088. this._pixels[2] = 0;
  3089. this._pixels[3] = 0;
  3090. }
  3091. /**
  3092. * Set the thickness from a string value
  3093. * @param thickness format is "top: <value>, left:<value>, right:<value>, bottom:<value>" or "<value>" (same for all edges) each are optional, auto will be set if it's omitted.
  3094. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3095. */
  3096. PrimitiveThickness.prototype.fromString = function (thickness) {
  3097. this._clear();
  3098. var m = thickness.trim().split(",");
  3099. // Special case, one value to apply to all edges
  3100. if (m.length === 1 && thickness.indexOf(":") === -1) {
  3101. this._setStringValue(m[0], 0, false);
  3102. this._setStringValue(m[0], 1, false);
  3103. this._setStringValue(m[0], 2, false);
  3104. this._setStringValue(m[0], 3, false);
  3105. this.onChangeCallback();
  3106. return;
  3107. }
  3108. var res = false;
  3109. for (var _i = 0, m_2 = m; _i < m_2.length; _i++) {
  3110. var cm = m_2[_i];
  3111. res = this._extractString(cm, false) || res;
  3112. }
  3113. if (!res) {
  3114. throw new Error("Can't parse the string to create a PrimitiveMargin object, format must be: 'top: <value>, left:<value>, right:<value>, bottom:<value>");
  3115. }
  3116. // Check the margin that weren't set and set them in auto
  3117. if ((this._flags & 0x000F) === 0)
  3118. this._flags |= PrimitiveThickness.Pixel << 0;
  3119. if ((this._flags & 0x00F0) === 0)
  3120. this._flags |= PrimitiveThickness.Pixel << 4;
  3121. if ((this._flags & 0x0F00) === 0)
  3122. this._flags |= PrimitiveThickness.Pixel << 8;
  3123. if ((this._flags & 0xF000) === 0)
  3124. this._flags |= PrimitiveThickness.Pixel << 12;
  3125. this.onChangeCallback();
  3126. };
  3127. /**
  3128. * Set the thickness from multiple string
  3129. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3130. * @param top the top thickness to set
  3131. * @param left the left thickness to set
  3132. * @param right the right thickness to set
  3133. * @param bottom the bottom thickness to set
  3134. */
  3135. PrimitiveThickness.prototype.fromStrings = function (top, left, right, bottom) {
  3136. this._clear();
  3137. this._setStringValue(top, 0, false);
  3138. this._setStringValue(left, 1, false);
  3139. this._setStringValue(right, 2, false);
  3140. this._setStringValue(bottom, 3, false);
  3141. this.onChangeCallback();
  3142. return this;
  3143. };
  3144. /**
  3145. * Set the thickness from pixel values
  3146. * @param top the top thickness in pixels to set
  3147. * @param left the left thickness in pixels to set
  3148. * @param right the right thickness in pixels to set
  3149. * @param bottom the bottom thickness in pixels to set
  3150. */
  3151. PrimitiveThickness.prototype.fromPixels = function (top, left, right, bottom) {
  3152. this._clear();
  3153. this._pixels[0] = top;
  3154. this._pixels[1] = left;
  3155. this._pixels[2] = right;
  3156. this._pixels[3] = bottom;
  3157. this.onChangeCallback();
  3158. return this;
  3159. };
  3160. /**
  3161. * Apply the same pixel value to all edges
  3162. * @param margin the value to set, in pixels.
  3163. */
  3164. PrimitiveThickness.prototype.fromUniformPixels = function (margin) {
  3165. this._clear();
  3166. this._pixels[0] = margin;
  3167. this._pixels[1] = margin;
  3168. this._pixels[2] = margin;
  3169. this._pixels[3] = margin;
  3170. this.onChangeCallback();
  3171. return this;
  3172. };
  3173. PrimitiveThickness.prototype.copyFrom = function (pt) {
  3174. this._clear();
  3175. for (var i = 0; i < 4; i++) {
  3176. this._pixels[i] = pt._pixels[i];
  3177. this._percentages[i] = pt._percentages[i];
  3178. }
  3179. this._flags = pt._flags;
  3180. this.onChangeCallback();
  3181. };
  3182. /**
  3183. * Set all edges in auto
  3184. */
  3185. PrimitiveThickness.prototype.auto = function () {
  3186. this._clear();
  3187. this._flags = (PrimitiveThickness.Auto << 0) | (PrimitiveThickness.Auto << 4) | (PrimitiveThickness.Auto << 8) | (PrimitiveThickness.Auto << 12);
  3188. this._pixels[0] = 0;
  3189. this._pixels[1] = 0;
  3190. this._pixels[2] = 0;
  3191. this._pixels[3] = 0;
  3192. this.onChangeCallback();
  3193. return this;
  3194. };
  3195. PrimitiveThickness.prototype._clear = function () {
  3196. this._flags = 0;
  3197. this._pixels[0] = 0;
  3198. this._pixels[1] = 0;
  3199. this._pixels[2] = 0;
  3200. this._pixels[3] = 0;
  3201. this._percentages[0] = null;
  3202. this._percentages[1] = null;
  3203. this._percentages[2] = null;
  3204. this._percentages[3] = null;
  3205. };
  3206. PrimitiveThickness.prototype._extractString = function (value, emitChanged) {
  3207. var v = value.trim().toLocaleLowerCase();
  3208. if (v.indexOf("top:") === 0) {
  3209. v = v.substr(4).trim();
  3210. return this._setStringValue(v, 0, emitChanged);
  3211. }
  3212. if (v.indexOf("left:") === 0) {
  3213. v = v.substr(5).trim();
  3214. return this._setStringValue(v, 1, emitChanged);
  3215. }
  3216. if (v.indexOf("right:") === 0) {
  3217. v = v.substr(6).trim();
  3218. return this._setStringValue(v, 2, emitChanged);
  3219. }
  3220. if (v.indexOf("bottom:") === 0) {
  3221. v = v.substr(7).trim();
  3222. return this._setStringValue(v, 3, emitChanged);
  3223. }
  3224. return false;
  3225. };
  3226. PrimitiveThickness.prototype._setStringValue = function (value, index, emitChanged) {
  3227. // Check for auto
  3228. var v = value.trim().toLocaleLowerCase();
  3229. if (v === "auto") {
  3230. if (this._isType(index, PrimitiveThickness.Auto)) {
  3231. return true;
  3232. }
  3233. this._setType(index, PrimitiveThickness.Auto);
  3234. this._pixels[index] = 0;
  3235. if (emitChanged) {
  3236. this.onChangeCallback();
  3237. }
  3238. }
  3239. else if (v === "inherit") {
  3240. if (this._isType(index, PrimitiveThickness.Inherit)) {
  3241. return true;
  3242. }
  3243. this._setType(index, PrimitiveThickness.Inherit);
  3244. this._pixels[index] = null;
  3245. if (emitChanged) {
  3246. this.onChangeCallback();
  3247. }
  3248. }
  3249. else {
  3250. var pI = v.indexOf("%");
  3251. // Check for percentage
  3252. if (pI !== -1) {
  3253. var n_1 = v.substr(0, pI);
  3254. var number_1 = Math.round(Number(n_1)) / 100; // Normalize the percentage to [0;1] with a 0.01 precision
  3255. if (this._isType(index, PrimitiveThickness.Percentage) && (this._percentages[index] === number_1)) {
  3256. return true;
  3257. }
  3258. this._setType(index, PrimitiveThickness.Percentage);
  3259. if (isNaN(number_1)) {
  3260. return false;
  3261. }
  3262. this._percentages[index] = number_1;
  3263. if (emitChanged) {
  3264. this.onChangeCallback();
  3265. }
  3266. return true;
  3267. }
  3268. // Check for pixel
  3269. var n = void 0;
  3270. pI = v.indexOf("px");
  3271. if (pI !== -1) {
  3272. n = v.substr(0, pI).trim();
  3273. }
  3274. else {
  3275. n = v;
  3276. }
  3277. var number = Number(n);
  3278. if (this._isType(index, PrimitiveThickness.Pixel) && (this._pixels[index] === number)) {
  3279. return true;
  3280. }
  3281. if (isNaN(number)) {
  3282. return false;
  3283. }
  3284. this._pixels[index] = number;
  3285. this._setType(index, PrimitiveThickness.Pixel);
  3286. if (emitChanged) {
  3287. this.onChangeCallback();
  3288. }
  3289. return true;
  3290. }
  3291. };
  3292. PrimitiveThickness.prototype._setPixels = function (value, index, emitChanged) {
  3293. // Round the value because, well, it's the thing to do! Otherwise we'll have sub-pixel stuff, and the no change comparison just below will almost never work for PrimitiveThickness values inside a hierarchy of Primitives
  3294. value = Math.round(value);
  3295. if (this._isType(index, PrimitiveThickness.Pixel) && this._pixels[index] === value) {
  3296. return;
  3297. }
  3298. this._setType(index, PrimitiveThickness.Pixel);
  3299. this._pixels[index] = value;
  3300. if (emitChanged) {
  3301. this.onChangeCallback();
  3302. }
  3303. };
  3304. PrimitiveThickness.prototype._setPercentage = function (value, index, emitChanged) {
  3305. // Clip Value to bounds
  3306. value = Math.min(1, value);
  3307. value = Math.max(0, value);
  3308. value = Math.round(value * 100) / 100; // 0.01 precision
  3309. if (this._isType(index, PrimitiveThickness.Percentage) && this._percentages[index] === value) {
  3310. return;
  3311. }
  3312. this._setType(index, PrimitiveThickness.Percentage);
  3313. this._percentages[index] = value;
  3314. if (emitChanged) {
  3315. this.onChangeCallback();
  3316. }
  3317. };
  3318. PrimitiveThickness.prototype._getStringValue = function (index) {
  3319. var f = (this._flags >> (index * 4)) & 0xF;
  3320. switch (f) {
  3321. case PrimitiveThickness.Auto:
  3322. return "auto";
  3323. case PrimitiveThickness.Pixel:
  3324. return this._pixels[index] + "px";
  3325. case PrimitiveThickness.Percentage:
  3326. return this._percentages[index] * 100 + "%";
  3327. case PrimitiveThickness.Inherit:
  3328. return "inherit";
  3329. }
  3330. return "";
  3331. };
  3332. PrimitiveThickness.prototype._isType = function (index, type) {
  3333. var f = (this._flags >> (index * 4)) & 0xF;
  3334. return f === type;
  3335. };
  3336. PrimitiveThickness.prototype._getType = function (index, processInherit) {
  3337. var t = (this._flags >> (index * 4)) & 0xF;
  3338. if (processInherit && (t === PrimitiveThickness.Inherit)) {
  3339. var p = this._parentAccess();
  3340. if (p) {
  3341. return p._getType(index, true);
  3342. }
  3343. return PrimitiveThickness.Auto;
  3344. }
  3345. return t;
  3346. };
  3347. PrimitiveThickness.prototype._setType = function (index, type) {
  3348. this._flags &= ~(0xF << (index * 4));
  3349. this._flags |= type << (index * 4);
  3350. };
  3351. PrimitiveThickness.prototype.setTop = function (value) {
  3352. if (typeof value === "string") {
  3353. this._setStringValue(value, 0, true);
  3354. }
  3355. else {
  3356. this.topPixels = value;
  3357. }
  3358. };
  3359. PrimitiveThickness.prototype.setLeft = function (value) {
  3360. if (typeof value === "string") {
  3361. this._setStringValue(value, 1, true);
  3362. }
  3363. else {
  3364. this.leftPixels = value;
  3365. }
  3366. };
  3367. PrimitiveThickness.prototype.setRight = function (value) {
  3368. if (typeof value === "string") {
  3369. this._setStringValue(value, 2, true);
  3370. }
  3371. else {
  3372. this.rightPixels = value;
  3373. }
  3374. };
  3375. PrimitiveThickness.prototype.setBottom = function (value) {
  3376. if (typeof value === "string") {
  3377. this._setStringValue(value, 3, true);
  3378. }
  3379. else {
  3380. this.bottomPixels = value;
  3381. }
  3382. };
  3383. Object.defineProperty(PrimitiveThickness.prototype, "top", {
  3384. /**
  3385. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3386. */
  3387. get: function () {
  3388. return this._getStringValue(0);
  3389. },
  3390. set: function (value) {
  3391. this._setStringValue(value, 0, true);
  3392. },
  3393. enumerable: true,
  3394. configurable: true
  3395. });
  3396. Object.defineProperty(PrimitiveThickness.prototype, "left", {
  3397. /**
  3398. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3399. */
  3400. get: function () {
  3401. return this._getStringValue(1);
  3402. },
  3403. set: function (value) {
  3404. this._setStringValue(value, 1, true);
  3405. },
  3406. enumerable: true,
  3407. configurable: true
  3408. });
  3409. Object.defineProperty(PrimitiveThickness.prototype, "right", {
  3410. /**
  3411. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3412. */
  3413. get: function () {
  3414. return this._getStringValue(2);
  3415. },
  3416. set: function (value) {
  3417. this._setStringValue(value, 2, true);
  3418. },
  3419. enumerable: true,
  3420. configurable: true
  3421. });
  3422. Object.defineProperty(PrimitiveThickness.prototype, "bottom", {
  3423. /**
  3424. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  3425. */
  3426. get: function () {
  3427. return this._getStringValue(3);
  3428. },
  3429. set: function (value) {
  3430. this._setStringValue(value, 3, true);
  3431. },
  3432. enumerable: true,
  3433. configurable: true
  3434. });
  3435. Object.defineProperty(PrimitiveThickness.prototype, "topPixels", {
  3436. /**
  3437. * Get/set the top thickness in pixel.
  3438. */
  3439. get: function () {
  3440. return this._pixels[0];
  3441. },
  3442. set: function (value) {
  3443. this._setPixels(value, 0, true);
  3444. },
  3445. enumerable: true,
  3446. configurable: true
  3447. });
  3448. Object.defineProperty(PrimitiveThickness.prototype, "leftPixels", {
  3449. /**
  3450. * Get/set the left thickness in pixel.
  3451. */
  3452. get: function () {
  3453. return this._pixels[1];
  3454. },
  3455. set: function (value) {
  3456. this._setPixels(value, 1, true);
  3457. },
  3458. enumerable: true,
  3459. configurable: true
  3460. });
  3461. Object.defineProperty(PrimitiveThickness.prototype, "rightPixels", {
  3462. /**
  3463. * Get/set the right thickness in pixel.
  3464. */
  3465. get: function () {
  3466. return this._pixels[2];
  3467. },
  3468. set: function (value) {
  3469. this._setPixels(value, 2, true);
  3470. },
  3471. enumerable: true,
  3472. configurable: true
  3473. });
  3474. Object.defineProperty(PrimitiveThickness.prototype, "bottomPixels", {
  3475. /**
  3476. * Get/set the bottom thickness in pixel.
  3477. */
  3478. get: function () {
  3479. return this._pixels[3];
  3480. },
  3481. set: function (value) {
  3482. this._setPixels(value, 3, true);
  3483. },
  3484. enumerable: true,
  3485. configurable: true
  3486. });
  3487. Object.defineProperty(PrimitiveThickness.prototype, "topPercentage", {
  3488. /**
  3489. * Get/set the top thickness in percentage.
  3490. * The get will return a valid value only if the edge type is percentage.
  3491. * The Set will change the edge mode if needed
  3492. */
  3493. get: function () {
  3494. return this._percentages[0];
  3495. },
  3496. set: function (value) {
  3497. this._setPercentage(value, 0, true);
  3498. },
  3499. enumerable: true,
  3500. configurable: true
  3501. });
  3502. Object.defineProperty(PrimitiveThickness.prototype, "leftPercentage", {
  3503. /**
  3504. * Get/set the left thickness in percentage.
  3505. * The get will return a valid value only if the edge mode is percentage.
  3506. * The Set will change the edge mode if needed
  3507. */
  3508. get: function () {
  3509. return this._percentages[1];
  3510. },
  3511. set: function (value) {
  3512. this._setPercentage(value, 1, true);
  3513. },
  3514. enumerable: true,
  3515. configurable: true
  3516. });
  3517. Object.defineProperty(PrimitiveThickness.prototype, "rightPercentage", {
  3518. /**
  3519. * Get/set the right thickness in percentage.
  3520. * The get will return a valid value only if the edge mode is percentage.
  3521. * The Set will change the edge mode if needed
  3522. */
  3523. get: function () {
  3524. return this._percentages[2];
  3525. },
  3526. set: function (value) {
  3527. this._setPercentage(value, 2, true);
  3528. },
  3529. enumerable: true,
  3530. configurable: true
  3531. });
  3532. Object.defineProperty(PrimitiveThickness.prototype, "bottomPercentage", {
  3533. /**
  3534. * Get/set the bottom thickness in percentage.
  3535. * The get will return a valid value only if the edge mode is percentage.
  3536. * The Set will change the edge mode if needed
  3537. */
  3538. get: function () {
  3539. return this._percentages[3];
  3540. },
  3541. set: function (value) {
  3542. this._setPercentage(value, 3, true);
  3543. },
  3544. enumerable: true,
  3545. configurable: true
  3546. });
  3547. Object.defineProperty(PrimitiveThickness.prototype, "topMode", {
  3548. /**
  3549. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  3550. */
  3551. get: function () {
  3552. return this._getType(0, false);
  3553. },
  3554. set: function (mode) {
  3555. this._setType(0, mode);
  3556. },
  3557. enumerable: true,
  3558. configurable: true
  3559. });
  3560. Object.defineProperty(PrimitiveThickness.prototype, "leftMode", {
  3561. /**
  3562. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  3563. */
  3564. get: function () {
  3565. return this._getType(1, false);
  3566. },
  3567. set: function (mode) {
  3568. this._setType(1, mode);
  3569. },
  3570. enumerable: true,
  3571. configurable: true
  3572. });
  3573. Object.defineProperty(PrimitiveThickness.prototype, "rightMode", {
  3574. /**
  3575. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  3576. */
  3577. get: function () {
  3578. return this._getType(2, false);
  3579. },
  3580. set: function (mode) {
  3581. this._setType(2, mode);
  3582. },
  3583. enumerable: true,
  3584. configurable: true
  3585. });
  3586. Object.defineProperty(PrimitiveThickness.prototype, "bottomMode", {
  3587. /**
  3588. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  3589. */
  3590. get: function () {
  3591. return this._getType(3, false);
  3592. },
  3593. set: function (mode) {
  3594. this._setType(3, mode);
  3595. },
  3596. enumerable: true,
  3597. configurable: true
  3598. });
  3599. Object.defineProperty(PrimitiveThickness.prototype, "isDefault", {
  3600. get: function () {
  3601. return this._flags === 0x1111;
  3602. },
  3603. enumerable: true,
  3604. configurable: true
  3605. });
  3606. PrimitiveThickness.prototype._computePixels = function (index, sourceArea, emitChanged) {
  3607. var type = this._getType(index, false);
  3608. if (type === PrimitiveThickness.Inherit) {
  3609. this._parentAccess()._computePixels(index, sourceArea, emitChanged);
  3610. return;
  3611. }
  3612. if (type !== PrimitiveThickness.Percentage) {
  3613. return;
  3614. }
  3615. var pixels = ((index === 0 || index === 3) ? sourceArea.height : sourceArea.width) * this._percentages[index];
  3616. this._pixels[index] = pixels;
  3617. if (emitChanged) {
  3618. this.onChangeCallback();
  3619. }
  3620. };
  3621. PrimitiveThickness.prototype.onChangeCallback = function () {
  3622. if (this._changedCallback) {
  3623. this._changedCallback();
  3624. }
  3625. };
  3626. /**
  3627. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  3628. * @param sourceArea the source area where the content must be sized/positioned
  3629. * @param contentSize the content size to position/resize
  3630. * @param alignment the alignment setting
  3631. * @param dstOffset the position of the content
  3632. * @param dstArea the new size of the content
  3633. */
  3634. PrimitiveThickness.prototype.computeWithAlignment = function (sourceArea, contentSize, alignment, dstOffset, dstArea, computeLayoutArea) {
  3635. if (computeLayoutArea === void 0) { computeLayoutArea = false; }
  3636. // Fetch some data
  3637. var topType = this._getType(0, true);
  3638. var leftType = this._getType(1, true);
  3639. var rightType = this._getType(2, true);
  3640. var bottomType = this._getType(3, true);
  3641. var hasWidth = contentSize && (contentSize.width != null);
  3642. var hasHeight = contentSize && (contentSize.height != null);
  3643. var width = hasWidth ? contentSize.width : 0;
  3644. var height = hasHeight ? contentSize.height : 0;
  3645. var isTopAuto = topType === PrimitiveThickness.Auto;
  3646. var isLeftAuto = leftType === PrimitiveThickness.Auto;
  3647. var isRightAuto = rightType === PrimitiveThickness.Auto;
  3648. var isBottomAuto = bottomType === PrimitiveThickness.Auto;
  3649. switch (alignment.horizontal) {
  3650. case PrimitiveAlignment.AlignLeft:
  3651. {
  3652. if (isLeftAuto) {
  3653. dstOffset.x = 0;
  3654. }
  3655. else {
  3656. this._computePixels(1, sourceArea, true);
  3657. dstOffset.x = this.leftPixels;
  3658. }
  3659. dstArea.width = width;
  3660. if (computeLayoutArea) {
  3661. dstArea.width += this.leftPixels;
  3662. }
  3663. break;
  3664. }
  3665. case PrimitiveAlignment.AlignRight:
  3666. {
  3667. if (isRightAuto) {
  3668. dstOffset.x = Math.round(sourceArea.width - width);
  3669. }
  3670. else {
  3671. this._computePixels(2, sourceArea, true);
  3672. dstOffset.x = Math.round(sourceArea.width - (width + this.rightPixels));
  3673. }
  3674. dstArea.width = width;
  3675. if (computeLayoutArea) {
  3676. dstArea.width += this.rightPixels;
  3677. }
  3678. break;
  3679. }
  3680. case PrimitiveAlignment.AlignStretch:
  3681. {
  3682. if (isLeftAuto) {
  3683. dstOffset.x = 0;
  3684. }
  3685. else {
  3686. this._computePixels(1, sourceArea, true);
  3687. dstOffset.x = this.leftPixels;
  3688. }
  3689. var right = 0;
  3690. if (!isRightAuto) {
  3691. this._computePixels(2, sourceArea, true);
  3692. right = this.rightPixels;
  3693. }
  3694. dstArea.width = sourceArea.width - (dstOffset.x + right);
  3695. break;
  3696. }
  3697. case PrimitiveAlignment.AlignCenter:
  3698. {
  3699. if (!isLeftAuto) {
  3700. this._computePixels(1, sourceArea, true);
  3701. }
  3702. if (!isRightAuto) {
  3703. this._computePixels(2, sourceArea, true);
  3704. }
  3705. var offset = (isLeftAuto ? 0 : this.leftPixels) - (isRightAuto ? 0 : this.rightPixels);
  3706. dstOffset.x = Math.round(((sourceArea.width - width) / 2) + offset);
  3707. dstArea.width = width;
  3708. break;
  3709. }
  3710. }
  3711. switch (alignment.vertical) {
  3712. case PrimitiveAlignment.AlignTop:
  3713. {
  3714. if (isTopAuto) {
  3715. dstOffset.y = sourceArea.height - height;
  3716. }
  3717. else {
  3718. this._computePixels(0, sourceArea, true);
  3719. dstOffset.y = Math.round(sourceArea.height - (height + this.topPixels));
  3720. }
  3721. dstArea.height = height;
  3722. if (computeLayoutArea) {
  3723. dstArea.height += this.topPixels;
  3724. }
  3725. break;
  3726. }
  3727. case PrimitiveAlignment.AlignBottom:
  3728. {
  3729. if (isBottomAuto) {
  3730. dstOffset.y = 0;
  3731. }
  3732. else {
  3733. this._computePixels(3, sourceArea, true);
  3734. dstOffset.y = this.bottomPixels;
  3735. }
  3736. dstArea.height = height;
  3737. if (computeLayoutArea) {
  3738. dstArea.height += this.bottomPixels;
  3739. }
  3740. break;
  3741. }
  3742. case PrimitiveAlignment.AlignStretch:
  3743. {
  3744. if (isBottomAuto) {
  3745. dstOffset.y = 0;
  3746. }
  3747. else {
  3748. this._computePixels(3, sourceArea, true);
  3749. dstOffset.y = this.bottomPixels;
  3750. }
  3751. var top_1 = 0;
  3752. if (!isTopAuto) {
  3753. this._computePixels(0, sourceArea, true);
  3754. top_1 = this.topPixels;
  3755. }
  3756. dstArea.height = sourceArea.height - (dstOffset.y + top_1);
  3757. break;
  3758. }
  3759. case PrimitiveAlignment.AlignCenter:
  3760. {
  3761. if (!isTopAuto) {
  3762. this._computePixels(0, sourceArea, true);
  3763. }
  3764. if (!isBottomAuto) {
  3765. this._computePixels(3, sourceArea, true);
  3766. }
  3767. var offset = (isBottomAuto ? 0 : this.bottomPixels) - (isTopAuto ? 0 : this.topPixels);
  3768. dstOffset.y = Math.round(((sourceArea.height - height) / 2) + offset);
  3769. dstArea.height = height;
  3770. break;
  3771. }
  3772. }
  3773. };
  3774. /**
  3775. * Compute an area and its position considering this thickness properties based on a given source area
  3776. * @param sourceArea the source area
  3777. * @param dstOffset the position of the resulting area
  3778. * @param dstArea the size of the resulting area
  3779. */
  3780. PrimitiveThickness.prototype.compute = function (sourceArea, dstOffset, dstArea) {
  3781. this._computePixels(0, sourceArea, true);
  3782. this._computePixels(1, sourceArea, true);
  3783. this._computePixels(2, sourceArea, true);
  3784. this._computePixels(3, sourceArea, true);
  3785. dstOffset.x = this.leftPixels;
  3786. dstArea.width = sourceArea.width - (dstOffset.x + this.rightPixels);
  3787. dstOffset.y = this.bottomPixels;
  3788. dstArea.height = sourceArea.height - (dstOffset.y + this.topPixels);
  3789. };
  3790. /**
  3791. * Compute an area considering this thickness properties based on a given source area
  3792. * @param sourceArea the source area
  3793. * @param result the resulting area
  3794. */
  3795. PrimitiveThickness.prototype.computeArea = function (sourceArea, result) {
  3796. this._computePixels(0, sourceArea, true);
  3797. this._computePixels(1, sourceArea, true);
  3798. this._computePixels(2, sourceArea, true);
  3799. this._computePixels(3, sourceArea, true);
  3800. result.width = this.leftPixels + sourceArea.width + this.rightPixels;
  3801. result.height = this.bottomPixels + sourceArea.height + this.topPixels;
  3802. };
  3803. PrimitiveThickness.prototype.enlarge = function (sourceArea, dstOffset, enlargedArea) {
  3804. this._computePixels(0, sourceArea, true);
  3805. this._computePixels(1, sourceArea, true);
  3806. this._computePixels(2, sourceArea, true);
  3807. this._computePixels(3, sourceArea, true);
  3808. dstOffset.x = this.leftPixels;
  3809. enlargedArea.width = sourceArea.width + (dstOffset.x + this.rightPixels);
  3810. dstOffset.y = this.bottomPixels;
  3811. enlargedArea.height = sourceArea.height + (dstOffset.y + this.topPixels);
  3812. };
  3813. PrimitiveThickness.Auto = 0x1;
  3814. PrimitiveThickness.Inherit = 0x2;
  3815. PrimitiveThickness.Percentage = 0x4;
  3816. PrimitiveThickness.Pixel = 0x8;
  3817. PrimitiveThickness = __decorate([
  3818. BABYLON.className("PrimitiveThickness", "BABYLON")
  3819. ], PrimitiveThickness);
  3820. return PrimitiveThickness;
  3821. }());
  3822. BABYLON.PrimitiveThickness = PrimitiveThickness;
  3823. /**
  3824. * Main class used for the Primitive Intersection API
  3825. */
  3826. var IntersectInfo2D = (function () {
  3827. function IntersectInfo2D() {
  3828. this.findFirstOnly = false;
  3829. this.intersectHidden = false;
  3830. this.pickPosition = BABYLON.Vector2.Zero();
  3831. }
  3832. Object.defineProperty(IntersectInfo2D.prototype, "isIntersected", {
  3833. /**
  3834. * true if at least one primitive intersected during the test
  3835. */
  3836. get: function () {
  3837. return this.intersectedPrimitives && this.intersectedPrimitives.length > 0;
  3838. },
  3839. enumerable: true,
  3840. configurable: true
  3841. });
  3842. IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
  3843. for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
  3844. var cur = _a[_i];
  3845. if (cur.prim === prim) {
  3846. return cur.intersectionLocation;
  3847. }
  3848. }
  3849. return null;
  3850. };
  3851. // Internals, don't use
  3852. IntersectInfo2D.prototype._exit = function (firstLevel) {
  3853. if (firstLevel) {
  3854. this._globalPickPosition = null;
  3855. }
  3856. };
  3857. return IntersectInfo2D;
  3858. }());
  3859. BABYLON.IntersectInfo2D = IntersectInfo2D;
  3860. var Prim2DBase = (function (_super) {
  3861. __extends(Prim2DBase, _super);
  3862. function Prim2DBase(settings) {
  3863. // Avoid checking every time if the object exists
  3864. if (settings == null) {
  3865. settings = {};
  3866. }
  3867. // BASE CLASS CALL
  3868. _super.call(this);
  3869. // Fetch the owner, parent. There're many ways to do it and we can end up with nothing for both
  3870. var owner;
  3871. var parent;
  3872. if (Prim2DBase._isCanvasInit) {
  3873. owner = this;
  3874. parent = null;
  3875. this._canvasPreInit(settings);
  3876. }
  3877. else {
  3878. if (settings.parent != null) {
  3879. parent = settings.parent;
  3880. owner = settings.parent.owner;
  3881. if (!owner) {
  3882. throw new Error("Parent " + parent.id + " of " + settings.id + " doesn't have a valid owner!");
  3883. }
  3884. if (!(this instanceof BABYLON.Group2D) && !(this instanceof BABYLON.Sprite2D && settings.id != null && settings.id.indexOf("__cachedSpriteOfGroup__") === 0) && (owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) && (parent === owner)) {
  3885. throw new Error("Can't create a primitive with the canvas as direct parent when the caching strategy is TOPLEVELGROUPS. You need to create a Group below the canvas and use it as the parent for the primitive");
  3886. }
  3887. }
  3888. }
  3889. // Fields initialization
  3890. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  3891. this._size = null; //Size.Zero();
  3892. this._scale = new BABYLON.Vector2(1, 1);
  3893. this._actualSize = null;
  3894. this._boundingSize = BABYLON.Size.Zero();
  3895. this._layoutArea = BABYLON.Size.Zero();
  3896. this._layoutAreaPos = null;
  3897. this._layoutBoundingInfo = null;
  3898. this._marginOffset = BABYLON.Vector2.Zero();
  3899. this._paddingOffset = BABYLON.Vector2.Zero();
  3900. this._parentPaddingOffset = BABYLON.Vector2.Zero();
  3901. this._parentContentArea = BABYLON.Size.Zero();
  3902. this._lastAutoSizeArea = BABYLON.Size.Zero();
  3903. this._contentArea = new BABYLON.Size(null, null);
  3904. this._pointerEventObservable = new BABYLON.Observable();
  3905. this._boundingInfo = new BABYLON.BoundingInfo2D();
  3906. this._owner = owner;
  3907. this._parent = null;
  3908. this._margin = null;
  3909. this._padding = null;
  3910. this._marginAlignment = null;
  3911. this._id = settings.id;
  3912. this._children = new Array();
  3913. this._localTransform = new BABYLON.Matrix();
  3914. this._globalTransform = null;
  3915. this._invGlobalTransform = null;
  3916. this._globalTransformProcessStep = 0;
  3917. this._globalTransformStep = 0;
  3918. this._renderGroup = null;
  3919. this._primLinearPosition = 0;
  3920. this._manualZOrder = null;
  3921. this._zOrder = 0;
  3922. this._zMax = 0;
  3923. this._firstZDirtyIndex = Prim2DBase._bigInt;
  3924. this._actualOpacity = 0;
  3925. this._actualScale = BABYLON.Vector2.Zero();
  3926. var isPickable = true;
  3927. var isContainer = true;
  3928. if (settings.isPickable !== undefined) {
  3929. isPickable = settings.isPickable;
  3930. }
  3931. if (settings.isContainer !== undefined) {
  3932. isContainer = settings.isContainer;
  3933. }
  3934. if (settings.dontInheritParentScale) {
  3935. this._setFlags(BABYLON.SmartPropertyPrim.flagDontInheritParentScale);
  3936. }
  3937. this._setFlags((isPickable ? BABYLON.SmartPropertyPrim.flagIsPickable : 0) | BABYLON.SmartPropertyPrim.flagBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagActualOpacityDirty | (isContainer ? BABYLON.SmartPropertyPrim.flagIsContainer : 0) | BABYLON.SmartPropertyPrim.flagActualScaleDirty | BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  3938. if (settings.opacity != null) {
  3939. this._opacity = settings.opacity;
  3940. }
  3941. else {
  3942. this._opacity = 1;
  3943. }
  3944. this._updateRenderMode();
  3945. if (settings.childrenFlatZOrder) {
  3946. this._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  3947. }
  3948. // If the parent is given, initialize the hierarchy/owner related data
  3949. if (parent != null) {
  3950. parent.addChild(this);
  3951. this._hierarchyDepth = parent._hierarchyDepth + 1;
  3952. this._patchHierarchy(parent.owner);
  3953. }
  3954. // If it's a group, detect its own states
  3955. if (this.owner && this instanceof BABYLON.Group2D) {
  3956. var group = this;
  3957. group.detectGroupStates();
  3958. }
  3959. // Time to insert children if some are specified
  3960. if (settings.children != null) {
  3961. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  3962. var child = _a[_i];
  3963. this.addChild(child);
  3964. // Good time to patch the hierarchy, it won't go very far if there's no need to
  3965. if (this.owner != null) {
  3966. child._patchHierarchy(this.owner);
  3967. }
  3968. }
  3969. }
  3970. if (settings.zOrder != null) {
  3971. this.zOrder = settings.zOrder;
  3972. }
  3973. // Set the model related properties
  3974. if (settings.position != null) {
  3975. this.position = settings.position;
  3976. }
  3977. else if (settings.x != null || settings.y != null) {
  3978. this.position = new BABYLON.Vector2(settings.x || 0, settings.y || 0);
  3979. }
  3980. else {
  3981. this._position = null;
  3982. }
  3983. this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
  3984. if (settings.scale != null) {
  3985. this.scale = settings.scale;
  3986. }
  3987. else {
  3988. if (settings.scaleX != null) {
  3989. this.scaleX = settings.scaleX;
  3990. }
  3991. if (settings.scaleY != null) {
  3992. this.scaleY = settings.scaleY;
  3993. }
  3994. }
  3995. this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
  3996. this.origin = settings.origin || new BABYLON.Vector2(0.5, 0.5);
  3997. // Layout Engine
  3998. if (settings.layoutEngine != null) {
  3999. if (typeof settings.layoutEngine === "string") {
  4000. var name_1 = settings.layoutEngine.toLocaleLowerCase().trim();
  4001. if (name_1 === "canvas" || name_1 === "canvaslayoutengine") {
  4002. this.layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4003. }
  4004. else if (name_1.indexOf("stackpanel") === 0 || name_1.indexOf("horizontalstackpanel") === 0) {
  4005. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Horizontal;
  4006. }
  4007. else if (name_1.indexOf("verticalstackpanel") === 0) {
  4008. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Vertical;
  4009. }
  4010. }
  4011. else if (settings.layoutEngine instanceof BABYLON.LayoutEngineBase) {
  4012. this.layoutEngine = settings.layoutEngine;
  4013. }
  4014. }
  4015. // Set the layout/margin stuffs
  4016. if (settings.marginTop) {
  4017. this.margin.setTop(settings.marginTop);
  4018. }
  4019. if (settings.marginLeft) {
  4020. this.margin.setLeft(settings.marginLeft);
  4021. }
  4022. if (settings.marginRight) {
  4023. this.margin.setRight(settings.marginRight);
  4024. }
  4025. if (settings.marginBottom) {
  4026. this.margin.setBottom(settings.marginBottom);
  4027. }
  4028. if (settings.margin) {
  4029. if (typeof settings.margin === "string") {
  4030. this.margin.fromString(settings.margin);
  4031. }
  4032. else {
  4033. this.margin.fromUniformPixels(settings.margin);
  4034. }
  4035. }
  4036. if (settings.marginHAlignment) {
  4037. this.marginAlignment.horizontal = settings.marginHAlignment;
  4038. }
  4039. if (settings.marginVAlignment) {
  4040. this.marginAlignment.vertical = settings.marginVAlignment;
  4041. }
  4042. if (settings.marginAlignment) {
  4043. this.marginAlignment.fromString(settings.marginAlignment);
  4044. }
  4045. if (settings.paddingTop) {
  4046. this.padding.setTop(settings.paddingTop);
  4047. }
  4048. if (settings.paddingLeft) {
  4049. this.padding.setLeft(settings.paddingLeft);
  4050. }
  4051. if (settings.paddingRight) {
  4052. this.padding.setRight(settings.paddingRight);
  4053. }
  4054. if (settings.paddingBottom) {
  4055. this.padding.setBottom(settings.paddingBottom);
  4056. }
  4057. if (settings.padding) {
  4058. this.padding.fromString(settings.padding);
  4059. }
  4060. // Dirty layout and positioning
  4061. this._parentLayoutDirty();
  4062. this._positioningDirty();
  4063. }
  4064. Object.defineProperty(Prim2DBase.prototype, "actionManager", {
  4065. get: function () {
  4066. if (!this._actionManager) {
  4067. this._actionManager = new BABYLON.ActionManager(this.owner.scene);
  4068. }
  4069. return this._actionManager;
  4070. },
  4071. enumerable: true,
  4072. configurable: true
  4073. });
  4074. /**
  4075. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  4076. * @param predicate the predicate to test on each parent
  4077. * @return the first primitive where the predicate was successful
  4078. */
  4079. Prim2DBase.prototype.traverseUp = function (predicate) {
  4080. var p = this;
  4081. while (p != null) {
  4082. if (predicate(p)) {
  4083. return p;
  4084. }
  4085. p = p._parent;
  4086. }
  4087. return null;
  4088. };
  4089. Object.defineProperty(Prim2DBase.prototype, "owner", {
  4090. /**
  4091. * Retrieve the owner Canvas2D
  4092. */
  4093. get: function () {
  4094. return this._owner;
  4095. },
  4096. enumerable: true,
  4097. configurable: true
  4098. });
  4099. Object.defineProperty(Prim2DBase.prototype, "parent", {
  4100. /**
  4101. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  4102. */
  4103. get: function () {
  4104. return this._parent;
  4105. },
  4106. enumerable: true,
  4107. configurable: true
  4108. });
  4109. Object.defineProperty(Prim2DBase.prototype, "children", {
  4110. /**
  4111. * The array of direct children primitives
  4112. */
  4113. get: function () {
  4114. return this._children;
  4115. },
  4116. enumerable: true,
  4117. configurable: true
  4118. });
  4119. Object.defineProperty(Prim2DBase.prototype, "id", {
  4120. /**
  4121. * The identifier of this primitive, may not be unique, it's for information purpose only
  4122. */
  4123. get: function () {
  4124. return this._id;
  4125. },
  4126. enumerable: true,
  4127. configurable: true
  4128. });
  4129. Object.defineProperty(Prim2DBase.prototype, "actualPosition", {
  4130. get: function () {
  4131. if (this._actualPosition != null) {
  4132. return this._actualPosition;
  4133. }
  4134. if (this._position != null) {
  4135. return this._position;
  4136. }
  4137. // At least return 0,0, we can't return null on actualPosition
  4138. return Prim2DBase._nullPosition;
  4139. },
  4140. /**
  4141. * DO NOT INVOKE for internal purpose only
  4142. */
  4143. set: function (val) {
  4144. this._actualPosition = val;
  4145. },
  4146. enumerable: true,
  4147. configurable: true
  4148. });
  4149. Object.defineProperty(Prim2DBase.prototype, "actualX", {
  4150. /**
  4151. * Shortcut to actualPosition.x
  4152. */
  4153. get: function () {
  4154. return this.actualPosition.x;
  4155. },
  4156. set: function (val) {
  4157. this._actualPosition.x = val;
  4158. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualPosition);
  4159. },
  4160. enumerable: true,
  4161. configurable: true
  4162. });
  4163. Object.defineProperty(Prim2DBase.prototype, "actualY", {
  4164. /**
  4165. * Shortcut to actualPosition.y
  4166. */
  4167. get: function () {
  4168. return this.actualPosition.y;
  4169. },
  4170. set: function (val) {
  4171. this._actualPosition.y = val;
  4172. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualPosition);
  4173. },
  4174. enumerable: true,
  4175. configurable: true
  4176. });
  4177. Object.defineProperty(Prim2DBase.prototype, "position", {
  4178. /**
  4179. * Position of the primitive, relative to its parent.
  4180. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  4181. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  4182. * Setting this property may have no effect is specific alignment are in effect.
  4183. */
  4184. get: function () {
  4185. return this._position || Prim2DBase._nullPosition;
  4186. },
  4187. set: function (value) {
  4188. if (!this._checkPositionChange()) {
  4189. return;
  4190. }
  4191. this._position = value;
  4192. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4193. },
  4194. enumerable: true,
  4195. configurable: true
  4196. });
  4197. Object.defineProperty(Prim2DBase.prototype, "x", {
  4198. /**
  4199. * Direct access to the position.x value of the primitive
  4200. * Use this property when you only want to change one component of the position property
  4201. */
  4202. get: function () {
  4203. if (!this._position) {
  4204. return null;
  4205. }
  4206. return this._position.x;
  4207. },
  4208. set: function (value) {
  4209. if (!this._checkPositionChange()) {
  4210. return;
  4211. }
  4212. if (!this._position) {
  4213. this._position = BABYLON.Vector2.Zero();
  4214. }
  4215. if (this._position.x === value) {
  4216. return;
  4217. }
  4218. this._position.x = value;
  4219. this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
  4220. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4221. },
  4222. enumerable: true,
  4223. configurable: true
  4224. });
  4225. Object.defineProperty(Prim2DBase.prototype, "y", {
  4226. /**
  4227. * Direct access to the position.y value of the primitive
  4228. * Use this property when you only want to change one component of the position property
  4229. */
  4230. get: function () {
  4231. if (!this._position) {
  4232. return null;
  4233. }
  4234. return this._position.y;
  4235. },
  4236. set: function (value) {
  4237. if (!this._checkPositionChange()) {
  4238. return;
  4239. }
  4240. if (!this._position) {
  4241. this._position = BABYLON.Vector2.Zero();
  4242. }
  4243. if (this._position.y === value) {
  4244. return;
  4245. }
  4246. this._position.y = value;
  4247. this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
  4248. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
  4249. },
  4250. enumerable: true,
  4251. configurable: true
  4252. });
  4253. Object.defineProperty(Prim2DBase.prototype, "size", {
  4254. /**
  4255. * Size of the primitive or its bounding area
  4256. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  4257. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  4258. */
  4259. get: function () {
  4260. if (!this._size || this._size.width == null || this._size.height == null) {
  4261. if (Prim2DBase.boundinbBoxReentrency) {
  4262. return Prim2DBase.nullSize;
  4263. }
  4264. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  4265. return this._boundingSize;
  4266. }
  4267. Prim2DBase.boundinbBoxReentrency = true;
  4268. var b = this.boundingInfo;
  4269. Prim2DBase.boundinbBoxReentrency = false;
  4270. return this._boundingSize;
  4271. }
  4272. return this._size;
  4273. },
  4274. set: function (value) {
  4275. this._size = value;
  4276. },
  4277. enumerable: true,
  4278. configurable: true
  4279. });
  4280. Object.defineProperty(Prim2DBase.prototype, "width", {
  4281. /**
  4282. * Direct access to the size.width value of the primitive
  4283. * Use this property when you only want to change one component of the size property
  4284. */
  4285. get: function () {
  4286. if (!this.size) {
  4287. return null;
  4288. }
  4289. return this.size.width;
  4290. },
  4291. set: function (value) {
  4292. if (this.size && this.size.width === value) {
  4293. return;
  4294. }
  4295. if (!this.size) {
  4296. this.size = new BABYLON.Size(value, 0);
  4297. }
  4298. else {
  4299. this.size.width = value;
  4300. }
  4301. this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
  4302. this._positioningDirty();
  4303. },
  4304. enumerable: true,
  4305. configurable: true
  4306. });
  4307. Object.defineProperty(Prim2DBase.prototype, "height", {
  4308. /**
  4309. * Direct access to the size.height value of the primitive
  4310. * Use this property when you only want to change one component of the size property
  4311. */
  4312. get: function () {
  4313. if (!this.size) {
  4314. return null;
  4315. }
  4316. return this.size.height;
  4317. },
  4318. set: function (value) {
  4319. if (this.size && this.size.height === value) {
  4320. return;
  4321. }
  4322. if (!this.size) {
  4323. this.size = new BABYLON.Size(0, value);
  4324. }
  4325. else {
  4326. this.size.height = value;
  4327. }
  4328. this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
  4329. this._positioningDirty();
  4330. },
  4331. enumerable: true,
  4332. configurable: true
  4333. });
  4334. Object.defineProperty(Prim2DBase.prototype, "rotation", {
  4335. get: function () {
  4336. return this._rotation;
  4337. },
  4338. set: function (value) {
  4339. this._rotation = value;
  4340. },
  4341. enumerable: true,
  4342. configurable: true
  4343. });
  4344. Object.defineProperty(Prim2DBase.prototype, "scale", {
  4345. get: function () {
  4346. return this._scale.x;
  4347. },
  4348. set: function (value) {
  4349. this._scale.x = this._scale.y = value;
  4350. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4351. this._spreadActualScaleDirty();
  4352. },
  4353. enumerable: true,
  4354. configurable: true
  4355. });
  4356. Object.defineProperty(Prim2DBase.prototype, "actualSize", {
  4357. /**
  4358. * Return the size of the primitive as it's being rendered into the target.
  4359. * This value may be different of the size property when layout/alignment is used or specific primitive types can implement a custom logic through this property.
  4360. * BEWARE: don't use the setter, it's for internal purpose only
  4361. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  4362. */
  4363. get: function () {
  4364. if (this._actualSize) {
  4365. return this._actualSize;
  4366. }
  4367. return this._size;
  4368. },
  4369. set: function (value) {
  4370. if (this._actualSize.equals(value)) {
  4371. return;
  4372. }
  4373. this._actualSize = value;
  4374. },
  4375. enumerable: true,
  4376. configurable: true
  4377. });
  4378. Object.defineProperty(Prim2DBase.prototype, "actualWidth", {
  4379. /**
  4380. * Shortcut to actualSize.width
  4381. */
  4382. get: function () {
  4383. return this.actualSize.width;
  4384. },
  4385. set: function (val) {
  4386. this._actualSize.width = val;
  4387. this._triggerPropertyChanged(Prim2DBase.actualSizeProperty, this._actualSize);
  4388. },
  4389. enumerable: true,
  4390. configurable: true
  4391. });
  4392. Object.defineProperty(Prim2DBase.prototype, "actualHeight", {
  4393. /**
  4394. * Shortcut to actualPosition.height
  4395. */
  4396. get: function () {
  4397. return this.actualSize.width;
  4398. },
  4399. set: function (val) {
  4400. this._actualSize.height = val;
  4401. this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, this._actualSize);
  4402. },
  4403. enumerable: true,
  4404. configurable: true
  4405. });
  4406. Object.defineProperty(Prim2DBase.prototype, "actualZOffset", {
  4407. get: function () {
  4408. if (this._manualZOrder != null) {
  4409. return this._manualZOrder;
  4410. }
  4411. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  4412. this._updateZOrder();
  4413. }
  4414. return (1 - this._zOrder);
  4415. },
  4416. enumerable: true,
  4417. configurable: true
  4418. });
  4419. Object.defineProperty(Prim2DBase.prototype, "minSize", {
  4420. /**
  4421. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  4422. * The Primitive's size won't be less than specified.
  4423. * The default value depends of the Primitive type
  4424. */
  4425. get: function () {
  4426. return this._minSize;
  4427. },
  4428. set: function (value) {
  4429. if (this._minSize && value && this._minSize.equals(value)) {
  4430. return;
  4431. }
  4432. this._minSize = value;
  4433. this._parentLayoutDirty();
  4434. },
  4435. enumerable: true,
  4436. configurable: true
  4437. });
  4438. Object.defineProperty(Prim2DBase.prototype, "maxSize", {
  4439. /**
  4440. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  4441. * The Primitive's size won't be more than specified.
  4442. * The default value depends of the Primitive type
  4443. */
  4444. get: function () {
  4445. return this._maxSize;
  4446. },
  4447. set: function (value) {
  4448. if (this._maxSize && value && this._maxSize.equals(value)) {
  4449. return;
  4450. }
  4451. this._maxSize = value;
  4452. this._parentLayoutDirty();
  4453. },
  4454. enumerable: true,
  4455. configurable: true
  4456. });
  4457. Object.defineProperty(Prim2DBase.prototype, "origin", {
  4458. /**
  4459. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  4460. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  4461. * For instance:
  4462. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  4463. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  4464. * 0,1 means the center is top/left
  4465. * @returns The normalized center.
  4466. */
  4467. get: function () {
  4468. return this._origin;
  4469. },
  4470. set: function (value) {
  4471. this._origin = value;
  4472. },
  4473. enumerable: true,
  4474. configurable: true
  4475. });
  4476. Object.defineProperty(Prim2DBase.prototype, "levelVisible", {
  4477. get: function () {
  4478. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagLevelVisible);
  4479. },
  4480. set: function (value) {
  4481. this._changeFlags(BABYLON.SmartPropertyPrim.flagLevelVisible, value);
  4482. },
  4483. enumerable: true,
  4484. configurable: true
  4485. });
  4486. Object.defineProperty(Prim2DBase.prototype, "isVisible", {
  4487. get: function () {
  4488. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsVisible);
  4489. },
  4490. set: function (value) {
  4491. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsVisible, value);
  4492. },
  4493. enumerable: true,
  4494. configurable: true
  4495. });
  4496. Object.defineProperty(Prim2DBase.prototype, "zOrder", {
  4497. get: function () {
  4498. return this._manualZOrder;
  4499. },
  4500. set: function (value) {
  4501. if (this._manualZOrder === value) {
  4502. return;
  4503. }
  4504. this._manualZOrder = value;
  4505. this.onZOrderChanged();
  4506. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  4507. this._actualZOrderChangedObservable.notifyObservers(value);
  4508. }
  4509. },
  4510. enumerable: true,
  4511. configurable: true
  4512. });
  4513. Object.defineProperty(Prim2DBase.prototype, "isManualZOrder", {
  4514. get: function () {
  4515. return this._manualZOrder != null;
  4516. },
  4517. enumerable: true,
  4518. configurable: true
  4519. });
  4520. Object.defineProperty(Prim2DBase.prototype, "margin", {
  4521. get: function () {
  4522. var _this = this;
  4523. if (!this._margin) {
  4524. this._margin = new PrimitiveThickness(function () {
  4525. if (!_this.parent) {
  4526. return null;
  4527. }
  4528. return _this.parent.margin;
  4529. }, function () { return _this._positioningDirty(); });
  4530. }
  4531. return this._margin;
  4532. },
  4533. set: function (value) {
  4534. this.margin.copyFrom(value);
  4535. },
  4536. enumerable: true,
  4537. configurable: true
  4538. });
  4539. Object.defineProperty(Prim2DBase.prototype, "_hasMargin", {
  4540. /**
  4541. * Check for both margin and marginAlignment, return true if at least one of them is specified with a non default value
  4542. */
  4543. get: function () {
  4544. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4545. },
  4546. enumerable: true,
  4547. configurable: true
  4548. });
  4549. Object.defineProperty(Prim2DBase.prototype, "padding", {
  4550. get: function () {
  4551. var _this = this;
  4552. if (!this._padding) {
  4553. this._padding = new PrimitiveThickness(function () {
  4554. if (!_this.parent) {
  4555. return null;
  4556. }
  4557. return _this.parent.padding;
  4558. }, function () { return _this._positioningDirty(); });
  4559. }
  4560. return this._padding;
  4561. },
  4562. set: function (value) {
  4563. this.padding.copyFrom(value);
  4564. },
  4565. enumerable: true,
  4566. configurable: true
  4567. });
  4568. Object.defineProperty(Prim2DBase.prototype, "_hasPadding", {
  4569. get: function () {
  4570. return this._padding !== null && !this._padding.isDefault;
  4571. },
  4572. enumerable: true,
  4573. configurable: true
  4574. });
  4575. Object.defineProperty(Prim2DBase.prototype, "marginAlignment", {
  4576. get: function () {
  4577. var _this = this;
  4578. if (!this._marginAlignment) {
  4579. this._marginAlignment = new PrimitiveAlignment(function () { return _this._positioningDirty(); });
  4580. }
  4581. return this._marginAlignment;
  4582. },
  4583. set: function (value) {
  4584. this.marginAlignment.copyFrom(value);
  4585. },
  4586. enumerable: true,
  4587. configurable: true
  4588. });
  4589. Object.defineProperty(Prim2DBase.prototype, "_hasMarginAlignment", {
  4590. /**
  4591. * Check if there a marginAlignment specified (non null and not default)
  4592. */
  4593. get: function () {
  4594. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  4595. },
  4596. enumerable: true,
  4597. configurable: true
  4598. });
  4599. Object.defineProperty(Prim2DBase.prototype, "opacity", {
  4600. get: function () {
  4601. return this._opacity;
  4602. },
  4603. set: function (value) {
  4604. if (value < 0) {
  4605. value = 0;
  4606. }
  4607. else if (value > 1) {
  4608. value = 1;
  4609. }
  4610. if (this._opacity === value) {
  4611. return;
  4612. }
  4613. this._opacity = value;
  4614. this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4615. this._spreadActualOpacityChanged();
  4616. this._updateRenderMode();
  4617. },
  4618. enumerable: true,
  4619. configurable: true
  4620. });
  4621. Object.defineProperty(Prim2DBase.prototype, "scaleX", {
  4622. get: function () {
  4623. return this._scale.x;
  4624. },
  4625. set: function (value) {
  4626. this._scale.x = value;
  4627. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4628. this._spreadActualScaleDirty();
  4629. },
  4630. enumerable: true,
  4631. configurable: true
  4632. });
  4633. Object.defineProperty(Prim2DBase.prototype, "scaleY", {
  4634. get: function () {
  4635. return this._scale.y;
  4636. },
  4637. set: function (value) {
  4638. this._scale.y = value;
  4639. this._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4640. this._spreadActualScaleDirty();
  4641. },
  4642. enumerable: true,
  4643. configurable: true
  4644. });
  4645. Prim2DBase.prototype._spreadActualScaleDirty = function () {
  4646. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  4647. var child = _a[_i];
  4648. child._setFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4649. child._spreadActualScaleDirty();
  4650. }
  4651. };
  4652. Object.defineProperty(Prim2DBase.prototype, "actualScale", {
  4653. /**
  4654. * Returns the actual scale of this Primitive, the value is computed from the scale property of this primitive, multiplied by the actualScale of its parent one (if any). The Vector2 object returned contains the scale for both X and Y axis
  4655. */
  4656. get: function () {
  4657. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualScaleDirty)) {
  4658. var cur = this._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : this.parent;
  4659. var sx = this.scaleX;
  4660. var sy = this.scaleY;
  4661. while (cur) {
  4662. sx *= cur.scaleX;
  4663. sy *= cur.scaleY;
  4664. cur = cur._isFlagSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? null : cur.parent;
  4665. }
  4666. this._actualScale.copyFromFloats(sx, sy);
  4667. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualScaleDirty);
  4668. }
  4669. return this._actualScale;
  4670. },
  4671. enumerable: true,
  4672. configurable: true
  4673. });
  4674. Object.defineProperty(Prim2DBase.prototype, "actualScaleX", {
  4675. /**
  4676. * Get the actual Scale of the X axis, shortcut for this.actualScale.x
  4677. */
  4678. get: function () {
  4679. return this.actualScale.x;
  4680. },
  4681. enumerable: true,
  4682. configurable: true
  4683. });
  4684. Object.defineProperty(Prim2DBase.prototype, "actualScaleY", {
  4685. /**
  4686. * Get the actual Scale of the Y axis, shortcut for this.actualScale.y
  4687. */
  4688. get: function () {
  4689. return this.actualScale.y;
  4690. },
  4691. enumerable: true,
  4692. configurable: true
  4693. });
  4694. Object.defineProperty(Prim2DBase.prototype, "actualOpacity", {
  4695. /**
  4696. * Get the actual opacity level, this property is computed from the opacity property, multiplied by the actualOpacity of its parent (if any)
  4697. */
  4698. get: function () {
  4699. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualOpacityDirty)) {
  4700. var cur = this.parent;
  4701. var op = this.opacity;
  4702. while (cur) {
  4703. op *= cur.opacity;
  4704. cur = cur.parent;
  4705. }
  4706. this._actualOpacity = op;
  4707. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  4708. }
  4709. return this._actualOpacity;
  4710. },
  4711. enumerable: true,
  4712. configurable: true
  4713. });
  4714. Object.defineProperty(Prim2DBase.prototype, "layoutEngine", {
  4715. /**
  4716. * Get/set the layout engine to use for this primitive.
  4717. * The default layout engine is the CanvasLayoutEngine.
  4718. */
  4719. get: function () {
  4720. if (!this._layoutEngine) {
  4721. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  4722. }
  4723. return this._layoutEngine;
  4724. },
  4725. set: function (value) {
  4726. if (this._layoutEngine === value) {
  4727. return;
  4728. }
  4729. this._changeLayoutEngine(value);
  4730. },
  4731. enumerable: true,
  4732. configurable: true
  4733. });
  4734. Object.defineProperty(Prim2DBase.prototype, "layoutArea", {
  4735. /**
  4736. * Get/set the layout are of this primitive.
  4737. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  4738. * The setter should only be called by a Layout Engine class.
  4739. */
  4740. get: function () {
  4741. return this._layoutArea;
  4742. },
  4743. set: function (val) {
  4744. if (this._layoutArea.equals(val)) {
  4745. return;
  4746. }
  4747. this._positioningDirty();
  4748. if (this.parent) {
  4749. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4750. }
  4751. this._layoutArea = val;
  4752. },
  4753. enumerable: true,
  4754. configurable: true
  4755. });
  4756. Object.defineProperty(Prim2DBase.prototype, "layoutAreaPos", {
  4757. /**
  4758. * Get/set the layout area position (relative to the parent primitive).
  4759. * The setter should only be called by a Layout Engine class.
  4760. */
  4761. get: function () {
  4762. return this._layoutAreaPos || Prim2DBase._nullPosition;
  4763. },
  4764. set: function (val) {
  4765. if (this._layoutAreaPos && this._layoutAreaPos.equals(val)) {
  4766. return;
  4767. }
  4768. if (this.parent) {
  4769. this.parent._setFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4770. }
  4771. this._positioningDirty();
  4772. this._layoutAreaPos = val;
  4773. },
  4774. enumerable: true,
  4775. configurable: true
  4776. });
  4777. Object.defineProperty(Prim2DBase.prototype, "isPickable", {
  4778. /**
  4779. * Define if the Primitive can be subject to intersection test or not (default is true)
  4780. */
  4781. get: function () {
  4782. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsPickable);
  4783. },
  4784. set: function (value) {
  4785. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsPickable, value);
  4786. },
  4787. enumerable: true,
  4788. configurable: true
  4789. });
  4790. Object.defineProperty(Prim2DBase.prototype, "isContainer", {
  4791. /**
  4792. * Define if the Primitive acts as a container or not
  4793. * A container will encapsulate its children for interaction event.
  4794. * If it's not a container events will be process down to children if the primitive is not pickable.
  4795. * Default value is true
  4796. */
  4797. get: function () {
  4798. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsContainer);
  4799. },
  4800. set: function (value) {
  4801. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsContainer, value);
  4802. },
  4803. enumerable: true,
  4804. configurable: true
  4805. });
  4806. Object.defineProperty(Prim2DBase.prototype, "hierarchyDepth", {
  4807. /**
  4808. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  4809. */
  4810. get: function () {
  4811. return this._hierarchyDepth;
  4812. },
  4813. enumerable: true,
  4814. configurable: true
  4815. });
  4816. Object.defineProperty(Prim2DBase.prototype, "renderGroup", {
  4817. /**
  4818. * Retrieve the Group that is responsible to render this primitive
  4819. */
  4820. get: function () {
  4821. return this._renderGroup;
  4822. },
  4823. enumerable: true,
  4824. configurable: true
  4825. });
  4826. Object.defineProperty(Prim2DBase.prototype, "globalTransform", {
  4827. /**
  4828. * Get the global transformation matrix of the primitive
  4829. */
  4830. get: function () {
  4831. this._updateLocalTransform();
  4832. return this._globalTransform;
  4833. },
  4834. enumerable: true,
  4835. configurable: true
  4836. });
  4837. /**
  4838. * return the global position of the primitive, relative to its canvas
  4839. */
  4840. Prim2DBase.prototype.getGlobalPosition = function () {
  4841. var v = new BABYLON.Vector2(0, 0);
  4842. this.getGlobalPositionByRef(v);
  4843. return v;
  4844. };
  4845. /**
  4846. * return the global position of the primitive, relative to its canvas
  4847. * @param v the valid Vector2 object where the global position will be stored
  4848. */
  4849. Prim2DBase.prototype.getGlobalPositionByRef = function (v) {
  4850. v.x = this.globalTransform.m[12];
  4851. v.y = this.globalTransform.m[13];
  4852. };
  4853. Object.defineProperty(Prim2DBase.prototype, "invGlobalTransform", {
  4854. /**
  4855. * Get invert of the global transformation matrix of the primitive
  4856. */
  4857. get: function () {
  4858. this._updateLocalTransform();
  4859. return this._invGlobalTransform;
  4860. },
  4861. enumerable: true,
  4862. configurable: true
  4863. });
  4864. Object.defineProperty(Prim2DBase.prototype, "localTransform", {
  4865. /**
  4866. * Get the local transformation of the primitive
  4867. */
  4868. get: function () {
  4869. this._updateLocalTransform();
  4870. return this._localTransform;
  4871. },
  4872. enumerable: true,
  4873. configurable: true
  4874. });
  4875. Object.defineProperty(Prim2DBase.prototype, "boundingInfo", {
  4876. /**
  4877. * Get the boundingInfo associated to the primitive and its children.
  4878. * The value is supposed to be always up to date
  4879. */
  4880. get: function () {
  4881. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  4882. if (this.owner) {
  4883. this.owner.boundingInfoRecomputeCounter.addCount(1, false);
  4884. }
  4885. if (this.isSizedByContent) {
  4886. this._boundingInfo.clear();
  4887. }
  4888. else {
  4889. this._boundingInfo.copyFrom(this.levelBoundingInfo);
  4890. }
  4891. var bi = this._boundingInfo;
  4892. var tps = new BABYLON.BoundingInfo2D();
  4893. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  4894. var curChild = _a[_i];
  4895. var bb = curChild.boundingInfo;
  4896. bb.transformToRef(curChild.localTransform, tps);
  4897. bi.unionToRef(tps, bi);
  4898. }
  4899. this._boundingInfo.maxToRef(Prim2DBase._bMax);
  4900. this._boundingSize.copyFromFloats((!this._size || this._size.width == null) ? Math.ceil(Prim2DBase._bMax.x) : this._size.width, (!this._size || this._size.height == null) ? Math.ceil(Prim2DBase._bMax.y) : this._size.height);
  4901. this._clearFlags(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty);
  4902. }
  4903. return this._boundingInfo;
  4904. },
  4905. enumerable: true,
  4906. configurable: true
  4907. });
  4908. Object.defineProperty(Prim2DBase.prototype, "layoutBoundingInfo", {
  4909. /**
  4910. * Get the boundingInfo of the primitive's content arranged by a layout Engine
  4911. * If a particular child is not arranged by layout, it's boundingInfo is used instead to produce something as accurate as possible
  4912. */
  4913. get: function () {
  4914. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty)) {
  4915. if (!this._layoutBoundingInfo) {
  4916. this._layoutBoundingInfo = new BABYLON.BoundingInfo2D();
  4917. }
  4918. if (this.isSizedByContent) {
  4919. this._layoutBoundingInfo.clear();
  4920. }
  4921. else {
  4922. this._layoutBoundingInfo.copyFrom(this.levelBoundingInfo);
  4923. }
  4924. var bi = this._layoutBoundingInfo;
  4925. var tps = new BABYLON.BoundingInfo2D();
  4926. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  4927. var curChild = _a[_i];
  4928. var bb = void 0;
  4929. if (curChild._layoutAreaPos) {
  4930. var s = curChild._layoutArea;
  4931. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(0, s.width, 0, s.height, Prim2DBase._tpsBB);
  4932. bb = Prim2DBase._tpsBB;
  4933. }
  4934. else {
  4935. bb = curChild.boundingInfo;
  4936. }
  4937. bb.transformToRef(curChild.localTransform, tps);
  4938. bi.unionToRef(tps, bi);
  4939. }
  4940. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutBoundingInfoDirty);
  4941. }
  4942. return this._layoutBoundingInfo;
  4943. },
  4944. enumerable: true,
  4945. configurable: true
  4946. });
  4947. Object.defineProperty(Prim2DBase.prototype, "isSizeAuto", {
  4948. /**
  4949. * Determine if the size is automatically computed or fixed because manually specified.
  4950. * Use the actualSize property to get the final/real size of the primitive
  4951. * @returns true if the size is automatically computed, false if it were manually specified.
  4952. */
  4953. get: function () {
  4954. return this._size == null;
  4955. },
  4956. enumerable: true,
  4957. configurable: true
  4958. });
  4959. Object.defineProperty(Prim2DBase.prototype, "isSizedByContent", {
  4960. /**
  4961. * Return true if this prim has an auto size which is set by the children's global bounding box
  4962. */
  4963. get: function () {
  4964. return (this._size == null) && (this._children.length > 0);
  4965. },
  4966. enumerable: true,
  4967. configurable: true
  4968. });
  4969. Object.defineProperty(Prim2DBase.prototype, "isPositionAuto", {
  4970. /**
  4971. * Determine if the position is automatically computed or fixed because manually specified.
  4972. * Use the actualPosition property to get the final/real position of the primitive
  4973. * @returns true if the position is automatically computed, false if it were manually specified.
  4974. */
  4975. get: function () {
  4976. return this._position == null;
  4977. },
  4978. enumerable: true,
  4979. configurable: true
  4980. });
  4981. Object.defineProperty(Prim2DBase.prototype, "pointerEventObservable", {
  4982. /**
  4983. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  4984. */
  4985. get: function () {
  4986. return this._pointerEventObservable;
  4987. },
  4988. enumerable: true,
  4989. configurable: true
  4990. });
  4991. Object.defineProperty(Prim2DBase.prototype, "zActualOrderChangedObservable", {
  4992. get: function () {
  4993. if (!this._actualZOrderChangedObservable) {
  4994. this._actualZOrderChangedObservable = new BABYLON.Observable();
  4995. }
  4996. return this._actualZOrderChangedObservable;
  4997. },
  4998. enumerable: true,
  4999. configurable: true
  5000. });
  5001. Prim2DBase.prototype.findById = function (id) {
  5002. if (this._id === id) {
  5003. return this;
  5004. }
  5005. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5006. var child = _a[_i];
  5007. var r = child.findById(id);
  5008. if (r != null) {
  5009. return r;
  5010. }
  5011. }
  5012. };
  5013. Prim2DBase.prototype.onZOrderChanged = function () {
  5014. };
  5015. Prim2DBase.prototype.levelIntersect = function (intersectInfo) {
  5016. return false;
  5017. };
  5018. /**
  5019. * Capture all the Events of the given PointerId for this primitive.
  5020. * Don't forget to call releasePointerEventsCapture when done.
  5021. * @param pointerId the Id of the pointer to capture the events from.
  5022. */
  5023. Prim2DBase.prototype.setPointerEventCapture = function (pointerId) {
  5024. return this.owner._setPointerCapture(pointerId, this);
  5025. };
  5026. /**
  5027. * Release a captured pointer made with setPointerEventCapture.
  5028. * @param pointerId the Id of the pointer to release the capture from.
  5029. */
  5030. Prim2DBase.prototype.releasePointerEventsCapture = function (pointerId) {
  5031. return this.owner._releasePointerCapture(pointerId, this);
  5032. };
  5033. /**
  5034. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  5035. * @param intersectInfo contains the settings of the intersection to perform, to setup before calling this method as well as the result, available after a call to this method.
  5036. */
  5037. Prim2DBase.prototype.intersect = function (intersectInfo) {
  5038. if (!intersectInfo) {
  5039. return false;
  5040. }
  5041. // If this is null it means this method is call for the first level, initialize stuffs
  5042. var firstLevel = !intersectInfo._globalPickPosition;
  5043. if (firstLevel) {
  5044. // Compute the pickPosition in global space and use it to find the local position for each level down, always relative from the world to get the maximum accuracy (and speed). The other way would have been to compute in local every level down relative to its parent's local, which wouldn't be as accurate (even if javascript number is 80bits accurate).
  5045. intersectInfo._globalPickPosition = BABYLON.Vector2.Zero();
  5046. BABYLON.Vector2.TransformToRef(intersectInfo.pickPosition, this.globalTransform, intersectInfo._globalPickPosition);
  5047. intersectInfo._localPickPosition = intersectInfo.pickPosition.clone();
  5048. intersectInfo.intersectedPrimitives = new Array();
  5049. intersectInfo.topMostIntersectedPrimitive = null;
  5050. }
  5051. if (!intersectInfo.intersectHidden && !this.isVisible) {
  5052. return false;
  5053. }
  5054. var id = this.id;
  5055. if (id != null && id.indexOf("__cachedSpriteOfGroup__") === 0) {
  5056. var ownerGroup = this.getExternalData("__cachedGroup__");
  5057. return ownerGroup.intersect(intersectInfo);
  5058. }
  5059. // If we're testing a cachedGroup, we must reject pointer outside its levelBoundingInfo because children primitives could be partially clipped outside so we must not accept them as intersected when it's the case (because they're not visually visible).
  5060. var isIntersectionTest = false;
  5061. if (this instanceof BABYLON.Group2D) {
  5062. var g = this;
  5063. isIntersectionTest = g.isCachedGroup;
  5064. }
  5065. if (isIntersectionTest && !this.levelBoundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5066. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5067. intersectInfo._exit(firstLevel);
  5068. return false;
  5069. }
  5070. // Fast rejection test with boundingInfo
  5071. if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  5072. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  5073. intersectInfo._exit(firstLevel);
  5074. return false;
  5075. }
  5076. // We hit the boundingInfo that bounds this primitive and its children, now we have to test on the primitive of this level
  5077. var levelIntersectRes = false;
  5078. if (this.isPickable) {
  5079. levelIntersectRes = this.levelIntersect(intersectInfo);
  5080. if (levelIntersectRes) {
  5081. var pii = new PrimitiveIntersectedInfo(this, intersectInfo._localPickPosition.clone());
  5082. intersectInfo.intersectedPrimitives.push(pii);
  5083. if (!intersectInfo.topMostIntersectedPrimitive || (intersectInfo.topMostIntersectedPrimitive.prim.actualZOffset > pii.prim.actualZOffset)) {
  5084. intersectInfo.topMostIntersectedPrimitive = pii;
  5085. }
  5086. // If we must stop at the first intersection, we're done, quit!
  5087. if (intersectInfo.findFirstOnly) {
  5088. intersectInfo._exit(firstLevel);
  5089. return true;
  5090. }
  5091. }
  5092. }
  5093. // Recurse to children if needed
  5094. if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
  5095. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5096. var curChild = _a[_i];
  5097. // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
  5098. if ((!curChild.isPickable && curChild.isContainer) || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
  5099. continue;
  5100. }
  5101. // Must compute the localPickLocation for the children level
  5102. BABYLON.Vector2.TransformToRef(intersectInfo._globalPickPosition, curChild.invGlobalTransform, intersectInfo._localPickPosition);
  5103. // If we got an intersection with the child and we only need to find the first one, quit!
  5104. if (curChild.intersect(intersectInfo) && intersectInfo.findFirstOnly) {
  5105. intersectInfo._exit(firstLevel);
  5106. return true;
  5107. }
  5108. }
  5109. }
  5110. intersectInfo._exit(firstLevel);
  5111. return intersectInfo.isIntersected;
  5112. };
  5113. /**
  5114. * Move a child object into a new position regarding its siblings to change its rendering order.
  5115. * You can also use the shortcut methods to move top/bottom: moveChildToTop, moveChildToBottom, moveToTop, moveToBottom.
  5116. * @param child the object to move
  5117. * @param previous the object which will be before "child", if child has to be the first among sibling, set "previous" to null.
  5118. */
  5119. Prim2DBase.prototype.moveChild = function (child, previous) {
  5120. if (child.parent !== this) {
  5121. return false;
  5122. }
  5123. var childIndex = this._children.indexOf(child);
  5124. var prevIndex = previous ? this._children.indexOf(previous) : -1;
  5125. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5126. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5127. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, prevIndex + 1);
  5128. }
  5129. this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
  5130. return true;
  5131. };
  5132. /**
  5133. * Move the given child so it's displayed on the top of all its siblings
  5134. * @param child the primitive to move to the top
  5135. */
  5136. Prim2DBase.prototype.moveChildToTop = function (child) {
  5137. return this.moveChild(child, this._children[this._children.length - 1]);
  5138. };
  5139. /**
  5140. * Move the given child so it's displayed on the bottom of all its siblings
  5141. * @param child the primitive to move to the top
  5142. */
  5143. Prim2DBase.prototype.moveChildToBottom = function (child) {
  5144. return this.moveChild(child, null);
  5145. };
  5146. /**
  5147. * Move this primitive to be at the top among all its sibling
  5148. */
  5149. Prim2DBase.prototype.moveToTop = function () {
  5150. if (this.parent == null) {
  5151. return false;
  5152. }
  5153. return this.parent.moveChildToTop(this);
  5154. };
  5155. /**
  5156. * Move this primitive to be at the bottom among all its sibling
  5157. */
  5158. Prim2DBase.prototype.moveToBottom = function () {
  5159. if (this.parent == null) {
  5160. return false;
  5161. }
  5162. return this.parent.moveChildToBottom(this);
  5163. };
  5164. Prim2DBase.prototype.addChild = function (child) {
  5165. child._parent = this;
  5166. this._boundingBoxDirty();
  5167. var flat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5168. if (flat) {
  5169. child._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5170. child._setZOrder(this._zOrder, true);
  5171. child._zMax = this._zOrder;
  5172. }
  5173. else {
  5174. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5175. }
  5176. var length = this._children.push(child);
  5177. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, length - 1);
  5178. };
  5179. /**
  5180. * Dispose the primitive, remove it from its parent.
  5181. */
  5182. Prim2DBase.prototype.dispose = function () {
  5183. if (!_super.prototype.dispose.call(this)) {
  5184. return false;
  5185. }
  5186. if (this._actionManager) {
  5187. this._actionManager.dispose();
  5188. this._actionManager = null;
  5189. }
  5190. // If there's a parent, remove this object from its parent list
  5191. if (this._parent) {
  5192. if (this instanceof BABYLON.Group2D) {
  5193. var g = this;
  5194. if (g.isRenderableGroup) {
  5195. var parentRenderable = this.parent.traverseUp(function (p) { return (p instanceof BABYLON.Group2D && p.isRenderableGroup); });
  5196. if (parentRenderable != null) {
  5197. var l = parentRenderable._renderableData._childrenRenderableGroups;
  5198. var i_1 = l.indexOf(g);
  5199. if (i_1 !== -1) {
  5200. l.splice(i_1, 1);
  5201. }
  5202. }
  5203. }
  5204. }
  5205. var i = this._parent._children.indexOf(this);
  5206. if (i !== undefined) {
  5207. this._parent._children.splice(i, 1);
  5208. }
  5209. this._parent = null;
  5210. }
  5211. // Recurse dispose to children
  5212. if (this._children) {
  5213. while (this._children.length > 0) {
  5214. this._children[this._children.length - 1].dispose();
  5215. }
  5216. }
  5217. return true;
  5218. };
  5219. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  5220. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  5221. this._renderGroup._addPrimToDirtyList(this);
  5222. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  5223. }
  5224. };
  5225. Prim2DBase.prototype._needPrepare = function () {
  5226. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty | BABYLON.SmartPropertyPrim.flagNeedRefresh) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  5227. };
  5228. Prim2DBase.prototype._prepareRender = function (context) {
  5229. this._prepareRenderPre(context);
  5230. this._prepareRenderPost(context);
  5231. };
  5232. Prim2DBase.prototype._prepareRenderPre = function (context) {
  5233. };
  5234. Prim2DBase.prototype._prepareRenderPost = function (context) {
  5235. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  5236. if (this instanceof BABYLON.Group2D) {
  5237. var self = this;
  5238. if (self.isRenderableGroup) {
  5239. return;
  5240. }
  5241. }
  5242. // Check if we need to recurse the prepare to children primitives
  5243. // - must have children
  5244. // - the global transform of this level have changed, or
  5245. // - the visible state of primitive has changed
  5246. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  5247. this.checkPropertiesDirty(Prim2DBase.isVisibleProperty.flagId))) {
  5248. this._children.forEach(function (c) {
  5249. // As usual stop the recursion if we meet a renderable group
  5250. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  5251. c._prepareRender(context);
  5252. }
  5253. });
  5254. }
  5255. // Finally reset the dirty flags as we've processed everything
  5256. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  5257. this._instanceDirtyFlags = 0;
  5258. };
  5259. Prim2DBase.prototype._canvasPreInit = function (settings) {
  5260. };
  5261. Prim2DBase.CheckParent = function (parent) {
  5262. //if (!Prim2DBase._isCanvasInit && !parent) {
  5263. // throw new Error("A Primitive needs a valid Parent, it can be any kind of Primitives based types, even the Canvas (with the exception that only Group2D can be direct child of a Canvas if the cache strategy used is TOPLEVELGROUPS)");
  5264. //}
  5265. };
  5266. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  5267. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  5268. var cur = list_1[_i];
  5269. cur.updateCachedStates(recurse);
  5270. }
  5271. };
  5272. Prim2DBase.prototype._parentLayoutDirty = function () {
  5273. if (!this._parent || this._parent.isDisposed) {
  5274. return;
  5275. }
  5276. this._parent._setLayoutDirty();
  5277. };
  5278. Prim2DBase.prototype._setLayoutDirty = function () {
  5279. this.onPrimBecomesDirty();
  5280. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5281. };
  5282. Prim2DBase.prototype._checkPositionChange = function () {
  5283. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  5284. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  5285. return false;
  5286. }
  5287. return true;
  5288. };
  5289. Prim2DBase.prototype._positioningDirty = function () {
  5290. this.onPrimBecomesDirty();
  5291. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5292. };
  5293. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  5294. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5295. var child = _a[_i];
  5296. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  5297. child._updateRenderMode();
  5298. child.onPrimBecomesDirty();
  5299. child._spreadActualOpacityChanged();
  5300. }
  5301. };
  5302. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  5303. this._layoutEngine = engine;
  5304. };
  5305. Prim2DBase.prototype._updateLocalTransform = function () {
  5306. var tflags = Prim2DBase.actualPositionProperty.flagId | Prim2DBase.rotationProperty.flagId | Prim2DBase.scaleProperty.flagId | Prim2DBase.scaleXProperty.flagId | Prim2DBase.scaleYProperty.flagId | Prim2DBase.originProperty.flagId;
  5307. if (this.checkPropertiesDirty(tflags)) {
  5308. if (this.owner) {
  5309. this.owner.addupdateLocalTransformCounter(1);
  5310. }
  5311. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  5312. var local;
  5313. var pos = this._position ? this.position : this.layoutAreaPos;
  5314. if (this._origin.x === 0 && this._origin.y === 0) {
  5315. local = BABYLON.Matrix.Compose(new BABYLON.Vector3(this._scale.x, this._scale.y, 1), rot, new BABYLON.Vector3(pos.x + this._marginOffset.x, pos.y + this._marginOffset.y, 0));
  5316. this._localTransform = local;
  5317. }
  5318. else {
  5319. // -Origin offset
  5320. var as = this.actualSize;
  5321. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase._t0);
  5322. // -Origin * rotation
  5323. rot.toRotationMatrix(Prim2DBase._t1);
  5324. Prim2DBase._t0.multiplyToRef(Prim2DBase._t1, Prim2DBase._t2);
  5325. // -Origin * rotation * scale
  5326. BABYLON.Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase._t0);
  5327. Prim2DBase._t2.multiplyToRef(Prim2DBase._t0, Prim2DBase._t1);
  5328. // -Origin * rotation * scale * (Origin + Position)
  5329. BABYLON.Matrix.TranslationToRef((as.width * this._origin.x) + pos.x + this._marginOffset.x, (as.height * this._origin.y) + pos.y + this._marginOffset.y, 0, Prim2DBase._t2);
  5330. Prim2DBase._t1.multiplyToRef(Prim2DBase._t2, this._localTransform);
  5331. }
  5332. this.clearPropertiesDirty(tflags);
  5333. this._setFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5334. return true;
  5335. }
  5336. return false;
  5337. };
  5338. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  5339. if (this.isDisposed) {
  5340. return;
  5341. }
  5342. this.owner.addCachedGroupRenderCounter(1);
  5343. // Check if the parent is synced
  5344. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  5345. this._parent.updateCachedStates(false);
  5346. }
  5347. // Update Z-Order if needed
  5348. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5349. this._updateZOrder();
  5350. }
  5351. // Update actualSize only if there' not positioning to recompute and the size changed
  5352. // Otherwise positioning will take care of it.
  5353. var sizeDirty = this.checkPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5354. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  5355. var size = this.size;
  5356. if (size) {
  5357. if (this.size.width != null) {
  5358. this.actualSize.width = this.size.width;
  5359. }
  5360. if (this.size.height != null) {
  5361. this.actualSize.height = this.size.height;
  5362. }
  5363. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5364. }
  5365. }
  5366. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5367. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5368. // Check for layout update
  5369. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  5370. this.owner.addUpdateLayoutCounter(1);
  5371. this._layoutEngine.updateLayout(this);
  5372. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  5373. }
  5374. var autoContentChanged = false;
  5375. if (this.isSizeAuto) {
  5376. if (!this._lastAutoSizeArea) {
  5377. autoContentChanged = this.actualSize !== null;
  5378. }
  5379. else {
  5380. autoContentChanged = (!this._lastAutoSizeArea.equals(this.actualSize));
  5381. }
  5382. }
  5383. // Check for positioning update
  5384. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  5385. this._updatePositioning();
  5386. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5387. if (sizeDirty) {
  5388. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  5389. }
  5390. positioningComputed = true;
  5391. }
  5392. if (positioningComputed && this._parent) {
  5393. this._parentContentArea.copyFrom(this._parent.contentArea);
  5394. }
  5395. // Check if we must update this prim
  5396. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  5397. this.owner.addUpdateGlobalTransformCounter(1);
  5398. var curVisibleState = this.isVisible;
  5399. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  5400. // Detect a change of visibility
  5401. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  5402. // Get/compute the localTransform
  5403. var localDirty = this._updateLocalTransform();
  5404. var parentPaddingChanged = false;
  5405. var parentPaddingOffset = Prim2DBase._v0;
  5406. if (this._parent) {
  5407. parentPaddingOffset = this._parent._paddingOffset;
  5408. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  5409. }
  5410. // Check if there are changes in the parent that will force us to update the global matrix
  5411. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  5412. // Check if we have to update the globalTransform
  5413. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged || this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty)) {
  5414. var globalTransform = this._parent ? this._parent._globalTransform : null;
  5415. var localTransform = void 0;
  5416. Prim2DBase._transMtx.copyFrom(this._localTransform);
  5417. Prim2DBase._transMtx.m[12] += parentPaddingOffset.x;
  5418. Prim2DBase._transMtx.m[13] += parentPaddingOffset.y;
  5419. localTransform = Prim2DBase._transMtx;
  5420. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  5421. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  5422. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  5423. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  5424. this._clearFlags(BABYLON.SmartPropertyPrim.flagGlobalTransformDirty);
  5425. }
  5426. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  5427. }
  5428. if (recurse) {
  5429. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5430. var child = _a[_i];
  5431. // Stop the recursion if we meet a renderable group
  5432. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  5433. }
  5434. }
  5435. };
  5436. Prim2DBase.prototype._updatePositioning = function () {
  5437. if (this.owner) {
  5438. this.owner.addUpdatePositioningCounter(1);
  5439. }
  5440. // From this point we assume that the primitive layoutArea is computed and up to date.
  5441. // We know have to :
  5442. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  5443. // 2. Determine the contentArea based on the padding property.
  5444. var isSizeAuto = this.isSizeAuto;
  5445. // Auto Create PaddingArea if there's no actualSize on width&|height to allocate the whole content available to the paddingArea where the actualSize is null
  5446. if (!this._hasMarginAlignment && (isSizeAuto || (this.actualSize.width == null || this.actualSize.height == null))) {
  5447. if (isSizeAuto || this.actualSize.width == null) {
  5448. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  5449. }
  5450. if (isSizeAuto || this.actualSize.height == null) {
  5451. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  5452. }
  5453. }
  5454. // Apply margin
  5455. if (this._hasMargin) {
  5456. this.margin.computeWithAlignment(this.layoutArea, this.size || this.actualSize, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  5457. this.actualSize = Prim2DBase._size.clone();
  5458. }
  5459. if (this._hasPadding) {
  5460. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so me resize the primitive itself
  5461. if (isSizeAuto) {
  5462. var content = this.size.clone();
  5463. this._getActualSizeFromContentToRef(content, Prim2DBase._icArea);
  5464. this.padding.enlarge(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  5465. this._contentArea.copyFrom(content);
  5466. this.actualSize = Prim2DBase._size.clone();
  5467. // Changing the padding has resize the prim, which forces us to recompute margin again
  5468. if (this._hasMargin) {
  5469. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase._size, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  5470. }
  5471. }
  5472. else {
  5473. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icPos, Prim2DBase._icArea);
  5474. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  5475. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  5476. this.padding.compute(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  5477. this._paddingOffset.x += Prim2DBase._icPos.x;
  5478. this._paddingOffset.y += Prim2DBase._icPos.y;
  5479. this._contentArea.copyFrom(Prim2DBase._size);
  5480. }
  5481. }
  5482. else {
  5483. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icPos, Prim2DBase._icArea);
  5484. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  5485. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  5486. this._paddingOffset.copyFrom(Prim2DBase._icPos);
  5487. this._contentArea.copyFrom(Prim2DBase._icArea);
  5488. }
  5489. if (!this._position) {
  5490. var aPos = new BABYLON.Vector2(this.layoutAreaPos.x + this._marginOffset.x, this.layoutAreaPos.y + this._marginOffset.y);
  5491. this.actualPosition = aPos;
  5492. }
  5493. if (isSizeAuto) {
  5494. this._lastAutoSizeArea = this.actualSize;
  5495. }
  5496. };
  5497. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  5498. /**
  5499. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  5500. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  5501. */
  5502. get: function () {
  5503. // Check for positioning update
  5504. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  5505. this._updatePositioning();
  5506. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  5507. }
  5508. return this._contentArea;
  5509. },
  5510. enumerable: true,
  5511. configurable: true
  5512. });
  5513. Prim2DBase.prototype._patchHierarchy = function (owner) {
  5514. this._owner = owner;
  5515. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  5516. if (this._renderGroup != null) {
  5517. return;
  5518. }
  5519. if (this instanceof BABYLON.Group2D) {
  5520. var group = this;
  5521. group.detectGroupStates();
  5522. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  5523. group.owner._registerTrackedNode(this);
  5524. }
  5525. }
  5526. this._renderGroup = this.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  5527. if (this._parent) {
  5528. this._parentLayoutDirty();
  5529. }
  5530. // Make sure the prim is in the dirtyList if it should be
  5531. if (this._renderGroup && this.isDirty) {
  5532. var list = this._renderGroup._renderableData._primDirtyList;
  5533. var i = list.indexOf(this);
  5534. if (i === -1) {
  5535. list.push(this);
  5536. }
  5537. }
  5538. // Recurse
  5539. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5540. var child = _a[_i];
  5541. child._hierarchyDepth = this._hierarchyDepth + 1;
  5542. child._patchHierarchy(owner);
  5543. }
  5544. };
  5545. Prim2DBase.prototype._updateZOrder = function () {
  5546. var prevLinPos = this._primLinearPosition;
  5547. var startI = 0;
  5548. var startZ = this._zOrder;
  5549. // We must start rebuilding Z-Order from the Prim before the first one that changed, because we know its Z-Order is correct, so are its children, but it's better to recompute everything from this point instead of finding the last valid children
  5550. var childrenCount = this._children.length;
  5551. if (this._firstZDirtyIndex > 0) {
  5552. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  5553. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  5554. prevLinPos = prevPrim._primLinearPosition;
  5555. startI = this._firstZDirtyIndex - 1;
  5556. startZ = prevPrim._zOrder;
  5557. }
  5558. }
  5559. var startPos = prevLinPos;
  5560. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  5561. Prim2DBase._totalCount = 0;
  5562. for (var i = startI; i < childrenCount; i++) {
  5563. var child = this._children[i];
  5564. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5565. }
  5566. // Compute the new Z-Order for all the primitives
  5567. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  5568. var zDelta = (this._zMax - startZ) / (Prim2DBase._totalCount * (Prim2DBase._zRebuildReentrency ? 1 : 1.2));
  5569. // If the computed delta is less than the smallest allowed by the depth buffer, we rebuild the Z-Order from the very beginning of the primitive's children (that is, the first) to redistribute uniformly the Z.
  5570. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  5571. // Check for re-entrance, if the flag is true we already attempted a rebuild but couldn't get a better zDelta, go up in the hierarchy to rebuilt one level up, hoping to get this time a decent delta, otherwise, recurse until we got it or when no parent is reached, which would mean the canvas would have more than 16 millions of primitives...
  5572. if (Prim2DBase._zRebuildReentrency) {
  5573. var p = this._parent;
  5574. if (p == null) {
  5575. // Can't find a good Z delta and we're in the canvas, which mean we're dealing with too many objects (which should never happen, but well...)
  5576. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  5577. Prim2DBase._zRebuildReentrency = false;
  5578. return;
  5579. }
  5580. p._firstZDirtyIndex = 0;
  5581. return p._updateZOrder();
  5582. }
  5583. Prim2DBase._zRebuildReentrency = true;
  5584. this._firstZDirtyIndex = 0;
  5585. this._updateZOrder();
  5586. Prim2DBase._zRebuildReentrency = false;
  5587. }
  5588. for (var i = startI; i < childrenCount; i++) {
  5589. var child = this._children[i];
  5590. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  5591. }
  5592. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  5593. for (var _i = 0, _a = Prim2DBase._zOrderChangedNotifList; _i < _a.length; _i++) {
  5594. var p = _a[_i];
  5595. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  5596. }
  5597. Prim2DBase._zOrderChangedNotifList.splice(0);
  5598. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5599. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5600. };
  5601. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  5602. if (this.isManualZOrder) {
  5603. return prevLinPos;
  5604. }
  5605. this._primLinearPosition = ++prevLinPos;
  5606. Prim2DBase._totalCount++;
  5607. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5608. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  5609. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5610. var child = _a[_i];
  5611. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  5612. }
  5613. }
  5614. return prevLinPos;
  5615. };
  5616. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  5617. if (this.isManualZOrder) {
  5618. return null;
  5619. }
  5620. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  5621. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  5622. this._setZOrder(newZ, false);
  5623. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5624. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5625. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5626. }
  5627. var curZ = newZ;
  5628. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  5629. if (isFlat) {
  5630. if (this._children.length > 0) {
  5631. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  5632. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5633. var child = _a[_i];
  5634. child._updatePrimitiveFlatZOrder(this._zOrder);
  5635. }
  5636. }
  5637. }
  5638. else {
  5639. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  5640. var child = _c[_b];
  5641. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  5642. if (r != null) {
  5643. curZ = r;
  5644. }
  5645. }
  5646. }
  5647. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  5648. return curZ;
  5649. };
  5650. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  5651. if (this.isManualZOrder) {
  5652. return;
  5653. }
  5654. this._setZOrder(newZ, false);
  5655. this._zMax = newZ;
  5656. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  5657. this._firstZDirtyIndex = Prim2DBase._bigInt;
  5658. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  5659. }
  5660. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  5661. var child = _a[_i];
  5662. child._updatePrimitiveFlatZOrder(newZ);
  5663. }
  5664. };
  5665. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  5666. if (newZ !== this._zOrder) {
  5667. this._zOrder = newZ;
  5668. this.onPrimBecomesDirty();
  5669. this.onZOrderChanged();
  5670. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  5671. if (directEmit) {
  5672. this._actualZOrderChangedObservable.notifyObservers(newZ);
  5673. }
  5674. else {
  5675. Prim2DBase._zOrderChangedNotifList.push(this);
  5676. }
  5677. }
  5678. }
  5679. };
  5680. Prim2DBase.prototype._updateRenderMode = function () {
  5681. };
  5682. /**
  5683. * This method is used to alter the contentArea of the Primitive before margin is applied.
  5684. * In most of the case you won't need to override this method, but it can prove some usefulness, check the Rectangle2D class for a concrete application.
  5685. * @param primSize the current size of the primitive
  5686. * @param initialContentPosition the position of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  5687. * @param initialContentArea the size of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  5688. */
  5689. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  5690. initialContentArea.copyFrom(primSize);
  5691. initialContentPosition.x = initialContentPosition.y = 0;
  5692. };
  5693. /**
  5694. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  5695. * Check the Rectangle2D implementation for a concrete application.
  5696. * @param primSize the current size of the primitive
  5697. * @param newPrimSize the new size of the primitive. PLEASE ROUND THE values, we're talking about pixels and fraction of them are not our friends!
  5698. */
  5699. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  5700. newPrimSize.copyFrom(primSize);
  5701. };
  5702. Prim2DBase.PRIM2DBASE_PROPCOUNT = 24;
  5703. Prim2DBase._bigInt = Math.pow(2, 30);
  5704. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  5705. Prim2DBase.boundinbBoxReentrency = false;
  5706. Prim2DBase.nullSize = BABYLON.Size.Zero();
  5707. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  5708. Prim2DBase._tpsBB = new BABYLON.BoundingInfo2D();
  5709. Prim2DBase._isCanvasInit = false;
  5710. Prim2DBase._t0 = new BABYLON.Matrix();
  5711. Prim2DBase._t1 = new BABYLON.Matrix();
  5712. Prim2DBase._t2 = new BABYLON.Matrix();
  5713. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  5714. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  5715. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  5716. Prim2DBase._icArea = BABYLON.Size.Zero();
  5717. Prim2DBase._size = BABYLON.Size.Zero();
  5718. Prim2DBase._zOrderChangedNotifList = new Array();
  5719. Prim2DBase._zRebuildReentrency = false;
  5720. Prim2DBase._totalCount = 0;
  5721. __decorate([
  5722. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase.actualPositionProperty = pi; }, false, false, true)
  5723. ], Prim2DBase.prototype, "actualPosition", null);
  5724. __decorate([
  5725. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 1, function (pi) { return Prim2DBase.actualXProperty = pi; }, false, false, true)
  5726. ], Prim2DBase.prototype, "actualX", null);
  5727. __decorate([
  5728. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 2, function (pi) { return Prim2DBase.actualYProperty = pi; }, false, false, true)
  5729. ], Prim2DBase.prototype, "actualY", null);
  5730. __decorate([
  5731. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 3, function (pi) { return Prim2DBase.positionProperty = pi; }, false, false, true)
  5732. ], Prim2DBase.prototype, "position", null);
  5733. __decorate([
  5734. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 4, function (pi) { return Prim2DBase.xProperty = pi; }, false, false, true)
  5735. ], Prim2DBase.prototype, "x", null);
  5736. __decorate([
  5737. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 5, function (pi) { return Prim2DBase.yProperty = pi; }, false, false, true)
  5738. ], Prim2DBase.prototype, "y", null);
  5739. __decorate([
  5740. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 6, function (pi) { return Prim2DBase.sizeProperty = pi; }, false, true)
  5741. ], Prim2DBase.prototype, "size", null);
  5742. __decorate([
  5743. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 7, function (pi) { return Prim2DBase.widthProperty = pi; }, false, true)
  5744. ], Prim2DBase.prototype, "width", null);
  5745. __decorate([
  5746. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 8, function (pi) { return Prim2DBase.heightProperty = pi; }, false, true)
  5747. ], Prim2DBase.prototype, "height", null);
  5748. __decorate([
  5749. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 9, function (pi) { return Prim2DBase.rotationProperty = pi; }, false, true)
  5750. ], Prim2DBase.prototype, "rotation", null);
  5751. __decorate([
  5752. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 10, function (pi) { return Prim2DBase.scaleProperty = pi; }, false, true)
  5753. ], Prim2DBase.prototype, "scale", null);
  5754. __decorate([
  5755. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 11, function (pi) { return Prim2DBase.actualSizeProperty = pi; }, false, true)
  5756. ], Prim2DBase.prototype, "actualSize", null);
  5757. __decorate([
  5758. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 12, function (pi) { return Prim2DBase.actualWidthProperty = pi; }, false, true)
  5759. ], Prim2DBase.prototype, "actualWidth", null);
  5760. __decorate([
  5761. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 13, function (pi) { return Prim2DBase.actualHeightProperty = pi; }, false, true)
  5762. ], Prim2DBase.prototype, "actualHeight", null);
  5763. __decorate([
  5764. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 14, function (pi) { return Prim2DBase.originProperty = pi; }, false, true)
  5765. ], Prim2DBase.prototype, "origin", null);
  5766. __decorate([
  5767. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 15, function (pi) { return Prim2DBase.levelVisibleProperty = pi; })
  5768. ], Prim2DBase.prototype, "levelVisible", null);
  5769. __decorate([
  5770. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 16, function (pi) { return Prim2DBase.isVisibleProperty = pi; })
  5771. ], Prim2DBase.prototype, "isVisible", null);
  5772. __decorate([
  5773. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 17, function (pi) { return Prim2DBase.zOrderProperty = pi; })
  5774. ], Prim2DBase.prototype, "zOrder", null);
  5775. __decorate([
  5776. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 18, function (pi) { return Prim2DBase.marginProperty = pi; })
  5777. ], Prim2DBase.prototype, "margin", null);
  5778. __decorate([
  5779. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 19, function (pi) { return Prim2DBase.paddingProperty = pi; })
  5780. ], Prim2DBase.prototype, "padding", null);
  5781. __decorate([
  5782. BABYLON.dynamicLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 20, function (pi) { return Prim2DBase.marginAlignmentProperty = pi; })
  5783. ], Prim2DBase.prototype, "marginAlignment", null);
  5784. __decorate([
  5785. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 21, function (pi) { return Prim2DBase.opacityProperty = pi; })
  5786. ], Prim2DBase.prototype, "opacity", null);
  5787. __decorate([
  5788. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 22, function (pi) { return Prim2DBase.scaleXProperty = pi; }, false, true)
  5789. ], Prim2DBase.prototype, "scaleX", null);
  5790. __decorate([
  5791. BABYLON.instanceLevelProperty(BABYLON.SmartPropertyPrim.SMARTPROPERTYPRIM_PROPCOUNT + 23, function (pi) { return Prim2DBase.scaleYProperty = pi; }, false, true)
  5792. ], Prim2DBase.prototype, "scaleY", null);
  5793. Prim2DBase = __decorate([
  5794. BABYLON.className("Prim2DBase", "BABYLON")
  5795. ], Prim2DBase);
  5796. return Prim2DBase;
  5797. }(BABYLON.SmartPropertyPrim));
  5798. BABYLON.Prim2DBase = Prim2DBase;
  5799. })(BABYLON || (BABYLON = {}));
  5800. var BABYLON;
  5801. (function (BABYLON) {
  5802. var GroupInstanceInfo = (function () {
  5803. function GroupInstanceInfo(owner, mrc, partCount) {
  5804. this._partCount = partCount;
  5805. this.owner = owner;
  5806. this.modelRenderCache = mrc;
  5807. this.modelRenderCache.addRef();
  5808. this.partIndexFromId = new BABYLON.StringDictionary();
  5809. this._usedShaderCategories = new Array(partCount);
  5810. this._strides = new Array(partCount);
  5811. this._opaqueData = null;
  5812. this._alphaTestData = null;
  5813. this._transparentData = null;
  5814. this.opaqueDirty = this.alphaTestDirty = this.transparentDirty = this.transparentOrderDirty = false;
  5815. }
  5816. GroupInstanceInfo.prototype.dispose = function () {
  5817. if (this._isDisposed) {
  5818. return false;
  5819. }
  5820. if (this.modelRenderCache) {
  5821. this.modelRenderCache.dispose();
  5822. this.modelRenderCache = null;
  5823. }
  5824. var engine = this.owner.owner.engine;
  5825. if (this._opaqueData) {
  5826. this._opaqueData.forEach(function (d) { return d.dispose(engine); });
  5827. this._opaqueData = null;
  5828. }
  5829. if (this._alphaTestData) {
  5830. this._alphaTestData.forEach(function (d) { return d.dispose(engine); });
  5831. this._alphaTestData = null;
  5832. }
  5833. if (this._transparentData) {
  5834. this._transparentData.forEach(function (d) { return d.dispose(engine); });
  5835. this._transparentData = null;
  5836. }
  5837. this.partIndexFromId = null;
  5838. this._isDisposed = true;
  5839. return true;
  5840. };
  5841. Object.defineProperty(GroupInstanceInfo.prototype, "hasOpaqueData", {
  5842. get: function () {
  5843. return this._opaqueData != null;
  5844. },
  5845. enumerable: true,
  5846. configurable: true
  5847. });
  5848. Object.defineProperty(GroupInstanceInfo.prototype, "hasAlphaTestData", {
  5849. get: function () {
  5850. return this._alphaTestData != null;
  5851. },
  5852. enumerable: true,
  5853. configurable: true
  5854. });
  5855. Object.defineProperty(GroupInstanceInfo.prototype, "hasTransparentData", {
  5856. get: function () {
  5857. return this._transparentData != null;
  5858. },
  5859. enumerable: true,
  5860. configurable: true
  5861. });
  5862. Object.defineProperty(GroupInstanceInfo.prototype, "opaqueData", {
  5863. get: function () {
  5864. if (!this._opaqueData) {
  5865. this._opaqueData = new Array(this._partCount);
  5866. for (var i = 0; i < this._partCount; i++) {
  5867. this._opaqueData[i] = new GroupInfoPartData(this._strides[i]);
  5868. }
  5869. }
  5870. return this._opaqueData;
  5871. },
  5872. enumerable: true,
  5873. configurable: true
  5874. });
  5875. Object.defineProperty(GroupInstanceInfo.prototype, "alphaTestData", {
  5876. get: function () {
  5877. if (!this._alphaTestData) {
  5878. this._alphaTestData = new Array(this._partCount);
  5879. for (var i = 0; i < this._partCount; i++) {
  5880. this._alphaTestData[i] = new GroupInfoPartData(this._strides[i]);
  5881. }
  5882. }
  5883. return this._alphaTestData;
  5884. },
  5885. enumerable: true,
  5886. configurable: true
  5887. });
  5888. Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", {
  5889. get: function () {
  5890. if (!this._transparentData) {
  5891. this._transparentData = new Array(this._partCount);
  5892. for (var i = 0; i < this._partCount; i++) {
  5893. var zoff = this.modelRenderCache._partData[i]._zBiasOffset;
  5894. this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff);
  5895. }
  5896. }
  5897. return this._transparentData;
  5898. },
  5899. enumerable: true,
  5900. configurable: true
  5901. });
  5902. GroupInstanceInfo.prototype.sortTransparentData = function () {
  5903. if (!this.transparentOrderDirty) {
  5904. return;
  5905. }
  5906. for (var i = 0; i < this._transparentData.length; i++) {
  5907. var td = this._transparentData[i];
  5908. td._partData.sort();
  5909. }
  5910. this.transparentOrderDirty = false;
  5911. };
  5912. Object.defineProperty(GroupInstanceInfo.prototype, "usedShaderCategories", {
  5913. get: function () {
  5914. return this._usedShaderCategories;
  5915. },
  5916. enumerable: true,
  5917. configurable: true
  5918. });
  5919. Object.defineProperty(GroupInstanceInfo.prototype, "strides", {
  5920. get: function () {
  5921. return this._strides;
  5922. },
  5923. enumerable: true,
  5924. configurable: true
  5925. });
  5926. return GroupInstanceInfo;
  5927. }());
  5928. BABYLON.GroupInstanceInfo = GroupInstanceInfo;
  5929. var TransparentSegment = (function () {
  5930. function TransparentSegment() {
  5931. this.groupInsanceInfo = null;
  5932. this.startZ = 0;
  5933. this.endZ = 0;
  5934. this.startDataIndex = BABYLON.Prim2DBase._bigInt;
  5935. this.endDataIndex = 0;
  5936. this.partBuffers = null;
  5937. }
  5938. TransparentSegment.prototype.dispose = function (engine) {
  5939. if (this.partBuffers) {
  5940. this.partBuffers.forEach(function (b) { return engine._releaseBuffer(b); });
  5941. this.partBuffers.splice(0);
  5942. this.partBuffers = null;
  5943. }
  5944. };
  5945. return TransparentSegment;
  5946. }());
  5947. BABYLON.TransparentSegment = TransparentSegment;
  5948. var GroupInfoPartData = (function () {
  5949. function GroupInfoPartData(stride) {
  5950. this._partData = null;
  5951. this._partBuffer = null;
  5952. this._partBufferSize = 0;
  5953. this._partData = new BABYLON.DynamicFloatArray(stride / 4, 50);
  5954. this._isDisposed = false;
  5955. }
  5956. GroupInfoPartData.prototype.dispose = function (engine) {
  5957. if (this._isDisposed) {
  5958. return false;
  5959. }
  5960. if (this._partBuffer) {
  5961. engine._releaseBuffer(this._partBuffer);
  5962. this._partBuffer = null;
  5963. }
  5964. this._partData = null;
  5965. this._isDisposed = true;
  5966. };
  5967. return GroupInfoPartData;
  5968. }());
  5969. BABYLON.GroupInfoPartData = GroupInfoPartData;
  5970. var TransparentGroupInfoPartData = (function (_super) {
  5971. __extends(TransparentGroupInfoPartData, _super);
  5972. function TransparentGroupInfoPartData(stride, zoff) {
  5973. _super.call(this, stride);
  5974. this._partData.compareValueOffset = zoff;
  5975. this._partData.sortingAscending = false;
  5976. }
  5977. return TransparentGroupInfoPartData;
  5978. }(GroupInfoPartData));
  5979. BABYLON.TransparentGroupInfoPartData = TransparentGroupInfoPartData;
  5980. var ModelRenderCache = (function () {
  5981. function ModelRenderCache(engine, modelKey) {
  5982. this._engine = engine;
  5983. this._modelKey = modelKey;
  5984. this._nextKey = 1;
  5985. this._refCounter = 1;
  5986. this._partData = null;
  5987. }
  5988. ModelRenderCache.prototype.dispose = function () {
  5989. if (--this._refCounter !== 0) {
  5990. return false;
  5991. }
  5992. // Remove the Model Render Cache from the global dictionary
  5993. var edata = this._engine.getExternalData("__BJSCANVAS2D__");
  5994. if (edata) {
  5995. edata.DisposeModelRenderCache(this);
  5996. }
  5997. return true;
  5998. };
  5999. Object.defineProperty(ModelRenderCache.prototype, "isDisposed", {
  6000. get: function () {
  6001. return this._refCounter <= 0;
  6002. },
  6003. enumerable: true,
  6004. configurable: true
  6005. });
  6006. ModelRenderCache.prototype.addRef = function () {
  6007. return ++this._refCounter;
  6008. };
  6009. Object.defineProperty(ModelRenderCache.prototype, "modelKey", {
  6010. get: function () {
  6011. return this._modelKey;
  6012. },
  6013. enumerable: true,
  6014. configurable: true
  6015. });
  6016. /**
  6017. * Render the model instances
  6018. * @param instanceInfo
  6019. * @param context
  6020. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  6021. */
  6022. ModelRenderCache.prototype.render = function (instanceInfo, context) {
  6023. return true;
  6024. };
  6025. ModelRenderCache.prototype.getPartIndexFromId = function (partId) {
  6026. for (var i = 0; i < this._partData.length; i++) {
  6027. if (this._partData[i]._partId === partId) {
  6028. return i;
  6029. }
  6030. }
  6031. return null;
  6032. };
  6033. ModelRenderCache.prototype.loadInstancingAttributes = function (partId, effect) {
  6034. var i = this.getPartIndexFromId(partId);
  6035. if (i === null) {
  6036. return null;
  6037. }
  6038. var ci = this._partsClassInfo[i];
  6039. var categories = this._partData[i]._partUsedCategories;
  6040. var res = ci.classContent.getInstancingAttributeInfos(effect, categories);
  6041. return res;
  6042. };
  6043. ModelRenderCache.prototype.setupUniforms = function (effect, partIndex, data, elementCount) {
  6044. var pd = this._partData[partIndex];
  6045. var offset = (pd._partDataStride / 4) * elementCount;
  6046. var pci = this._partsClassInfo[partIndex];
  6047. var self = this;
  6048. pci.fullContent.forEach(function (k, v) {
  6049. if (!v.category || pd._partUsedCategories.indexOf(v.category) !== -1) {
  6050. switch (v.dataType) {
  6051. case 4 /* float */:
  6052. {
  6053. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6054. effect.setFloat(v.attributeName, data.buffer[offset + attribOffset]);
  6055. break;
  6056. }
  6057. case 0 /* Vector2 */:
  6058. {
  6059. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6060. ModelRenderCache.v2.x = data.buffer[offset + attribOffset + 0];
  6061. ModelRenderCache.v2.y = data.buffer[offset + attribOffset + 1];
  6062. effect.setVector2(v.attributeName, ModelRenderCache.v2);
  6063. break;
  6064. }
  6065. case 5 /* Color3 */:
  6066. case 1 /* Vector3 */:
  6067. {
  6068. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6069. ModelRenderCache.v3.x = data.buffer[offset + attribOffset + 0];
  6070. ModelRenderCache.v3.y = data.buffer[offset + attribOffset + 1];
  6071. ModelRenderCache.v3.z = data.buffer[offset + attribOffset + 2];
  6072. effect.setVector3(v.attributeName, ModelRenderCache.v3);
  6073. break;
  6074. }
  6075. case 6 /* Color4 */:
  6076. case 2 /* Vector4 */:
  6077. {
  6078. var attribOffset = v.instanceOffset.get(pd._partJoinedUsedCategories);
  6079. ModelRenderCache.v4.x = data.buffer[offset + attribOffset + 0];
  6080. ModelRenderCache.v4.y = data.buffer[offset + attribOffset + 1];
  6081. ModelRenderCache.v4.z = data.buffer[offset + attribOffset + 2];
  6082. ModelRenderCache.v4.w = data.buffer[offset + attribOffset + 3];
  6083. effect.setVector4(v.attributeName, ModelRenderCache.v4);
  6084. break;
  6085. }
  6086. default:
  6087. }
  6088. }
  6089. });
  6090. };
  6091. //setupUniformsLocation(effect: Effect, uniforms: string[], partId: number) {
  6092. // let i = this.getPartIndexFromId(partId);
  6093. // if (i === null) {
  6094. // return null;
  6095. // }
  6096. // let pci = this._partsClassInfo[i];
  6097. // pci.fullContent.forEach((k, v) => {
  6098. // if (uniforms.indexOf(v.attributeName) !== -1) {
  6099. // v.uniformLocation = effect.getUniform(v.attributeName);
  6100. // }
  6101. // });
  6102. //}
  6103. ModelRenderCache.v2 = BABYLON.Vector2.Zero();
  6104. ModelRenderCache.v3 = BABYLON.Vector3.Zero();
  6105. ModelRenderCache.v4 = BABYLON.Vector4.Zero();
  6106. return ModelRenderCache;
  6107. }());
  6108. BABYLON.ModelRenderCache = ModelRenderCache;
  6109. var ModelRenderCachePartData = (function () {
  6110. function ModelRenderCachePartData() {
  6111. }
  6112. return ModelRenderCachePartData;
  6113. }());
  6114. BABYLON.ModelRenderCachePartData = ModelRenderCachePartData;
  6115. })(BABYLON || (BABYLON = {}));
  6116. var BABYLON;
  6117. (function (BABYLON) {
  6118. var InstanceClassInfo = (function () {
  6119. function InstanceClassInfo(base) {
  6120. this._baseInfo = base;
  6121. this._nextOffset = new BABYLON.StringDictionary();
  6122. this._attributes = new Array();
  6123. }
  6124. InstanceClassInfo.prototype.mapProperty = function (propInfo, push) {
  6125. var curOff = this._nextOffset.getOrAdd(InstanceClassInfo._CurCategories, 0);
  6126. propInfo.instanceOffset.add(InstanceClassInfo._CurCategories, this._getBaseOffset(InstanceClassInfo._CurCategories) + curOff);
  6127. //console.log(`[${InstanceClassInfo._CurCategories}] New PropInfo. Category: ${propInfo.category}, Name: ${propInfo.attributeName}, Offset: ${propInfo.instanceOffset.get(InstanceClassInfo._CurCategories)}, Size: ${propInfo.size / 4}`);
  6128. this._nextOffset.set(InstanceClassInfo._CurCategories, curOff + (propInfo.size / 4));
  6129. if (push) {
  6130. this._attributes.push(propInfo);
  6131. }
  6132. };
  6133. InstanceClassInfo.prototype.getInstancingAttributeInfos = function (effect, categories) {
  6134. var catInline = ";" + categories.join(";") + ";";
  6135. var res = new Array();
  6136. var curInfo = this;
  6137. while (curInfo) {
  6138. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6139. var attrib = _a[_i];
  6140. // Only map if there's no category assigned to the instance data or if there's a category and it's in the given list
  6141. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6142. var index = effect.getAttributeLocationByName(attrib.attributeName);
  6143. var iai = new BABYLON.InstancingAttributeInfo();
  6144. iai.index = index;
  6145. iai.attributeSize = attrib.size / 4; // attrib.size is in byte and we need to store in "component" (i.e float is 1, vec3 is 3)
  6146. iai.offset = attrib.instanceOffset.get(catInline) * 4; // attrib.instanceOffset is in float, iai.offset must be in bytes
  6147. iai.attributeName = attrib.attributeName;
  6148. res.push(iai);
  6149. }
  6150. }
  6151. curInfo = curInfo._baseInfo;
  6152. }
  6153. return res;
  6154. };
  6155. InstanceClassInfo.prototype.getShaderAttributes = function (categories) {
  6156. var res = new Array();
  6157. var curInfo = this;
  6158. while (curInfo) {
  6159. for (var _i = 0, _a = curInfo._attributes; _i < _a.length; _i++) {
  6160. var attrib = _a[_i];
  6161. // Only map if there's no category assigned to the instance data or if there's a category and it's in the given list
  6162. if (!attrib.category || categories.indexOf(attrib.category) !== -1) {
  6163. res.push(attrib.attributeName);
  6164. }
  6165. }
  6166. curInfo = curInfo._baseInfo;
  6167. }
  6168. return res;
  6169. };
  6170. InstanceClassInfo.prototype._getBaseOffset = function (categories) {
  6171. var curOffset = 0;
  6172. var curBase = this._baseInfo;
  6173. while (curBase) {
  6174. curOffset += curBase._nextOffset.getOrAdd(categories, 0);
  6175. curBase = curBase._baseInfo;
  6176. }
  6177. return curOffset;
  6178. };
  6179. return InstanceClassInfo;
  6180. }());
  6181. BABYLON.InstanceClassInfo = InstanceClassInfo;
  6182. var InstancePropInfo = (function () {
  6183. function InstancePropInfo() {
  6184. this.instanceOffset = new BABYLON.StringDictionary();
  6185. }
  6186. InstancePropInfo.prototype.setSize = function (val) {
  6187. if (val instanceof BABYLON.Vector2) {
  6188. this.size = 8;
  6189. this.dataType = 0 /* Vector2 */;
  6190. return;
  6191. }
  6192. if (val instanceof BABYLON.Vector3) {
  6193. this.size = 12;
  6194. this.dataType = 1 /* Vector3 */;
  6195. return;
  6196. }
  6197. if (val instanceof BABYLON.Vector4) {
  6198. this.size = 16;
  6199. this.dataType = 2 /* Vector4 */;
  6200. return;
  6201. }
  6202. if (val instanceof BABYLON.Matrix) {
  6203. throw new Error("Matrix type is not supported by WebGL Instance Buffer, you have to use four Vector4 properties instead");
  6204. }
  6205. if (typeof (val) === "number") {
  6206. this.size = 4;
  6207. this.dataType = 4 /* float */;
  6208. return;
  6209. }
  6210. if (val instanceof BABYLON.Color3) {
  6211. this.size = 12;
  6212. this.dataType = 5 /* Color3 */;
  6213. return;
  6214. }
  6215. if (val instanceof BABYLON.Color4) {
  6216. this.size = 16;
  6217. this.dataType = 6 /* Color4 */;
  6218. return;
  6219. }
  6220. if (val instanceof BABYLON.Size) {
  6221. this.size = 8;
  6222. this.dataType = 7 /* Size */;
  6223. return;
  6224. }
  6225. return;
  6226. };
  6227. InstancePropInfo.prototype.writeData = function (array, offset, val) {
  6228. switch (this.dataType) {
  6229. case 0 /* Vector2 */:
  6230. {
  6231. var v = val;
  6232. array[offset + 0] = v.x;
  6233. array[offset + 1] = v.y;
  6234. break;
  6235. }
  6236. case 1 /* Vector3 */:
  6237. {
  6238. var v = val;
  6239. array[offset + 0] = v.x;
  6240. array[offset + 1] = v.y;
  6241. array[offset + 2] = v.z;
  6242. break;
  6243. }
  6244. case 2 /* Vector4 */:
  6245. {
  6246. var v = val;
  6247. array[offset + 0] = v.x;
  6248. array[offset + 1] = v.y;
  6249. array[offset + 2] = v.z;
  6250. array[offset + 3] = v.w;
  6251. break;
  6252. }
  6253. case 5 /* Color3 */:
  6254. {
  6255. var v = val;
  6256. array[offset + 0] = v.r;
  6257. array[offset + 1] = v.g;
  6258. array[offset + 2] = v.b;
  6259. break;
  6260. }
  6261. case 6 /* Color4 */:
  6262. {
  6263. var v = val;
  6264. array[offset + 0] = v.r;
  6265. array[offset + 1] = v.g;
  6266. array[offset + 2] = v.b;
  6267. array[offset + 3] = v.a;
  6268. break;
  6269. }
  6270. case 4 /* float */:
  6271. {
  6272. var v = val;
  6273. array[offset] = v;
  6274. break;
  6275. }
  6276. case 3 /* Matrix */:
  6277. {
  6278. var v = val;
  6279. for (var i = 0; i < 16; i++) {
  6280. array[offset + i] = v.m[i];
  6281. }
  6282. break;
  6283. }
  6284. case 7 /* Size */:
  6285. {
  6286. var s = val;
  6287. array[offset + 0] = s.width;
  6288. array[offset + 1] = s.height;
  6289. break;
  6290. }
  6291. }
  6292. };
  6293. return InstancePropInfo;
  6294. }());
  6295. BABYLON.InstancePropInfo = InstancePropInfo;
  6296. function instanceData(category, shaderAttributeName) {
  6297. return function (target, propName, descriptor) {
  6298. var dic = BABYLON.ClassTreeInfo.getOrRegister(target, function (base) { return new InstanceClassInfo(base); });
  6299. var node = dic.getLevelOf(target);
  6300. var instanceDataName = propName;
  6301. shaderAttributeName = shaderAttributeName || instanceDataName;
  6302. var info = node.levelContent.get(instanceDataName);
  6303. if (info) {
  6304. throw new Error("The ID " + instanceDataName + " is already taken by another instance data");
  6305. }
  6306. info = new InstancePropInfo();
  6307. info.attributeName = shaderAttributeName;
  6308. info.category = category || null;
  6309. if (info.category) {
  6310. info.delimitedCategory = ";" + info.category + ";";
  6311. }
  6312. node.levelContent.add(instanceDataName, info);
  6313. descriptor.get = function () {
  6314. return null;
  6315. };
  6316. descriptor.set = function (val) {
  6317. // Check that we're not trying to set a property that belongs to a category that is not allowed (current)
  6318. // Quit if it's the case, otherwise we could overwrite data somewhere...
  6319. if (info.category && InstanceClassInfo._CurCategories.indexOf(info.delimitedCategory) === -1) {
  6320. return;
  6321. }
  6322. if (!info.size) {
  6323. info.setSize(val);
  6324. node.classContent.mapProperty(info, true);
  6325. }
  6326. else if (!info.instanceOffset.contains(InstanceClassInfo._CurCategories)) {
  6327. node.classContent.mapProperty(info, false);
  6328. }
  6329. var obj = this;
  6330. if (obj.dataBuffer && obj.dataElements) {
  6331. var offset = obj.dataElements[obj.curElement].offset + info.instanceOffset.get(InstanceClassInfo._CurCategories);
  6332. info.writeData(obj.dataBuffer.buffer, offset, val);
  6333. }
  6334. };
  6335. };
  6336. }
  6337. BABYLON.instanceData = instanceData;
  6338. var InstanceDataBase = (function () {
  6339. function InstanceDataBase(partId, dataElementCount) {
  6340. this.id = partId;
  6341. this.curElement = 0;
  6342. this._dataElementCount = dataElementCount;
  6343. this.renderMode = 0;
  6344. this.arrayLengthChanged = false;
  6345. }
  6346. Object.defineProperty(InstanceDataBase.prototype, "zBias", {
  6347. get: function () {
  6348. return null;
  6349. },
  6350. set: function (value) {
  6351. },
  6352. enumerable: true,
  6353. configurable: true
  6354. });
  6355. Object.defineProperty(InstanceDataBase.prototype, "transformX", {
  6356. get: function () {
  6357. return null;
  6358. },
  6359. set: function (value) {
  6360. },
  6361. enumerable: true,
  6362. configurable: true
  6363. });
  6364. Object.defineProperty(InstanceDataBase.prototype, "transformY", {
  6365. get: function () {
  6366. return null;
  6367. },
  6368. set: function (value) {
  6369. },
  6370. enumerable: true,
  6371. configurable: true
  6372. });
  6373. Object.defineProperty(InstanceDataBase.prototype, "opacity", {
  6374. get: function () {
  6375. return null;
  6376. },
  6377. set: function (value) {
  6378. },
  6379. enumerable: true,
  6380. configurable: true
  6381. });
  6382. InstanceDataBase.prototype.getClassTreeInfo = function () {
  6383. if (!this.typeInfo) {
  6384. this.typeInfo = BABYLON.ClassTreeInfo.get(Object.getPrototypeOf(this));
  6385. }
  6386. return this.typeInfo;
  6387. };
  6388. InstanceDataBase.prototype.allocElements = function () {
  6389. if (!this.dataBuffer || this.dataElements) {
  6390. return;
  6391. }
  6392. var res = new Array(this.dataElementCount);
  6393. for (var i = 0; i < this.dataElementCount; i++) {
  6394. res[i] = this.dataBuffer.allocElement();
  6395. }
  6396. this.dataElements = res;
  6397. };
  6398. InstanceDataBase.prototype.freeElements = function () {
  6399. if (!this.dataElements) {
  6400. return;
  6401. }
  6402. for (var _i = 0, _a = this.dataElements; _i < _a.length; _i++) {
  6403. var ei = _a[_i];
  6404. this.dataBuffer.freeElement(ei);
  6405. }
  6406. this.dataElements = null;
  6407. };
  6408. Object.defineProperty(InstanceDataBase.prototype, "dataElementCount", {
  6409. get: function () {
  6410. return this._dataElementCount;
  6411. },
  6412. set: function (value) {
  6413. if (value === this._dataElementCount) {
  6414. return;
  6415. }
  6416. this.arrayLengthChanged = true;
  6417. this.freeElements();
  6418. this._dataElementCount = value;
  6419. this.allocElements();
  6420. },
  6421. enumerable: true,
  6422. configurable: true
  6423. });
  6424. __decorate([
  6425. instanceData()
  6426. ], InstanceDataBase.prototype, "zBias", null);
  6427. __decorate([
  6428. instanceData()
  6429. ], InstanceDataBase.prototype, "transformX", null);
  6430. __decorate([
  6431. instanceData()
  6432. ], InstanceDataBase.prototype, "transformY", null);
  6433. __decorate([
  6434. instanceData()
  6435. ], InstanceDataBase.prototype, "opacity", null);
  6436. return InstanceDataBase;
  6437. }());
  6438. BABYLON.InstanceDataBase = InstanceDataBase;
  6439. var RenderablePrim2D = (function (_super) {
  6440. __extends(RenderablePrim2D, _super);
  6441. function RenderablePrim2D(settings) {
  6442. _super.call(this, settings);
  6443. this._transparentPrimitiveInfo = null;
  6444. }
  6445. Object.defineProperty(RenderablePrim2D.prototype, "isAlphaTest", {
  6446. get: function () {
  6447. return this._useTextureAlpha() || this._isPrimAlphaTest();
  6448. },
  6449. enumerable: true,
  6450. configurable: true
  6451. });
  6452. Object.defineProperty(RenderablePrim2D.prototype, "isTransparent", {
  6453. get: function () {
  6454. return (this.actualOpacity < 1) || this._shouldUseAlphaFromTexture() || this._isPrimTransparent();
  6455. },
  6456. enumerable: true,
  6457. configurable: true
  6458. });
  6459. Object.defineProperty(RenderablePrim2D.prototype, "renderMode", {
  6460. get: function () {
  6461. return this._renderMode;
  6462. },
  6463. enumerable: true,
  6464. configurable: true
  6465. });
  6466. /**
  6467. * Dispose the primitive and its resources, remove it from its parent
  6468. */
  6469. RenderablePrim2D.prototype.dispose = function () {
  6470. if (!_super.prototype.dispose.call(this)) {
  6471. return false;
  6472. }
  6473. if (this.renderGroup) {
  6474. this.renderGroup._setCacheGroupDirty();
  6475. }
  6476. if (this._transparentPrimitiveInfo) {
  6477. this.renderGroup._renderableData.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  6478. this._transparentPrimitiveInfo = null;
  6479. }
  6480. if (this._instanceDataParts) {
  6481. this._cleanupInstanceDataParts();
  6482. }
  6483. if (this._modelRenderCache) {
  6484. this._modelRenderCache.dispose();
  6485. this._modelRenderCache = null;
  6486. }
  6487. if (this._instanceDataParts) {
  6488. this._instanceDataParts.forEach(function (p) {
  6489. p.freeElements();
  6490. });
  6491. this._instanceDataParts = null;
  6492. }
  6493. return true;
  6494. };
  6495. RenderablePrim2D.prototype._cleanupInstanceDataParts = function () {
  6496. var gii = null;
  6497. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6498. var part = _a[_i];
  6499. part.freeElements();
  6500. gii = part.groupInstanceInfo;
  6501. }
  6502. if (gii) {
  6503. var usedCount = 0;
  6504. if (gii.hasOpaqueData) {
  6505. var od = gii.opaqueData[0];
  6506. usedCount += od._partData.usedElementCount;
  6507. gii.opaqueDirty = true;
  6508. }
  6509. if (gii.hasAlphaTestData) {
  6510. var atd = gii.alphaTestData[0];
  6511. usedCount += atd._partData.usedElementCount;
  6512. gii.alphaTestDirty = true;
  6513. }
  6514. if (gii.hasTransparentData) {
  6515. var td = gii.transparentData[0];
  6516. usedCount += td._partData.usedElementCount;
  6517. gii.transparentDirty = true;
  6518. }
  6519. if (usedCount === 0 && gii.modelRenderCache != null) {
  6520. this.renderGroup._renderableData._renderGroupInstancesInfo.remove(gii.modelRenderCache.modelKey);
  6521. gii.dispose();
  6522. }
  6523. if (this._modelRenderCache) {
  6524. this._modelRenderCache.dispose();
  6525. this._modelRenderCache = null;
  6526. }
  6527. }
  6528. this._instanceDataParts = null;
  6529. };
  6530. RenderablePrim2D.prototype._prepareRenderPre = function (context) {
  6531. _super.prototype._prepareRenderPre.call(this, context);
  6532. // If the model changed and we have already an instance, we must remove this instance from the obsolete model
  6533. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty) && this._instanceDataParts) {
  6534. this._cleanupInstanceDataParts();
  6535. }
  6536. // Need to create the model?
  6537. var setupModelRenderCache = false;
  6538. if (!this._modelRenderCache || this._isFlagSet(BABYLON.SmartPropertyPrim.flagModelDirty)) {
  6539. setupModelRenderCache = this._createModelRenderCache();
  6540. }
  6541. var gii = null;
  6542. var newInstance = false;
  6543. // Need to create the instance data parts?
  6544. if (!this._instanceDataParts) {
  6545. // Yes, flag it for later, more processing will have to be done
  6546. newInstance = true;
  6547. gii = this._createModelDataParts();
  6548. }
  6549. // If the ModelRenderCache is brand new, now is the time to call the implementation's specific setup method to create the rendering resources
  6550. if (setupModelRenderCache) {
  6551. this.setupModelRenderCache(this._modelRenderCache);
  6552. }
  6553. // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
  6554. // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
  6555. if (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagNeedRefresh) || context.forceRefreshPrimitive || newInstance || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep) || this._mustUpdateInstance()) {
  6556. this._updateInstanceDataParts(gii);
  6557. }
  6558. };
  6559. RenderablePrim2D.prototype._createModelRenderCache = function () {
  6560. var _this = this;
  6561. var setupModelRenderCache = false;
  6562. if (this._modelRenderCache) {
  6563. this._modelRenderCache.dispose();
  6564. }
  6565. this._modelRenderCache = this.owner._engineData.GetOrAddModelCache(this.modelKey, function (key) {
  6566. var mrc = _this.createModelRenderCache(key);
  6567. setupModelRenderCache = true;
  6568. return mrc;
  6569. });
  6570. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  6571. // if this is still false it means the MRC already exists, so we add a reference to it
  6572. if (!setupModelRenderCache) {
  6573. this._modelRenderCache.addRef();
  6574. }
  6575. return setupModelRenderCache;
  6576. };
  6577. RenderablePrim2D.prototype._createModelDataParts = function () {
  6578. var _this = this;
  6579. // Create the instance data parts of the primitive and store them
  6580. var parts = this.createInstanceDataParts();
  6581. this._instanceDataParts = parts;
  6582. // Check if the ModelRenderCache for this particular instance is also brand new, initialize it if it's the case
  6583. if (!this._modelRenderCache._partData) {
  6584. this._setupModelRenderCache(parts);
  6585. }
  6586. // The Rendering resources (Effect, VB, IB, Textures) are stored in the ModelRenderCache
  6587. // But it's the RenderGroup that will store all the Instanced related data to render all the primitive it owns.
  6588. // So for a given ModelKey we getOrAdd a GroupInstanceInfo that will store all these data
  6589. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.getOrAddWithFactory(this.modelKey, function (k) {
  6590. var res = new BABYLON.GroupInstanceInfo(_this.renderGroup, _this._modelRenderCache, _this._modelRenderCache._partData.length);
  6591. for (var j = 0; j < _this._modelRenderCache._partData.length; j++) {
  6592. var part = _this._instanceDataParts[j];
  6593. res.partIndexFromId.add(part.id.toString(), j);
  6594. res.usedShaderCategories[j] = ";" + _this.getUsedShaderCategories(part).join(";") + ";";
  6595. res.strides[j] = _this._modelRenderCache._partData[j]._partDataStride;
  6596. }
  6597. return res;
  6598. });
  6599. // Get the GroupInfoDataPart corresponding to the render category of the part
  6600. var rm = 0;
  6601. var gipd = null;
  6602. if (this.isTransparent) {
  6603. gipd = gii.transparentData;
  6604. rm = BABYLON.Render2DContext.RenderModeTransparent;
  6605. }
  6606. else if (this.isAlphaTest) {
  6607. gipd = gii.alphaTestData;
  6608. rm = BABYLON.Render2DContext.RenderModeAlphaTest;
  6609. }
  6610. else {
  6611. gipd = gii.opaqueData;
  6612. rm = BABYLON.Render2DContext.RenderModeOpaque;
  6613. }
  6614. // For each instance data part of the primitive, allocate the instanced element it needs for render
  6615. for (var i = 0; i < parts.length; i++) {
  6616. var part = parts[i];
  6617. part.dataBuffer = gipd[i]._partData;
  6618. part.allocElements();
  6619. part.renderMode = rm;
  6620. part.groupInstanceInfo = gii;
  6621. }
  6622. return gii;
  6623. };
  6624. RenderablePrim2D.prototype._setupModelRenderCache = function (parts) {
  6625. var ctiArray = new Array();
  6626. this._modelRenderCache._partData = new Array();
  6627. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  6628. var dataPart = parts_1[_i];
  6629. var pd = new BABYLON.ModelRenderCachePartData();
  6630. this._modelRenderCache._partData.push(pd);
  6631. var cat = this.getUsedShaderCategories(dataPart);
  6632. var cti = dataPart.getClassTreeInfo();
  6633. // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
  6634. var curVisible = this.isVisible;
  6635. this.isVisible = true;
  6636. // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
  6637. //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
  6638. var joinCat = ";" + cat.join(";") + ";";
  6639. pd._partJoinedUsedCategories = joinCat;
  6640. InstanceClassInfo._CurCategories = joinCat;
  6641. var obj = this.beforeRefreshForLayoutConstruction(dataPart);
  6642. if (!this.refreshInstanceDataPart(dataPart)) {
  6643. console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
  6644. }
  6645. this.afterRefreshForLayoutConstruction(dataPart, obj);
  6646. this.isVisible = curVisible;
  6647. var size = 0;
  6648. cti.fullContent.forEach(function (k, v) {
  6649. if (!v.category || cat.indexOf(v.category) !== -1) {
  6650. if (v.attributeName === "zBias") {
  6651. pd._zBiasOffset = v.instanceOffset.get(joinCat);
  6652. }
  6653. if (!v.size) {
  6654. console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
  6655. }
  6656. else {
  6657. size += v.size;
  6658. }
  6659. }
  6660. });
  6661. pd._partDataStride = size;
  6662. pd._partUsedCategories = cat;
  6663. pd._partId = dataPart.id;
  6664. ctiArray.push(cti);
  6665. }
  6666. this._modelRenderCache._partsClassInfo = ctiArray;
  6667. };
  6668. RenderablePrim2D.prototype.onZOrderChanged = function () {
  6669. if (this.isTransparent && this._transparentPrimitiveInfo) {
  6670. this.renderGroup._renderableData.transparentPrimitiveZChanged(this._transparentPrimitiveInfo);
  6671. var gii = this.renderGroup._renderableData._renderGroupInstancesInfo.get(this.modelKey);
  6672. // Flag the transparentData dirty has will have to sort it again
  6673. gii.transparentOrderDirty = true;
  6674. }
  6675. };
  6676. RenderablePrim2D.prototype._mustUpdateInstance = function () {
  6677. return false;
  6678. };
  6679. RenderablePrim2D.prototype._useTextureAlpha = function () {
  6680. return false;
  6681. };
  6682. RenderablePrim2D.prototype._shouldUseAlphaFromTexture = function () {
  6683. return false;
  6684. };
  6685. RenderablePrim2D.prototype._isPrimAlphaTest = function () {
  6686. return false;
  6687. };
  6688. RenderablePrim2D.prototype._isPrimTransparent = function () {
  6689. return false;
  6690. };
  6691. RenderablePrim2D.prototype._updateInstanceDataParts = function (gii) {
  6692. // Fetch the GroupInstanceInfo if we don't already have it
  6693. var rd = this.renderGroup._renderableData;
  6694. if (!gii) {
  6695. gii = rd._renderGroupInstancesInfo.get(this.modelKey);
  6696. }
  6697. var isTransparent = this.isTransparent;
  6698. var isAlphaTest = this.isAlphaTest;
  6699. var wereTransparent = false;
  6700. // Check a render mode change
  6701. var rmChanged = false;
  6702. if (this._instanceDataParts.length > 0) {
  6703. var firstPart = this._instanceDataParts[0];
  6704. var partRM = firstPart.renderMode;
  6705. var curRM = this.renderMode;
  6706. if (partRM !== curRM) {
  6707. wereTransparent = partRM === BABYLON.Render2DContext.RenderModeTransparent;
  6708. rmChanged = true;
  6709. var gipd = void 0;
  6710. switch (curRM) {
  6711. case BABYLON.Render2DContext.RenderModeTransparent:
  6712. gipd = gii.transparentData;
  6713. break;
  6714. case BABYLON.Render2DContext.RenderModeAlphaTest:
  6715. gipd = gii.alphaTestData;
  6716. break;
  6717. default:
  6718. gipd = gii.opaqueData;
  6719. }
  6720. for (var i = 0; i < this._instanceDataParts.length; i++) {
  6721. var part = this._instanceDataParts[i];
  6722. part.freeElements();
  6723. part.dataBuffer = gipd[i]._partData;
  6724. part.renderMode = curRM;
  6725. }
  6726. }
  6727. }
  6728. // Handle changes related to ZOffset
  6729. var visChanged = this._isFlagSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged);
  6730. if (isTransparent || wereTransparent) {
  6731. // Handle visibility change, which is also triggered when the primitive just got created
  6732. if (visChanged || rmChanged) {
  6733. if (this.isVisible && !wereTransparent) {
  6734. if (!this._transparentPrimitiveInfo) {
  6735. // Add the primitive to the list of transparent ones in the group that render is
  6736. this._transparentPrimitiveInfo = rd.addNewTransparentPrimitiveInfo(this, gii);
  6737. }
  6738. }
  6739. else {
  6740. if (this._transparentPrimitiveInfo) {
  6741. rd.removeTransparentPrimitiveInfo(this._transparentPrimitiveInfo);
  6742. this._transparentPrimitiveInfo = null;
  6743. }
  6744. }
  6745. gii.transparentOrderDirty = true;
  6746. }
  6747. }
  6748. var rebuildTrans = false;
  6749. // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
  6750. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6751. var part = _a[_i];
  6752. var justAllocated = false;
  6753. // Check if we need to allocate data elements (hidden prim which becomes visible again)
  6754. if (!part.dataElements && (visChanged || rmChanged || this.isVisible)) {
  6755. part.allocElements();
  6756. justAllocated = true;
  6757. }
  6758. InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
  6759. // Will return false if the instance should not be rendered (not visible or other any reasons)
  6760. part.arrayLengthChanged = false;
  6761. if (!this.refreshInstanceDataPart(part)) {
  6762. // Free the data element
  6763. if (part.dataElements) {
  6764. part.freeElements();
  6765. }
  6766. // The refresh couldn't succeed, push the primitive to be dirty again for the next render
  6767. if (this.isVisible) {
  6768. rd._primNewDirtyList.push(this);
  6769. }
  6770. }
  6771. rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
  6772. }
  6773. this._instanceDirtyFlags = 0;
  6774. // Make the appropriate data dirty
  6775. if (isTransparent) {
  6776. gii.transparentDirty = true;
  6777. if (rebuildTrans) {
  6778. rd._transparentListChanged = true;
  6779. }
  6780. }
  6781. else if (isAlphaTest) {
  6782. gii.alphaTestDirty = true;
  6783. }
  6784. else {
  6785. gii.opaqueDirty = true;
  6786. }
  6787. this._clearFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged); // Reset the flag as we've handled the case
  6788. };
  6789. RenderablePrim2D.prototype._updateTransparentSegmentIndices = function (ts) {
  6790. var minOff = BABYLON.Prim2DBase._bigInt;
  6791. var maxOff = 0;
  6792. for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
  6793. var part = _a[_i];
  6794. if (part && part.dataElements) {
  6795. part.dataBuffer.pack();
  6796. for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
  6797. var el = _c[_b];
  6798. minOff = Math.min(minOff, el.offset);
  6799. maxOff = Math.max(maxOff, el.offset);
  6800. }
  6801. ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
  6802. ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
  6803. }
  6804. }
  6805. };
  6806. // This internal method is mainly used for transparency processing
  6807. RenderablePrim2D.prototype._getNextPrimZOrder = function () {
  6808. var length = this._instanceDataParts.length;
  6809. for (var i = 0; i < length; i++) {
  6810. var part = this._instanceDataParts[i];
  6811. if (part) {
  6812. var stride = part.dataBuffer.stride;
  6813. var lastElementOffset = part.dataElements[part.dataElements.length - 1].offset;
  6814. // check if it's the last in the DFA
  6815. if (part.dataBuffer.totalElementCount * stride <= lastElementOffset) {
  6816. return null;
  6817. }
  6818. // Return the Z of the next primitive that lies in the DFA
  6819. return part.dataBuffer[lastElementOffset + stride + this.modelRenderCache._partData[i]._zBiasOffset];
  6820. }
  6821. }
  6822. return null;
  6823. };
  6824. // This internal method is mainly used for transparency processing
  6825. RenderablePrim2D.prototype._getPrevPrimZOrder = function () {
  6826. var length = this._instanceDataParts.length;
  6827. for (var i = 0; i < length; i++) {
  6828. var part = this._instanceDataParts[i];
  6829. if (part) {
  6830. var stride = part.dataBuffer.stride;
  6831. var firstElementOffset = part.dataElements[0].offset;
  6832. // check if it's the first in the DFA
  6833. if (firstElementOffset === 0) {
  6834. return null;
  6835. }
  6836. // Return the Z of the previous primitive that lies in the DFA
  6837. return part.dataBuffer[firstElementOffset - stride + this.modelRenderCache._partData[i]._zBiasOffset];
  6838. }
  6839. }
  6840. return null;
  6841. };
  6842. /**
  6843. * Transform a given point using the Primitive's origin setting.
  6844. * This method requires the Primitive's actualSize to be accurate
  6845. * @param p the point to transform
  6846. * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
  6847. * @param res an allocated Vector2 that will receive the transformed content
  6848. */
  6849. RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
  6850. var actualSize = this.actualSize;
  6851. res.x = p.x - ((this.origin.x + (originOffset ? originOffset.x : 0)) * actualSize.width);
  6852. res.y = p.y - ((this.origin.y + (originOffset ? originOffset.y : 0)) * actualSize.height);
  6853. };
  6854. RenderablePrim2D.prototype.transformPointWithOriginToRef = function (p, originOffset, res) {
  6855. this.transformPointWithOriginByRef(p, originOffset, res);
  6856. return res;
  6857. };
  6858. /**
  6859. * Get the info for a given effect based on the dataPart metadata
  6860. * @param dataPartId partId in part list to get the info
  6861. * @param vertexBufferAttributes vertex buffer attributes to manually add
  6862. * @param uniforms uniforms to manually add
  6863. * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
  6864. */
  6865. RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
  6866. if (uniforms === void 0) { uniforms = null; }
  6867. if (useInstanced === void 0) { useInstanced = null; }
  6868. var dataPart = BABYLON.Tools.first(this._instanceDataParts, function (i) { return i.id === dataPartId; });
  6869. if (!dataPart) {
  6870. return null;
  6871. }
  6872. var instancedArray = this.owner.supportInstancedArray;
  6873. if (useInstanced != null) {
  6874. // Check if the caller ask for Instanced Array and the engine does not support it, return null if it's the case
  6875. if (useInstanced && instancedArray === false) {
  6876. return null;
  6877. }
  6878. // Use the caller's setting
  6879. instancedArray = useInstanced;
  6880. }
  6881. var cti = dataPart.getClassTreeInfo();
  6882. var categories = this.getUsedShaderCategories(dataPart);
  6883. var att = cti.classContent.getShaderAttributes(categories);
  6884. var defines = "";
  6885. categories.forEach(function (c) { defines += "#define " + c + "\n"; });
  6886. if (instancedArray) {
  6887. defines += "#define Instanced\n";
  6888. }
  6889. return {
  6890. attributes: instancedArray ? vertexBufferAttributes.concat(att) : vertexBufferAttributes,
  6891. uniforms: instancedArray ? (uniforms != null ? uniforms : []) : ((uniforms != null) ? att.concat(uniforms) : (att != null ? att : [])),
  6892. defines: defines
  6893. };
  6894. };
  6895. Object.defineProperty(RenderablePrim2D.prototype, "modelRenderCache", {
  6896. get: function () {
  6897. return this._modelRenderCache;
  6898. },
  6899. enumerable: true,
  6900. configurable: true
  6901. });
  6902. RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
  6903. return null;
  6904. };
  6905. RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  6906. };
  6907. RenderablePrim2D.prototype.createInstanceDataParts = function () {
  6908. return null;
  6909. };
  6910. RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
  6911. return [];
  6912. };
  6913. RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  6914. };
  6915. RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  6916. };
  6917. RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
  6918. return true;
  6919. };
  6920. RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
  6921. if (!this.isVisible) {
  6922. return false;
  6923. }
  6924. part.isVisible = this.isVisible;
  6925. // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
  6926. if (part.dataElementCount === 1) {
  6927. part.curElement = 0;
  6928. this.updateInstanceDataPart(part);
  6929. }
  6930. return true;
  6931. };
  6932. /**
  6933. * Update the instanceDataBase level properties of a part
  6934. * @param part the part to update
  6935. * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
  6936. */
  6937. RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
  6938. if (positionOffset === void 0) { positionOffset = null; }
  6939. var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
  6940. var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
  6941. var size = this.renderGroup.viewportSize;
  6942. var zBias = this.actualZOffset;
  6943. var offX = 0;
  6944. var offY = 0;
  6945. // If there's an offset, apply the global transformation matrix on it to get a global offset
  6946. if (positionOffset) {
  6947. offX = positionOffset.x * t.m[0] + positionOffset.y * t.m[4];
  6948. offY = positionOffset.x * t.m[1] + positionOffset.y * t.m[5];
  6949. }
  6950. // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
  6951. // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
  6952. // So for X:
  6953. // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
  6954. // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
  6955. // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
  6956. var w = size.width;
  6957. var h = size.height;
  6958. var invZBias = 1 / zBias;
  6959. var tx = new BABYLON.Vector4(t.m[0] * rgScale.x * 2 / w, t.m[4] * 2 / w, 0 /*t.m[8]*/, ((t.m[12] + offX) * rgScale.x * 2 / w) - 1);
  6960. var ty = new BABYLON.Vector4(t.m[1] * 2 / h, t.m[5] * rgScale.y * 2 / h, 0 /*t.m[9]*/, ((t.m[13] + offY) * rgScale.y * 2 / h) - 1);
  6961. if (!this.applyActualScaleOnTransform()) {
  6962. var las = this.actualScale;
  6963. tx.x /= las.x;
  6964. ty.y /= las.y;
  6965. }
  6966. part.transformX = tx;
  6967. part.transformY = ty;
  6968. part.opacity = this.actualOpacity;
  6969. // Stores zBias and it's inverse value because that's needed to compute the clip space W coordinate (which is 1/Z, so 1/zBias)
  6970. part.zBias = new BABYLON.Vector2(zBias, invZBias);
  6971. };
  6972. RenderablePrim2D.prototype._updateRenderMode = function () {
  6973. if (this.isTransparent) {
  6974. this._renderMode = BABYLON.Render2DContext.RenderModeTransparent;
  6975. }
  6976. else if (this.isAlphaTest) {
  6977. this._renderMode = BABYLON.Render2DContext.RenderModeAlphaTest;
  6978. }
  6979. else {
  6980. this._renderMode = BABYLON.Render2DContext.RenderModeOpaque;
  6981. }
  6982. };
  6983. RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  6984. RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
  6985. __decorate([
  6986. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D.isAlphaTestProperty = pi; })
  6987. ], RenderablePrim2D.prototype, "isAlphaTest", null);
  6988. __decorate([
  6989. BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return RenderablePrim2D.isTransparentProperty = pi; })
  6990. ], RenderablePrim2D.prototype, "isTransparent", null);
  6991. RenderablePrim2D = __decorate([
  6992. BABYLON.className("RenderablePrim2D", "BABYLON")
  6993. ], RenderablePrim2D);
  6994. return RenderablePrim2D;
  6995. }(BABYLON.Prim2DBase));
  6996. BABYLON.RenderablePrim2D = RenderablePrim2D;
  6997. })(BABYLON || (BABYLON = {}));
  6998. var BABYLON;
  6999. (function (BABYLON) {
  7000. var Shape2D = (function (_super) {
  7001. __extends(Shape2D, _super);
  7002. function Shape2D(settings) {
  7003. _super.call(this, settings);
  7004. if (!settings) {
  7005. settings = {};
  7006. }
  7007. var borderBrush = null;
  7008. if (settings.border) {
  7009. if (typeof (settings.border) === "string") {
  7010. borderBrush = BABYLON.Canvas2D.GetBrushFromString(settings.border);
  7011. }
  7012. else {
  7013. borderBrush = settings.border;
  7014. }
  7015. }
  7016. var fillBrush = null;
  7017. if (settings.fill) {
  7018. if (typeof (settings.fill) === "string") {
  7019. fillBrush = BABYLON.Canvas2D.GetBrushFromString(settings.fill);
  7020. }
  7021. else {
  7022. fillBrush = settings.fill;
  7023. }
  7024. }
  7025. this._isTransparent = false;
  7026. this._oldTransparent = false;
  7027. this.border = borderBrush;
  7028. this.fill = fillBrush;
  7029. this._updateTransparencyStatus();
  7030. this.borderThickness = settings.borderThickness;
  7031. }
  7032. Object.defineProperty(Shape2D.prototype, "border", {
  7033. get: function () {
  7034. return this._border;
  7035. },
  7036. set: function (value) {
  7037. this._border = value;
  7038. this._updateTransparencyStatus();
  7039. },
  7040. enumerable: true,
  7041. configurable: true
  7042. });
  7043. Object.defineProperty(Shape2D.prototype, "fill", {
  7044. /**
  7045. * Get/set the brush to render the Fill part of the Primitive
  7046. */
  7047. get: function () {
  7048. return this._fill;
  7049. },
  7050. set: function (value) {
  7051. this._fill = value;
  7052. this._updateTransparencyStatus();
  7053. },
  7054. enumerable: true,
  7055. configurable: true
  7056. });
  7057. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  7058. get: function () {
  7059. return this._borderThickness;
  7060. },
  7061. set: function (value) {
  7062. this._borderThickness = value;
  7063. },
  7064. enumerable: true,
  7065. configurable: true
  7066. });
  7067. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  7068. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  7069. // Fill Part
  7070. if (dataPart.id === Shape2D.SHAPE2D_FILLPARTID) {
  7071. var fill = this.fill;
  7072. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7073. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLSOLID);
  7074. }
  7075. if (fill instanceof BABYLON.GradientColorBrush2D) {
  7076. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT);
  7077. }
  7078. }
  7079. // Border Part
  7080. if (dataPart.id === Shape2D.SHAPE2D_BORDERPARTID) {
  7081. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDER);
  7082. var border = this.border;
  7083. if (border instanceof BABYLON.SolidColorBrush2D) {
  7084. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID);
  7085. }
  7086. if (border instanceof BABYLON.GradientColorBrush2D) {
  7087. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT);
  7088. }
  7089. }
  7090. return cat;
  7091. };
  7092. Shape2D.prototype.applyActualScaleOnTransform = function () {
  7093. return false;
  7094. };
  7095. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  7096. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  7097. return false;
  7098. }
  7099. // Fill Part
  7100. if (part.id === Shape2D.SHAPE2D_FILLPARTID) {
  7101. var d = part;
  7102. if (this.fill) {
  7103. var fill = this.fill;
  7104. if (fill instanceof BABYLON.SolidColorBrush2D) {
  7105. d.fillSolidColor = fill.color;
  7106. }
  7107. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  7108. d.fillGradientColor1 = fill.color1;
  7109. d.fillGradientColor2 = fill.color2;
  7110. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(fill.scale, fill.scale, fill.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), fill.rotation), new BABYLON.Vector3(fill.translation.x, fill.translation.y, 0));
  7111. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7112. d.fillGradientTY = ty;
  7113. }
  7114. }
  7115. }
  7116. else if (part.id === Shape2D.SHAPE2D_BORDERPARTID) {
  7117. var d = part;
  7118. if (this.border) {
  7119. d.borderThickness = this.borderThickness;
  7120. var border = this.border;
  7121. if (border instanceof BABYLON.SolidColorBrush2D) {
  7122. d.borderSolidColor = border.color;
  7123. }
  7124. else if (border instanceof BABYLON.GradientColorBrush2D) {
  7125. d.borderGradientColor1 = border.color1;
  7126. d.borderGradientColor2 = border.color2;
  7127. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(border.scale, border.scale, border.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), border.rotation), new BABYLON.Vector3(border.translation.x, border.translation.y, 0));
  7128. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  7129. d.borderGradientTY = ty;
  7130. }
  7131. }
  7132. }
  7133. return true;
  7134. };
  7135. Shape2D.prototype._updateTransparencyStatus = function () {
  7136. this._isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent()) || (this.actualOpacity < 1);
  7137. if (this._isTransparent !== this._oldTransparent) {
  7138. this._oldTransparent = this._isTransparent;
  7139. this._updateRenderMode();
  7140. }
  7141. };
  7142. Shape2D.prototype._mustUpdateInstance = function () {
  7143. var res = this._oldTransparent !== this._isTransparent;
  7144. if (res) {
  7145. this._updateRenderMode();
  7146. this._oldTransparent = this._isTransparent;
  7147. }
  7148. return res;
  7149. };
  7150. Shape2D.prototype._isPrimTransparent = function () {
  7151. return this._isTransparent;
  7152. };
  7153. Shape2D.SHAPE2D_BORDERPARTID = 1;
  7154. Shape2D.SHAPE2D_FILLPARTID = 2;
  7155. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  7156. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  7157. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  7158. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  7159. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  7160. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  7161. __decorate([
  7162. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D.borderProperty = pi; }, true)
  7163. ], Shape2D.prototype, "border", null);
  7164. __decorate([
  7165. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D.fillProperty = pi; }, true)
  7166. ], Shape2D.prototype, "fill", null);
  7167. __decorate([
  7168. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D.borderThicknessProperty = pi; })
  7169. ], Shape2D.prototype, "borderThickness", null);
  7170. Shape2D = __decorate([
  7171. BABYLON.className("Shape2D", "BABYLON")
  7172. ], Shape2D);
  7173. return Shape2D;
  7174. }(BABYLON.RenderablePrim2D));
  7175. BABYLON.Shape2D = Shape2D;
  7176. var Shape2DInstanceData = (function (_super) {
  7177. __extends(Shape2DInstanceData, _super);
  7178. function Shape2DInstanceData() {
  7179. _super.apply(this, arguments);
  7180. }
  7181. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  7182. // FILL ATTRIBUTES
  7183. get: function () {
  7184. return null;
  7185. },
  7186. set: function (value) {
  7187. },
  7188. enumerable: true,
  7189. configurable: true
  7190. });
  7191. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  7192. get: function () {
  7193. return null;
  7194. },
  7195. set: function (value) {
  7196. },
  7197. enumerable: true,
  7198. configurable: true
  7199. });
  7200. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  7201. get: function () {
  7202. return null;
  7203. },
  7204. set: function (value) {
  7205. },
  7206. enumerable: true,
  7207. configurable: true
  7208. });
  7209. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  7210. get: function () {
  7211. return null;
  7212. },
  7213. set: function (value) {
  7214. },
  7215. enumerable: true,
  7216. configurable: true
  7217. });
  7218. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  7219. // BORDER ATTRIBUTES
  7220. get: function () {
  7221. return null;
  7222. },
  7223. set: function (value) {
  7224. },
  7225. enumerable: true,
  7226. configurable: true
  7227. });
  7228. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  7229. get: function () {
  7230. return null;
  7231. },
  7232. set: function (value) {
  7233. },
  7234. enumerable: true,
  7235. configurable: true
  7236. });
  7237. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  7238. get: function () {
  7239. return null;
  7240. },
  7241. set: function (value) {
  7242. },
  7243. enumerable: true,
  7244. configurable: true
  7245. });
  7246. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  7247. get: function () {
  7248. return null;
  7249. },
  7250. set: function (value) {
  7251. },
  7252. enumerable: true,
  7253. configurable: true
  7254. });
  7255. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  7256. get: function () {
  7257. return null;
  7258. },
  7259. set: function (value) {
  7260. },
  7261. enumerable: true,
  7262. configurable: true
  7263. });
  7264. __decorate([
  7265. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  7266. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  7267. __decorate([
  7268. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7269. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  7270. __decorate([
  7271. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7272. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  7273. __decorate([
  7274. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  7275. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  7276. __decorate([
  7277. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  7278. ], Shape2DInstanceData.prototype, "borderThickness", null);
  7279. __decorate([
  7280. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  7281. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  7282. __decorate([
  7283. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7284. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  7285. __decorate([
  7286. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7287. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  7288. __decorate([
  7289. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  7290. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  7291. return Shape2DInstanceData;
  7292. }(BABYLON.InstanceDataBase));
  7293. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  7294. })(BABYLON || (BABYLON = {}));
  7295. var BABYLON;
  7296. (function (BABYLON) {
  7297. var Group2D = (function (_super) {
  7298. __extends(Group2D, _super);
  7299. /**
  7300. * Create an Logical or Renderable Group.
  7301. * @param settings a combination of settings, possible ones are
  7302. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  7303. * - children: an array of direct children
  7304. * - id a text identifier, for information purpose
  7305. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  7306. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  7307. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  7308. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  7309. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  7310. * - zOrder: override the zOrder with the specified value
  7311. * - origin: define the normalized origin point location, default [0.5;0.5]
  7312. * - size: the size of the group. Alternatively the width and height properties can be set. If null the size will be computed from its content, default is null.
  7313. * - cacheBehavior: Define how the group should behave regarding the Canvas's cache strategy, default is Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY
  7314. * - layoutEngine: either an instance of a layout engine based class (StackPanel.Vertical, StackPanel.Horizontal) or a string ('canvas' for Canvas layout, 'StackPanel' or 'HorizontalStackPanel' for horizontal Stack Panel layout, 'VerticalStackPanel' for vertical Stack Panel layout).
  7315. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  7316. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  7317. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  7318. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  7319. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7320. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7321. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7322. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7323. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  7324. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  7325. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  7326. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  7327. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7328. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7329. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7330. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  7331. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  7332. */
  7333. function Group2D(settings) {
  7334. if (settings == null) {
  7335. settings = {};
  7336. }
  7337. if (settings.origin == null) {
  7338. settings.origin = new BABYLON.Vector2(0, 0);
  7339. }
  7340. _super.call(this, settings);
  7341. var size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new BABYLON.Size(settings.width || 0, settings.height || 0)));
  7342. this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
  7343. if (this._trackedNode && this.owner) {
  7344. this.owner._registerTrackedNode(this);
  7345. }
  7346. this._cacheBehavior = (settings.cacheBehavior == null) ? Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY : settings.cacheBehavior;
  7347. var rd = this._renderableData;
  7348. if (rd) {
  7349. rd._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  7350. }
  7351. this.size = size;
  7352. this._viewportPosition = BABYLON.Vector2.Zero();
  7353. this._viewportSize = BABYLON.Size.Zero();
  7354. }
  7355. Group2D._createCachedCanvasGroup = function (owner) {
  7356. var g = new Group2D({ parent: owner, id: "__cachedCanvasGroup__", position: BABYLON.Vector2.Zero(), origin: BABYLON.Vector2.Zero(), size: null, isVisible: true, isPickable: false, dontInheritParentScale: true });
  7357. return g;
  7358. };
  7359. Group2D.prototype.applyCachedTexture = function (vertexData, material) {
  7360. this._bindCacheTarget();
  7361. if (vertexData) {
  7362. var uv = vertexData.uvs;
  7363. var nodeuv = this._renderableData._cacheNodeUVs;
  7364. for (var i = 0; i < 4; i++) {
  7365. uv[i * 2 + 0] = nodeuv[i].x;
  7366. uv[i * 2 + 1] = nodeuv[i].y;
  7367. }
  7368. }
  7369. if (material) {
  7370. material.diffuseTexture = this._renderableData._cacheTexture;
  7371. material.emissiveColor = new BABYLON.Color3(1, 1, 1);
  7372. }
  7373. this._renderableData._cacheTexture.hasAlpha = true;
  7374. this._unbindCacheTarget();
  7375. };
  7376. Object.defineProperty(Group2D.prototype, "cachedRect", {
  7377. /**
  7378. * Allow you to access the information regarding the cached rectangle of the Group2D into the MapTexture.
  7379. * If the `noWorldSpaceNode` options was used at the creation of a WorldSpaceCanvas, the rendering of the canvas must be made by the caller, so typically you want to bind the cacheTexture property to some material/mesh and you MUST use the Group2D.cachedUVs property to get the UV coordinates to use for your quad that will display the Canvas and NOT the PackedRect.UVs property which are incorrect because the allocated surface may be bigger (due to over-provisioning or shrinking without deallocating) than what the Group is actually using.
  7380. */
  7381. get: function () {
  7382. if (!this._renderableData) {
  7383. return null;
  7384. }
  7385. return this._renderableData._cacheNode;
  7386. },
  7387. enumerable: true,
  7388. configurable: true
  7389. });
  7390. Object.defineProperty(Group2D.prototype, "cachedUVs", {
  7391. /**
  7392. * The UVs into the MapTexture that map the cached group
  7393. */
  7394. get: function () {
  7395. if (!this._renderableData) {
  7396. return null;
  7397. }
  7398. return this._renderableData._cacheNodeUVs;
  7399. },
  7400. enumerable: true,
  7401. configurable: true
  7402. });
  7403. Object.defineProperty(Group2D.prototype, "cachedUVsChanged", {
  7404. get: function () {
  7405. if (!this._renderableData) {
  7406. return null;
  7407. }
  7408. if (!this._renderableData._cacheNodeUVsChangedObservable) {
  7409. this._renderableData._cacheNodeUVsChangedObservable = new BABYLON.Observable();
  7410. }
  7411. return this._renderableData._cacheNodeUVsChangedObservable;
  7412. },
  7413. enumerable: true,
  7414. configurable: true
  7415. });
  7416. Object.defineProperty(Group2D.prototype, "cacheTexture", {
  7417. /**
  7418. * Access the texture that maintains a cached version of the Group2D.
  7419. * This is useful only if you're not using a WorldSpaceNode for your WorldSpace Canvas and therefore need to perform the rendering yourself.
  7420. */
  7421. get: function () {
  7422. if (!this._renderableData) {
  7423. return null;
  7424. }
  7425. return this._renderableData._cacheTexture;
  7426. },
  7427. enumerable: true,
  7428. configurable: true
  7429. });
  7430. /**
  7431. * Call this method to remove this Group and its children from the Canvas
  7432. */
  7433. Group2D.prototype.dispose = function () {
  7434. if (!_super.prototype.dispose.call(this)) {
  7435. return false;
  7436. }
  7437. if (this._trackedNode != null) {
  7438. this.owner._unregisterTrackedNode(this);
  7439. this._trackedNode = null;
  7440. }
  7441. if (this._renderableData) {
  7442. this._renderableData.dispose(this.owner);
  7443. this._renderableData = null;
  7444. }
  7445. return true;
  7446. };
  7447. Object.defineProperty(Group2D.prototype, "isRenderableGroup", {
  7448. /**
  7449. * @returns Returns true if the Group render content, false if it's a logical group only
  7450. */
  7451. get: function () {
  7452. return this._isRenderableGroup;
  7453. },
  7454. enumerable: true,
  7455. configurable: true
  7456. });
  7457. Object.defineProperty(Group2D.prototype, "isCachedGroup", {
  7458. /**
  7459. * @returns only meaningful for isRenderableGroup, will be true if the content of the Group is cached into a texture, false if it's rendered every time
  7460. */
  7461. get: function () {
  7462. return this._isCachedGroup;
  7463. },
  7464. enumerable: true,
  7465. configurable: true
  7466. });
  7467. Object.defineProperty(Group2D.prototype, "size", {
  7468. get: function () {
  7469. return this._size;
  7470. },
  7471. /**
  7472. * Get/Set the size of the group. If null the size of the group will be determine from its content.
  7473. * BEWARE: if the Group is a RenderableGroup and its content is cache the texture will be resized each time the group is getting bigger. For performance reason the opposite won't be true: the texture won't shrink if the group does.
  7474. */
  7475. set: function (val) {
  7476. this._size = val;
  7477. },
  7478. enumerable: true,
  7479. configurable: true
  7480. });
  7481. Object.defineProperty(Group2D.prototype, "viewportSize", {
  7482. get: function () {
  7483. return this._viewportSize;
  7484. },
  7485. enumerable: true,
  7486. configurable: true
  7487. });
  7488. Object.defineProperty(Group2D.prototype, "actualSize", {
  7489. get: function () {
  7490. // The computed size will be floor on both width and height
  7491. var actualSize;
  7492. // Return the actualSize if set
  7493. if (this._actualSize) {
  7494. return this._actualSize;
  7495. }
  7496. // Return the size if set by the user
  7497. if (this._size) {
  7498. actualSize = new BABYLON.Size(Math.ceil(this._size.width), Math.ceil(this._size.height));
  7499. }
  7500. else {
  7501. var m = this.layoutBoundingInfo.max();
  7502. actualSize = new BABYLON.Size(Math.ceil(m.x), Math.ceil(m.y));
  7503. }
  7504. // Compare the size with the one we previously had, if it differs we set the property dirty and trigger a GroupChanged to synchronize a displaySprite (if any)
  7505. if (!actualSize.equals(this._actualSize)) {
  7506. this.onPrimitivePropertyDirty(Group2D.actualSizeProperty.flagId);
  7507. this._actualSize = actualSize;
  7508. this.handleGroupChanged(Group2D.actualSizeProperty);
  7509. }
  7510. return actualSize;
  7511. },
  7512. set: function (value) {
  7513. this._actualSize = value;
  7514. },
  7515. enumerable: true,
  7516. configurable: true
  7517. });
  7518. Object.defineProperty(Group2D.prototype, "cacheBehavior", {
  7519. /**
  7520. * Get/set the Cache Behavior, used in case the Canvas Cache Strategy is set to CACHESTRATEGY_ALLGROUPS. Can be either GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP, GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE or GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY. See their documentation for more information.
  7521. * GROUPCACHEBEHAVIOR_NORESIZEONSCALE can also be set if you set it at creation time.
  7522. * It is critical to understand than you HAVE TO play with this behavior in order to achieve a good performance/memory ratio. Caching all groups would certainly be the worst strategy of all.
  7523. */
  7524. get: function () {
  7525. return this._cacheBehavior;
  7526. },
  7527. enumerable: true,
  7528. configurable: true
  7529. });
  7530. Group2D.prototype._addPrimToDirtyList = function (prim) {
  7531. this._renderableData._primDirtyList.push(prim);
  7532. };
  7533. Group2D.prototype._renderCachedCanvas = function () {
  7534. this.owner._addGroupRenderCount(1);
  7535. this.updateCachedStates(true);
  7536. var context = new BABYLON.PrepareRender2DContext();
  7537. this._prepareGroupRender(context);
  7538. this._groupRender();
  7539. };
  7540. Object.defineProperty(Group2D.prototype, "trackedNode", {
  7541. /**
  7542. * Get/set the Scene's Node that should be tracked, the group's position will follow the projected position of the Node.
  7543. */
  7544. get: function () {
  7545. return this._trackedNode;
  7546. },
  7547. set: function (val) {
  7548. if (val != null) {
  7549. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7550. this.owner._registerTrackedNode(this);
  7551. }
  7552. this._trackedNode = val;
  7553. }
  7554. else {
  7555. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  7556. this.owner._unregisterTrackedNode(this);
  7557. }
  7558. this._trackedNode = null;
  7559. }
  7560. },
  7561. enumerable: true,
  7562. configurable: true
  7563. });
  7564. Group2D.prototype.levelIntersect = function (intersectInfo) {
  7565. // If we've made it so far it means the boundingInfo intersection test succeed, the Group2D is shaped the same, so we always return true
  7566. return true;
  7567. };
  7568. Group2D.prototype.updateLevelBoundingInfo = function () {
  7569. var size;
  7570. // If the size is set by the user, the boundingInfo is computed from this value
  7571. if (this.size) {
  7572. size = this.size;
  7573. }
  7574. else {
  7575. size = new BABYLON.Size(0, 0);
  7576. }
  7577. BABYLON.BoundingInfo2D.CreateFromSizeToRef(size, this._levelBoundingInfo);
  7578. };
  7579. // Method called only on renderable groups to prepare the rendering
  7580. Group2D.prototype._prepareGroupRender = function (context) {
  7581. var sortedDirtyList = null;
  7582. // Update the Global Transformation and visibility status of the changed primitives
  7583. var rd = this._renderableData;
  7584. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  7585. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  7586. this.updateCachedStatesOf(sortedDirtyList, true);
  7587. }
  7588. var s = this.actualSize;
  7589. var a = this.actualScale;
  7590. var sw = Math.ceil(s.width * a.x);
  7591. var sh = Math.ceil(s.height * a.y);
  7592. // The dimension must be overridden when using the designSize feature, the ratio is maintain to compute a uniform scale, which is mandatory but if the designSize's ratio is different from the rendering surface's ratio, content will be clipped in some cases.
  7593. // So we set the width/height to the rendering's one because that's what we want for the viewport!
  7594. if (this instanceof BABYLON.Canvas2D) {
  7595. var c = this;
  7596. if (c.designSize != null) {
  7597. sw = this.owner.engine.getRenderWidth();
  7598. sh = this.owner.engine.getRenderHeight();
  7599. }
  7600. }
  7601. // Setup the size of the rendering viewport
  7602. // In non cache mode, we're rendering directly to the rendering canvas, in this case we have to detect if the canvas size changed since the previous iteration, if it's the case all primitives must be prepared again because their transformation must be recompute
  7603. if (!this._isCachedGroup) {
  7604. // Compute the WebGL viewport's location/size
  7605. var t = this._globalTransform.getTranslation();
  7606. var rs = this.owner._renderingSize;
  7607. sh = Math.min(sh, rs.height - t.y);
  7608. sw = Math.min(sw, rs.width - t.x);
  7609. var x = t.x;
  7610. var y = t.y;
  7611. // The viewport where we're rendering must be the size of the canvas if this one fit in the rendering screen or clipped to the screen dimensions if needed
  7612. this._viewportPosition.x = x;
  7613. this._viewportPosition.y = y;
  7614. }
  7615. // For a cachedGroup we also check of the group's actualSize is changing, if it's the case then the rendering zone will be change so we also have to dirty all primitives to prepare them again.
  7616. if (this._viewportSize.width !== sw || this._viewportSize.height !== sh) {
  7617. context.forceRefreshPrimitive = true;
  7618. this._viewportSize.width = sw;
  7619. this._viewportSize.height = sh;
  7620. }
  7621. if ((rd._primDirtyList.length > 0) || context.forceRefreshPrimitive) {
  7622. // If the group is cached, set the dirty flag to true because of the incoming changes
  7623. this._cacheGroupDirty = this._isCachedGroup;
  7624. rd._primNewDirtyList.splice(0);
  7625. // If it's a force refresh, prepare all the children
  7626. if (context.forceRefreshPrimitive) {
  7627. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7628. var p = _a[_i];
  7629. p._prepareRender(context);
  7630. }
  7631. }
  7632. else {
  7633. // Each primitive that changed at least once was added into the primDirtyList, we have to sort this level using
  7634. // the hierarchyDepth in order to prepare primitives from top to bottom
  7635. if (!sortedDirtyList) {
  7636. sortedDirtyList = rd._primDirtyList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  7637. }
  7638. sortedDirtyList.forEach(function (p) {
  7639. // We need to check if prepare is needed because even if the primitive is in the dirtyList, its parent primitive may also have been modified, then prepared, then recurse on its children primitives (this one for instance) if the changes where impacting them.
  7640. // For instance: a Rect's position change, the position of its children primitives will also change so a prepare will be call on them. If a child was in the dirtyList we will avoid a second prepare by making this check.
  7641. if (!p.isDisposed && p._needPrepare()) {
  7642. p._prepareRender(context);
  7643. }
  7644. });
  7645. }
  7646. // Everything is updated, clear the dirty list
  7647. rd._primDirtyList.forEach(function (p) {
  7648. if (rd._primNewDirtyList.indexOf(p) === -1) {
  7649. p._resetPropertiesDirty();
  7650. }
  7651. else {
  7652. p._setFlags(BABYLON.SmartPropertyPrim.flagNeedRefresh);
  7653. }
  7654. });
  7655. rd._primDirtyList.splice(0);
  7656. rd._primDirtyList = rd._primDirtyList.concat(rd._primNewDirtyList);
  7657. }
  7658. // A renderable group has a list of direct children that are also renderable groups, we recurse on them to also prepare them
  7659. rd._childrenRenderableGroups.forEach(function (g) {
  7660. g._prepareGroupRender(context);
  7661. });
  7662. };
  7663. Group2D.prototype._groupRender = function () {
  7664. var _this = this;
  7665. var engine = this.owner.engine;
  7666. var failedCount = 0;
  7667. // First recurse to children render group to render them (in their cache or on screen)
  7668. for (var _i = 0, _a = this._renderableData._childrenRenderableGroups; _i < _a.length; _i++) {
  7669. var childGroup = _a[_i];
  7670. childGroup._groupRender();
  7671. }
  7672. // Render the primitives if needed: either if we don't cache the content or if the content is cached but has changed
  7673. if (!this.isCachedGroup || this._cacheGroupDirty) {
  7674. this.owner._addGroupRenderCount(1);
  7675. if (this.isCachedGroup) {
  7676. this._bindCacheTarget();
  7677. }
  7678. else {
  7679. var curVP = engine.setDirectViewport(this._viewportPosition.x, this._viewportPosition.y, this._viewportSize.width, this._viewportSize.height);
  7680. }
  7681. var curAlphaTest = engine.getAlphaTesting() === true;
  7682. var curDepthWrite = engine.getDepthWrite() === true;
  7683. // ===================================================================
  7684. // First pass, update the InstancedArray and render Opaque primitives
  7685. // Disable Alpha Testing, Enable Depth Write
  7686. engine.setAlphaTesting(false);
  7687. engine.setDepthWrite(true);
  7688. // For each different model of primitive to render
  7689. var context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeOpaque);
  7690. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  7691. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  7692. var renderCount = _this._prepareContext(engine, context_1, v);
  7693. // If null is returned, there's no opaque data to render
  7694. if (renderCount === null) {
  7695. return;
  7696. }
  7697. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  7698. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  7699. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  7700. var renderFailed = !v.modelRenderCache.render(v, context_1);
  7701. // Update dirty flag/related
  7702. v.opaqueDirty = renderFailed;
  7703. failedCount += renderFailed ? 1 : 0;
  7704. }
  7705. });
  7706. // =======================================================================
  7707. // Second pass, update the InstancedArray and render AlphaTest primitives
  7708. // Enable Alpha Testing, Enable Depth Write
  7709. engine.setAlphaTesting(true);
  7710. engine.setDepthWrite(true);
  7711. // For each different model of primitive to render
  7712. context_1 = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeAlphaTest);
  7713. this._renderableData._renderGroupInstancesInfo.forEach(function (k, v) {
  7714. // Prepare the context object, update the WebGL Instanced Array buffer if needed
  7715. var renderCount = _this._prepareContext(engine, context_1, v);
  7716. // If null is returned, there's no opaque data to render
  7717. if (renderCount === null) {
  7718. return;
  7719. }
  7720. // Submit render only if we have something to render (everything may be hidden and the floatarray empty)
  7721. if (!_this.owner.supportInstancedArray || renderCount > 0) {
  7722. // render all the instances of this model, if the render method returns true then our instances are no longer dirty
  7723. var renderFailed = !v.modelRenderCache.render(v, context_1);
  7724. // Update dirty flag/related
  7725. v.opaqueDirty = renderFailed;
  7726. failedCount += renderFailed ? 1 : 0;
  7727. }
  7728. });
  7729. // =======================================================================
  7730. // Third pass, transparent primitive rendering
  7731. // Enable Alpha Testing, Disable Depth Write
  7732. engine.setAlphaTesting(true);
  7733. engine.setDepthWrite(false);
  7734. // First Check if the transparent List change so we can update the TransparentSegment and PartData (sort if needed)
  7735. if (this._renderableData._transparentListChanged) {
  7736. this._updateTransparentData();
  7737. }
  7738. // From this point on we have up to date data to render, so let's go
  7739. failedCount += this._renderTransparentData();
  7740. // =======================================================================
  7741. // Unbind target/restore viewport setting, clear dirty flag, and quit
  7742. // The group's content is no longer dirty
  7743. this._cacheGroupDirty = failedCount !== 0;
  7744. if (this.isCachedGroup) {
  7745. this._unbindCacheTarget();
  7746. }
  7747. else {
  7748. if (curVP) {
  7749. engine.setViewport(curVP);
  7750. }
  7751. }
  7752. // Restore saved states
  7753. engine.setAlphaTesting(curAlphaTest);
  7754. engine.setDepthWrite(curDepthWrite);
  7755. }
  7756. };
  7757. Group2D.prototype._setCacheGroupDirty = function () {
  7758. this._cacheGroupDirty = true;
  7759. };
  7760. Group2D.prototype._updateTransparentData = function () {
  7761. this.owner._addUpdateTransparentDataCount(1);
  7762. var rd = this._renderableData;
  7763. // Sort all the primitive from their depth, max (bottom) to min (top)
  7764. rd._transparentPrimitives.sort(function (a, b) { return b._primitive.actualZOffset - a._primitive.actualZOffset; });
  7765. var checkAndAddPrimInSegment = function (seg, tpiI) {
  7766. var tpi = rd._transparentPrimitives[tpiI];
  7767. // Fast rejection: if gii are different
  7768. if (seg.groupInsanceInfo !== tpi._groupInstanceInfo) {
  7769. return false;
  7770. }
  7771. //let tpiZ = tpi._primitive.actualZOffset;
  7772. // We've made it so far, the tpi can be part of the segment, add it
  7773. tpi._transparentSegment = seg;
  7774. tpi._primitive._updateTransparentSegmentIndices(seg);
  7775. return true;
  7776. };
  7777. // Free the existing TransparentSegments
  7778. for (var _i = 0, _a = rd._transparentSegments; _i < _a.length; _i++) {
  7779. var ts = _a[_i];
  7780. ts.dispose(this.owner.engine);
  7781. }
  7782. rd._transparentSegments.splice(0);
  7783. var prevSeg = null;
  7784. for (var tpiI = 0; tpiI < rd._transparentPrimitives.length; tpiI++) {
  7785. var tpi = rd._transparentPrimitives[tpiI];
  7786. // Check if the Data in which the primitive is stored is not sorted properly
  7787. if (tpi._groupInstanceInfo.transparentOrderDirty) {
  7788. tpi._groupInstanceInfo.sortTransparentData();
  7789. }
  7790. // Reset the segment, we have to create/rebuild it
  7791. tpi._transparentSegment = null;
  7792. // If there's a previous valid segment, check if this prim can be part of it
  7793. if (prevSeg) {
  7794. checkAndAddPrimInSegment(prevSeg, tpiI);
  7795. }
  7796. // If we couldn't insert in the adjacent segments, he have to create one
  7797. if (!tpi._transparentSegment) {
  7798. var ts = new BABYLON.TransparentSegment();
  7799. ts.groupInsanceInfo = tpi._groupInstanceInfo;
  7800. var prim = tpi._primitive;
  7801. ts.startZ = prim.actualZOffset;
  7802. prim._updateTransparentSegmentIndices(ts);
  7803. ts.endZ = ts.startZ;
  7804. tpi._transparentSegment = ts;
  7805. rd._transparentSegments.push(ts);
  7806. }
  7807. // Update prevSeg
  7808. prevSeg = tpi._transparentSegment;
  7809. }
  7810. //rd._firstChangedPrim = null;
  7811. rd._transparentListChanged = false;
  7812. };
  7813. Group2D.prototype._renderTransparentData = function () {
  7814. var failedCount = 0;
  7815. var context = new BABYLON.Render2DContext(BABYLON.Render2DContext.RenderModeTransparent);
  7816. var rd = this._renderableData;
  7817. var useInstanced = this.owner.supportInstancedArray;
  7818. var length = rd._transparentSegments.length;
  7819. for (var i = 0; i < length; i++) {
  7820. context.instancedBuffers = null;
  7821. var ts = rd._transparentSegments[i];
  7822. var gii = ts.groupInsanceInfo;
  7823. var mrc = gii.modelRenderCache;
  7824. var engine = this.owner.engine;
  7825. var count = ts.endDataIndex - ts.startDataIndex;
  7826. // Use Instanced Array if it's supported and if there's at least 5 prims to draw.
  7827. // We don't want to create an Instanced Buffer for less that 5 prims
  7828. if (useInstanced && count >= 5) {
  7829. if (!ts.partBuffers) {
  7830. var buffers = new Array();
  7831. for (var j = 0; j < gii.transparentData.length; j++) {
  7832. var gitd = gii.transparentData[j];
  7833. var dfa = gitd._partData;
  7834. var data = dfa.pack();
  7835. var stride = dfa.stride;
  7836. var neededSize = count * stride * 4;
  7837. var buffer = engine.createInstancesBuffer(neededSize); // Create + bind
  7838. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  7839. engine.updateArrayBuffer(segData);
  7840. buffers.push(buffer);
  7841. }
  7842. ts.partBuffers = buffers;
  7843. }
  7844. else if (gii.transparentDirty) {
  7845. for (var j = 0; j < gii.transparentData.length; j++) {
  7846. var gitd = gii.transparentData[j];
  7847. var dfa = gitd._partData;
  7848. var data = dfa.pack();
  7849. var stride = dfa.stride;
  7850. var buffer = ts.partBuffers[j];
  7851. var segData = data.subarray(ts.startDataIndex * stride, ts.endDataIndex * stride);
  7852. engine.bindArrayBuffer(buffer);
  7853. engine.updateArrayBuffer(segData);
  7854. }
  7855. }
  7856. context.useInstancing = true;
  7857. context.instancesCount = count;
  7858. context.instancedBuffers = ts.partBuffers;
  7859. context.groupInfoPartData = gii.transparentData;
  7860. var renderFailed = !mrc.render(gii, context);
  7861. failedCount += renderFailed ? 1 : 0;
  7862. }
  7863. else {
  7864. context.useInstancing = false;
  7865. context.partDataStartIndex = ts.startDataIndex;
  7866. context.partDataEndIndex = ts.endDataIndex;
  7867. context.groupInfoPartData = gii.transparentData;
  7868. var renderFailed = !mrc.render(gii, context);
  7869. failedCount += renderFailed ? 1 : 0;
  7870. }
  7871. }
  7872. return failedCount;
  7873. };
  7874. Group2D.prototype._prepareContext = function (engine, context, gii) {
  7875. var gipd = null;
  7876. var setDirty;
  7877. var getDirty;
  7878. // Render Mode specifics
  7879. switch (context.renderMode) {
  7880. case BABYLON.Render2DContext.RenderModeOpaque:
  7881. {
  7882. if (!gii.hasOpaqueData) {
  7883. return null;
  7884. }
  7885. setDirty = function (dirty) { gii.opaqueDirty = dirty; };
  7886. getDirty = function () { return gii.opaqueDirty; };
  7887. context.groupInfoPartData = gii.opaqueData;
  7888. gipd = gii.opaqueData;
  7889. break;
  7890. }
  7891. case BABYLON.Render2DContext.RenderModeAlphaTest:
  7892. {
  7893. if (!gii.hasAlphaTestData) {
  7894. return null;
  7895. }
  7896. setDirty = function (dirty) { gii.alphaTestDirty = dirty; };
  7897. getDirty = function () { return gii.alphaTestDirty; };
  7898. context.groupInfoPartData = gii.alphaTestData;
  7899. gipd = gii.alphaTestData;
  7900. break;
  7901. }
  7902. default:
  7903. throw new Error("_prepareContext is only for opaque or alphaTest");
  7904. }
  7905. var renderCount = 0;
  7906. // This part will pack the dynamicfloatarray and update the instanced array WebGLBufffer
  7907. // Skip it if instanced arrays are not supported
  7908. if (this.owner.supportInstancedArray) {
  7909. // Flag for instancing
  7910. context.useInstancing = true;
  7911. // Make sure all the WebGLBuffers of the Instanced Array are created/up to date for the parts to render.
  7912. for (var i = 0; i < gipd.length; i++) {
  7913. var pid = gipd[i];
  7914. // If the instances of the model was changed, pack the data
  7915. var array = pid._partData;
  7916. var instanceData_1 = array.pack();
  7917. renderCount += array.usedElementCount;
  7918. // Compute the size the instance buffer should have
  7919. var neededSize = array.usedElementCount * array.stride * 4;
  7920. // Check if we have to (re)create the instancesBuffer because there's none or the size is too small
  7921. if (!pid._partBuffer || (pid._partBufferSize < neededSize)) {
  7922. if (pid._partBuffer) {
  7923. engine.deleteInstancesBuffer(pid._partBuffer);
  7924. }
  7925. pid._partBuffer = engine.createInstancesBuffer(neededSize); // Create + bind
  7926. pid._partBufferSize = neededSize;
  7927. setDirty(false);
  7928. // Update the WebGL buffer to match the new content of the instances data
  7929. engine.updateArrayBuffer(instanceData_1);
  7930. }
  7931. else if (getDirty()) {
  7932. // Update the WebGL buffer to match the new content of the instances data
  7933. engine.bindArrayBuffer(pid._partBuffer);
  7934. engine.updateArrayBuffer(instanceData_1);
  7935. }
  7936. }
  7937. setDirty(false);
  7938. }
  7939. else {
  7940. context.partDataStartIndex = 0;
  7941. // Find the first valid object to get the count
  7942. if (context.groupInfoPartData.length > 0) {
  7943. var i = 0;
  7944. while (!context.groupInfoPartData[i]) {
  7945. i++;
  7946. }
  7947. context.partDataEndIndex = context.groupInfoPartData[i]._partData.usedElementCount;
  7948. }
  7949. }
  7950. return renderCount;
  7951. };
  7952. Group2D.prototype._setRenderingScale = function (scale) {
  7953. if (this._renderableData._renderingScale === scale) {
  7954. return;
  7955. }
  7956. this._renderableData._renderingScale = scale;
  7957. };
  7958. Group2D.prototype._bindCacheTarget = function () {
  7959. var curWidth;
  7960. var curHeight;
  7961. var rd = this._renderableData;
  7962. var rs = rd._renderingScale;
  7963. var noResizeScale = rd._noResizeOnScale;
  7964. var isCanvas = this.parent == null;
  7965. var scale;
  7966. if (noResizeScale) {
  7967. scale = isCanvas ? Group2D._uV : this.parent.actualScale;
  7968. }
  7969. else {
  7970. scale = this.actualScale;
  7971. }
  7972. Group2D._s.width = Math.ceil(this.actualSize.width * scale.x * rs);
  7973. Group2D._s.height = Math.ceil(this.actualSize.height * scale.y * rs);
  7974. var sizeChanged = !Group2D._s.equals(rd._cacheSize);
  7975. if (rd._cacheNode) {
  7976. var size = rd._cacheNode.contentSize;
  7977. // Check if we have to deallocate because the size is too small
  7978. if ((size.width < Group2D._s.width) || (size.height < Group2D._s.height)) {
  7979. // For Screen space: over-provisioning of 7% more to avoid frequent resizing for few pixels...
  7980. // For World space: no over-provisioning
  7981. var overprovisioning = this.owner.isScreenSpace ? 1.07 : 1;
  7982. curWidth = Math.floor(Group2D._s.width * overprovisioning);
  7983. curHeight = Math.floor(Group2D._s.height * overprovisioning);
  7984. //console.log(`[${this._globalTransformProcessStep}] Resize group ${this.id}, width: ${curWidth}, height: ${curHeight}`);
  7985. rd._cacheTexture.freeRect(rd._cacheNode);
  7986. rd._cacheNode = null;
  7987. }
  7988. }
  7989. if (!rd._cacheNode) {
  7990. // Check if we have to allocate a rendering zone in the global cache texture
  7991. var res = this.owner._allocateGroupCache(this, this.parent && this.parent.renderGroup, curWidth ? new BABYLON.Size(curWidth, curHeight) : null, rd._useMipMap, rd._anisotropicLevel);
  7992. rd._cacheNode = res.node;
  7993. rd._cacheTexture = res.texture;
  7994. rd._cacheRenderSprite = res.sprite;
  7995. sizeChanged = true;
  7996. }
  7997. if (sizeChanged) {
  7998. rd._cacheSize.copyFrom(Group2D._s);
  7999. rd._cacheNodeUVs = rd._cacheNode.getUVsForCustomSize(rd._cacheSize);
  8000. if (rd._cacheNodeUVsChangedObservable && rd._cacheNodeUVsChangedObservable.hasObservers()) {
  8001. rd._cacheNodeUVsChangedObservable.notifyObservers(rd._cacheNodeUVs);
  8002. }
  8003. this._setFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  8004. }
  8005. var n = rd._cacheNode;
  8006. rd._cacheTexture.bindTextureForPosSize(n.pos, Group2D._s, true);
  8007. };
  8008. Group2D.prototype._unbindCacheTarget = function () {
  8009. if (this._renderableData._cacheTexture) {
  8010. this._renderableData._cacheTexture.unbindTexture();
  8011. }
  8012. };
  8013. Group2D.prototype.handleGroupChanged = function (prop) {
  8014. // This method is only for cachedGroup
  8015. var rd = this._renderableData;
  8016. if (!rd) {
  8017. return;
  8018. }
  8019. var cachedSprite = rd._cacheRenderSprite;
  8020. if (!this.isCachedGroup || !cachedSprite) {
  8021. return;
  8022. }
  8023. // For now we only support these property changes
  8024. // TODO: add more! :)
  8025. if (prop.id === BABYLON.Prim2DBase.actualPositionProperty.id) {
  8026. cachedSprite.actualPosition = this.actualPosition.clone();
  8027. if (cachedSprite.position != null) {
  8028. cachedSprite.position = cachedSprite.actualPosition.clone();
  8029. }
  8030. }
  8031. else if (prop.id === BABYLON.Prim2DBase.rotationProperty.id) {
  8032. cachedSprite.rotation = this.rotation;
  8033. }
  8034. else if (prop.id === BABYLON.Prim2DBase.scaleProperty.id) {
  8035. cachedSprite.scale = this.scale;
  8036. }
  8037. else if (prop.id === BABYLON.Prim2DBase.originProperty.id) {
  8038. cachedSprite.origin = this.origin.clone();
  8039. }
  8040. else if (prop.id === Group2D.actualSizeProperty.id) {
  8041. cachedSprite.size = this.actualSize.clone();
  8042. }
  8043. };
  8044. Group2D.prototype.detectGroupStates = function () {
  8045. var isCanvas = this instanceof BABYLON.Canvas2D;
  8046. var canvasStrat = this.owner.cachingStrategy;
  8047. // In Don't Cache mode, only the canvas is renderable, all the other groups are logical. There are not a single cached group.
  8048. if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE) {
  8049. this._isRenderableGroup = isCanvas;
  8050. this._isCachedGroup = false;
  8051. }
  8052. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_CANVAS) {
  8053. if (isCanvas) {
  8054. this._isRenderableGroup = true;
  8055. this._isCachedGroup = true;
  8056. }
  8057. else {
  8058. this._isRenderableGroup = this.id === "__cachedCanvasGroup__";
  8059. this._isCachedGroup = false;
  8060. }
  8061. }
  8062. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  8063. if (isCanvas) {
  8064. this._isRenderableGroup = true;
  8065. this._isCachedGroup = false;
  8066. }
  8067. else {
  8068. if (this.hierarchyDepth === 1) {
  8069. this._isRenderableGroup = true;
  8070. this._isCachedGroup = true;
  8071. }
  8072. else {
  8073. this._isRenderableGroup = false;
  8074. this._isCachedGroup = false;
  8075. }
  8076. }
  8077. }
  8078. else if (canvasStrat === BABYLON.Canvas2D.CACHESTRATEGY_ALLGROUPS) {
  8079. var gcb = this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK;
  8080. if ((gcb === Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE) || (gcb === Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP)) {
  8081. this._isRenderableGroup = gcb === Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE;
  8082. this._isCachedGroup = false;
  8083. }
  8084. if (gcb === Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY) {
  8085. this._isRenderableGroup = true;
  8086. this._isCachedGroup = true;
  8087. }
  8088. }
  8089. if (this._isRenderableGroup) {
  8090. // Yes, we do need that check, trust me, unfortunately we can call _detectGroupStates many time on the same object...
  8091. if (!this._renderableData) {
  8092. this._renderableData = new RenderableGroupData();
  8093. }
  8094. }
  8095. // If the group is tagged as renderable we add it to the renderable tree
  8096. if (this._isCachedGroup) {
  8097. this._renderableData._noResizeOnScale = (this.cacheBehavior & Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE) !== 0;
  8098. var cur = this.parent;
  8099. while (cur) {
  8100. if (cur instanceof Group2D && cur._isRenderableGroup) {
  8101. if (cur._renderableData._childrenRenderableGroups.indexOf(this) === -1) {
  8102. cur._renderableData._childrenRenderableGroups.push(this);
  8103. }
  8104. break;
  8105. }
  8106. cur = cur.parent;
  8107. }
  8108. }
  8109. };
  8110. Group2D.GROUP2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
  8111. /**
  8112. * Default behavior, the group will use the caching strategy defined at the Canvas Level
  8113. */
  8114. Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY = 0;
  8115. /**
  8116. * When used, this group's content won't be cached, no matter which strategy used.
  8117. * If the group is part of a WorldSpace Canvas, its content will be drawn in the Canvas cache bitmap.
  8118. */
  8119. Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE = 1;
  8120. /**
  8121. * When used, the group's content will be cached in the nearest cached parent group/canvas
  8122. */
  8123. Group2D.GROUPCACHEBEHAVIOR_CACHEINPARENTGROUP = 2;
  8124. /**
  8125. * You can specify this behavior to any cached Group2D to indicate that you don't want the cached content to be resized when the Group's actualScale is changing. It will draw the content stretched or shrink which is faster than a resize. This setting is obviously for performance consideration, don't use it if you want the best rendering quality
  8126. */
  8127. Group2D.GROUPCACHEBEHAVIOR_NORESIZEONSCALE = 0x100;
  8128. Group2D.GROUPCACHEBEHAVIOR_OPTIONMASK = 0xFF;
  8129. Group2D._uV = new BABYLON.Vector2(1, 1);
  8130. Group2D._s = BABYLON.Size.Zero();
  8131. __decorate([
  8132. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 1, function (pi) { return Group2D.sizeProperty = pi; }, false, true)
  8133. ], Group2D.prototype, "size", null);
  8134. __decorate([
  8135. BABYLON.instanceLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 2, function (pi) { return Group2D.actualSizeProperty = pi; })
  8136. ], Group2D.prototype, "actualSize", null);
  8137. Group2D = __decorate([
  8138. BABYLON.className("Group2D", "BABYLON")
  8139. ], Group2D);
  8140. return Group2D;
  8141. }(BABYLON.Prim2DBase));
  8142. BABYLON.Group2D = Group2D;
  8143. var RenderableGroupData = (function () {
  8144. function RenderableGroupData() {
  8145. this._primDirtyList = new Array();
  8146. this._primNewDirtyList = new Array();
  8147. this._childrenRenderableGroups = new Array();
  8148. this._renderGroupInstancesInfo = new BABYLON.StringDictionary();
  8149. this._transparentPrimitives = new Array();
  8150. this._transparentSegments = new Array();
  8151. this._transparentListChanged = false;
  8152. this._cacheNode = null;
  8153. this._cacheTexture = null;
  8154. this._cacheRenderSprite = null;
  8155. this._renderingScale = 1;
  8156. this._cacheNodeUVs = null;
  8157. this._cacheNodeUVsChangedObservable = null;
  8158. this._cacheSize = BABYLON.Size.Zero();
  8159. this._useMipMap = false;
  8160. this._anisotropicLevel = 1;
  8161. this._noResizeOnScale = false;
  8162. }
  8163. RenderableGroupData.prototype.dispose = function (owner) {
  8164. var engine = owner.engine;
  8165. if (this._cacheRenderSprite) {
  8166. this._cacheRenderSprite.dispose();
  8167. this._cacheRenderSprite = null;
  8168. }
  8169. if (this._cacheTexture && this._cacheNode) {
  8170. this._cacheTexture.freeRect(this._cacheNode);
  8171. this._cacheTexture = null;
  8172. this._cacheNode = null;
  8173. }
  8174. if (this._primDirtyList) {
  8175. this._primDirtyList.splice(0);
  8176. this._primDirtyList = null;
  8177. }
  8178. if (this._renderGroupInstancesInfo) {
  8179. this._renderGroupInstancesInfo.forEach(function (k, v) {
  8180. v.dispose();
  8181. });
  8182. this._renderGroupInstancesInfo = null;
  8183. }
  8184. if (this._cacheNodeUVsChangedObservable) {
  8185. this._cacheNodeUVsChangedObservable.clear();
  8186. this._cacheNodeUVsChangedObservable = null;
  8187. }
  8188. if (this._transparentSegments) {
  8189. for (var _i = 0, _a = this._transparentSegments; _i < _a.length; _i++) {
  8190. var ts = _a[_i];
  8191. ts.dispose(engine);
  8192. }
  8193. this._transparentSegments.splice(0);
  8194. this._transparentSegments = null;
  8195. }
  8196. };
  8197. RenderableGroupData.prototype.addNewTransparentPrimitiveInfo = function (prim, gii) {
  8198. var tpi = new TransparentPrimitiveInfo();
  8199. tpi._primitive = prim;
  8200. tpi._groupInstanceInfo = gii;
  8201. tpi._transparentSegment = null;
  8202. this._transparentPrimitives.push(tpi);
  8203. this._transparentListChanged = true;
  8204. return tpi;
  8205. };
  8206. RenderableGroupData.prototype.removeTransparentPrimitiveInfo = function (tpi) {
  8207. var index = this._transparentPrimitives.indexOf(tpi);
  8208. if (index !== -1) {
  8209. this._transparentPrimitives.splice(index, 1);
  8210. this._transparentListChanged = true;
  8211. }
  8212. };
  8213. RenderableGroupData.prototype.transparentPrimitiveZChanged = function (tpi) {
  8214. this._transparentListChanged = true;
  8215. //this.updateSmallestZChangedPrim(tpi);
  8216. };
  8217. return RenderableGroupData;
  8218. }());
  8219. BABYLON.RenderableGroupData = RenderableGroupData;
  8220. var TransparentPrimitiveInfo = (function () {
  8221. function TransparentPrimitiveInfo() {
  8222. }
  8223. return TransparentPrimitiveInfo;
  8224. }());
  8225. BABYLON.TransparentPrimitiveInfo = TransparentPrimitiveInfo;
  8226. })(BABYLON || (BABYLON = {}));
  8227. var BABYLON;
  8228. (function (BABYLON) {
  8229. var Rectangle2DRenderCache = (function (_super) {
  8230. __extends(Rectangle2DRenderCache, _super);
  8231. function Rectangle2DRenderCache(engine, modelKey) {
  8232. _super.call(this, engine, modelKey);
  8233. this.effectsReady = false;
  8234. this.fillVB = null;
  8235. this.fillIB = null;
  8236. this.fillIndicesCount = 0;
  8237. this.instancingFillAttributes = null;
  8238. this.effectFill = null;
  8239. this.effectFillInstanced = null;
  8240. this.borderVB = null;
  8241. this.borderIB = null;
  8242. this.borderIndicesCount = 0;
  8243. this.instancingBorderAttributes = null;
  8244. this.effectBorder = null;
  8245. this.effectBorderInstanced = null;
  8246. }
  8247. Rectangle2DRenderCache.prototype.render = function (instanceInfo, context) {
  8248. // Do nothing if the shader is still loading/preparing
  8249. if (!this.effectsReady) {
  8250. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  8251. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  8252. return false;
  8253. }
  8254. this.effectsReady = true;
  8255. }
  8256. var canvas = instanceInfo.owner.owner;
  8257. var engine = canvas.engine;
  8258. var depthFunction = 0;
  8259. if (this.effectFill && this.effectBorder) {
  8260. depthFunction = engine.getDepthFunction();
  8261. engine.setDepthFunctionToLessOrEqual();
  8262. }
  8263. var curAlphaMode = engine.getAlphaMode();
  8264. if (this.effectFill) {
  8265. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  8266. var pid = context.groupInfoPartData[partIndex];
  8267. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8268. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8269. }
  8270. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  8271. engine.enableEffect(effect);
  8272. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  8273. if (context.useInstancing) {
  8274. if (!this.instancingFillAttributes) {
  8275. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  8276. }
  8277. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8278. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8279. canvas._addDrawCallCount(1, context.renderMode);
  8280. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  8281. engine.draw(true, 0, this.fillIndicesCount, count);
  8282. engine.unbindInstanceAttributes();
  8283. }
  8284. else {
  8285. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8286. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8287. this.setupUniforms(effect, partIndex, pid._partData, i);
  8288. engine.draw(true, 0, this.fillIndicesCount);
  8289. }
  8290. }
  8291. }
  8292. if (this.effectBorder) {
  8293. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  8294. var pid = context.groupInfoPartData[partIndex];
  8295. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8296. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8297. }
  8298. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  8299. engine.enableEffect(effect);
  8300. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  8301. if (context.useInstancing) {
  8302. if (!this.instancingBorderAttributes) {
  8303. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  8304. }
  8305. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8306. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8307. canvas._addDrawCallCount(1, context.renderMode);
  8308. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  8309. engine.draw(true, 0, this.borderIndicesCount, count);
  8310. engine.unbindInstanceAttributes();
  8311. }
  8312. else {
  8313. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8314. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8315. this.setupUniforms(effect, partIndex, pid._partData, i);
  8316. engine.draw(true, 0, this.borderIndicesCount);
  8317. }
  8318. }
  8319. }
  8320. engine.setAlphaMode(curAlphaMode, true);
  8321. if (this.effectFill && this.effectBorder) {
  8322. engine.setDepthFunction(depthFunction);
  8323. }
  8324. return true;
  8325. };
  8326. Rectangle2DRenderCache.prototype.dispose = function () {
  8327. if (!_super.prototype.dispose.call(this)) {
  8328. return false;
  8329. }
  8330. if (this.fillVB) {
  8331. this._engine._releaseBuffer(this.fillVB);
  8332. this.fillVB = null;
  8333. }
  8334. if (this.fillIB) {
  8335. this._engine._releaseBuffer(this.fillIB);
  8336. this.fillIB = null;
  8337. }
  8338. this.effectFill = null;
  8339. this.effectFillInstanced = null;
  8340. this.effectBorder = null;
  8341. this.effectBorderInstanced = null;
  8342. if (this.borderVB) {
  8343. this._engine._releaseBuffer(this.borderVB);
  8344. this.borderVB = null;
  8345. }
  8346. if (this.borderIB) {
  8347. this._engine._releaseBuffer(this.borderIB);
  8348. this.borderIB = null;
  8349. }
  8350. return true;
  8351. };
  8352. return Rectangle2DRenderCache;
  8353. }(BABYLON.ModelRenderCache));
  8354. BABYLON.Rectangle2DRenderCache = Rectangle2DRenderCache;
  8355. var Rectangle2DInstanceData = (function (_super) {
  8356. __extends(Rectangle2DInstanceData, _super);
  8357. function Rectangle2DInstanceData(partId) {
  8358. _super.call(this, partId, 1);
  8359. }
  8360. Object.defineProperty(Rectangle2DInstanceData.prototype, "properties", {
  8361. get: function () {
  8362. return null;
  8363. },
  8364. set: function (value) {
  8365. },
  8366. enumerable: true,
  8367. configurable: true
  8368. });
  8369. __decorate([
  8370. BABYLON.instanceData()
  8371. ], Rectangle2DInstanceData.prototype, "properties", null);
  8372. return Rectangle2DInstanceData;
  8373. }(BABYLON.Shape2DInstanceData));
  8374. BABYLON.Rectangle2DInstanceData = Rectangle2DInstanceData;
  8375. var Rectangle2D = (function (_super) {
  8376. __extends(Rectangle2D, _super);
  8377. /**
  8378. * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
  8379. * @param settings a combination of settings, possible ones are
  8380. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  8381. * - children: an array of direct children
  8382. * - id a text identifier, for information purpose
  8383. * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
  8384. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8385. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8386. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8387. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8388. * - zOrder: override the zOrder with the specified value
  8389. * - origin: define the normalized origin point location, default [0.5;0.5]
  8390. * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
  8391. * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
  8392. * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  8393. * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
  8394. * - borderThickness: the thickness of the drawn border, default is 1.
  8395. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  8396. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  8397. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  8398. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  8399. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8400. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8401. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8402. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8403. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8404. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8405. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8406. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8407. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8408. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8409. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8410. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8411. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8412. */
  8413. function Rectangle2D(settings) {
  8414. // Avoid checking every time if the object exists
  8415. if (settings == null) {
  8416. settings = {};
  8417. }
  8418. _super.call(this, settings);
  8419. if (settings.size != null) {
  8420. this.size = settings.size;
  8421. }
  8422. else if (settings.width || settings.height) {
  8423. var size = new BABYLON.Size(settings.width, settings.height);
  8424. this.size = size;
  8425. }
  8426. //let size = settings.size || (new Size((settings.width === null) ? null : (settings.width || 10), (settings.height === null) ? null : (settings.height || 10)));
  8427. var roundRadius = (settings.roundRadius == null) ? 0 : settings.roundRadius;
  8428. var borderThickness = (settings.borderThickness == null) ? 1 : settings.borderThickness;
  8429. //this.size = size;
  8430. this.roundRadius = roundRadius;
  8431. this.borderThickness = borderThickness;
  8432. }
  8433. Object.defineProperty(Rectangle2D.prototype, "actualSize", {
  8434. get: function () {
  8435. if (this._actualSize) {
  8436. return this._actualSize;
  8437. }
  8438. return this.size;
  8439. },
  8440. set: function (value) {
  8441. this._actualSize = value;
  8442. },
  8443. enumerable: true,
  8444. configurable: true
  8445. });
  8446. Object.defineProperty(Rectangle2D.prototype, "notRounded", {
  8447. get: function () {
  8448. return this._notRounded;
  8449. },
  8450. set: function (value) {
  8451. this._notRounded = value;
  8452. },
  8453. enumerable: true,
  8454. configurable: true
  8455. });
  8456. Object.defineProperty(Rectangle2D.prototype, "roundRadius", {
  8457. get: function () {
  8458. return this._roundRadius;
  8459. },
  8460. set: function (value) {
  8461. this._roundRadius = value;
  8462. this.notRounded = value === 0;
  8463. this._positioningDirty();
  8464. },
  8465. enumerable: true,
  8466. configurable: true
  8467. });
  8468. Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
  8469. // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
  8470. if (this.notRounded) {
  8471. return true;
  8472. }
  8473. // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
  8474. // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
  8475. // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
  8476. // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
  8477. var size = this.size;
  8478. Rectangle2D._i0.x = intersectInfo._localPickPosition.x;
  8479. Rectangle2D._i0.y = intersectInfo._localPickPosition.y;
  8480. var rr = this.roundRadius;
  8481. var rrs = rr * rr;
  8482. // Check if the point is in the bottom/left quarter area
  8483. Rectangle2D._i1.x = rr;
  8484. Rectangle2D._i1.y = rr;
  8485. if (Rectangle2D._i0.x <= Rectangle2D._i1.x && Rectangle2D._i0.y <= Rectangle2D._i1.y) {
  8486. // Compute the intersection point in the quarter local space
  8487. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8488. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8489. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8490. return Rectangle2D._i2.lengthSquared() <= rrs;
  8491. }
  8492. // Check if the point is in the top/left quarter area
  8493. Rectangle2D._i1.x = rr;
  8494. Rectangle2D._i1.y = size.height - rr;
  8495. if (Rectangle2D._i0.x <= Rectangle2D._i1.x && Rectangle2D._i0.y >= Rectangle2D._i1.y) {
  8496. // Compute the intersection point in the quarter local space
  8497. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8498. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8499. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8500. return Rectangle2D._i2.lengthSquared() <= rrs;
  8501. }
  8502. // Check if the point is in the top/right quarter area
  8503. Rectangle2D._i1.x = size.width - rr;
  8504. Rectangle2D._i1.y = size.height - rr;
  8505. if (Rectangle2D._i0.x >= Rectangle2D._i1.x && Rectangle2D._i0.y >= Rectangle2D._i1.y) {
  8506. // Compute the intersection point in the quarter local space
  8507. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8508. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8509. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8510. return Rectangle2D._i2.lengthSquared() <= rrs;
  8511. }
  8512. // Check if the point is in the bottom/right quarter area
  8513. Rectangle2D._i1.x = size.width - rr;
  8514. Rectangle2D._i1.y = rr;
  8515. if (Rectangle2D._i0.x >= Rectangle2D._i1.x && Rectangle2D._i0.y <= Rectangle2D._i1.y) {
  8516. // Compute the intersection point in the quarter local space
  8517. Rectangle2D._i2.x = Rectangle2D._i0.x - Rectangle2D._i1.x;
  8518. Rectangle2D._i2.y = Rectangle2D._i0.y - Rectangle2D._i1.y;
  8519. // It's a hit if the squared distance is less/equal to the squared radius of the round circle
  8520. return Rectangle2D._i2.lengthSquared() <= rrs;
  8521. }
  8522. // At any other locations the point is guarantied to be inside
  8523. return true;
  8524. };
  8525. Rectangle2D.prototype.updateLevelBoundingInfo = function () {
  8526. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  8527. };
  8528. Rectangle2D.prototype.createModelRenderCache = function (modelKey) {
  8529. var renderCache = new Rectangle2DRenderCache(this.owner.engine, modelKey);
  8530. return renderCache;
  8531. };
  8532. Rectangle2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8533. var renderCache = modelRenderCache;
  8534. var engine = this.owner.engine;
  8535. // Need to create WebGL resources for fill part?
  8536. if (this.fill) {
  8537. var vbSize = ((this.notRounded ? 1 : Rectangle2D.roundSubdivisions) * 4) + 1;
  8538. var vb = new Float32Array(vbSize);
  8539. for (var i = 0; i < vbSize; i++) {
  8540. vb[i] = i;
  8541. }
  8542. renderCache.fillVB = engine.createVertexBuffer(vb);
  8543. var triCount = vbSize - 1;
  8544. var ib = new Float32Array(triCount * 3);
  8545. for (var i = 0; i < triCount; i++) {
  8546. ib[i * 3 + 0] = 0;
  8547. ib[i * 3 + 2] = i + 1;
  8548. ib[i * 3 + 1] = i + 2;
  8549. }
  8550. ib[triCount * 3 - 2] = 1;
  8551. renderCache.fillIB = engine.createIndexBuffer(ib);
  8552. renderCache.fillIndicesCount = triCount * 3;
  8553. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  8554. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  8555. if (ei) {
  8556. renderCache.effectFillInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8557. }
  8558. // Get the non instanced version
  8559. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  8560. renderCache.effectFill = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8561. }
  8562. // Need to create WebGL resource for border part?
  8563. if (this.border) {
  8564. var vbSize = (this.notRounded ? 1 : Rectangle2D.roundSubdivisions) * 4 * 2;
  8565. var vb = new Float32Array(vbSize);
  8566. for (var i = 0; i < vbSize; i++) {
  8567. vb[i] = i;
  8568. }
  8569. renderCache.borderVB = engine.createVertexBuffer(vb);
  8570. var triCount = vbSize;
  8571. var rs = triCount / 2;
  8572. var ib = new Float32Array(triCount * 3);
  8573. for (var i = 0; i < rs; i++) {
  8574. var r0 = i;
  8575. var r1 = (i + 1) % rs;
  8576. ib[i * 6 + 0] = rs + r1;
  8577. ib[i * 6 + 1] = rs + r0;
  8578. ib[i * 6 + 2] = r0;
  8579. ib[i * 6 + 3] = r1;
  8580. ib[i * 6 + 4] = rs + r1;
  8581. ib[i * 6 + 5] = r0;
  8582. }
  8583. renderCache.borderIB = engine.createIndexBuffer(ib);
  8584. renderCache.borderIndicesCount = triCount * 3;
  8585. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  8586. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  8587. if (ei) {
  8588. renderCache.effectBorderInstanced = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8589. }
  8590. // Get the non instanced version
  8591. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  8592. renderCache.effectBorder = engine.createEffect("rect2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8593. }
  8594. return renderCache;
  8595. };
  8596. // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
  8597. Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  8598. // Fall back to default implementation if there's no round Radius
  8599. if (this._notRounded) {
  8600. _super.prototype._getInitialContentAreaToRef.call(this, primSize, initialContentPosition, initialContentArea);
  8601. }
  8602. else {
  8603. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  8604. initialContentPosition.x = initialContentPosition.y = rr;
  8605. initialContentArea.width = Math.max(0, primSize.width - (rr * 2));
  8606. initialContentArea.height = Math.max(0, primSize.height - (rr * 2));
  8607. }
  8608. };
  8609. Rectangle2D.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  8610. // Fall back to default implementation if there's no round Radius
  8611. if (this._notRounded) {
  8612. _super.prototype._getActualSizeFromContentToRef.call(this, primSize, newPrimSize);
  8613. }
  8614. else {
  8615. var rr = Math.round((this.roundRadius - (this.roundRadius / Math.sqrt(2))) * 1.3);
  8616. newPrimSize.copyFrom(primSize);
  8617. newPrimSize.width += rr * 2;
  8618. newPrimSize.height += rr * 2;
  8619. }
  8620. };
  8621. Rectangle2D.prototype.createInstanceDataParts = function () {
  8622. var res = new Array();
  8623. if (this.border) {
  8624. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  8625. }
  8626. if (this.fill) {
  8627. res.push(new Rectangle2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  8628. }
  8629. return res;
  8630. };
  8631. Rectangle2D.prototype.refreshInstanceDataPart = function (part) {
  8632. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  8633. return false;
  8634. }
  8635. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  8636. var d = part;
  8637. var size = this.actualSize;
  8638. var s = this.actualScale;
  8639. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  8640. }
  8641. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  8642. var d = part;
  8643. var size = this.actualSize;
  8644. var s = this.actualScale;
  8645. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.roundRadius || 0);
  8646. }
  8647. return true;
  8648. };
  8649. Rectangle2D._i0 = BABYLON.Vector2.Zero();
  8650. Rectangle2D._i1 = BABYLON.Vector2.Zero();
  8651. Rectangle2D._i2 = BABYLON.Vector2.Zero();
  8652. Rectangle2D.roundSubdivisions = 16;
  8653. __decorate([
  8654. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Rectangle2D.actualSizeProperty = pi; }, false, true)
  8655. ], Rectangle2D.prototype, "actualSize", null);
  8656. __decorate([
  8657. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Rectangle2D.notRoundedProperty = pi; })
  8658. ], Rectangle2D.prototype, "notRounded", null);
  8659. __decorate([
  8660. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Rectangle2D.roundRadiusProperty = pi; })
  8661. ], Rectangle2D.prototype, "roundRadius", null);
  8662. Rectangle2D = __decorate([
  8663. BABYLON.className("Rectangle2D", "BABYLON")
  8664. ], Rectangle2D);
  8665. return Rectangle2D;
  8666. }(BABYLON.Shape2D));
  8667. BABYLON.Rectangle2D = Rectangle2D;
  8668. })(BABYLON || (BABYLON = {}));
  8669. var BABYLON;
  8670. (function (BABYLON) {
  8671. var Ellipse2DRenderCache = (function (_super) {
  8672. __extends(Ellipse2DRenderCache, _super);
  8673. function Ellipse2DRenderCache(engine, modelKey) {
  8674. _super.call(this, engine, modelKey);
  8675. this.effectsReady = false;
  8676. this.fillVB = null;
  8677. this.fillIB = null;
  8678. this.fillIndicesCount = 0;
  8679. this.instancingFillAttributes = null;
  8680. this.effectFillInstanced = null;
  8681. this.effectFill = null;
  8682. this.borderVB = null;
  8683. this.borderIB = null;
  8684. this.borderIndicesCount = 0;
  8685. this.instancingBorderAttributes = null;
  8686. this.effectBorderInstanced = null;
  8687. this.effectBorder = null;
  8688. }
  8689. Ellipse2DRenderCache.prototype.render = function (instanceInfo, context) {
  8690. // Do nothing if the shader is still loading/preparing
  8691. if (!this.effectsReady) {
  8692. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  8693. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  8694. return false;
  8695. }
  8696. this.effectsReady = true;
  8697. }
  8698. var canvas = instanceInfo.owner.owner;
  8699. var engine = canvas.engine;
  8700. var depthFunction = 0;
  8701. if (this.effectFill && this.effectBorder) {
  8702. depthFunction = engine.getDepthFunction();
  8703. engine.setDepthFunctionToLessOrEqual();
  8704. }
  8705. var curAlphaMode = engine.getAlphaMode();
  8706. if (this.effectFill) {
  8707. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  8708. var pid = context.groupInfoPartData[partIndex];
  8709. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8710. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8711. }
  8712. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  8713. engine.enableEffect(effect);
  8714. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [1], 4, effect);
  8715. if (context.useInstancing) {
  8716. if (!this.instancingFillAttributes) {
  8717. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  8718. }
  8719. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8720. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8721. canvas._addDrawCallCount(1, context.renderMode);
  8722. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  8723. engine.draw(true, 0, this.fillIndicesCount, count);
  8724. engine.unbindInstanceAttributes();
  8725. }
  8726. else {
  8727. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8728. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8729. this.setupUniforms(effect, partIndex, pid._partData, i);
  8730. engine.draw(true, 0, this.fillIndicesCount);
  8731. }
  8732. }
  8733. }
  8734. if (this.effectBorder) {
  8735. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  8736. var pid = context.groupInfoPartData[partIndex];
  8737. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  8738. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  8739. }
  8740. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  8741. engine.enableEffect(effect);
  8742. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [1], 4, effect);
  8743. if (context.useInstancing) {
  8744. if (!this.instancingBorderAttributes) {
  8745. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  8746. }
  8747. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  8748. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  8749. canvas._addDrawCallCount(1, context.renderMode);
  8750. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  8751. engine.draw(true, 0, this.borderIndicesCount, count);
  8752. engine.unbindInstanceAttributes();
  8753. }
  8754. else {
  8755. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  8756. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  8757. this.setupUniforms(effect, partIndex, pid._partData, i);
  8758. engine.draw(true, 0, this.borderIndicesCount);
  8759. }
  8760. }
  8761. }
  8762. engine.setAlphaMode(curAlphaMode, true);
  8763. if (this.effectFill && this.effectBorder) {
  8764. engine.setDepthFunction(depthFunction);
  8765. }
  8766. return true;
  8767. };
  8768. Ellipse2DRenderCache.prototype.dispose = function () {
  8769. if (!_super.prototype.dispose.call(this)) {
  8770. return false;
  8771. }
  8772. if (this.fillVB) {
  8773. this._engine._releaseBuffer(this.fillVB);
  8774. this.fillVB = null;
  8775. }
  8776. if (this.fillIB) {
  8777. this._engine._releaseBuffer(this.fillIB);
  8778. this.fillIB = null;
  8779. }
  8780. this.effectFill = null;
  8781. this.effectFillInstanced = null;
  8782. this.effectBorder = null;
  8783. this.effectBorderInstanced = null;
  8784. if (this.borderVB) {
  8785. this._engine._releaseBuffer(this.borderVB);
  8786. this.borderVB = null;
  8787. }
  8788. if (this.borderIB) {
  8789. this._engine._releaseBuffer(this.borderIB);
  8790. this.borderIB = null;
  8791. }
  8792. return true;
  8793. };
  8794. return Ellipse2DRenderCache;
  8795. }(BABYLON.ModelRenderCache));
  8796. BABYLON.Ellipse2DRenderCache = Ellipse2DRenderCache;
  8797. var Ellipse2DInstanceData = (function (_super) {
  8798. __extends(Ellipse2DInstanceData, _super);
  8799. function Ellipse2DInstanceData(partId) {
  8800. _super.call(this, partId, 1);
  8801. }
  8802. Object.defineProperty(Ellipse2DInstanceData.prototype, "properties", {
  8803. get: function () {
  8804. return null;
  8805. },
  8806. set: function (value) {
  8807. },
  8808. enumerable: true,
  8809. configurable: true
  8810. });
  8811. __decorate([
  8812. BABYLON.instanceData()
  8813. ], Ellipse2DInstanceData.prototype, "properties", null);
  8814. return Ellipse2DInstanceData;
  8815. }(BABYLON.Shape2DInstanceData));
  8816. BABYLON.Ellipse2DInstanceData = Ellipse2DInstanceData;
  8817. var Ellipse2D = (function (_super) {
  8818. __extends(Ellipse2D, _super);
  8819. /**
  8820. * Create an Ellipse 2D Shape primitive
  8821. * @param settings a combination of settings, possible ones are
  8822. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  8823. * - children: an array of direct children
  8824. * - id: a text identifier, for information purpose
  8825. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  8826. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  8827. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  8828. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  8829. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  8830. * - zOrder: override the zOrder with the specified value
  8831. * - origin: define the normalized origin point location, default [0.5;0.5]
  8832. * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
  8833. * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
  8834. * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
  8835. * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  8836. * - borderThickness: the thickness of the drawn border, default is 1.
  8837. * - isVisible: true if the group must be visible, false for hidden. Default is true.
  8838. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  8839. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  8840. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  8841. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8842. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8843. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8844. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8845. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  8846. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  8847. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  8848. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  8849. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8850. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8851. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8852. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  8853. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  8854. */
  8855. function Ellipse2D(settings) {
  8856. // Avoid checking every time if the object exists
  8857. if (settings == null) {
  8858. settings = {};
  8859. }
  8860. _super.call(this, settings);
  8861. if (settings.size != null) {
  8862. this.size = settings.size;
  8863. }
  8864. else if (settings.width || settings.height) {
  8865. var size = new BABYLON.Size(settings.width, settings.height);
  8866. this.size = size;
  8867. }
  8868. var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
  8869. this.subdivisions = sub;
  8870. }
  8871. Object.defineProperty(Ellipse2D.prototype, "actualSize", {
  8872. get: function () {
  8873. if (this._actualSize) {
  8874. return this._actualSize;
  8875. }
  8876. return this.size;
  8877. },
  8878. set: function (value) {
  8879. this._actualSize = value;
  8880. },
  8881. enumerable: true,
  8882. configurable: true
  8883. });
  8884. Object.defineProperty(Ellipse2D.prototype, "subdivisions", {
  8885. get: function () {
  8886. return this._subdivisions;
  8887. },
  8888. set: function (value) {
  8889. this._subdivisions = value;
  8890. },
  8891. enumerable: true,
  8892. configurable: true
  8893. });
  8894. Ellipse2D.prototype.levelIntersect = function (intersectInfo) {
  8895. var w = this.size.width / 2;
  8896. var h = this.size.height / 2;
  8897. var x = intersectInfo._localPickPosition.x - w;
  8898. var y = intersectInfo._localPickPosition.y - h;
  8899. return ((x * x) / (w * w) + (y * y) / (h * h)) <= 1;
  8900. };
  8901. Ellipse2D.prototype.updateLevelBoundingInfo = function () {
  8902. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  8903. };
  8904. Ellipse2D.prototype.createModelRenderCache = function (modelKey) {
  8905. var renderCache = new Ellipse2DRenderCache(this.owner.engine, modelKey);
  8906. return renderCache;
  8907. };
  8908. Ellipse2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  8909. var renderCache = modelRenderCache;
  8910. var engine = this.owner.engine;
  8911. // Need to create WebGL resources for fill part?
  8912. if (this.fill) {
  8913. var vbSize = this.subdivisions + 1;
  8914. var vb = new Float32Array(vbSize);
  8915. for (var i = 0; i < vbSize; i++) {
  8916. vb[i] = i;
  8917. }
  8918. renderCache.fillVB = engine.createVertexBuffer(vb);
  8919. var triCount = vbSize - 1;
  8920. var ib = new Float32Array(triCount * 3);
  8921. for (var i = 0; i < triCount; i++) {
  8922. ib[i * 3 + 0] = 0;
  8923. ib[i * 3 + 2] = i + 1;
  8924. ib[i * 3 + 1] = i + 2;
  8925. }
  8926. ib[triCount * 3 - 2] = 1;
  8927. renderCache.fillIB = engine.createIndexBuffer(ib);
  8928. renderCache.fillIndicesCount = triCount * 3;
  8929. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  8930. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, true);
  8931. if (ei) {
  8932. renderCache.effectFillInstanced = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  8933. }
  8934. // Get the non instanced version
  8935. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["index"], null, false);
  8936. renderCache.effectFill = engine.createEffect({ vertex: "ellipse2d", fragment: "ellipse2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  8937. }
  8938. // Need to create WebGL resource for border part?
  8939. if (this.border) {
  8940. var vbSize = this.subdivisions * 2;
  8941. var vb = new Float32Array(vbSize);
  8942. for (var i = 0; i < vbSize; i++) {
  8943. vb[i] = i;
  8944. }
  8945. renderCache.borderVB = engine.createVertexBuffer(vb);
  8946. var triCount = vbSize;
  8947. var rs = triCount / 2;
  8948. var ib = new Float32Array(triCount * 3);
  8949. for (var i = 0; i < rs; i++) {
  8950. var r0 = i;
  8951. var r1 = (i + 1) % rs;
  8952. ib[i * 6 + 0] = rs + r1;
  8953. ib[i * 6 + 1] = rs + r0;
  8954. ib[i * 6 + 2] = r0;
  8955. ib[i * 6 + 3] = r1;
  8956. ib[i * 6 + 4] = rs + r1;
  8957. ib[i * 6 + 5] = r0;
  8958. }
  8959. renderCache.borderIB = engine.createIndexBuffer(ib);
  8960. renderCache.borderIndicesCount = (triCount * 3);
  8961. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  8962. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, true);
  8963. if (ei) {
  8964. renderCache.effectBorderInstanced = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8965. }
  8966. // Get the non instanced version
  8967. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["index"], null, false);
  8968. renderCache.effectBorder = engine.createEffect("ellipse2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  8969. }
  8970. return renderCache;
  8971. };
  8972. Ellipse2D.prototype.createInstanceDataParts = function () {
  8973. var res = new Array();
  8974. if (this.border) {
  8975. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  8976. }
  8977. if (this.fill) {
  8978. res.push(new Ellipse2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  8979. }
  8980. return res;
  8981. };
  8982. Ellipse2D.prototype.refreshInstanceDataPart = function (part) {
  8983. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  8984. return false;
  8985. }
  8986. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  8987. var d = part;
  8988. var size = this.actualSize;
  8989. var s = this.actualScale;
  8990. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  8991. }
  8992. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  8993. var d = part;
  8994. var size = this.actualSize;
  8995. var s = this.actualScale;
  8996. d.properties = new BABYLON.Vector3(size.width * s.x, size.height * s.y, this.subdivisions);
  8997. }
  8998. return true;
  8999. };
  9000. __decorate([
  9001. BABYLON.instanceLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Ellipse2D.acutalSizeProperty = pi; }, false, true)
  9002. ], Ellipse2D.prototype, "actualSize", null);
  9003. __decorate([
  9004. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Ellipse2D.subdivisionsProperty = pi; })
  9005. ], Ellipse2D.prototype, "subdivisions", null);
  9006. Ellipse2D = __decorate([
  9007. BABYLON.className("Ellipse2D", "BABYLON")
  9008. ], Ellipse2D);
  9009. return Ellipse2D;
  9010. }(BABYLON.Shape2D));
  9011. BABYLON.Ellipse2D = Ellipse2D;
  9012. })(BABYLON || (BABYLON = {}));
  9013. var BABYLON;
  9014. (function (BABYLON) {
  9015. var Sprite2DRenderCache = (function (_super) {
  9016. __extends(Sprite2DRenderCache, _super);
  9017. function Sprite2DRenderCache() {
  9018. _super.apply(this, arguments);
  9019. this.effectsReady = false;
  9020. this.vb = null;
  9021. this.ib = null;
  9022. this.instancingAttributes = null;
  9023. this.texture = null;
  9024. this.effect = null;
  9025. this.effectInstanced = null;
  9026. }
  9027. Sprite2DRenderCache.prototype.render = function (instanceInfo, context) {
  9028. // Do nothing if the shader is still loading/preparing
  9029. if (!this.effectsReady) {
  9030. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9031. return false;
  9032. }
  9033. this.effectsReady = true;
  9034. }
  9035. // Compute the offset locations of the attributes in the vertex shader that will be mapped to the instance buffer data
  9036. var canvas = instanceInfo.owner.owner;
  9037. var engine = canvas.engine;
  9038. var cur = engine.getAlphaMode();
  9039. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9040. engine.enableEffect(effect);
  9041. effect.setTexture("diffuseSampler", this.texture);
  9042. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9043. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9044. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9045. }
  9046. effect.setBool("alphaTest", context.renderMode === BABYLON.Render2DContext.RenderModeAlphaTest);
  9047. var pid = context.groupInfoPartData[0];
  9048. if (context.useInstancing) {
  9049. if (!this.instancingAttributes) {
  9050. this.instancingAttributes = this.loadInstancingAttributes(Sprite2D.SPRITE2D_MAINPARTID, effect);
  9051. }
  9052. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9053. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9054. canvas._addDrawCallCount(1, context.renderMode);
  9055. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  9056. engine.draw(true, 0, 6, count);
  9057. engine.unbindInstanceAttributes();
  9058. }
  9059. else {
  9060. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9061. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9062. this.setupUniforms(effect, 0, pid._partData, i);
  9063. engine.draw(true, 0, 6);
  9064. }
  9065. }
  9066. engine.setAlphaMode(cur, true);
  9067. return true;
  9068. };
  9069. Sprite2DRenderCache.prototype.dispose = function () {
  9070. if (!_super.prototype.dispose.call(this)) {
  9071. return false;
  9072. }
  9073. if (this.vb) {
  9074. this._engine._releaseBuffer(this.vb);
  9075. this.vb = null;
  9076. }
  9077. if (this.ib) {
  9078. this._engine._releaseBuffer(this.ib);
  9079. this.ib = null;
  9080. }
  9081. //if (this.texture) {
  9082. // this.texture.dispose();
  9083. // this.texture = null;
  9084. //}
  9085. this.effect = null;
  9086. this.effectInstanced = null;
  9087. return true;
  9088. };
  9089. return Sprite2DRenderCache;
  9090. }(BABYLON.ModelRenderCache));
  9091. BABYLON.Sprite2DRenderCache = Sprite2DRenderCache;
  9092. var Sprite2DInstanceData = (function (_super) {
  9093. __extends(Sprite2DInstanceData, _super);
  9094. function Sprite2DInstanceData(partId) {
  9095. _super.call(this, partId, 1);
  9096. }
  9097. Object.defineProperty(Sprite2DInstanceData.prototype, "topLeftUV", {
  9098. get: function () {
  9099. return null;
  9100. },
  9101. set: function (value) {
  9102. },
  9103. enumerable: true,
  9104. configurable: true
  9105. });
  9106. Object.defineProperty(Sprite2DInstanceData.prototype, "sizeUV", {
  9107. get: function () {
  9108. return null;
  9109. },
  9110. set: function (value) {
  9111. },
  9112. enumerable: true,
  9113. configurable: true
  9114. });
  9115. Object.defineProperty(Sprite2DInstanceData.prototype, "scaleFactor", {
  9116. get: function () {
  9117. return null;
  9118. },
  9119. set: function (value) {
  9120. },
  9121. enumerable: true,
  9122. configurable: true
  9123. });
  9124. Object.defineProperty(Sprite2DInstanceData.prototype, "textureSize", {
  9125. get: function () {
  9126. return null;
  9127. },
  9128. set: function (value) {
  9129. },
  9130. enumerable: true,
  9131. configurable: true
  9132. });
  9133. Object.defineProperty(Sprite2DInstanceData.prototype, "properties", {
  9134. // 3 floats being:
  9135. // - x: frame number to display
  9136. // - y: invertY setting
  9137. // - z: alignToPixel setting
  9138. get: function () {
  9139. return null;
  9140. },
  9141. set: function (value) {
  9142. },
  9143. enumerable: true,
  9144. configurable: true
  9145. });
  9146. __decorate([
  9147. BABYLON.instanceData()
  9148. ], Sprite2DInstanceData.prototype, "topLeftUV", null);
  9149. __decorate([
  9150. BABYLON.instanceData()
  9151. ], Sprite2DInstanceData.prototype, "sizeUV", null);
  9152. __decorate([
  9153. BABYLON.instanceData()
  9154. ], Sprite2DInstanceData.prototype, "scaleFactor", null);
  9155. __decorate([
  9156. BABYLON.instanceData()
  9157. ], Sprite2DInstanceData.prototype, "textureSize", null);
  9158. __decorate([
  9159. BABYLON.instanceData()
  9160. ], Sprite2DInstanceData.prototype, "properties", null);
  9161. return Sprite2DInstanceData;
  9162. }(BABYLON.InstanceDataBase));
  9163. BABYLON.Sprite2DInstanceData = Sprite2DInstanceData;
  9164. var Sprite2D = (function (_super) {
  9165. __extends(Sprite2D, _super);
  9166. /**
  9167. * Create an 2D Sprite primitive
  9168. * @param texture the texture that stores the sprite to render
  9169. * @param settings a combination of settings, possible ones are
  9170. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  9171. * - children: an array of direct children
  9172. * - id a text identifier, for information purpose
  9173. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9174. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9175. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9176. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9177. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9178. * - zOrder: override the zOrder with the specified value
  9179. * - origin: define the normalized origin point location, default [0.5;0.5]
  9180. * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
  9181. * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
  9182. * - spriteScaleFactor: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
  9183. * - invertY: if true the texture Y will be inverted, default is false.
  9184. * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
  9185. * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
  9186. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  9187. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  9188. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  9189. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9190. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9191. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9192. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9193. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9194. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9195. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9196. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9197. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9198. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9199. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9200. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9201. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9202. */
  9203. function Sprite2D(texture, settings) {
  9204. var _this = this;
  9205. if (!settings) {
  9206. settings = {};
  9207. }
  9208. _super.call(this, settings);
  9209. this.texture = texture;
  9210. this.texture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9211. this.texture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  9212. this.size = settings.spriteSize;
  9213. this.spriteLocation = settings.spriteLocation || new BABYLON.Vector2(0, 0);
  9214. this.spriteScaleFactor = settings.spriteScaleFactor || new BABYLON.Vector2(1, 1);
  9215. this.spriteFrame = 0;
  9216. this.invertY = (settings.invertY == null) ? false : settings.invertY;
  9217. this.alignToPixel = (settings.alignToPixel == null) ? true : settings.alignToPixel;
  9218. this.useAlphaFromTexture = true;
  9219. if (settings.spriteSize == null || !texture.isReady()) {
  9220. if (texture.isReady()) {
  9221. this.size = texture.getBaseSize();
  9222. }
  9223. else {
  9224. texture.onLoadObservable.add(function () {
  9225. if (settings.spriteSize == null) {
  9226. _this.size = texture.getBaseSize();
  9227. }
  9228. _this._positioningDirty();
  9229. _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
  9230. });
  9231. }
  9232. }
  9233. }
  9234. Object.defineProperty(Sprite2D.prototype, "texture", {
  9235. get: function () {
  9236. return this._texture;
  9237. },
  9238. set: function (value) {
  9239. this._texture = value;
  9240. this._oldTextureHasAlpha = this._texture && this.texture.hasAlpha;
  9241. },
  9242. enumerable: true,
  9243. configurable: true
  9244. });
  9245. Object.defineProperty(Sprite2D.prototype, "useAlphaFromTexture", {
  9246. get: function () {
  9247. return this._useAlphaFromTexture;
  9248. },
  9249. set: function (value) {
  9250. if (this._useAlphaFromTexture === value) {
  9251. return;
  9252. }
  9253. this._useAlphaFromTexture = value;
  9254. this._updateRenderMode();
  9255. },
  9256. enumerable: true,
  9257. configurable: true
  9258. });
  9259. Object.defineProperty(Sprite2D.prototype, "actualSize", {
  9260. get: function () {
  9261. if (this._actualSize) {
  9262. return this._actualSize;
  9263. }
  9264. return this.size;
  9265. },
  9266. set: function (value) {
  9267. this._actualSize = value;
  9268. },
  9269. enumerable: true,
  9270. configurable: true
  9271. });
  9272. Object.defineProperty(Sprite2D.prototype, "spriteLocation", {
  9273. get: function () {
  9274. return this._location;
  9275. },
  9276. set: function (value) {
  9277. this._location = value;
  9278. },
  9279. enumerable: true,
  9280. configurable: true
  9281. });
  9282. Object.defineProperty(Sprite2D.prototype, "spriteFrame", {
  9283. get: function () {
  9284. return this._spriteFrame;
  9285. },
  9286. set: function (value) {
  9287. this._spriteFrame = value;
  9288. },
  9289. enumerable: true,
  9290. configurable: true
  9291. });
  9292. Object.defineProperty(Sprite2D.prototype, "invertY", {
  9293. get: function () {
  9294. return this._invertY;
  9295. },
  9296. set: function (value) {
  9297. this._invertY = value;
  9298. },
  9299. enumerable: true,
  9300. configurable: true
  9301. });
  9302. Object.defineProperty(Sprite2D.prototype, "spriteScaleFactor", {
  9303. get: function () {
  9304. return this._spriteScaleFactor;
  9305. },
  9306. set: function (value) {
  9307. this._spriteScaleFactor = value;
  9308. },
  9309. enumerable: true,
  9310. configurable: true
  9311. });
  9312. /**
  9313. * Sets the scale of the sprite using a BABYLON.Size(w,h).
  9314. * Keeps proportion by taking the maximum of the two scale for x and y.
  9315. * @param {Size} size Size(width,height)
  9316. */
  9317. Sprite2D.prototype.scaleToSize = function (size) {
  9318. var baseSize = this.size;
  9319. if (baseSize == null || !this.texture.isReady()) {
  9320. // we're probably at initiation of the scene, size is not set
  9321. if (this.texture.isReady()) {
  9322. baseSize = this.texture.getBaseSize();
  9323. }
  9324. else {
  9325. // the texture is not ready, wait for it to load before calling scaleToSize again
  9326. var thisObject = this;
  9327. this.texture.onLoadObservable.add(function () {
  9328. thisObject.scaleToSize(size);
  9329. });
  9330. return;
  9331. }
  9332. }
  9333. this.scale = Math.max(size.height / baseSize.height, size.width / baseSize.width);
  9334. };
  9335. Object.defineProperty(Sprite2D.prototype, "alignToPixel", {
  9336. /**
  9337. * Get/set if the sprite rendering should be aligned to the target rendering device pixel or not
  9338. */
  9339. get: function () {
  9340. return this._alignToPixel;
  9341. },
  9342. set: function (value) {
  9343. this._alignToPixel = value;
  9344. },
  9345. enumerable: true,
  9346. configurable: true
  9347. });
  9348. Sprite2D.prototype.updateLevelBoundingInfo = function () {
  9349. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.size, this._levelBoundingInfo);
  9350. };
  9351. /**
  9352. * Get the animatable array (see http://doc.babylonjs.com/tutorials/Animations)
  9353. */
  9354. Sprite2D.prototype.getAnimatables = function () {
  9355. var res = new Array();
  9356. if (this.texture && this.texture.animations && this.texture.animations.length > 0) {
  9357. res.push(this.texture);
  9358. }
  9359. return res;
  9360. };
  9361. Sprite2D.prototype.levelIntersect = function (intersectInfo) {
  9362. // If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
  9363. return true;
  9364. };
  9365. Sprite2D._createCachedCanvasSprite = function (owner, texture, size, pos) {
  9366. var sprite = new Sprite2D(texture, { parent: owner, id: "__cachedCanvasSprite__", position: BABYLON.Vector2.Zero(), origin: BABYLON.Vector2.Zero(), spriteSize: size, spriteLocation: pos, alignToPixel: true });
  9367. return sprite;
  9368. };
  9369. Sprite2D.prototype.createModelRenderCache = function (modelKey) {
  9370. var renderCache = new Sprite2DRenderCache(this.owner.engine, modelKey);
  9371. return renderCache;
  9372. };
  9373. Sprite2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9374. var renderCache = modelRenderCache;
  9375. var engine = this.owner.engine;
  9376. var vb = new Float32Array(4);
  9377. for (var i = 0; i < 4; i++) {
  9378. vb[i] = i;
  9379. }
  9380. renderCache.vb = engine.createVertexBuffer(vb);
  9381. var ib = new Float32Array(6);
  9382. ib[0] = 0;
  9383. ib[1] = 2;
  9384. ib[2] = 1;
  9385. ib[3] = 0;
  9386. ib[4] = 3;
  9387. ib[5] = 2;
  9388. renderCache.ib = engine.createIndexBuffer(ib);
  9389. renderCache.texture = this.texture;
  9390. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  9391. var ei = this.getDataPartEffectInfo(Sprite2D.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], true);
  9392. if (ei) {
  9393. renderCache.effectInstanced = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9394. }
  9395. ei = this.getDataPartEffectInfo(Sprite2D.SPRITE2D_MAINPARTID, ["index"], ["alphaTest"], false);
  9396. renderCache.effect = engine.createEffect("sprite2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9397. return renderCache;
  9398. };
  9399. Sprite2D.prototype.createInstanceDataParts = function () {
  9400. return [new Sprite2DInstanceData(Sprite2D.SPRITE2D_MAINPARTID)];
  9401. };
  9402. Sprite2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  9403. Sprite2D.layoutConstructMode = true;
  9404. };
  9405. // if obj contains something, we restore the _text property
  9406. Sprite2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  9407. Sprite2D.layoutConstructMode = false;
  9408. };
  9409. Sprite2D.prototype.refreshInstanceDataPart = function (part) {
  9410. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9411. return false;
  9412. }
  9413. if (!this.texture.isReady() && !Sprite2D.layoutConstructMode) {
  9414. return false;
  9415. }
  9416. if (part.id === Sprite2D.SPRITE2D_MAINPARTID) {
  9417. var d = this._instanceDataParts[0];
  9418. if (Sprite2D.layoutConstructMode) {
  9419. d.topLeftUV = BABYLON.Vector2.Zero();
  9420. d.sizeUV = BABYLON.Vector2.Zero();
  9421. d.properties = BABYLON.Vector3.Zero();
  9422. d.textureSize = BABYLON.Vector2.Zero();
  9423. d.scaleFactor = BABYLON.Vector2.Zero();
  9424. }
  9425. else {
  9426. var ts = this.texture.getBaseSize();
  9427. var sl = this.spriteLocation;
  9428. var ss = this.actualSize;
  9429. var ssf = this.spriteScaleFactor;
  9430. d.topLeftUV = new BABYLON.Vector2(sl.x / ts.width, sl.y / ts.height);
  9431. var suv = new BABYLON.Vector2(ss.width / ts.width, ss.height / ts.height);
  9432. d.sizeUV = suv;
  9433. d.scaleFactor = ssf;
  9434. Sprite2D._prop.x = this.spriteFrame;
  9435. Sprite2D._prop.y = this.invertY ? 1 : 0;
  9436. Sprite2D._prop.z = this.alignToPixel ? 1 : 0;
  9437. d.properties = Sprite2D._prop;
  9438. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  9439. }
  9440. }
  9441. return true;
  9442. };
  9443. Sprite2D.prototype._mustUpdateInstance = function () {
  9444. var res = this._oldTextureHasAlpha !== (this.texture != null && this.texture.hasAlpha);
  9445. this._oldTextureHasAlpha = this.texture != null && this.texture.hasAlpha;
  9446. if (res) {
  9447. this._updateRenderMode();
  9448. }
  9449. return res;
  9450. };
  9451. Sprite2D.prototype._useTextureAlpha = function () {
  9452. return this.texture != null && this.texture.hasAlpha;
  9453. };
  9454. Sprite2D.prototype._shouldUseAlphaFromTexture = function () {
  9455. return this.texture != null && this.texture.hasAlpha && this.useAlphaFromTexture;
  9456. };
  9457. Sprite2D.SPRITE2D_MAINPARTID = 1;
  9458. Sprite2D._prop = BABYLON.Vector3.Zero();
  9459. Sprite2D.layoutConstructMode = false;
  9460. __decorate([
  9461. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Sprite2D.textureProperty = pi; })
  9462. ], Sprite2D.prototype, "texture", null);
  9463. __decorate([
  9464. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Sprite2D.useAlphaFromTextureProperty = pi; })
  9465. ], Sprite2D.prototype, "useAlphaFromTexture", null);
  9466. __decorate([
  9467. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Sprite2D.actualSizeProperty = pi; }, false, true)
  9468. ], Sprite2D.prototype, "actualSize", null);
  9469. __decorate([
  9470. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Sprite2D.spriteLocationProperty = pi; })
  9471. ], Sprite2D.prototype, "spriteLocation", null);
  9472. __decorate([
  9473. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, function (pi) { return Sprite2D.spriteFrameProperty = pi; })
  9474. ], Sprite2D.prototype, "spriteFrame", null);
  9475. __decorate([
  9476. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, function (pi) { return Sprite2D.invertYProperty = pi; })
  9477. ], Sprite2D.prototype, "invertY", null);
  9478. __decorate([
  9479. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 7, function (pi) { return Sprite2D.spriteScaleFactorProperty = pi; })
  9480. ], Sprite2D.prototype, "spriteScaleFactor", null);
  9481. Sprite2D = __decorate([
  9482. BABYLON.className("Sprite2D", "BABYLON")
  9483. ], Sprite2D);
  9484. return Sprite2D;
  9485. }(BABYLON.RenderablePrim2D));
  9486. BABYLON.Sprite2D = Sprite2D;
  9487. })(BABYLON || (BABYLON = {}));
  9488. var BABYLON;
  9489. (function (BABYLON) {
  9490. var Text2DRenderCache = (function (_super) {
  9491. __extends(Text2DRenderCache, _super);
  9492. function Text2DRenderCache() {
  9493. _super.apply(this, arguments);
  9494. this.effectsReady = false;
  9495. this.vb = null;
  9496. this.ib = null;
  9497. this.instancingAttributes = null;
  9498. this.fontTexture = null;
  9499. this.effect = null;
  9500. this.effectInstanced = null;
  9501. }
  9502. Text2DRenderCache.prototype.render = function (instanceInfo, context) {
  9503. // Do nothing if the shader is still loading/preparing
  9504. if (!this.effectsReady) {
  9505. if ((this.effect && (!this.effect.isReady() || (this.effectInstanced && !this.effectInstanced.isReady())))) {
  9506. return false;
  9507. }
  9508. this.effectsReady = true;
  9509. }
  9510. var canvas = instanceInfo.owner.owner;
  9511. var engine = canvas.engine;
  9512. this.fontTexture.update();
  9513. var effect = context.useInstancing ? this.effectInstanced : this.effect;
  9514. engine.enableEffect(effect);
  9515. effect.setTexture("diffuseSampler", this.fontTexture);
  9516. engine.bindBuffersDirectly(this.vb, this.ib, [1], 4, effect);
  9517. var curAlphaMode = engine.getAlphaMode();
  9518. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9519. var pid = context.groupInfoPartData[0];
  9520. if (context.useInstancing) {
  9521. if (!this.instancingAttributes) {
  9522. this.instancingAttributes = this.loadInstancingAttributes(Text2D.TEXT2D_MAINPARTID, effect);
  9523. }
  9524. var glBuffer = context.instancedBuffers ? context.instancedBuffers[0] : pid._partBuffer;
  9525. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  9526. canvas._addDrawCallCount(1, context.renderMode);
  9527. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingAttributes);
  9528. engine.draw(true, 0, 6, count);
  9529. engine.unbindInstanceAttributes();
  9530. }
  9531. else {
  9532. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  9533. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  9534. this.setupUniforms(effect, 0, pid._partData, i);
  9535. engine.draw(true, 0, 6);
  9536. }
  9537. }
  9538. engine.setAlphaMode(curAlphaMode, true);
  9539. return true;
  9540. };
  9541. Text2DRenderCache.prototype.dispose = function () {
  9542. if (!_super.prototype.dispose.call(this)) {
  9543. return false;
  9544. }
  9545. if (this.vb) {
  9546. this._engine._releaseBuffer(this.vb);
  9547. this.vb = null;
  9548. }
  9549. if (this.ib) {
  9550. this._engine._releaseBuffer(this.ib);
  9551. this.ib = null;
  9552. }
  9553. if (this.fontTexture) {
  9554. this.fontTexture.decCachedFontTextureCounter();
  9555. this.fontTexture = null;
  9556. }
  9557. this.effect = null;
  9558. this.effectInstanced = null;
  9559. return true;
  9560. };
  9561. return Text2DRenderCache;
  9562. }(BABYLON.ModelRenderCache));
  9563. BABYLON.Text2DRenderCache = Text2DRenderCache;
  9564. var Text2DInstanceData = (function (_super) {
  9565. __extends(Text2DInstanceData, _super);
  9566. function Text2DInstanceData(partId, dataElementCount) {
  9567. _super.call(this, partId, dataElementCount);
  9568. }
  9569. Object.defineProperty(Text2DInstanceData.prototype, "topLeftUV", {
  9570. get: function () {
  9571. return null;
  9572. },
  9573. set: function (value) {
  9574. },
  9575. enumerable: true,
  9576. configurable: true
  9577. });
  9578. Object.defineProperty(Text2DInstanceData.prototype, "sizeUV", {
  9579. get: function () {
  9580. return null;
  9581. },
  9582. set: function (value) {
  9583. },
  9584. enumerable: true,
  9585. configurable: true
  9586. });
  9587. Object.defineProperty(Text2DInstanceData.prototype, "textureSize", {
  9588. get: function () {
  9589. return null;
  9590. },
  9591. set: function (value) {
  9592. },
  9593. enumerable: true,
  9594. configurable: true
  9595. });
  9596. Object.defineProperty(Text2DInstanceData.prototype, "color", {
  9597. get: function () {
  9598. return null;
  9599. },
  9600. set: function (value) {
  9601. },
  9602. enumerable: true,
  9603. configurable: true
  9604. });
  9605. Object.defineProperty(Text2DInstanceData.prototype, "superSampleFactor", {
  9606. get: function () {
  9607. return null;
  9608. },
  9609. set: function (value) {
  9610. },
  9611. enumerable: true,
  9612. configurable: true
  9613. });
  9614. __decorate([
  9615. BABYLON.instanceData()
  9616. ], Text2DInstanceData.prototype, "topLeftUV", null);
  9617. __decorate([
  9618. BABYLON.instanceData()
  9619. ], Text2DInstanceData.prototype, "sizeUV", null);
  9620. __decorate([
  9621. BABYLON.instanceData()
  9622. ], Text2DInstanceData.prototype, "textureSize", null);
  9623. __decorate([
  9624. BABYLON.instanceData()
  9625. ], Text2DInstanceData.prototype, "color", null);
  9626. __decorate([
  9627. BABYLON.instanceData()
  9628. ], Text2DInstanceData.prototype, "superSampleFactor", null);
  9629. return Text2DInstanceData;
  9630. }(BABYLON.InstanceDataBase));
  9631. BABYLON.Text2DInstanceData = Text2DInstanceData;
  9632. var Text2D = (function (_super) {
  9633. __extends(Text2D, _super);
  9634. /**
  9635. * Create a Text primitive
  9636. * @param text the text to display
  9637. * @param settings a combination of settings, possible ones are
  9638. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  9639. * - children: an array of direct children
  9640. * - id a text identifier, for information purpose
  9641. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  9642. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  9643. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  9644. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  9645. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  9646. * - zOrder: override the zOrder with the specified value
  9647. * - origin: define the normalized origin point location, default [0.5;0.5]
  9648. * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
  9649. * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
  9650. * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
  9651. * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
  9652. * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
  9653. * - isVisible: true if the text must be visible, false for hidden. Default is true.
  9654. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  9655. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  9656. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  9657. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9658. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9659. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9660. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9661. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  9662. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  9663. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  9664. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  9665. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9666. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9667. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9668. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  9669. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  9670. */
  9671. function Text2D(text, settings) {
  9672. if (!settings) {
  9673. settings = {};
  9674. }
  9675. _super.call(this, settings);
  9676. this.fontName = (settings.fontName == null) ? "12pt Arial" : settings.fontName;
  9677. this._fontSuperSample = (settings.fontSuperSample != null && settings.fontSuperSample);
  9678. this.defaultFontColor = (settings.defaultFontColor == null) ? new BABYLON.Color4(1, 1, 1, 1) : settings.defaultFontColor;
  9679. this._tabulationSize = (settings.tabulationSize == null) ? 4 : settings.tabulationSize;
  9680. this._textSize = null;
  9681. this.text = text;
  9682. this.size = (settings.size == null) ? null : settings.size;
  9683. this._updateRenderMode();
  9684. }
  9685. Object.defineProperty(Text2D.prototype, "fontName", {
  9686. get: function () {
  9687. return this._fontName;
  9688. },
  9689. set: function (value) {
  9690. if (this._fontName) {
  9691. throw new Error("Font Name change is not supported right now.");
  9692. }
  9693. this._fontName = value;
  9694. },
  9695. enumerable: true,
  9696. configurable: true
  9697. });
  9698. Object.defineProperty(Text2D.prototype, "defaultFontColor", {
  9699. get: function () {
  9700. return this._defaultFontColor;
  9701. },
  9702. set: function (value) {
  9703. this._defaultFontColor = value;
  9704. },
  9705. enumerable: true,
  9706. configurable: true
  9707. });
  9708. Object.defineProperty(Text2D.prototype, "text", {
  9709. get: function () {
  9710. return this._text;
  9711. },
  9712. set: function (value) {
  9713. if (!value) {
  9714. value = "";
  9715. }
  9716. this._text = value;
  9717. this._textSize = null; // A change of text will reset the TextSize which will be recomputed next time it's used
  9718. this._size = null;
  9719. this._updateCharCount();
  9720. // Trigger a textSize to for a sizeChange if necessary, which is needed for layout to recompute
  9721. var s = this.textSize;
  9722. },
  9723. enumerable: true,
  9724. configurable: true
  9725. });
  9726. Object.defineProperty(Text2D.prototype, "size", {
  9727. get: function () {
  9728. if (this._size != null) {
  9729. return this._size;
  9730. }
  9731. return this.textSize;
  9732. },
  9733. set: function (value) {
  9734. this._size = value;
  9735. },
  9736. enumerable: true,
  9737. configurable: true
  9738. });
  9739. Object.defineProperty(Text2D.prototype, "isSizeAuto", {
  9740. get: function () {
  9741. return false;
  9742. },
  9743. enumerable: true,
  9744. configurable: true
  9745. });
  9746. Object.defineProperty(Text2D.prototype, "actualSize", {
  9747. /**
  9748. * Get the actual size of the Text2D primitive
  9749. */
  9750. get: function () {
  9751. if (this._actualSize) {
  9752. return this._actualSize;
  9753. }
  9754. return this.size;
  9755. },
  9756. enumerable: true,
  9757. configurable: true
  9758. });
  9759. Object.defineProperty(Text2D.prototype, "textSize", {
  9760. /**
  9761. * Get the area that bounds the text associated to the primitive
  9762. */
  9763. get: function () {
  9764. if (!this._textSize) {
  9765. if (this.owner && this._text) {
  9766. var newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
  9767. if (!newSize.equals(this._textSize)) {
  9768. this.onPrimitivePropertyDirty(BABYLON.Prim2DBase.sizeProperty.flagId);
  9769. this._positioningDirty();
  9770. }
  9771. this._textSize = newSize;
  9772. }
  9773. else {
  9774. return Text2D.nullSize;
  9775. }
  9776. }
  9777. return this._textSize;
  9778. },
  9779. enumerable: true,
  9780. configurable: true
  9781. });
  9782. Object.defineProperty(Text2D.prototype, "fontTexture", {
  9783. get: function () {
  9784. if (this._fontTexture) {
  9785. return this._fontTexture;
  9786. }
  9787. if (this.fontName == null || this.owner == null || this.owner.scene == null) {
  9788. return null;
  9789. }
  9790. this._fontTexture = BABYLON.FontTexture.GetCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample);
  9791. return this._fontTexture;
  9792. },
  9793. enumerable: true,
  9794. configurable: true
  9795. });
  9796. /**
  9797. * Dispose the primitive, remove it from its parent
  9798. */
  9799. Text2D.prototype.dispose = function () {
  9800. if (!_super.prototype.dispose.call(this)) {
  9801. return false;
  9802. }
  9803. if (this._fontTexture) {
  9804. BABYLON.FontTexture.ReleaseCachedFontTexture(this.owner.scene, this.fontName, this._fontSuperSample);
  9805. this._fontTexture = null;
  9806. }
  9807. return true;
  9808. };
  9809. Text2D.prototype.updateLevelBoundingInfo = function () {
  9810. BABYLON.BoundingInfo2D.CreateFromSizeToRef(this.actualSize, this._levelBoundingInfo);
  9811. };
  9812. Text2D.prototype.levelIntersect = function (intersectInfo) {
  9813. // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
  9814. return true;
  9815. };
  9816. Text2D.prototype.createModelRenderCache = function (modelKey) {
  9817. var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
  9818. return renderCache;
  9819. };
  9820. Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  9821. var renderCache = modelRenderCache;
  9822. var engine = this.owner.engine;
  9823. renderCache.fontTexture = this.fontTexture;
  9824. renderCache.fontTexture.incCachedFontTextureCounter();
  9825. var vb = new Float32Array(4);
  9826. for (var i = 0; i < 4; i++) {
  9827. vb[i] = i;
  9828. }
  9829. renderCache.vb = engine.createVertexBuffer(vb);
  9830. var ib = new Float32Array(6);
  9831. ib[0] = 0;
  9832. ib[1] = 2;
  9833. ib[2] = 1;
  9834. ib[3] = 0;
  9835. ib[4] = 3;
  9836. ib[5] = 2;
  9837. renderCache.ib = engine.createIndexBuffer(ib);
  9838. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  9839. var ei = this.getDataPartEffectInfo(Text2D.TEXT2D_MAINPARTID, ["index"], null, true);
  9840. if (ei) {
  9841. renderCache.effectInstanced = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9842. }
  9843. ei = this.getDataPartEffectInfo(Text2D.TEXT2D_MAINPARTID, ["index"], null, false);
  9844. renderCache.effect = engine.createEffect("text2d", ei.attributes, ei.uniforms, ["diffuseSampler"], ei.defines, null);
  9845. return renderCache;
  9846. };
  9847. Text2D.prototype.createInstanceDataParts = function () {
  9848. return [new Text2DInstanceData(Text2D.TEXT2D_MAINPARTID, this._charCount)];
  9849. };
  9850. // Looks like a hack!? Yes! Because that's what it is!
  9851. // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
  9852. // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
  9853. Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
  9854. if (!this._charCount) {
  9855. var curText = this._text;
  9856. this.text = "A";
  9857. return curText;
  9858. }
  9859. };
  9860. // if obj contains something, we restore the _text property
  9861. Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
  9862. if (obj !== undefined) {
  9863. this.text = obj;
  9864. }
  9865. };
  9866. Text2D.prototype.refreshInstanceDataPart = function (part) {
  9867. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  9868. return false;
  9869. }
  9870. if (part.id === Text2D.TEXT2D_MAINPARTID) {
  9871. var d = part;
  9872. var texture = this.fontTexture;
  9873. var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
  9874. var ts = texture.getSize();
  9875. var offset = BABYLON.Vector2.Zero();
  9876. var lh = this.fontTexture.lineHeight;
  9877. offset.y = ((this.textSize.height / lh) - 1) * lh; // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
  9878. var charxpos = 0;
  9879. d.dataElementCount = this._charCount;
  9880. d.curElement = 0;
  9881. for (var _i = 0, _a = this.text; _i < _a.length; _i++) {
  9882. var char = _a[_i];
  9883. // Line feed
  9884. if (char === "\n") {
  9885. offset.x = 0;
  9886. offset.y -= texture.lineHeight;
  9887. }
  9888. // Tabulation ?
  9889. if (char === "\t") {
  9890. var nextPos = charxpos + this._tabulationSize;
  9891. nextPos = nextPos - (nextPos % this._tabulationSize);
  9892. offset.x += (nextPos - charxpos) * texture.spaceWidth;
  9893. charxpos = nextPos;
  9894. continue;
  9895. }
  9896. if (char < " ") {
  9897. continue;
  9898. }
  9899. this.updateInstanceDataPart(d, offset);
  9900. var ci = texture.getChar(char);
  9901. offset.x += ci.charWidth;
  9902. d.topLeftUV = ci.topLeftUV;
  9903. var suv = ci.bottomRightUV.subtract(ci.topLeftUV);
  9904. d.sizeUV = suv;
  9905. d.textureSize = new BABYLON.Vector2(ts.width, ts.height);
  9906. d.color = this.defaultFontColor;
  9907. d.superSampleFactor = superSampleFactor;
  9908. ++d.curElement;
  9909. }
  9910. }
  9911. return true;
  9912. };
  9913. Text2D.prototype._updateCharCount = function () {
  9914. var count = 0;
  9915. for (var _i = 0, _a = this._text; _i < _a.length; _i++) {
  9916. var char = _a[_i];
  9917. if (char === "\r" || char === "\n" || char === "\t" || char < " ") {
  9918. continue;
  9919. }
  9920. ++count;
  9921. }
  9922. this._charCount = count;
  9923. };
  9924. Text2D.prototype._useTextureAlpha = function () {
  9925. return this.fontTexture != null && this.fontTexture.hasAlpha;
  9926. };
  9927. Text2D.prototype._shouldUseAlphaFromTexture = function () {
  9928. return true;
  9929. };
  9930. Text2D.TEXT2D_MAINPARTID = 1;
  9931. __decorate([
  9932. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Text2D.fontProperty = pi; }, false, true)
  9933. ], Text2D.prototype, "fontName", null);
  9934. __decorate([
  9935. BABYLON.dynamicLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Text2D.defaultFontColorProperty = pi; })
  9936. ], Text2D.prototype, "defaultFontColor", null);
  9937. __decorate([
  9938. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Text2D.textProperty = pi; }, false, true)
  9939. ], Text2D.prototype, "text", null);
  9940. __decorate([
  9941. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 4, function (pi) { return Text2D.sizeProperty = pi; })
  9942. ], Text2D.prototype, "size", null);
  9943. Text2D = __decorate([
  9944. BABYLON.className("Text2D", "BABYLON")
  9945. ], Text2D);
  9946. return Text2D;
  9947. }(BABYLON.RenderablePrim2D));
  9948. BABYLON.Text2D = Text2D;
  9949. })(BABYLON || (BABYLON = {}));
  9950. var BABYLON;
  9951. (function (BABYLON) {
  9952. var Lines2DRenderCache = (function (_super) {
  9953. __extends(Lines2DRenderCache, _super);
  9954. function Lines2DRenderCache(engine, modelKey) {
  9955. _super.call(this, engine, modelKey);
  9956. this.effectsReady = false;
  9957. this.fillVB = null;
  9958. this.fillIB = null;
  9959. this.fillIndicesCount = 0;
  9960. this.instancingFillAttributes = null;
  9961. this.effectFill = null;
  9962. this.effectFillInstanced = null;
  9963. this.borderVB = null;
  9964. this.borderIB = null;
  9965. this.borderIndicesCount = 0;
  9966. this.instancingBorderAttributes = null;
  9967. this.effectBorder = null;
  9968. this.effectBorderInstanced = null;
  9969. }
  9970. Lines2DRenderCache.prototype.render = function (instanceInfo, context) {
  9971. // Do nothing if the shader is still loading/preparing
  9972. if (!this.effectsReady) {
  9973. if ((this.effectFill && (!this.effectFill.isReady() || (this.effectFillInstanced && !this.effectFillInstanced.isReady()))) ||
  9974. (this.effectBorder && (!this.effectBorder.isReady() || (this.effectBorderInstanced && !this.effectBorderInstanced.isReady())))) {
  9975. return false;
  9976. }
  9977. this.effectsReady = true;
  9978. }
  9979. var canvas = instanceInfo.owner.owner;
  9980. var engine = canvas.engine;
  9981. var depthFunction = 0;
  9982. if (this.effectFill && this.effectBorder) {
  9983. depthFunction = engine.getDepthFunction();
  9984. engine.setDepthFunctionToLessOrEqual();
  9985. }
  9986. var curAlphaMode = engine.getAlphaMode();
  9987. if (this.effectFill) {
  9988. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_FILLPARTID.toString());
  9989. var pid = context.groupInfoPartData[partIndex];
  9990. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  9991. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  9992. }
  9993. var effect = context.useInstancing ? this.effectFillInstanced : this.effectFill;
  9994. engine.enableEffect(effect);
  9995. engine.bindBuffersDirectly(this.fillVB, this.fillIB, [2], 2 * 4, effect);
  9996. if (context.useInstancing) {
  9997. if (!this.instancingFillAttributes) {
  9998. this.instancingFillAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_FILLPARTID, effect);
  9999. }
  10000. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10001. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10002. canvas._addDrawCallCount(1, context.renderMode);
  10003. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingFillAttributes);
  10004. engine.draw(true, 0, this.fillIndicesCount, count);
  10005. engine.unbindInstanceAttributes();
  10006. }
  10007. else {
  10008. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10009. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10010. this.setupUniforms(effect, partIndex, pid._partData, i);
  10011. engine.draw(true, 0, this.fillIndicesCount);
  10012. }
  10013. }
  10014. }
  10015. if (this.effectBorder) {
  10016. var partIndex = instanceInfo.partIndexFromId.get(BABYLON.Shape2D.SHAPE2D_BORDERPARTID.toString());
  10017. var pid = context.groupInfoPartData[partIndex];
  10018. if (context.renderMode !== BABYLON.Render2DContext.RenderModeOpaque) {
  10019. engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE, true);
  10020. }
  10021. var effect = context.useInstancing ? this.effectBorderInstanced : this.effectBorder;
  10022. engine.enableEffect(effect);
  10023. engine.bindBuffersDirectly(this.borderVB, this.borderIB, [2], 2 * 4, effect);
  10024. if (context.useInstancing) {
  10025. if (!this.instancingBorderAttributes) {
  10026. this.instancingBorderAttributes = this.loadInstancingAttributes(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, effect);
  10027. }
  10028. var glBuffer = context.instancedBuffers ? context.instancedBuffers[partIndex] : pid._partBuffer;
  10029. var count = context.instancedBuffers ? context.instancesCount : pid._partData.usedElementCount;
  10030. canvas._addDrawCallCount(1, context.renderMode);
  10031. engine.updateAndBindInstancesBuffer(glBuffer, null, this.instancingBorderAttributes);
  10032. engine.draw(true, 0, this.borderIndicesCount, count);
  10033. engine.unbindInstanceAttributes();
  10034. }
  10035. else {
  10036. canvas._addDrawCallCount(context.partDataEndIndex - context.partDataStartIndex, context.renderMode);
  10037. for (var i = context.partDataStartIndex; i < context.partDataEndIndex; i++) {
  10038. this.setupUniforms(effect, partIndex, pid._partData, i);
  10039. engine.draw(true, 0, this.borderIndicesCount);
  10040. }
  10041. }
  10042. }
  10043. engine.setAlphaMode(curAlphaMode, true);
  10044. if (this.effectFill && this.effectBorder) {
  10045. engine.setDepthFunction(depthFunction);
  10046. }
  10047. return true;
  10048. };
  10049. Lines2DRenderCache.prototype.dispose = function () {
  10050. if (!_super.prototype.dispose.call(this)) {
  10051. return false;
  10052. }
  10053. if (this.fillVB) {
  10054. this._engine._releaseBuffer(this.fillVB);
  10055. this.fillVB = null;
  10056. }
  10057. if (this.fillIB) {
  10058. this._engine._releaseBuffer(this.fillIB);
  10059. this.fillIB = null;
  10060. }
  10061. this.effectFill = null;
  10062. this.effectFillInstanced = null;
  10063. this.effectBorder = null;
  10064. this.effectBorderInstanced = null;
  10065. if (this.borderVB) {
  10066. this._engine._releaseBuffer(this.borderVB);
  10067. this.borderVB = null;
  10068. }
  10069. if (this.borderIB) {
  10070. this._engine._releaseBuffer(this.borderIB);
  10071. this.borderIB = null;
  10072. }
  10073. return true;
  10074. };
  10075. return Lines2DRenderCache;
  10076. }(BABYLON.ModelRenderCache));
  10077. BABYLON.Lines2DRenderCache = Lines2DRenderCache;
  10078. var Lines2DInstanceData = (function (_super) {
  10079. __extends(Lines2DInstanceData, _super);
  10080. function Lines2DInstanceData(partId) {
  10081. _super.call(this, partId, 1);
  10082. }
  10083. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMin", {
  10084. get: function () {
  10085. return null;
  10086. },
  10087. set: function (value) {
  10088. },
  10089. enumerable: true,
  10090. configurable: true
  10091. });
  10092. Object.defineProperty(Lines2DInstanceData.prototype, "boundingMax", {
  10093. get: function () {
  10094. return null;
  10095. },
  10096. set: function (value) {
  10097. },
  10098. enumerable: true,
  10099. configurable: true
  10100. });
  10101. __decorate([
  10102. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10103. ], Lines2DInstanceData.prototype, "boundingMin", null);
  10104. __decorate([
  10105. BABYLON.instanceData(BABYLON.Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  10106. ], Lines2DInstanceData.prototype, "boundingMax", null);
  10107. return Lines2DInstanceData;
  10108. }(BABYLON.Shape2DInstanceData));
  10109. BABYLON.Lines2DInstanceData = Lines2DInstanceData;
  10110. var Lines2D = (function (_super) {
  10111. __extends(Lines2D, _super);
  10112. /**
  10113. * Create an 2D Lines Shape primitive. The defined lines may be opened or closed (see below)
  10114. * @param points an array that describe the points to use to draw the line, must contain at least two entries.
  10115. * @param settings a combination of settings, possible ones are
  10116. * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
  10117. * - children: an array of direct children
  10118. * - id a text identifier, for information purpose
  10119. * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
  10120. * - rotation: the initial rotation (in radian) of the primitive. default is 0
  10121. * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
  10122. * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
  10123. * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
  10124. * - zOrder: override the zOrder with the specified value
  10125. * - origin: define the normalized origin point location, default [0.5;0.5]
  10126. * - fillThickness: the thickness of the fill part of the line, can be null to draw nothing (but a border brush must be given), default is 1.
  10127. * - closed: if false the lines are said to be opened, the first point and the latest DON'T connect. if true the lines are said to be closed, the first and last point will be connected by a line. For instance you can define the 4 points of a rectangle, if you set closed to true a 4 edges rectangle will be drawn. If you set false, only three edges will be drawn, the edge formed by the first and last point won't exist. Default is false.
  10128. * - startCap: Draw a cap of the given type at the start of the first line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  10129. * - endCap: Draw a cap of the given type at the end of the last line, you can't define a Cap if the Lines2D is closed. Default is Lines2D.NoCap.
  10130. * - fill: the brush used to draw the fill content of the lines, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can be a string value (see Canvas2D.GetBrushFromString)
  10131. * - border: the brush used to draw the border of the lines, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
  10132. * - borderThickness: the thickness of the drawn border, default is 1.
  10133. * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
  10134. * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
  10135. * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
  10136. * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
  10137. * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10138. * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10139. * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10140. * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10141. * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
  10142. * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
  10143. * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
  10144. * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
  10145. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10146. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10147. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10148. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  10149. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  10150. */
  10151. function Lines2D(points, settings) {
  10152. if (!settings) {
  10153. settings = {};
  10154. }
  10155. _super.call(this, settings);
  10156. this._fillVB = null;
  10157. this._fillIB = null;
  10158. this._borderVB = null;
  10159. this._borderIB = null;
  10160. this._size = BABYLON.Size.Zero();
  10161. this._boundingMin = null;
  10162. this._boundingMax = null;
  10163. var fillThickness = (settings.fillThickness == null) ? 1 : settings.fillThickness;
  10164. var startCap = (settings.startCap == null) ? 0 : settings.startCap;
  10165. var endCap = (settings.endCap == null) ? 0 : settings.endCap;
  10166. var closed = (settings.closed == null) ? false : settings.closed;
  10167. this.points = points;
  10168. this.fillThickness = fillThickness;
  10169. this.startCap = startCap;
  10170. this.endCap = endCap;
  10171. this.closed = closed;
  10172. }
  10173. Object.defineProperty(Lines2D, "NoCap", {
  10174. /**
  10175. * No Cap to apply on the extremity
  10176. */
  10177. get: function () { return Lines2D._noCap; },
  10178. enumerable: true,
  10179. configurable: true
  10180. });
  10181. Object.defineProperty(Lines2D, "RoundCap", {
  10182. /**
  10183. * A round cap, will use the line thickness as diameter
  10184. */
  10185. get: function () { return Lines2D._roundCap; },
  10186. enumerable: true,
  10187. configurable: true
  10188. });
  10189. Object.defineProperty(Lines2D, "TriangleCap", {
  10190. /**
  10191. * Creates a triangle at the extremity.
  10192. */
  10193. get: function () { return Lines2D._triangleCap; },
  10194. enumerable: true,
  10195. configurable: true
  10196. });
  10197. Object.defineProperty(Lines2D, "SquareAnchorCap", {
  10198. /**
  10199. * Creates a Square anchor at the extremity, the square size is twice the thickness of the line
  10200. */
  10201. get: function () { return Lines2D._squareAnchorCap; },
  10202. enumerable: true,
  10203. configurable: true
  10204. });
  10205. Object.defineProperty(Lines2D, "RoundAnchorCap", {
  10206. /**
  10207. * Creates a round anchor at the extremity, the diameter is twice the thickness of the line
  10208. */
  10209. get: function () { return Lines2D._roundAnchorCap; },
  10210. enumerable: true,
  10211. configurable: true
  10212. });
  10213. Object.defineProperty(Lines2D, "DiamondAnchorCap", {
  10214. /**
  10215. * Creates a diamond anchor at the extremity.
  10216. */
  10217. get: function () { return Lines2D._diamondAnchorCap; },
  10218. enumerable: true,
  10219. configurable: true
  10220. });
  10221. Object.defineProperty(Lines2D, "ArrowCap", {
  10222. /**
  10223. * Creates an arrow anchor at the extremity. the arrow base size is twice the thickness of the line
  10224. */
  10225. get: function () { return Lines2D._arrowCap; },
  10226. enumerable: true,
  10227. configurable: true
  10228. });
  10229. Object.defineProperty(Lines2D.prototype, "points", {
  10230. get: function () {
  10231. return this._points;
  10232. },
  10233. set: function (value) {
  10234. this._points = value;
  10235. this._contour = null;
  10236. this._boundingBoxDirty();
  10237. },
  10238. enumerable: true,
  10239. configurable: true
  10240. });
  10241. Object.defineProperty(Lines2D.prototype, "fillThickness", {
  10242. get: function () {
  10243. return this._fillThickness;
  10244. },
  10245. set: function (value) {
  10246. this._fillThickness = value;
  10247. },
  10248. enumerable: true,
  10249. configurable: true
  10250. });
  10251. Object.defineProperty(Lines2D.prototype, "closed", {
  10252. get: function () {
  10253. return this._closed;
  10254. },
  10255. set: function (value) {
  10256. this._closed = value;
  10257. },
  10258. enumerable: true,
  10259. configurable: true
  10260. });
  10261. Object.defineProperty(Lines2D.prototype, "startCap", {
  10262. get: function () {
  10263. return this._startCap;
  10264. },
  10265. set: function (value) {
  10266. this._startCap = value;
  10267. },
  10268. enumerable: true,
  10269. configurable: true
  10270. });
  10271. Object.defineProperty(Lines2D.prototype, "endCap", {
  10272. get: function () {
  10273. return this._endCap;
  10274. },
  10275. set: function (value) {
  10276. this._endCap = value;
  10277. },
  10278. enumerable: true,
  10279. configurable: true
  10280. });
  10281. Lines2D.prototype.levelIntersect = function (intersectInfo) {
  10282. var _this = this;
  10283. if (this._contour == null) {
  10284. this._computeLines2D();
  10285. }
  10286. var pl = this.points.length;
  10287. var l = this.closed ? pl + 1 : pl;
  10288. var p = intersectInfo._localPickPosition;
  10289. this.transformPointWithOriginToRef(this._contour[0], null, Lines2D._prevA);
  10290. this.transformPointWithOriginToRef(this._contour[1], null, Lines2D._prevB);
  10291. for (var i = 1; i < l; i++) {
  10292. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 0], null, Lines2D._curA);
  10293. this.transformPointWithOriginToRef(this._contour[(i % pl) * 2 + 1], null, Lines2D._curB);
  10294. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._prevA, Lines2D._prevB, Lines2D._curA)) {
  10295. return true;
  10296. }
  10297. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._curA, Lines2D._prevB, Lines2D._curB)) {
  10298. return true;
  10299. }
  10300. Lines2D._prevA.x = Lines2D._curA.x;
  10301. Lines2D._prevA.y = Lines2D._curA.y;
  10302. Lines2D._prevB.x = Lines2D._curB.x;
  10303. Lines2D._prevB.y = Lines2D._curB.y;
  10304. }
  10305. var capIntersect = function (tri, points) {
  10306. var l = tri.length;
  10307. for (var i = 0; i < l; i += 3) {
  10308. Lines2D._curA.x = points[tri[i + 0] * 2 + 0];
  10309. Lines2D._curA.y = points[tri[i + 0] * 2 + 1];
  10310. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._curB);
  10311. Lines2D._curA.x = points[tri[i + 1] * 2 + 0];
  10312. Lines2D._curA.y = points[tri[i + 1] * 2 + 1];
  10313. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._prevA);
  10314. Lines2D._curA.x = points[tri[i + 2] * 2 + 0];
  10315. Lines2D._curA.y = points[tri[i + 2] * 2 + 1];
  10316. _this.transformPointWithOriginToRef(Lines2D._curA, null, Lines2D._prevB);
  10317. if (BABYLON.Vector2.PointInTriangle(p, Lines2D._prevA, Lines2D._prevB, Lines2D._curB)) {
  10318. return true;
  10319. }
  10320. }
  10321. return false;
  10322. };
  10323. if (this._startCapTriIndices) {
  10324. if (this._startCapTriIndices && capIntersect(this._startCapTriIndices, this._startCapContour)) {
  10325. return true;
  10326. }
  10327. if (this._endCapTriIndices && capIntersect(this._endCapTriIndices, this._endCapContour)) {
  10328. return true;
  10329. }
  10330. }
  10331. return false;
  10332. };
  10333. Object.defineProperty(Lines2D.prototype, "boundingMin", {
  10334. get: function () {
  10335. if (!this._boundingMin) {
  10336. this._computeLines2D();
  10337. }
  10338. return this._boundingMin;
  10339. },
  10340. enumerable: true,
  10341. configurable: true
  10342. });
  10343. Object.defineProperty(Lines2D.prototype, "boundingMax", {
  10344. get: function () {
  10345. if (!this._boundingMax) {
  10346. this._computeLines2D();
  10347. }
  10348. return this._boundingMax;
  10349. },
  10350. enumerable: true,
  10351. configurable: true
  10352. });
  10353. Lines2D.prototype.getUsedShaderCategories = function (dataPart) {
  10354. var res = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  10355. // Remove the BORDER category, we don't use it in the VertexShader
  10356. var i = res.indexOf(BABYLON.Shape2D.SHAPE2D_CATEGORY_BORDER);
  10357. if (i !== -1) {
  10358. res.splice(i, 1);
  10359. }
  10360. return res;
  10361. };
  10362. Lines2D.prototype.updateLevelBoundingInfo = function () {
  10363. if (!this._boundingMin) {
  10364. this._computeLines2D();
  10365. }
  10366. BABYLON.BoundingInfo2D.CreateFromMinMaxToRef(this._boundingMin.x, this._boundingMax.x, this._boundingMin.y, this._boundingMax.y, this._levelBoundingInfo);
  10367. };
  10368. Lines2D.prototype.createModelRenderCache = function (modelKey) {
  10369. var renderCache = new Lines2DRenderCache(this.owner.engine, modelKey);
  10370. return renderCache;
  10371. };
  10372. ///////////////////////////////////////////////////////////////////////////////////
  10373. // Methods for Lines building
  10374. Lines2D.prototype._perp = function (v, res) {
  10375. res.x = v.y;
  10376. res.y = -v.x;
  10377. };
  10378. ;
  10379. Lines2D.prototype._direction = function (a, b, res) {
  10380. a.subtractToRef(b, res);
  10381. res.normalize();
  10382. };
  10383. Lines2D.prototype._computeMiter = function (tangent, miter, a, b) {
  10384. a.addToRef(b, tangent);
  10385. tangent.normalize();
  10386. miter.x = -tangent.y;
  10387. miter.y = tangent.x;
  10388. Lines2D._miterTps.x = -a.y;
  10389. Lines2D._miterTps.y = a.x;
  10390. return 1 / BABYLON.Vector2.Dot(miter, Lines2D._miterTps);
  10391. };
  10392. Lines2D.prototype._intersect = function (x1, y1, x2, y2, x3, y3, x4, y4) {
  10393. var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  10394. if (d === 0)
  10395. return false;
  10396. var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; // Intersection point is xi/yi, just in case...
  10397. //let yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; // That's why I left it commented
  10398. if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2))
  10399. return false;
  10400. if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4))
  10401. return false;
  10402. return true;
  10403. };
  10404. Lines2D.prototype._updateMinMax = function (array, offset) {
  10405. if (offset >= array.length) {
  10406. return;
  10407. }
  10408. this._boundingMin.x = Math.min(this._boundingMin.x, array[offset]);
  10409. this._boundingMax.x = Math.max(this._boundingMax.x, array[offset]);
  10410. this._boundingMin.y = Math.min(this._boundingMin.y, array[offset + 1]);
  10411. this._boundingMax.y = Math.max(this._boundingMax.y, array[offset + 1]);
  10412. };
  10413. Lines2D.prototype._store = function (array, contour, index, max, p, n, halfThickness, borderThickness, detectFlip) {
  10414. var borderMode = borderThickness != null && !isNaN(borderThickness);
  10415. var off = index * (borderMode ? 8 : 4);
  10416. // Mandatory because we'll be out of bound in case of closed line, for the very last point (which is a duplicate of the first that we don't store in the vb)
  10417. if (off >= array.length) {
  10418. return;
  10419. }
  10420. // Store start/end normal, we need it for the cap construction
  10421. if (index === 0) {
  10422. this._perp(n, Lines2D._startDir);
  10423. }
  10424. else if (index === max - 1) {
  10425. this._perp(n, Lines2D._endDir);
  10426. Lines2D._endDir.x *= -1;
  10427. Lines2D._endDir.y *= -1;
  10428. }
  10429. var swap = false;
  10430. array[off + 0] = p.x + n.x * halfThickness;
  10431. array[off + 1] = p.y + n.y * halfThickness;
  10432. array[off + 2] = p.x + n.x * -halfThickness;
  10433. array[off + 3] = p.y + n.y * -halfThickness;
  10434. this._updateMinMax(array, off);
  10435. this._updateMinMax(array, off + 2);
  10436. // If an index is given we check if the two segments formed between [index+0;detectFlip+0] and [index+2;detectFlip+2] intersect themselves.
  10437. // It should not be the case, they should be parallel, so if they cross, we switch the order of storage to ensure we'll have parallel lines
  10438. if (detectFlip !== undefined) {
  10439. // Flip if intersect
  10440. var flipOff = detectFlip * (borderMode ? 8 : 4);
  10441. if (this._intersect(array[off + 0], array[off + 1], array[flipOff + 0], array[flipOff + 1], array[off + 2], array[off + 3], array[flipOff + 2], array[flipOff + 3])) {
  10442. swap = true;
  10443. var tps = array[off + 0];
  10444. array[off + 0] = array[off + 2];
  10445. array[off + 2] = tps;
  10446. tps = array[off + 1];
  10447. array[off + 1] = array[off + 3];
  10448. array[off + 3] = tps;
  10449. }
  10450. }
  10451. if (borderMode) {
  10452. var t = halfThickness + borderThickness;
  10453. array[off + 4] = p.x + n.x * (swap ? -t : t);
  10454. array[off + 5] = p.y + n.y * (swap ? -t : t);
  10455. array[off + 6] = p.x + n.x * (swap ? t : -t);
  10456. array[off + 7] = p.y + n.y * (swap ? t : -t);
  10457. this._updateMinMax(array, off + 4);
  10458. this._updateMinMax(array, off + 6);
  10459. }
  10460. if (contour) {
  10461. off += borderMode ? 4 : 0;
  10462. contour.push(new BABYLON.Vector2(array[off + 0], array[off + 1]));
  10463. contour.push(new BABYLON.Vector2(array[off + 2], array[off + 3]));
  10464. }
  10465. };
  10466. Lines2D.prototype._getCapSize = function (type, border) {
  10467. if (border === void 0) { border = false; }
  10468. var sd = Lines2D._roundCapSubDiv;
  10469. // If no array given, we call this to get the size
  10470. var vbsize = 0, ibsize = 0;
  10471. switch (type) {
  10472. case Lines2D.NoCap:
  10473. {
  10474. // If the line is not close and we're computing border, we add the size to generate the edge border
  10475. if (!this.closed && border) {
  10476. vbsize = 4;
  10477. ibsize = 6;
  10478. }
  10479. else {
  10480. vbsize = ibsize = 0;
  10481. }
  10482. break;
  10483. }
  10484. case Lines2D.RoundCap:
  10485. {
  10486. if (border) {
  10487. vbsize = sd;
  10488. ibsize = (sd - 2) * 3;
  10489. }
  10490. else {
  10491. vbsize = (sd / 2) + 1;
  10492. ibsize = (sd / 2) * 3;
  10493. }
  10494. break;
  10495. }
  10496. case Lines2D.ArrowCap:
  10497. {
  10498. if (border) {
  10499. vbsize = 12;
  10500. ibsize = 24;
  10501. }
  10502. else {
  10503. vbsize = 3;
  10504. ibsize = 3;
  10505. }
  10506. break;
  10507. }
  10508. case Lines2D.TriangleCap:
  10509. {
  10510. if (border) {
  10511. vbsize = 6;
  10512. ibsize = 12;
  10513. }
  10514. else {
  10515. vbsize = 3;
  10516. ibsize = 3;
  10517. }
  10518. break;
  10519. }
  10520. case Lines2D.DiamondAnchorCap:
  10521. {
  10522. if (border) {
  10523. vbsize = 10;
  10524. ibsize = 24;
  10525. }
  10526. else {
  10527. vbsize = 5;
  10528. ibsize = 9;
  10529. }
  10530. break;
  10531. }
  10532. case Lines2D.SquareAnchorCap:
  10533. {
  10534. if (border) {
  10535. vbsize = 12;
  10536. ibsize = 30;
  10537. }
  10538. else {
  10539. vbsize = 4;
  10540. ibsize = 6;
  10541. }
  10542. break;
  10543. }
  10544. case Lines2D.RoundAnchorCap:
  10545. {
  10546. if (border) {
  10547. vbsize = sd * 2;
  10548. ibsize = (sd - 1) * 6;
  10549. }
  10550. else {
  10551. vbsize = sd + 1;
  10552. ibsize = (sd + 1) * 3;
  10553. }
  10554. break;
  10555. }
  10556. }
  10557. return { vbsize: vbsize * 2, ibsize: ibsize };
  10558. };
  10559. Lines2D.prototype._storeVertex = function (vb, baseOffset, index, basePos, rotation, vertex, contour) {
  10560. var c = Math.cos(rotation);
  10561. var s = Math.sin(rotation);
  10562. Lines2D._tpsV.x = (c * vertex.x) + (-s * vertex.y) + basePos.x;
  10563. Lines2D._tpsV.y = (s * vertex.x) + (c * vertex.y) + basePos.y;
  10564. var offset = baseOffset + (index * 2);
  10565. vb[offset + 0] = Lines2D._tpsV.x;
  10566. vb[offset + 1] = Lines2D._tpsV.y;
  10567. if (contour) {
  10568. contour.push(Lines2D._tpsV.x);
  10569. contour.push(Lines2D._tpsV.y);
  10570. }
  10571. this._updateMinMax(vb, offset);
  10572. return (baseOffset + index * 2) / 2;
  10573. };
  10574. Lines2D.prototype._storeIndex = function (ib, baseOffset, index, vertexIndex) {
  10575. ib[baseOffset + index] = vertexIndex;
  10576. };
  10577. Lines2D.prototype._buildCap = function (vb, vbi, ib, ibi, pos, thickness, borderThickness, type, capDir, contour) {
  10578. // Compute the transformation from the direction of the cap to build relative to our default orientation [1;0] (our cap are by default pointing toward right, horizontal
  10579. var sd = Lines2D._roundCapSubDiv;
  10580. var dir = new BABYLON.Vector2(1, 0);
  10581. var angle = Math.atan2(capDir.y, capDir.x) - Math.atan2(dir.y, dir.x);
  10582. var ht = thickness / 2;
  10583. var t = thickness;
  10584. var borderMode = borderThickness != null;
  10585. var bt = borderThickness;
  10586. switch (type) {
  10587. case Lines2D.NoCap:
  10588. if (borderMode && !this.closed) {
  10589. var vi = 0;
  10590. var ii = 0;
  10591. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), contour);
  10592. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, ht + bt), contour);
  10593. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(bt, -(ht + bt)), contour);
  10594. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), contour);
  10595. this._storeIndex(ib, ibi, ii++, v1);
  10596. this._storeIndex(ib, ibi, ii++, v2);
  10597. this._storeIndex(ib, ibi, ii++, v3);
  10598. this._storeIndex(ib, ibi, ii++, v1);
  10599. this._storeIndex(ib, ibi, ii++, v3);
  10600. this._storeIndex(ib, ibi, ii++, v4);
  10601. }
  10602. break;
  10603. case Lines2D.ArrowCap:
  10604. ht *= 2;
  10605. case Lines2D.TriangleCap:
  10606. {
  10607. if (borderMode) {
  10608. var f = type === Lines2D.TriangleCap ? bt : Math.sqrt(bt * bt * 2);
  10609. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), null);
  10610. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), null);
  10611. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), null);
  10612. var v4 = this._storeVertex(vb, vbi, 3, pos, angle, new BABYLON.Vector2(0, ht + f), contour);
  10613. var v5 = this._storeVertex(vb, vbi, 4, pos, angle, new BABYLON.Vector2(ht + f, 0), contour);
  10614. var v6 = this._storeVertex(vb, vbi, 5, pos, angle, new BABYLON.Vector2(0, -(ht + f)), contour);
  10615. var ii = 0;
  10616. this._storeIndex(ib, ibi, ii++, v1);
  10617. this._storeIndex(ib, ibi, ii++, v4);
  10618. this._storeIndex(ib, ibi, ii++, v5);
  10619. this._storeIndex(ib, ibi, ii++, v1);
  10620. this._storeIndex(ib, ibi, ii++, v5);
  10621. this._storeIndex(ib, ibi, ii++, v2);
  10622. this._storeIndex(ib, ibi, ii++, v6);
  10623. this._storeIndex(ib, ibi, ii++, v3);
  10624. this._storeIndex(ib, ibi, ii++, v2);
  10625. this._storeIndex(ib, ibi, ii++, v6);
  10626. this._storeIndex(ib, ibi, ii++, v2);
  10627. this._storeIndex(ib, ibi, ii++, v5);
  10628. if (type === Lines2D.ArrowCap) {
  10629. var rht = thickness / 2;
  10630. var v10 = this._storeVertex(vb, vbi, 9, pos, angle, new BABYLON.Vector2(0, -(rht + bt)), null);
  10631. var v12 = this._storeVertex(vb, vbi, 11, pos, angle, new BABYLON.Vector2(-bt, -(ht + f)), contour);
  10632. var v11 = this._storeVertex(vb, vbi, 10, pos, angle, new BABYLON.Vector2(-bt, -(rht + bt)), contour);
  10633. var v7 = this._storeVertex(vb, vbi, 6, pos, angle, new BABYLON.Vector2(0, rht + bt), null);
  10634. var v8 = this._storeVertex(vb, vbi, 7, pos, angle, new BABYLON.Vector2(-bt, rht + bt), contour);
  10635. var v9 = this._storeVertex(vb, vbi, 8, pos, angle, new BABYLON.Vector2(-bt, ht + f), contour);
  10636. this._storeIndex(ib, ibi, ii++, v7);
  10637. this._storeIndex(ib, ibi, ii++, v8);
  10638. this._storeIndex(ib, ibi, ii++, v9);
  10639. this._storeIndex(ib, ibi, ii++, v7);
  10640. this._storeIndex(ib, ibi, ii++, v9);
  10641. this._storeIndex(ib, ibi, ii++, v4);
  10642. this._storeIndex(ib, ibi, ii++, v10);
  10643. this._storeIndex(ib, ibi, ii++, v12);
  10644. this._storeIndex(ib, ibi, ii++, v11);
  10645. this._storeIndex(ib, ibi, ii++, v10);
  10646. this._storeIndex(ib, ibi, ii++, v6);
  10647. this._storeIndex(ib, ibi, ii++, v12);
  10648. }
  10649. }
  10650. else {
  10651. var v1 = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, ht), contour);
  10652. var v2 = this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(ht, 0), contour);
  10653. var v3 = this._storeVertex(vb, vbi, 2, pos, angle, new BABYLON.Vector2(0, -ht), contour);
  10654. this._storeIndex(ib, ibi, 0, v1);
  10655. this._storeIndex(ib, ibi, 1, v2);
  10656. this._storeIndex(ib, ibi, 2, v3);
  10657. }
  10658. break;
  10659. }
  10660. case Lines2D.RoundCap:
  10661. {
  10662. if (borderMode) {
  10663. var curA = -Math.PI / 2;
  10664. var incA = Math.PI / (sd / 2 - 1);
  10665. var ii = 0;
  10666. for (var i = 0; i < (sd / 2); i++) {
  10667. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  10668. var v2 = this._storeVertex(vb, vbi, i * 2 + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * (ht + bt), Math.sin(curA) * (ht + bt)), contour);
  10669. if (i > 0) {
  10670. this._storeIndex(ib, ibi, ii++, v1 - 2);
  10671. this._storeIndex(ib, ibi, ii++, v2 - 2);
  10672. this._storeIndex(ib, ibi, ii++, v2);
  10673. this._storeIndex(ib, ibi, ii++, v1 - 2);
  10674. this._storeIndex(ib, ibi, ii++, v2);
  10675. this._storeIndex(ib, ibi, ii++, v1);
  10676. }
  10677. curA += incA;
  10678. }
  10679. }
  10680. else {
  10681. var c = this._storeVertex(vb, vbi, 0, pos, angle, new BABYLON.Vector2(0, 0), null);
  10682. var curA = -Math.PI / 2;
  10683. var incA = Math.PI / (sd / 2 - 1);
  10684. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), null);
  10685. curA += incA;
  10686. for (var i = 1; i < (sd / 2); i++) {
  10687. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(Math.cos(curA) * ht, Math.sin(curA) * ht), contour);
  10688. this._storeIndex(ib, ibi, i * 3 + 0, c);
  10689. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  10690. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  10691. curA += incA;
  10692. }
  10693. }
  10694. break;
  10695. }
  10696. case Lines2D.SquareAnchorCap:
  10697. {
  10698. var vi = 0;
  10699. var c = borderMode ? null : contour;
  10700. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, t), c);
  10701. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, t), c);
  10702. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2, -t), c);
  10703. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -t), c);
  10704. if (borderMode) {
  10705. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht + bt), null);
  10706. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, ht + bt), contour);
  10707. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, t + bt), contour);
  10708. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, t + bt), contour);
  10709. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(t * 2 + bt, -(t + bt)), contour);
  10710. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(t + bt)), contour);
  10711. var v11 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-bt, -(ht + bt)), contour);
  10712. var v12 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -(ht + bt)), null);
  10713. var ii = 0;
  10714. this._storeIndex(ib, ibi, ii++, v6);
  10715. this._storeIndex(ib, ibi, ii++, v1);
  10716. this._storeIndex(ib, ibi, ii++, v5);
  10717. this._storeIndex(ib, ibi, ii++, v6);
  10718. this._storeIndex(ib, ibi, ii++, v7);
  10719. this._storeIndex(ib, ibi, ii++, v1);
  10720. this._storeIndex(ib, ibi, ii++, v1);
  10721. this._storeIndex(ib, ibi, ii++, v7);
  10722. this._storeIndex(ib, ibi, ii++, v8);
  10723. this._storeIndex(ib, ibi, ii++, v1);
  10724. this._storeIndex(ib, ibi, ii++, v8);
  10725. this._storeIndex(ib, ibi, ii++, v2);
  10726. this._storeIndex(ib, ibi, ii++, v2);
  10727. this._storeIndex(ib, ibi, ii++, v8);
  10728. this._storeIndex(ib, ibi, ii++, v9);
  10729. this._storeIndex(ib, ibi, ii++, v2);
  10730. this._storeIndex(ib, ibi, ii++, v9);
  10731. this._storeIndex(ib, ibi, ii++, v3);
  10732. this._storeIndex(ib, ibi, ii++, v3);
  10733. this._storeIndex(ib, ibi, ii++, v9);
  10734. this._storeIndex(ib, ibi, ii++, v10);
  10735. this._storeIndex(ib, ibi, ii++, v3);
  10736. this._storeIndex(ib, ibi, ii++, v10);
  10737. this._storeIndex(ib, ibi, ii++, v4);
  10738. this._storeIndex(ib, ibi, ii++, v10);
  10739. this._storeIndex(ib, ibi, ii++, v11);
  10740. this._storeIndex(ib, ibi, ii++, v4);
  10741. this._storeIndex(ib, ibi, ii++, v11);
  10742. this._storeIndex(ib, ibi, ii++, v12);
  10743. this._storeIndex(ib, ibi, ii++, v4);
  10744. }
  10745. else {
  10746. this._storeIndex(ib, ibi, 0, v1);
  10747. this._storeIndex(ib, ibi, 1, v2);
  10748. this._storeIndex(ib, ibi, 2, v3);
  10749. this._storeIndex(ib, ibi, 3, v1);
  10750. this._storeIndex(ib, ibi, 4, v3);
  10751. this._storeIndex(ib, ibi, 5, v4);
  10752. }
  10753. break;
  10754. }
  10755. case Lines2D.RoundAnchorCap:
  10756. {
  10757. var cpos = Math.sqrt(t * t - ht * ht);
  10758. var center = new BABYLON.Vector2(cpos, 0);
  10759. var curA = BABYLON.Tools.ToRadians(-150);
  10760. var incA = BABYLON.Tools.ToRadians(300) / (sd - 1);
  10761. if (borderMode) {
  10762. var ii = 0;
  10763. for (var i = 0; i < sd; i++) {
  10764. var v1 = this._storeVertex(vb, vbi, i * 2 + 0, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  10765. var v2 = this._storeVertex(vb, vbi, i * 2 + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * (t + bt), Math.sin(curA) * (t + bt)), contour);
  10766. if (i > 0) {
  10767. this._storeIndex(ib, ibi, ii++, v1 - 2);
  10768. this._storeIndex(ib, ibi, ii++, v2 - 2);
  10769. this._storeIndex(ib, ibi, ii++, v2);
  10770. this._storeIndex(ib, ibi, ii++, v1 - 2);
  10771. this._storeIndex(ib, ibi, ii++, v2);
  10772. this._storeIndex(ib, ibi, ii++, v1);
  10773. }
  10774. curA += incA;
  10775. }
  10776. }
  10777. else {
  10778. var c = this._storeVertex(vb, vbi, 0, pos, angle, center, null);
  10779. this._storeVertex(vb, vbi, 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), null);
  10780. curA += incA;
  10781. for (var i = 1; i < sd; i++) {
  10782. var v2 = this._storeVertex(vb, vbi, i + 1, pos, angle, new BABYLON.Vector2(cpos + Math.cos(curA) * t, Math.sin(curA) * t), contour);
  10783. this._storeIndex(ib, ibi, i * 3 + 0, c);
  10784. this._storeIndex(ib, ibi, i * 3 + 1, v2 - 1);
  10785. this._storeIndex(ib, ibi, i * 3 + 2, v2);
  10786. curA += incA;
  10787. }
  10788. this._storeIndex(ib, ibi, sd * 3 + 0, c);
  10789. this._storeIndex(ib, ibi, sd * 3 + 1, c + 1);
  10790. this._storeIndex(ib, ibi, sd * 3 + 2, c + sd);
  10791. }
  10792. break;
  10793. }
  10794. case Lines2D.DiamondAnchorCap:
  10795. {
  10796. var vi = 0;
  10797. var c = borderMode ? null : contour;
  10798. var v1 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, ht), c);
  10799. var v2 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t), c);
  10800. var v3 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3, 0), c);
  10801. var v4 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -t), c);
  10802. var v5 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(0, -ht), c);
  10803. if (borderMode) {
  10804. var f = Math.sqrt(bt * bt * 2);
  10805. var v6 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, ht), contour);
  10806. var v7 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, t + f), contour);
  10807. var v8 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht * 3 + f, 0), contour);
  10808. var v9 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(ht, -(t + f)), contour);
  10809. var v10 = this._storeVertex(vb, vbi, vi++, pos, angle, new BABYLON.Vector2(-f, -ht), contour);
  10810. var ii = 0;
  10811. this._storeIndex(ib, ibi, ii++, v6);
  10812. this._storeIndex(ib, ibi, ii++, v7);
  10813. this._storeIndex(ib, ibi, ii++, v1);
  10814. this._storeIndex(ib, ibi, ii++, v1);
  10815. this._storeIndex(ib, ibi, ii++, v7);
  10816. this._storeIndex(ib, ibi, ii++, v2);
  10817. this._storeIndex(ib, ibi, ii++, v2);
  10818. this._storeIndex(ib, ibi, ii++, v7);
  10819. this._storeIndex(ib, ibi, ii++, v8);
  10820. this._storeIndex(ib, ibi, ii++, v2);
  10821. this._storeIndex(ib, ibi, ii++, v8);
  10822. this._storeIndex(ib, ibi, ii++, v3);
  10823. this._storeIndex(ib, ibi, ii++, v3);
  10824. this._storeIndex(ib, ibi, ii++, v8);
  10825. this._storeIndex(ib, ibi, ii++, v9);
  10826. this._storeIndex(ib, ibi, ii++, v3);
  10827. this._storeIndex(ib, ibi, ii++, v9);
  10828. this._storeIndex(ib, ibi, ii++, v4);
  10829. this._storeIndex(ib, ibi, ii++, v4);
  10830. this._storeIndex(ib, ibi, ii++, v9);
  10831. this._storeIndex(ib, ibi, ii++, v10);
  10832. this._storeIndex(ib, ibi, ii++, v4);
  10833. this._storeIndex(ib, ibi, ii++, v10);
  10834. this._storeIndex(ib, ibi, ii++, v5);
  10835. }
  10836. else {
  10837. this._storeIndex(ib, ibi, 0, v1);
  10838. this._storeIndex(ib, ibi, 1, v2);
  10839. this._storeIndex(ib, ibi, 2, v3);
  10840. this._storeIndex(ib, ibi, 3, v1);
  10841. this._storeIndex(ib, ibi, 4, v3);
  10842. this._storeIndex(ib, ibi, 5, v5);
  10843. this._storeIndex(ib, ibi, 6, v5);
  10844. this._storeIndex(ib, ibi, 7, v3);
  10845. this._storeIndex(ib, ibi, 8, v4);
  10846. }
  10847. break;
  10848. }
  10849. }
  10850. return null;
  10851. };
  10852. Lines2D.prototype._buildLine = function (vb, contour, ht, bt) {
  10853. var lineA = BABYLON.Vector2.Zero();
  10854. var lineB = BABYLON.Vector2.Zero();
  10855. var tangent = BABYLON.Vector2.Zero();
  10856. var miter = BABYLON.Vector2.Zero();
  10857. var curNormal = null;
  10858. if (this.closed) {
  10859. this.points.push(this.points[0]);
  10860. }
  10861. var total = this.points.length;
  10862. for (var i = 1; i < total; i++) {
  10863. var last = this.points[i - 1];
  10864. var cur = this.points[i];
  10865. var next = (i < (this.points.length - 1)) ? this.points[i + 1] : null;
  10866. this._direction(cur, last, lineA);
  10867. if (!curNormal) {
  10868. curNormal = BABYLON.Vector2.Zero();
  10869. this._perp(lineA, curNormal);
  10870. }
  10871. if (i === 1) {
  10872. this._store(vb, contour, 0, total, this.points[0], curNormal, ht, bt);
  10873. }
  10874. if (!next) {
  10875. this._perp(lineA, curNormal);
  10876. this._store(vb, contour, i, total, this.points[i], curNormal, ht, bt, i - 1);
  10877. }
  10878. else {
  10879. this._direction(next, cur, lineB);
  10880. var miterLen = this._computeMiter(tangent, miter, lineA, lineB);
  10881. this._store(vb, contour, i, total, this.points[i], miter, miterLen * ht, miterLen * bt, i - 1);
  10882. }
  10883. }
  10884. if (this.points.length > 2 && this.closed) {
  10885. var last2 = this.points[total - 2];
  10886. var cur2 = this.points[0];
  10887. var next2 = this.points[1];
  10888. this._direction(cur2, last2, lineA);
  10889. this._direction(next2, cur2, lineB);
  10890. this._perp(lineA, curNormal);
  10891. var miterLen2 = this._computeMiter(tangent, miter, lineA, lineB);
  10892. this._store(vb, null, 0, total, this.points[0], miter, miterLen2 * ht, miterLen2 * bt, 1);
  10893. // Patch contour
  10894. if (contour) {
  10895. var off = (bt == null) ? 0 : 4;
  10896. contour[0].x = vb[off + 0];
  10897. contour[0].y = vb[off + 1];
  10898. contour[1].x = vb[off + 2];
  10899. contour[1].y = vb[off + 3];
  10900. }
  10901. }
  10902. // Remove the point we added at the beginning
  10903. if (this.closed) {
  10904. this.points.splice(total - 1);
  10905. }
  10906. };
  10907. // Methods for Lines building
  10908. ///////////////////////////////////////////////////////////////////////////////////
  10909. Lines2D.prototype.setupModelRenderCache = function (modelRenderCache) {
  10910. var renderCache = modelRenderCache;
  10911. var engine = this.owner.engine;
  10912. if (this._fillVB === null) {
  10913. this._computeLines2D();
  10914. }
  10915. // Need to create WebGL resources for fill part?
  10916. if (this.fill) {
  10917. renderCache.fillVB = engine.createVertexBuffer(this._fillVB);
  10918. renderCache.fillIB = engine.createIndexBuffer(this._fillIB);
  10919. renderCache.fillIndicesCount = this._fillIB.length;
  10920. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  10921. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, true);
  10922. if (ei) {
  10923. renderCache.effectFillInstanced = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  10924. }
  10925. // Get the non instanced version
  10926. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_FILLPARTID, ["position"], null, false);
  10927. renderCache.effectFill = engine.createEffect("lines2d", ei.attributes, ei.uniforms, [], ei.defines, null);
  10928. }
  10929. // Need to create WebGL resources for border part?
  10930. if (this.border) {
  10931. renderCache.borderVB = engine.createVertexBuffer(this._borderVB);
  10932. renderCache.borderIB = engine.createIndexBuffer(this._borderIB);
  10933. renderCache.borderIndicesCount = this._borderIB.length;
  10934. // Get the instanced version of the effect, if the engine does not support it, null is return and we'll only draw on by one
  10935. var ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, true);
  10936. if (ei) {
  10937. renderCache.effectBorderInstanced = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  10938. }
  10939. // Get the non instanced version
  10940. ei = this.getDataPartEffectInfo(BABYLON.Shape2D.SHAPE2D_BORDERPARTID, ["position"], null, false);
  10941. renderCache.effectBorder = engine.createEffect({ vertex: "lines2d", fragment: "lines2d" }, ei.attributes, ei.uniforms, [], ei.defines, null);
  10942. }
  10943. this._fillVB = null;
  10944. this._fillIB = null;
  10945. this._borderVB = null;
  10946. this._borderIB = null;
  10947. return renderCache;
  10948. };
  10949. Lines2D.prototype._computeLines2D = function () {
  10950. // Init min/max because their being computed here
  10951. this._boundingMin = new BABYLON.Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
  10952. this._boundingMax = new BABYLON.Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
  10953. var contour = new Array();
  10954. var startCapContour = new Array();
  10955. var endCapContour = new Array();
  10956. // Need to create WebGL resources for fill part?
  10957. if (this.fill) {
  10958. var startCapInfo = this._getCapSize(this.startCap);
  10959. var endCapInfo = this._getCapSize(this.endCap);
  10960. var count = this.points.length;
  10961. var vbSize = (count * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  10962. this._fillVB = new Float32Array(vbSize);
  10963. var vb = this._fillVB;
  10964. var ht = this.fillThickness / 2;
  10965. var total = this.points.length;
  10966. this._buildLine(vb, this.border ? null : contour, ht);
  10967. var max = total * 2;
  10968. var triCount = (count - (this.closed ? 0 : 1)) * 2;
  10969. this._fillIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  10970. var ib = this._fillIB;
  10971. for (var i = 0; i < triCount; i += 2) {
  10972. ib[i * 3 + 0] = i + 0;
  10973. ib[i * 3 + 1] = i + 1;
  10974. ib[i * 3 + 2] = (i + 2) % max;
  10975. ib[i * 3 + 3] = i + 1;
  10976. ib[i * 3 + 4] = (i + 3) % max;
  10977. ib[i * 3 + 5] = (i + 2) % max;
  10978. }
  10979. this._buildCap(vb, count * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, null, this.startCap, Lines2D._startDir, this.border ? null : startCapContour);
  10980. this._buildCap(vb, (count * 2 * 2) + startCapInfo.vbsize, ib, (triCount * 3) + startCapInfo.ibsize, this.points[total - 1], this.fillThickness, null, this.endCap, Lines2D._endDir, this.border ? null : startCapContour);
  10981. }
  10982. // Need to create WebGL resources for border part?
  10983. if (this.border) {
  10984. var startCapInfo = this._getCapSize(this.startCap, true);
  10985. var endCapInfo = this._getCapSize(this.endCap, true);
  10986. var count = this.points.length;
  10987. var vbSize = (count * 2 * 2 * 2) + startCapInfo.vbsize + endCapInfo.vbsize;
  10988. this._borderVB = new Float32Array(vbSize);
  10989. var vb = this._borderVB;
  10990. var ht = this.fillThickness / 2;
  10991. var bt = this.borderThickness;
  10992. var total = this.points.length;
  10993. this._buildLine(vb, contour, ht, bt);
  10994. var max = total * 2 * 2;
  10995. var triCount = (count - (this.closed ? 0 : 1)) * 2 * 2;
  10996. this._borderIB = new Float32Array(triCount * 3 + startCapInfo.ibsize + endCapInfo.ibsize);
  10997. var ib = this._borderIB;
  10998. for (var i = 0; i < triCount; i += 4) {
  10999. ib[i * 3 + 0] = i + 0;
  11000. ib[i * 3 + 1] = i + 2;
  11001. ib[i * 3 + 2] = (i + 6) % max;
  11002. ib[i * 3 + 3] = i + 0;
  11003. ib[i * 3 + 4] = (i + 6) % max;
  11004. ib[i * 3 + 5] = (i + 4) % max;
  11005. ib[i * 3 + 6] = i + 3;
  11006. ib[i * 3 + 7] = i + 1;
  11007. ib[i * 3 + 8] = (i + 5) % max;
  11008. ib[i * 3 + 9] = i + 3;
  11009. ib[i * 3 + 10] = (i + 5) % max;
  11010. ib[i * 3 + 11] = (i + 7) % max;
  11011. }
  11012. this._buildCap(vb, count * 2 * 2 * 2, ib, triCount * 3, this.points[0], this.fillThickness, this.borderThickness, this.startCap, Lines2D._startDir, startCapContour);
  11013. this._buildCap(vb, (count * 2 * 2 * 2) + startCapInfo.vbsize, ib, (triCount * 3) + startCapInfo.ibsize, this.points[total - 1], this.fillThickness, this.borderThickness, this.endCap, Lines2D._endDir, endCapContour);
  11014. }
  11015. this._contour = contour;
  11016. if (startCapContour.length > 0) {
  11017. var startCapTri = Earcut.earcut(startCapContour, null, 2);
  11018. this._startCapTriIndices = startCapTri;
  11019. this._startCapContour = startCapContour;
  11020. }
  11021. else {
  11022. this._startCapTriIndices = null;
  11023. this._startCapContour = null;
  11024. }
  11025. if (endCapContour.length > 0) {
  11026. var endCapTri = Earcut.earcut(endCapContour, null, 2);
  11027. this._endCapContour = endCapContour;
  11028. this._endCapTriIndices = endCapTri;
  11029. }
  11030. else {
  11031. this._endCapContour = null;
  11032. this._endCapTriIndices = null;
  11033. }
  11034. var bs = this._boundingMax.subtract(this._boundingMin);
  11035. this._size.width = bs.x;
  11036. this._size.height = bs.y;
  11037. };
  11038. Object.defineProperty(Lines2D.prototype, "size", {
  11039. get: function () {
  11040. if (this._size == null) {
  11041. this._computeLines2D();
  11042. }
  11043. return this._size;
  11044. },
  11045. enumerable: true,
  11046. configurable: true
  11047. });
  11048. Lines2D.prototype.createInstanceDataParts = function () {
  11049. var res = new Array();
  11050. if (this.border) {
  11051. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_BORDERPARTID));
  11052. }
  11053. if (this.fill) {
  11054. res.push(new Lines2DInstanceData(BABYLON.Shape2D.SHAPE2D_FILLPARTID));
  11055. }
  11056. return res;
  11057. };
  11058. Lines2D.prototype.applyActualScaleOnTransform = function () {
  11059. return true;
  11060. };
  11061. Lines2D.prototype.refreshInstanceDataPart = function (part) {
  11062. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  11063. return false;
  11064. }
  11065. if (part.id === BABYLON.Shape2D.SHAPE2D_BORDERPARTID) {
  11066. var d = part;
  11067. if (this.border instanceof BABYLON.GradientColorBrush2D) {
  11068. d.boundingMin = this.boundingMin;
  11069. d.boundingMax = this.boundingMax;
  11070. }
  11071. }
  11072. else if (part.id === BABYLON.Shape2D.SHAPE2D_FILLPARTID) {
  11073. var d = part;
  11074. if (this.fill instanceof BABYLON.GradientColorBrush2D) {
  11075. d.boundingMin = this.boundingMin;
  11076. d.boundingMax = this.boundingMax;
  11077. }
  11078. }
  11079. return true;
  11080. };
  11081. Lines2D._prevA = BABYLON.Vector2.Zero();
  11082. Lines2D._prevB = BABYLON.Vector2.Zero();
  11083. Lines2D._curA = BABYLON.Vector2.Zero();
  11084. Lines2D._curB = BABYLON.Vector2.Zero();
  11085. Lines2D._miterTps = BABYLON.Vector2.Zero();
  11086. Lines2D._startDir = BABYLON.Vector2.Zero();
  11087. Lines2D._endDir = BABYLON.Vector2.Zero();
  11088. Lines2D._tpsV = BABYLON.Vector2.Zero();
  11089. Lines2D._noCap = 0;
  11090. Lines2D._roundCap = 1;
  11091. Lines2D._triangleCap = 2;
  11092. Lines2D._squareAnchorCap = 3;
  11093. Lines2D._roundAnchorCap = 4;
  11094. Lines2D._diamondAnchorCap = 5;
  11095. Lines2D._arrowCap = 6;
  11096. Lines2D._roundCapSubDiv = 36;
  11097. __decorate([
  11098. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 1, function (pi) { return Lines2D.pointsProperty = pi; })
  11099. ], Lines2D.prototype, "points", null);
  11100. __decorate([
  11101. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 2, function (pi) { return Lines2D.fillThicknessProperty = pi; })
  11102. ], Lines2D.prototype, "fillThickness", null);
  11103. __decorate([
  11104. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 3, function (pi) { return Lines2D.closedProperty = pi; })
  11105. ], Lines2D.prototype, "closed", null);
  11106. __decorate([
  11107. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 4, function (pi) { return Lines2D.startCapProperty = pi; })
  11108. ], Lines2D.prototype, "startCap", null);
  11109. __decorate([
  11110. BABYLON.modelLevelProperty(BABYLON.Shape2D.SHAPE2D_PROPCOUNT + 5, function (pi) { return Lines2D.endCapProperty = pi; })
  11111. ], Lines2D.prototype, "endCap", null);
  11112. Lines2D = __decorate([
  11113. BABYLON.className("Lines2D", "BABYLON")
  11114. ], Lines2D);
  11115. return Lines2D;
  11116. }(BABYLON.Shape2D));
  11117. BABYLON.Lines2D = Lines2D;
  11118. })(BABYLON || (BABYLON = {}));
  11119. var BABYLON;
  11120. (function (BABYLON) {
  11121. // This class contains data that lifetime is bounding to the Babylon Engine object
  11122. var Canvas2DEngineBoundData = (function () {
  11123. function Canvas2DEngineBoundData() {
  11124. this._modelCache = new BABYLON.StringDictionary();
  11125. }
  11126. Canvas2DEngineBoundData.prototype.GetOrAddModelCache = function (key, factory) {
  11127. return this._modelCache.getOrAddWithFactory(key, factory);
  11128. };
  11129. Canvas2DEngineBoundData.prototype.DisposeModelRenderCache = function (modelRenderCache) {
  11130. if (!modelRenderCache.isDisposed) {
  11131. return false;
  11132. }
  11133. this._modelCache.remove(modelRenderCache.modelKey);
  11134. return true;
  11135. };
  11136. return Canvas2DEngineBoundData;
  11137. }());
  11138. BABYLON.Canvas2DEngineBoundData = Canvas2DEngineBoundData;
  11139. var Canvas2D = (function (_super) {
  11140. __extends(Canvas2D, _super);
  11141. function Canvas2D(scene, settings) {
  11142. var _this = this;
  11143. _super.call(this, settings);
  11144. /**
  11145. * If you set your own WorldSpaceNode to display the Canvas2D you have to provide your own implementation of this method which computes the local position in the Canvas based on the given 3D World one.
  11146. * Beware that you have to take under consideration the origin in your calculations! Good luck!
  11147. */
  11148. this.worldSpaceToNodeLocal = function (worldPos) {
  11149. var node = _this._worldSpaceNode;
  11150. if (!node) {
  11151. return;
  11152. }
  11153. var mtx = node.getWorldMatrix().clone();
  11154. mtx.invert();
  11155. var v = BABYLON.Vector3.TransformCoordinates(worldPos, mtx);
  11156. var res = new BABYLON.Vector2(v.x, v.y);
  11157. var size = _this.actualSize;
  11158. res.x += size.width * 0.5; // res is centered, make it relative to bottom/left
  11159. res.y += size.height * 0.5;
  11160. return res;
  11161. };
  11162. /**
  11163. * If you use a custom WorldSpaceCanvasNode you have to override this property to update the UV of your object to reflect the changes due to a resizing of the cached bitmap
  11164. */
  11165. this.worldSpaceCacheChanged = function () {
  11166. var plane = _this.worldSpaceCanvasNode;
  11167. var vd = BABYLON.VertexData.ExtractFromMesh(plane); //new VertexData();
  11168. vd.uvs = new Float32Array(8);
  11169. var material = plane.material;
  11170. var tex = _this._renderableData._cacheTexture;
  11171. if (material.diffuseTexture !== tex) {
  11172. material.diffuseTexture = tex;
  11173. tex.hasAlpha = true;
  11174. }
  11175. var nodeuv = _this._renderableData._cacheNodeUVs;
  11176. for (var i = 0; i < 4; i++) {
  11177. vd.uvs[i * 2 + 0] = nodeuv[i].x;
  11178. vd.uvs[i * 2 + 1] = nodeuv[i].y;
  11179. }
  11180. vd.applyToMesh(plane);
  11181. };
  11182. this._notifDebugMode = false;
  11183. this._mapCounter = 0;
  11184. this._drawCallsOpaqueCounter = new BABYLON.PerfCounter();
  11185. this._drawCallsAlphaTestCounter = new BABYLON.PerfCounter();
  11186. this._drawCallsTransparentCounter = new BABYLON.PerfCounter();
  11187. this._groupRenderCounter = new BABYLON.PerfCounter();
  11188. this._updateTransparentDataCounter = new BABYLON.PerfCounter();
  11189. this._cachedGroupRenderCounter = new BABYLON.PerfCounter();
  11190. this._updateCachedStateCounter = new BABYLON.PerfCounter();
  11191. this._updateLayoutCounter = new BABYLON.PerfCounter();
  11192. this._updatePositioningCounter = new BABYLON.PerfCounter();
  11193. this._updateLocalTransformCounter = new BABYLON.PerfCounter();
  11194. this._updateGlobalTransformCounter = new BABYLON.PerfCounter();
  11195. this._boundingInfoRecomputeCounter = new BABYLON.PerfCounter();
  11196. this._uid = null;
  11197. this._cachedCanvasGroup = null;
  11198. this._profileInfoText = null;
  11199. BABYLON.Prim2DBase._isCanvasInit = false;
  11200. if (!settings) {
  11201. settings = {};
  11202. }
  11203. if (this._cachingStrategy !== Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  11204. this._background = new BABYLON.Rectangle2D({ parent: this, id: "###CANVAS BACKGROUND###", size: settings.size }); //TODO CHECK when size is null
  11205. this._background.zOrder = 1.0;
  11206. this._background.isPickable = false;
  11207. this._background.origin = BABYLON.Vector2.Zero();
  11208. this._background.levelVisible = false;
  11209. if (settings.backgroundRoundRadius != null) {
  11210. this.backgroundRoundRadius = settings.backgroundRoundRadius;
  11211. }
  11212. if (settings.backgroundBorder != null) {
  11213. if (typeof (settings.backgroundBorder) === "string") {
  11214. this.backgroundBorder = Canvas2D.GetBrushFromString(settings.backgroundBorder);
  11215. }
  11216. else {
  11217. this.backgroundBorder = settings.backgroundBorder;
  11218. }
  11219. }
  11220. if (settings.backgroundBorderThickNess != null) {
  11221. this.backgroundBorderThickness = settings.backgroundBorderThickNess;
  11222. }
  11223. if (settings.backgroundFill != null) {
  11224. if (typeof (settings.backgroundFill) === "string") {
  11225. this.backgroundFill = Canvas2D.GetBrushFromString(settings.backgroundFill);
  11226. }
  11227. else {
  11228. this.backgroundFill = settings.backgroundFill;
  11229. }
  11230. }
  11231. // Put a handler to resize the background whenever the canvas is resizing
  11232. this.propertyChanged.add(function (e, s) {
  11233. if (e.propertyName === "size") {
  11234. _this._background.size = _this.size;
  11235. }
  11236. }, BABYLON.Group2D.sizeProperty.flagId);
  11237. this._background._patchHierarchy(this);
  11238. }
  11239. var engine = scene.getEngine();
  11240. this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
  11241. this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
  11242. this._capturedPointers = new BABYLON.StringDictionary();
  11243. this._pickStartingPosition = BABYLON.Vector2.Zero();
  11244. this._hierarchyLevelMaxSiblingCount = 50;
  11245. this._hierarchyDepth = 0;
  11246. this._zOrder = 0;
  11247. this._zMax = 1;
  11248. this._scene = scene;
  11249. this._engine = engine;
  11250. this._renderingSize = new BABYLON.Size(0, 0);
  11251. this._designSize = settings.designSize || null;
  11252. this._designUseHorizAxis = settings.designUseHorizAxis === true;
  11253. this._trackedGroups = new Array();
  11254. this._maxAdaptiveWorldSpaceCanvasSize = null;
  11255. this._groupCacheMaps = new BABYLON.StringDictionary();
  11256. this._patchHierarchy(this);
  11257. var enableInteraction = (settings.enableInteraction == null) ? true : settings.enableInteraction;
  11258. this._fitRenderingDevice = !settings.size;
  11259. if (!settings.size) {
  11260. settings.size = new BABYLON.Size(engine.getRenderWidth(), engine.getRenderHeight());
  11261. }
  11262. // Register scene dispose to also dispose the canvas when it'll happens
  11263. scene.onDisposeObservable.add(function (d, s) {
  11264. _this.dispose();
  11265. });
  11266. if (this._isScreenSpace) {
  11267. this._afterRenderObserver = this._scene.onAfterRenderObservable.add(function (d, s) {
  11268. _this._engine.clear(null, false, true, true);
  11269. _this._render();
  11270. });
  11271. }
  11272. else {
  11273. this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function (d, s) {
  11274. _this._render();
  11275. });
  11276. }
  11277. this._supprtInstancedArray = this._engine.getCaps().instancedArrays !== null;
  11278. //this._supprtInstancedArray = false; // TODO REMOVE!!!
  11279. this._setupInteraction(enableInteraction);
  11280. // Register this instance
  11281. Canvas2D._INSTANCES.push(this);
  11282. }
  11283. Object.defineProperty(Canvas2D.prototype, "drawCallsOpaqueCounter", {
  11284. get: function () {
  11285. return this._drawCallsOpaqueCounter;
  11286. },
  11287. enumerable: true,
  11288. configurable: true
  11289. });
  11290. Object.defineProperty(Canvas2D.prototype, "drawCallsAlphaTestCounter", {
  11291. get: function () {
  11292. return this._drawCallsAlphaTestCounter;
  11293. },
  11294. enumerable: true,
  11295. configurable: true
  11296. });
  11297. Object.defineProperty(Canvas2D.prototype, "drawCallsTransparentCounter", {
  11298. get: function () {
  11299. return this._drawCallsTransparentCounter;
  11300. },
  11301. enumerable: true,
  11302. configurable: true
  11303. });
  11304. Object.defineProperty(Canvas2D.prototype, "groupRenderCounter", {
  11305. get: function () {
  11306. return this._groupRenderCounter;
  11307. },
  11308. enumerable: true,
  11309. configurable: true
  11310. });
  11311. Object.defineProperty(Canvas2D.prototype, "updateTransparentDataCounter", {
  11312. get: function () {
  11313. return this._updateTransparentDataCounter;
  11314. },
  11315. enumerable: true,
  11316. configurable: true
  11317. });
  11318. Object.defineProperty(Canvas2D.prototype, "cachedGroupRenderCounter", {
  11319. get: function () {
  11320. return this._cachedGroupRenderCounter;
  11321. },
  11322. enumerable: true,
  11323. configurable: true
  11324. });
  11325. Object.defineProperty(Canvas2D.prototype, "updateCachedStateCounter", {
  11326. get: function () {
  11327. return this._updateCachedStateCounter;
  11328. },
  11329. enumerable: true,
  11330. configurable: true
  11331. });
  11332. Object.defineProperty(Canvas2D.prototype, "updateLayoutCounter", {
  11333. get: function () {
  11334. return this._updateLayoutCounter;
  11335. },
  11336. enumerable: true,
  11337. configurable: true
  11338. });
  11339. Object.defineProperty(Canvas2D.prototype, "updatePositioningCounter", {
  11340. get: function () {
  11341. return this._updatePositioningCounter;
  11342. },
  11343. enumerable: true,
  11344. configurable: true
  11345. });
  11346. Object.defineProperty(Canvas2D.prototype, "updateLocalTransformCounter", {
  11347. get: function () {
  11348. return this._updateLocalTransformCounter;
  11349. },
  11350. enumerable: true,
  11351. configurable: true
  11352. });
  11353. Object.defineProperty(Canvas2D.prototype, "updateGlobalTransformCounter", {
  11354. get: function () {
  11355. return this._updateGlobalTransformCounter;
  11356. },
  11357. enumerable: true,
  11358. configurable: true
  11359. });
  11360. Object.defineProperty(Canvas2D.prototype, "boundingInfoRecomputeCounter", {
  11361. get: function () {
  11362. return this._boundingInfoRecomputeCounter;
  11363. },
  11364. enumerable: true,
  11365. configurable: true
  11366. });
  11367. Object.defineProperty(Canvas2D, "instances", {
  11368. get: function () {
  11369. return Canvas2D._INSTANCES;
  11370. },
  11371. enumerable: true,
  11372. configurable: true
  11373. });
  11374. Canvas2D.prototype._canvasPreInit = function (settings) {
  11375. var cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
  11376. this._cachingStrategy = cachingStrategy;
  11377. this._isScreenSpace = (settings.isScreenSpace == null) ? true : settings.isScreenSpace;
  11378. };
  11379. Canvas2D.prototype._setupInteraction = function (enable) {
  11380. var _this = this;
  11381. // No change detection
  11382. if (enable === this._interactionEnabled) {
  11383. return;
  11384. }
  11385. // Set the new state
  11386. this._interactionEnabled = enable;
  11387. // ScreenSpace mode
  11388. if (this._isScreenSpace) {
  11389. // Disable interaction
  11390. if (!enable) {
  11391. if (this._scenePrePointerObserver) {
  11392. this.scene.onPrePointerObservable.remove(this._scenePrePointerObserver);
  11393. this._scenePrePointerObserver = null;
  11394. }
  11395. return;
  11396. }
  11397. // Enable Interaction
  11398. // Register the observable
  11399. this._scenePrePointerObserver = this.scene.onPrePointerObservable.add(function (e, s) {
  11400. if (_this.isVisible === false) {
  11401. return;
  11402. }
  11403. var hs = 1 / _this.engine.getHardwareScalingLevel();
  11404. var localPos = e.localPosition.multiplyByFloats(hs, hs);
  11405. _this._handlePointerEventForInteraction(e, localPos, s);
  11406. });
  11407. }
  11408. else {
  11409. var scene = this.scene;
  11410. if (enable) {
  11411. scene.constantlyUpdateMeshUnderPointer = true;
  11412. this._scenePointerObserver = scene.onPointerObservable.add(function (e, s) {
  11413. if (_this.isVisible === false) {
  11414. return;
  11415. }
  11416. if (e.pickInfo.hit && e.pickInfo.pickedMesh === _this._worldSpaceNode && _this.worldSpaceToNodeLocal) {
  11417. var localPos = _this.worldSpaceToNodeLocal(e.pickInfo.pickedPoint);
  11418. _this._handlePointerEventForInteraction(e, localPos, s);
  11419. }
  11420. });
  11421. }
  11422. else {
  11423. if (this._scenePointerObserver) {
  11424. this.scene.onPointerObservable.remove(this._scenePointerObserver);
  11425. this._scenePointerObserver = null;
  11426. }
  11427. }
  11428. }
  11429. };
  11430. /**
  11431. * Internal method, you should use the Prim2DBase version instead
  11432. */
  11433. Canvas2D.prototype._setPointerCapture = function (pointerId, primitive) {
  11434. if (this.isPointerCaptured(pointerId)) {
  11435. return false;
  11436. }
  11437. // Try to capture the pointer on the HTML side
  11438. try {
  11439. this.engine.getRenderingCanvas().setPointerCapture(pointerId);
  11440. }
  11441. catch (e) {
  11442. }
  11443. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  11444. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
  11445. this._capturedPointers.add(pointerId.toString(), primitive);
  11446. return true;
  11447. };
  11448. /**
  11449. * Internal method, you should use the Prim2DBase version instead
  11450. */
  11451. Canvas2D.prototype._releasePointerCapture = function (pointerId, primitive) {
  11452. if (this._capturedPointers.get(pointerId.toString()) !== primitive) {
  11453. return false;
  11454. }
  11455. // Try to release the pointer on the HTML side
  11456. try {
  11457. this.engine.getRenderingCanvas().releasePointerCapture(pointerId);
  11458. }
  11459. catch (e) {
  11460. }
  11461. this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
  11462. this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
  11463. this._capturedPointers.remove(pointerId.toString());
  11464. return true;
  11465. };
  11466. /**
  11467. * Determine if the given pointer is captured or not
  11468. * @param pointerId the Id of the pointer
  11469. * @return true if it's captured, false otherwise
  11470. */
  11471. Canvas2D.prototype.isPointerCaptured = function (pointerId) {
  11472. return this._capturedPointers.contains(pointerId.toString());
  11473. };
  11474. Canvas2D.prototype.getCapturedPrimitive = function (pointerId) {
  11475. // Avoid unnecessary lookup
  11476. if (this._capturedPointers.count === 0) {
  11477. return null;
  11478. }
  11479. return this._capturedPointers.get(pointerId.toString());
  11480. };
  11481. Canvas2D.prototype._handlePointerEventForInteraction = function (eventData, localPosition, eventState) {
  11482. // Dispose check
  11483. if (this.isDisposed) {
  11484. return;
  11485. }
  11486. // Update the this._primPointerInfo structure we'll send to observers using the PointerEvent data
  11487. if (!this._updatePointerInfo(eventData, localPosition)) {
  11488. return;
  11489. }
  11490. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  11491. // Make sure the intersection list is up to date, we maintain this list either in response of a mouse event (here) or before rendering the canvas.
  11492. // Why before rendering the canvas? because some primitives may move and get away/under the mouse cursor (which is not moving). So we need to update at both location in order to always have an accurate list, which is needed for the hover state change.
  11493. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, capturedPrim !== null, true);
  11494. // Update the over status, same as above, it's could be done here or during rendering, but will be performed only once per render frame
  11495. this._updateOverStatus(true);
  11496. // Check if we have nothing to raise
  11497. if (!this._actualOverPrimitive && !capturedPrim) {
  11498. return;
  11499. }
  11500. // Update the relatedTarget info with the over primitive or the captured one (if any)
  11501. var targetPrim = capturedPrim || this._actualOverPrimitive.prim;
  11502. var targetPointerPos = capturedPrim ? this._primPointerInfo.canvasPointerPos.subtract(new BABYLON.Vector2(targetPrim.globalTransform.m[12], targetPrim.globalTransform.m[13])) : this._actualOverPrimitive.intersectionLocation;
  11503. this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
  11504. // Analyze the pointer event type and fire proper events on the primitive
  11505. var skip = false;
  11506. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  11507. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData);
  11508. }
  11509. else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  11510. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData);
  11511. }
  11512. else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
  11513. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData);
  11514. }
  11515. else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
  11516. skip = !this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData);
  11517. }
  11518. eventState.skipNextObservers = skip;
  11519. };
  11520. Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) {
  11521. var s = this.scale;
  11522. var pii = this._primPointerInfo;
  11523. if (!pii.canvasPointerPos) {
  11524. pii.canvasPointerPos = BABYLON.Vector2.Zero();
  11525. }
  11526. var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera;
  11527. if (!camera || !camera.viewport) {
  11528. return false;
  11529. }
  11530. var engine = this._scene.getEngine();
  11531. if (this._isScreenSpace) {
  11532. var cameraViewport = camera.viewport;
  11533. var viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  11534. // Moving coordinates to local viewport world
  11535. var x = localPosition.x - viewport.x;
  11536. var y = localPosition.y - viewport.y;
  11537. pii.canvasPointerPos.x = (x - this.actualPosition.x) / s;
  11538. pii.canvasPointerPos.y = (engine.getRenderHeight() - y - this.actualPosition.y) / s;
  11539. }
  11540. else {
  11541. pii.canvasPointerPos.x = localPosition.x / s;
  11542. pii.canvasPointerPos.y = localPosition.y / s;
  11543. }
  11544. //console.log(`UpdatePointerInfo for ${this.id}, X:${pii.canvasPointerPos.x}, Y:${pii.canvasPointerPos.y}`);
  11545. pii.mouseWheelDelta = 0;
  11546. if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
  11547. var event = eventData.event;
  11548. if (event.wheelDelta) {
  11549. pii.mouseWheelDelta = event.wheelDelta / (BABYLON.PrimitivePointerInfo.MouseWheelPrecision * 40);
  11550. }
  11551. else if (event.detail) {
  11552. pii.mouseWheelDelta = -event.detail / BABYLON.PrimitivePointerInfo.MouseWheelPrecision;
  11553. }
  11554. }
  11555. else {
  11556. var pe = eventData.event;
  11557. pii.ctrlKey = pe.ctrlKey;
  11558. pii.altKey = pe.altKey;
  11559. pii.shiftKey = pe.shiftKey;
  11560. pii.metaKey = pe.metaKey;
  11561. pii.button = pe.button;
  11562. pii.buttons = pe.buttons;
  11563. pii.pointerId = pe.pointerId;
  11564. pii.width = pe.width;
  11565. pii.height = pe.height;
  11566. pii.presssure = pe.pressure;
  11567. pii.tilt.x = pe.tiltX;
  11568. pii.tilt.y = pe.tiltY;
  11569. pii.isCaptured = this.getCapturedPrimitive(pe.pointerId) !== null;
  11570. }
  11571. return true;
  11572. };
  11573. Canvas2D.prototype._updateIntersectionList = function (mouseLocalPos, isCapture, force) {
  11574. if (!force && (this.scene.getRenderId() === this._intersectionRenderId)) {
  11575. return;
  11576. }
  11577. // A little safe guard, it might happens than the event is triggered before the first render and nothing is computed, this simple check will make sure everything will be fine
  11578. if (!this._globalTransform) {
  11579. this.updateCachedStates(true);
  11580. }
  11581. var ii = Canvas2D._interInfo;
  11582. ii.pickPosition.x = mouseLocalPos.x;
  11583. ii.pickPosition.y = mouseLocalPos.y;
  11584. ii.findFirstOnly = false;
  11585. // Fast rejection: test if the mouse pointer is outside the canvas's bounding Info
  11586. if (!isCapture && !this.levelBoundingInfo.doesIntersect(ii.pickPosition)) {
  11587. this._previousIntersectionList = this._actualIntersectionList;
  11588. this._actualIntersectionList = null;
  11589. this._previousOverPrimitive = this._actualOverPrimitive;
  11590. this._actualOverPrimitive = null;
  11591. return;
  11592. }
  11593. this.intersect(ii);
  11594. this._previousIntersectionList = this._actualIntersectionList;
  11595. this._actualIntersectionList = ii.intersectedPrimitives;
  11596. this._previousOverPrimitive = this._actualOverPrimitive;
  11597. this._actualOverPrimitive = ii.topMostIntersectedPrimitive;
  11598. if ((!this._actualOverPrimitive && !this._previousOverPrimitive) || !(this._actualOverPrimitive && this._previousOverPrimitive && this._actualOverPrimitive.prim === this._previousOverPrimitive.prim)) {
  11599. this.onPropertyChanged("overPrim", this._previousOverPrimitive ? this._previousOverPrimitive.prim : null, this._actualOverPrimitive ? this._actualOverPrimitive.prim : null);
  11600. }
  11601. this._intersectionRenderId = this.scene.getRenderId();
  11602. };
  11603. // Based on the previousIntersectionList and the actualInstersectionList we can determined which primitives are being hover state or loosing it
  11604. Canvas2D.prototype._updateOverStatus = function (force) {
  11605. if ((!force && (this.scene.getRenderId() === this._hoverStatusRenderId)) || !this._previousIntersectionList || !this._actualIntersectionList) {
  11606. return;
  11607. }
  11608. // Detect a change of over
  11609. var prevPrim = this._previousOverPrimitive ? this._previousOverPrimitive.prim : null;
  11610. var actualPrim = this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  11611. if (prevPrim !== actualPrim) {
  11612. // Detect if the current pointer is captured, only fire event if they belong to the capture primitive
  11613. var capturedPrim = this.getCapturedPrimitive(this._primPointerInfo.pointerId);
  11614. // Notify the previous "over" prim that the pointer is no longer over it
  11615. if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim)) {
  11616. this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
  11617. this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
  11618. }
  11619. // Notify the new "over" prim that the pointer is over it
  11620. if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
  11621. this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
  11622. this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
  11623. }
  11624. }
  11625. this._hoverStatusRenderId = this.scene.getRenderId();
  11626. };
  11627. Canvas2D.prototype._updatePrimPointerPos = function (prim) {
  11628. if (this._primPointerInfo.isCaptured) {
  11629. this._primPointerInfo.primitivePointerPos = this._primPointerInfo.relatedTargetPointerPos;
  11630. }
  11631. else {
  11632. for (var _i = 0, _a = this._actualIntersectionList; _i < _a.length; _i++) {
  11633. var pii = _a[_i];
  11634. if (pii.prim === prim) {
  11635. this._primPointerInfo.primitivePointerPos = pii.intersectionLocation;
  11636. return;
  11637. }
  11638. }
  11639. }
  11640. };
  11641. Canvas2D.prototype._debugExecObserver = function (prim, mask) {
  11642. if (!this._notifDebugMode) {
  11643. return;
  11644. }
  11645. var debug = "";
  11646. for (var i = 0; i < prim.hierarchyDepth; i++) {
  11647. debug += " ";
  11648. }
  11649. var pii = this._primPointerInfo;
  11650. debug += "[RID:" + this.scene.getRenderId() + "] [" + prim.hierarchyDepth + "] event:" + BABYLON.PrimitivePointerInfo.getEventTypeName(mask) + ", id: " + prim.id + " (" + BABYLON.Tools.getClassName(prim) + "), primPos: " + pii.primitivePointerPos.toString() + ", canvasPos: " + pii.canvasPointerPos.toString();
  11651. console.log(debug);
  11652. };
  11653. Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
  11654. var ppi = this._primPointerInfo;
  11655. var event = eventData ? eventData.event : null;
  11656. // In case of PointerOver/Out we will first notify the parent with PointerEnter/Leave
  11657. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
  11658. this._notifParents(prim, mask);
  11659. }
  11660. var bubbleCancelled = false;
  11661. var cur = prim;
  11662. while (cur) {
  11663. // Only trigger the observers if the primitive is intersected (except for out)
  11664. if (!bubbleCancelled) {
  11665. this._updatePrimPointerPos(cur);
  11666. // Exec the observers
  11667. this._debugExecObserver(cur, mask);
  11668. if (!cur._pointerEventObservable.notifyObservers(ppi, mask) && eventData instanceof BABYLON.PointerInfoPre) {
  11669. eventData.skipOnPointerObservable = true;
  11670. return false;
  11671. }
  11672. this._triggerActionManager(cur, ppi, mask, event);
  11673. // Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
  11674. // If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
  11675. if (ppi.cancelBubble) {
  11676. if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
  11677. return false;
  11678. }
  11679. // We're dealing with PointerOver/Out, let's keep looping to fire PointerEnter/Leave, but not Over/Out anymore
  11680. bubbleCancelled = true;
  11681. }
  11682. }
  11683. // If bubble is cancel we didn't update the Primitive Pointer Pos yet, let's do it
  11684. if (bubbleCancelled) {
  11685. this._updatePrimPointerPos(cur);
  11686. }
  11687. // Trigger a PointerEnter corresponding to the PointerOver
  11688. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  11689. this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerEnter);
  11690. cur._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerEnter);
  11691. }
  11692. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  11693. this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerLeave);
  11694. cur._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerLeave);
  11695. }
  11696. // Loop to the parent
  11697. cur = cur.parent;
  11698. }
  11699. return true;
  11700. };
  11701. Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
  11702. var _this = this;
  11703. // A little safe guard, it might happens than the event is triggered before the first render and nothing is computed, this simple check will make sure everything will be fine
  11704. if (!this._globalTransform) {
  11705. this.updateCachedStates(true);
  11706. }
  11707. // Process Trigger related to PointerDown
  11708. if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
  11709. // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
  11710. this._pickStartingPosition = ppi.primitivePointerPos.clone();
  11711. this._pickStartingTime = new Date().getTime();
  11712. this._pickedDownPrim = null;
  11713. if (prim.actionManager) {
  11714. this._pickedDownPrim = prim;
  11715. if (prim.actionManager.hasPickTriggers) {
  11716. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  11717. switch (eventData.button) {
  11718. case 0:
  11719. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
  11720. break;
  11721. case 1:
  11722. prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
  11723. break;
  11724. case 2:
  11725. prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
  11726. break;
  11727. }
  11728. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
  11729. }
  11730. if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  11731. window.setTimeout(function () {
  11732. var ppi = _this._primPointerInfo;
  11733. var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
  11734. _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null, true);
  11735. _this._updateOverStatus(false);
  11736. var ii = new BABYLON.IntersectInfo2D();
  11737. ii.pickPosition = ppi.canvasPointerPos.clone();
  11738. ii.findFirstOnly = false;
  11739. _this.intersect(ii);
  11740. if (ii.isPrimIntersected(prim) !== null) {
  11741. if (prim.actionManager) {
  11742. if (_this._pickStartingTime !== 0 && ((new Date().getTime() - _this._pickStartingTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(_this._pickStartingPosition.x - ii.pickPosition.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._pickStartingPosition.y - ii.pickPosition.y) < BABYLON.ActionManager.DragMovementThreshold)) {
  11743. _this._pickStartingTime = 0;
  11744. prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
  11745. }
  11746. }
  11747. }
  11748. }, BABYLON.ActionManager.LongPressDelay);
  11749. }
  11750. }
  11751. }
  11752. else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
  11753. this._pickStartingTime = 0;
  11754. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  11755. if (prim.actionManager) {
  11756. // OnPickUpTrigger
  11757. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
  11758. // OnPickTrigger
  11759. if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
  11760. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
  11761. }
  11762. }
  11763. // OnPickOutTrigger
  11764. if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
  11765. this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
  11766. }
  11767. }
  11768. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
  11769. if (prim.actionManager) {
  11770. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  11771. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
  11772. }
  11773. }
  11774. else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
  11775. if (prim.actionManager) {
  11776. var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
  11777. prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
  11778. }
  11779. }
  11780. };
  11781. Canvas2D.prototype._notifParents = function (prim, mask) {
  11782. var pii = this._primPointerInfo;
  11783. var curPrim = this;
  11784. while (curPrim) {
  11785. this._updatePrimPointerPos(curPrim);
  11786. // Fire the proper notification
  11787. if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
  11788. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerEnter);
  11789. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerEnter);
  11790. }
  11791. else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
  11792. this._debugExecObserver(curPrim, BABYLON.PrimitivePointerInfo.PointerLeave);
  11793. curPrim._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerLeave);
  11794. }
  11795. curPrim = curPrim.parent;
  11796. }
  11797. };
  11798. /**
  11799. * Don't forget to call the dispose method when you're done with the Canvas instance.
  11800. * But don't worry, if you dispose its scene, the canvas will be automatically disposed too.
  11801. */
  11802. Canvas2D.prototype.dispose = function () {
  11803. if (!_super.prototype.dispose.call(this)) {
  11804. return false;
  11805. }
  11806. if (this._profilingCanvas) {
  11807. this._profilingCanvas.dispose();
  11808. this._profilingCanvas = null;
  11809. }
  11810. if (this.interactionEnabled) {
  11811. this._setupInteraction(false);
  11812. }
  11813. if (this._beforeRenderObserver) {
  11814. this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
  11815. this._beforeRenderObserver = null;
  11816. }
  11817. if (this._afterRenderObserver) {
  11818. this._scene.onAfterRenderObservable.remove(this._afterRenderObserver);
  11819. this._afterRenderObserver = null;
  11820. }
  11821. if (this._groupCacheMaps) {
  11822. this._groupCacheMaps.forEach(function (k, m) { return m.forEach(function (e) { return e.dispose(); }); });
  11823. this._groupCacheMaps = null;
  11824. }
  11825. // Unregister this instance
  11826. var index = Canvas2D._INSTANCES.indexOf(this);
  11827. if (index > -1) {
  11828. Canvas2D._INSTANCES.splice(index, 1);
  11829. }
  11830. };
  11831. Object.defineProperty(Canvas2D.prototype, "scene", {
  11832. /**
  11833. * Accessor to the Scene that owns the Canvas
  11834. * @returns The instance of the Scene object
  11835. */
  11836. get: function () {
  11837. return this._scene;
  11838. },
  11839. enumerable: true,
  11840. configurable: true
  11841. });
  11842. Object.defineProperty(Canvas2D.prototype, "engine", {
  11843. /**
  11844. * Accessor to the Engine that drives the Scene used by this Canvas
  11845. * @returns The instance of the Engine object
  11846. */
  11847. get: function () {
  11848. return this._engine;
  11849. },
  11850. enumerable: true,
  11851. configurable: true
  11852. });
  11853. Object.defineProperty(Canvas2D.prototype, "uid", {
  11854. /**
  11855. * return a unique identifier for the Canvas2D
  11856. */
  11857. get: function () {
  11858. if (!this._uid) {
  11859. this._uid = BABYLON.Tools.RandomId();
  11860. }
  11861. return this._uid;
  11862. },
  11863. enumerable: true,
  11864. configurable: true
  11865. });
  11866. Object.defineProperty(Canvas2D.prototype, "renderObservable", {
  11867. /**
  11868. * And observable called during the Canvas rendering process.
  11869. * This observable is called twice per render, each time with a different mask:
  11870. * - 1: before render is executed
  11871. * - 2: after render is executed
  11872. */
  11873. get: function () {
  11874. if (!this._renderObservable) {
  11875. this._renderObservable = new BABYLON.Observable();
  11876. }
  11877. return this._renderObservable;
  11878. },
  11879. enumerable: true,
  11880. configurable: true
  11881. });
  11882. Object.defineProperty(Canvas2D.prototype, "cachingStrategy", {
  11883. /**
  11884. * Accessor of the Caching Strategy used by this Canvas.
  11885. * See Canvas2D.CACHESTRATEGY_xxxx static members for more information
  11886. * @returns the value corresponding to the used strategy.
  11887. */
  11888. get: function () {
  11889. return this._cachingStrategy;
  11890. },
  11891. enumerable: true,
  11892. configurable: true
  11893. });
  11894. Object.defineProperty(Canvas2D.prototype, "isScreenSpace", {
  11895. /**
  11896. * Return true if the Canvas is a Screen Space one, false if it's a World Space one.
  11897. * @returns {}
  11898. */
  11899. get: function () {
  11900. return this._isScreenSpace;
  11901. },
  11902. enumerable: true,
  11903. configurable: true
  11904. });
  11905. Object.defineProperty(Canvas2D.prototype, "worldSpaceCanvasNode", {
  11906. /**
  11907. * Only valid for World Space Canvas, returns the scene node that displays the canvas
  11908. */
  11909. get: function () {
  11910. return this._worldSpaceNode;
  11911. },
  11912. set: function (val) {
  11913. this._worldSpaceNode = val;
  11914. },
  11915. enumerable: true,
  11916. configurable: true
  11917. });
  11918. Object.defineProperty(Canvas2D.prototype, "supportInstancedArray", {
  11919. /**
  11920. * Check if the WebGL Instanced Array extension is supported or not
  11921. */
  11922. get: function () {
  11923. return this._supprtInstancedArray;
  11924. },
  11925. enumerable: true,
  11926. configurable: true
  11927. });
  11928. Object.defineProperty(Canvas2D.prototype, "backgroundFill", {
  11929. /**
  11930. * Property that defines the fill object used to draw the background of the Canvas.
  11931. * Note that Canvas with a Caching Strategy of
  11932. * @returns If the background is not set, null will be returned, otherwise a valid fill object is returned.
  11933. */
  11934. get: function () {
  11935. if (!this._background || !this._background.isVisible) {
  11936. return null;
  11937. }
  11938. return this._background.fill;
  11939. },
  11940. set: function (value) {
  11941. this.checkBackgroundAvailability();
  11942. if (value === this._background.fill) {
  11943. return;
  11944. }
  11945. this._background.fill = value;
  11946. this._background.levelVisible = true;
  11947. },
  11948. enumerable: true,
  11949. configurable: true
  11950. });
  11951. Object.defineProperty(Canvas2D.prototype, "backgroundBorder", {
  11952. /**
  11953. * Property that defines the border object used to draw the background of the Canvas.
  11954. * @returns If the background is not set, null will be returned, otherwise a valid border object is returned.
  11955. */
  11956. get: function () {
  11957. if (!this._background || !this._background.isVisible) {
  11958. return null;
  11959. }
  11960. return this._background.border;
  11961. },
  11962. set: function (value) {
  11963. this.checkBackgroundAvailability();
  11964. if (value === this._background.border) {
  11965. return;
  11966. }
  11967. this._background.border = value;
  11968. this._background.levelVisible = true;
  11969. },
  11970. enumerable: true,
  11971. configurable: true
  11972. });
  11973. Object.defineProperty(Canvas2D.prototype, "backgroundBorderThickness", {
  11974. /**
  11975. * Property that defines the thickness of the border object used to draw the background of the Canvas.
  11976. * @returns If the background is not set, null will be returned, otherwise a valid number matching the thickness is returned.
  11977. */
  11978. get: function () {
  11979. if (!this._background || !this._background.isVisible) {
  11980. return null;
  11981. }
  11982. return this._background.borderThickness;
  11983. },
  11984. set: function (value) {
  11985. this.checkBackgroundAvailability();
  11986. if (value === this._background.borderThickness) {
  11987. return;
  11988. }
  11989. this._background.borderThickness = value;
  11990. },
  11991. enumerable: true,
  11992. configurable: true
  11993. });
  11994. Object.defineProperty(Canvas2D.prototype, "backgroundRoundRadius", {
  11995. /**
  11996. * You can set the roundRadius of the background
  11997. * @returns The current roundRadius
  11998. */
  11999. get: function () {
  12000. if (!this._background || !this._background.isVisible) {
  12001. return null;
  12002. }
  12003. return this._background.roundRadius;
  12004. },
  12005. set: function (value) {
  12006. this.checkBackgroundAvailability();
  12007. if (value === this._background.roundRadius) {
  12008. return;
  12009. }
  12010. this._background.roundRadius = value;
  12011. this._background.levelVisible = true;
  12012. },
  12013. enumerable: true,
  12014. configurable: true
  12015. });
  12016. Object.defineProperty(Canvas2D.prototype, "interactionEnabled", {
  12017. /**
  12018. * Enable/Disable interaction for this Canvas
  12019. * When enabled the Prim2DBase.pointerEventObservable property will notified when appropriate events occur
  12020. */
  12021. get: function () {
  12022. return this._interactionEnabled;
  12023. },
  12024. set: function (enable) {
  12025. this._setupInteraction(enable);
  12026. },
  12027. enumerable: true,
  12028. configurable: true
  12029. });
  12030. Object.defineProperty(Canvas2D.prototype, "designSize", {
  12031. get: function () {
  12032. return this._designSize;
  12033. },
  12034. enumerable: true,
  12035. configurable: true
  12036. });
  12037. Object.defineProperty(Canvas2D.prototype, "designSizeUseHorizAxis", {
  12038. get: function () {
  12039. return this._designUseHorizAxis;
  12040. },
  12041. enumerable: true,
  12042. configurable: true
  12043. });
  12044. Object.defineProperty(Canvas2D.prototype, "overPrim", {
  12045. /**
  12046. * Return
  12047. */
  12048. get: function () {
  12049. return this._actualOverPrimitive ? this._actualOverPrimitive.prim : null;
  12050. },
  12051. enumerable: true,
  12052. configurable: true
  12053. });
  12054. Object.defineProperty(Canvas2D.prototype, "_engineData", {
  12055. /**
  12056. * Access the babylon.js' engine bound data, do not invoke this method, it's for internal purpose only
  12057. * @returns {}
  12058. */
  12059. get: function () {
  12060. return this.__engineData;
  12061. },
  12062. enumerable: true,
  12063. configurable: true
  12064. });
  12065. Canvas2D.prototype.createCanvasProfileInfoCanvas = function () {
  12066. if (this._profilingCanvas) {
  12067. return this._profilingCanvas;
  12068. }
  12069. var canvas = new ScreenSpaceCanvas2D(this.scene, {
  12070. id: "ProfileInfoCanvas", cachingStrategy: Canvas2D.CACHESTRATEGY_DONTCACHE, children: [
  12071. new BABYLON.Rectangle2D({
  12072. id: "ProfileBorder", border: "#FFFFFFFF", borderThickness: 2, roundRadius: 5, fill: "#C04040C0", marginAlignment: "h: left, v: top", margin: "10", padding: "10", children: [
  12073. new BABYLON.Text2D("Stats", { id: "ProfileInfoText", marginAlignment: "h: left, v: top", fontName: "10pt Lucida Console" })
  12074. ]
  12075. })
  12076. ]
  12077. });
  12078. this._profileInfoText = canvas.findById("ProfileInfoText");
  12079. this._profilingCanvas = canvas;
  12080. return canvas;
  12081. };
  12082. Canvas2D.prototype.checkBackgroundAvailability = function () {
  12083. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) {
  12084. throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
  12085. }
  12086. };
  12087. Canvas2D.prototype._initPerfMetrics = function () {
  12088. this._drawCallsOpaqueCounter.fetchNewFrame();
  12089. this._drawCallsAlphaTestCounter.fetchNewFrame();
  12090. this._drawCallsTransparentCounter.fetchNewFrame();
  12091. this._groupRenderCounter.fetchNewFrame();
  12092. this._updateTransparentDataCounter.fetchNewFrame();
  12093. this._cachedGroupRenderCounter.fetchNewFrame();
  12094. this._updateCachedStateCounter.fetchNewFrame();
  12095. this._updateLayoutCounter.fetchNewFrame();
  12096. this._updatePositioningCounter.fetchNewFrame();
  12097. this._updateLocalTransformCounter.fetchNewFrame();
  12098. this._updateGlobalTransformCounter.fetchNewFrame();
  12099. this._boundingInfoRecomputeCounter.fetchNewFrame();
  12100. };
  12101. Canvas2D.prototype._fetchPerfMetrics = function () {
  12102. this._drawCallsOpaqueCounter.addCount(0, true);
  12103. this._drawCallsAlphaTestCounter.addCount(0, true);
  12104. this._drawCallsTransparentCounter.addCount(0, true);
  12105. this._groupRenderCounter.addCount(0, true);
  12106. this._updateTransparentDataCounter.addCount(0, true);
  12107. this._cachedGroupRenderCounter.addCount(0, true);
  12108. this._updateCachedStateCounter.addCount(0, true);
  12109. this._updateLayoutCounter.addCount(0, true);
  12110. this._updatePositioningCounter.addCount(0, true);
  12111. this._updateLocalTransformCounter.addCount(0, true);
  12112. this._updateGlobalTransformCounter.addCount(0, true);
  12113. this._boundingInfoRecomputeCounter.addCount(0, true);
  12114. };
  12115. Canvas2D.prototype._updateProfileCanvas = function () {
  12116. if (this._profileInfoText == null) {
  12117. return;
  12118. }
  12119. var format = function (v) { return (Math.round(v * 100) / 100).toString(); };
  12120. var p = "Draw Calls:\n" +
  12121. (" - Opaque: " + format(this.drawCallsOpaqueCounter.current) + ", (avg:" + format(this.drawCallsOpaqueCounter.lastSecAverage) + ", t:" + format(this.drawCallsOpaqueCounter.total) + ")\n") +
  12122. (" - AlphaTest: " + format(this.drawCallsAlphaTestCounter.current) + ", (avg:" + format(this.drawCallsAlphaTestCounter.lastSecAverage) + ", t:" + format(this.drawCallsAlphaTestCounter.total) + ")\n") +
  12123. (" - Transparent: " + format(this.drawCallsTransparentCounter.current) + ", (avg:" + format(this.drawCallsTransparentCounter.lastSecAverage) + ", t:" + format(this.drawCallsTransparentCounter.total) + ")\n") +
  12124. ("Group Render: " + this.groupRenderCounter.current + ", (avg:" + format(this.groupRenderCounter.lastSecAverage) + ", t:" + format(this.groupRenderCounter.total) + ")\n") +
  12125. ("Update Transparent Data: " + this.updateTransparentDataCounter.current + ", (avg:" + format(this.updateTransparentDataCounter.lastSecAverage) + ", t:" + format(this.updateTransparentDataCounter.total) + ")\n") +
  12126. ("Cached Group Render: " + this.cachedGroupRenderCounter.current + ", (avg:" + format(this.cachedGroupRenderCounter.lastSecAverage) + ", t:" + format(this.cachedGroupRenderCounter.total) + ")\n") +
  12127. ("Update Cached States: " + this.updateCachedStateCounter.current + ", (avg:" + format(this.updateCachedStateCounter.lastSecAverage) + ", t:" + format(this.updateCachedStateCounter.total) + ")\n") +
  12128. (" - Update Layout: " + this.updateLayoutCounter.current + ", (avg:" + format(this.updateLayoutCounter.lastSecAverage) + ", t:" + format(this.updateLayoutCounter.total) + ")\n") +
  12129. (" - Update Positioning: " + this.updatePositioningCounter.current + ", (avg:" + format(this.updatePositioningCounter.lastSecAverage) + ", t:" + format(this.updatePositioningCounter.total) + ")\n") +
  12130. (" - Update Local Trans: " + this.updateLocalTransformCounter.current + ", (avg:" + format(this.updateLocalTransformCounter.lastSecAverage) + ", t:" + format(this.updateLocalTransformCounter.total) + ")\n") +
  12131. (" - Update Global Trans: " + this.updateGlobalTransformCounter.current + ", (avg:" + format(this.updateGlobalTransformCounter.lastSecAverage) + ", t:" + format(this.updateGlobalTransformCounter.total) + ")\n") +
  12132. (" - BoundingInfo Recompute: " + this.boundingInfoRecomputeCounter.current + ", (avg:" + format(this.boundingInfoRecomputeCounter.lastSecAverage) + ", t:" + format(this.boundingInfoRecomputeCounter.total) + ")\n");
  12133. this._profileInfoText.text = p;
  12134. };
  12135. Canvas2D.prototype._addDrawCallCount = function (count, renderMode) {
  12136. switch (renderMode) {
  12137. case BABYLON.Render2DContext.RenderModeOpaque:
  12138. this._drawCallsOpaqueCounter.addCount(count, false);
  12139. return;
  12140. case BABYLON.Render2DContext.RenderModeAlphaTest:
  12141. this._drawCallsAlphaTestCounter.addCount(count, false);
  12142. return;
  12143. case BABYLON.Render2DContext.RenderModeTransparent:
  12144. this._drawCallsTransparentCounter.addCount(count, false);
  12145. return;
  12146. }
  12147. };
  12148. Canvas2D.prototype._addGroupRenderCount = function (count) {
  12149. this._groupRenderCounter.addCount(count, false);
  12150. };
  12151. Canvas2D.prototype._addUpdateTransparentDataCount = function (count) {
  12152. this._updateTransparentDataCounter.addCount(count, false);
  12153. };
  12154. Canvas2D.prototype.addCachedGroupRenderCounter = function (count) {
  12155. this._cachedGroupRenderCounter.addCount(count, false);
  12156. };
  12157. Canvas2D.prototype.addUpdateCachedStateCounter = function (count) {
  12158. this._updateCachedStateCounter.addCount(count, false);
  12159. };
  12160. Canvas2D.prototype.addUpdateLayoutCounter = function (count) {
  12161. this._updateLayoutCounter.addCount(count, false);
  12162. };
  12163. Canvas2D.prototype.addUpdatePositioningCounter = function (count) {
  12164. this._updatePositioningCounter.addCount(count, false);
  12165. };
  12166. Canvas2D.prototype.addupdateLocalTransformCounter = function (count) {
  12167. this._updateLocalTransformCounter.addCount(count, false);
  12168. };
  12169. Canvas2D.prototype.addUpdateGlobalTransformCounter = function (count) {
  12170. this._updateGlobalTransformCounter.addCount(count, false);
  12171. };
  12172. Canvas2D.prototype._updateTrackedNodes = function () {
  12173. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12174. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D._m);
  12175. var rh = this.engine.getRenderHeight();
  12176. var v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
  12177. for (var _i = 0, _a = this._trackedGroups; _i < _a.length; _i++) {
  12178. var group = _a[_i];
  12179. if (group.isDisposed || !group.isVisible) {
  12180. continue;
  12181. }
  12182. var node = group.trackedNode;
  12183. var worldMtx = node.getWorldMatrix();
  12184. var proj = BABYLON.Vector3.Project(Canvas2D._v, worldMtx, Canvas2D._m, v);
  12185. var s = this.scale;
  12186. group.x = Math.round(proj.x / s);
  12187. group.y = Math.round((rh - proj.y) / s);
  12188. }
  12189. };
  12190. /**
  12191. * Call this method change you want to have layout related data computed and up to date (layout area, primitive area, local/global transformation matrices)
  12192. */
  12193. Canvas2D.prototype.updateCanvasLayout = function (forceRecompute) {
  12194. this._updateCanvasState(forceRecompute);
  12195. };
  12196. Canvas2D.prototype._updateAdaptiveSizeWorldCanvas = function () {
  12197. if (this._globalTransformStep < 2) {
  12198. return;
  12199. }
  12200. var n = this.worldSpaceCanvasNode;
  12201. var bi = n.getBoundingInfo().boundingBox;
  12202. var v = bi.vectorsWorld;
  12203. var cam = this.scene.cameraToUseForPointers || this.scene.activeCamera;
  12204. cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D._m);
  12205. var vp = cam.viewport.toGlobal(this.engine.getRenderWidth(), this.engine.getRenderHeight());
  12206. var projPoints = new Array(4);
  12207. for (var i = 0; i < 4; i++) {
  12208. projPoints[i] = BABYLON.Vector3.Project(v[i], Canvas2D._mI, Canvas2D._m, vp);
  12209. }
  12210. var left = projPoints[3].subtract(projPoints[0]).length();
  12211. var top = projPoints[3].subtract(projPoints[1]).length();
  12212. var right = projPoints[1].subtract(projPoints[2]).length();
  12213. var bottom = projPoints[2].subtract(projPoints[0]).length();
  12214. var w = Math.round(Math.max(top, bottom));
  12215. var h = Math.round(Math.max(right, left));
  12216. var isW = w > h;
  12217. // Basically if it's under 256 we use 256, otherwise we take the biggest power of 2
  12218. var edge = Math.max(w, h);
  12219. if (edge < 256) {
  12220. edge = 256;
  12221. }
  12222. else {
  12223. edge = Math.pow(2, Math.ceil(Math.log(edge) / Math.log(2)));
  12224. }
  12225. // Clip values if needed
  12226. edge = Math.min(edge, this._maxAdaptiveWorldSpaceCanvasSize);
  12227. var newScale = edge / ((isW) ? this.size.width : this.size.height);
  12228. if (newScale !== this.scale) {
  12229. var scale = newScale;
  12230. // console.log(`New adaptive scale for Canvas ${this.id}, w: ${w}, h: ${h}, scale: ${scale}, edge: ${edge}, isW: ${isW}`);
  12231. this._setRenderingScale(scale);
  12232. }
  12233. };
  12234. Canvas2D.prototype._updateCanvasState = function (forceRecompute) {
  12235. // Check if the update has already been made for this render Frame
  12236. if (!forceRecompute && this.scene.getRenderId() === this._updateRenderId) {
  12237. return;
  12238. }
  12239. // Detect a change of rendering size
  12240. var renderingSizeChanged = false;
  12241. var newWidth = this.engine.getRenderWidth();
  12242. if (newWidth !== this._renderingSize.width) {
  12243. renderingSizeChanged = true;
  12244. }
  12245. this._renderingSize.width = newWidth;
  12246. var newHeight = this.engine.getRenderHeight();
  12247. if (newHeight !== this._renderingSize.height) {
  12248. renderingSizeChanged = true;
  12249. }
  12250. this._renderingSize.height = newHeight;
  12251. // If the canvas fit the rendering size and it changed, update
  12252. if (renderingSizeChanged && this._fitRenderingDevice) {
  12253. this._actualSize = this._renderingSize.clone();
  12254. this._size = this._renderingSize.clone();
  12255. if (this._background) {
  12256. this._background.size = this.size;
  12257. }
  12258. // Dirty the Layout at the Canvas level to recompute as the size changed
  12259. this._setLayoutDirty();
  12260. }
  12261. // If there's a design size, update the scale according to the renderingSize
  12262. if (this._designSize) {
  12263. var scale = void 0;
  12264. if (this._designUseHorizAxis) {
  12265. scale = this._renderingSize.width / this._designSize.width;
  12266. }
  12267. else {
  12268. scale = this._renderingSize.height / this._designSize.height;
  12269. }
  12270. this.size = this._designSize.clone();
  12271. this.actualSize = this._designSize.clone();
  12272. this.scale = scale;
  12273. }
  12274. var context = new BABYLON.PrepareRender2DContext();
  12275. ++this._globalTransformProcessStep;
  12276. this.updateCachedStates(false);
  12277. this._prepareGroupRender(context);
  12278. this._updateRenderId = this.scene.getRenderId();
  12279. };
  12280. /**
  12281. * Method that renders the Canvas, you should not invoke
  12282. */
  12283. Canvas2D.prototype._render = function () {
  12284. this._initPerfMetrics();
  12285. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12286. this._renderObservable.notifyObservers(this, Canvas2D.RENDEROBSERVABLE_PRE);
  12287. }
  12288. this._updateCanvasState(false);
  12289. this._updateTrackedNodes();
  12290. // Nothing to do is the Canvas is not visible
  12291. if (this.isVisible === false) {
  12292. return;
  12293. }
  12294. if (!this._isScreenSpace) {
  12295. this._updateAdaptiveSizeWorldCanvas();
  12296. }
  12297. this._updateCanvasState(false);
  12298. if (this._primPointerInfo.canvasPointerPos) {
  12299. this._updateIntersectionList(this._primPointerInfo.canvasPointerPos, false, false);
  12300. this._updateOverStatus(false);
  12301. }
  12302. this.engine.setState(false);
  12303. this._groupRender();
  12304. if (!this._isScreenSpace) {
  12305. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagWorldCacheChanged)) {
  12306. this.worldSpaceCacheChanged();
  12307. this._clearFlags(BABYLON.SmartPropertyPrim.flagWorldCacheChanged);
  12308. }
  12309. }
  12310. // If the canvas is cached at canvas level, we must manually render the sprite that will display its content
  12311. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_CANVAS && this._cachedCanvasGroup) {
  12312. this._cachedCanvasGroup._renderCachedCanvas();
  12313. }
  12314. this._fetchPerfMetrics();
  12315. this._updateProfileCanvas();
  12316. if (this._renderObservable && this._renderObservable.hasObservers()) {
  12317. this._renderObservable.notifyObservers(this, Canvas2D.RENDEROBSERVABLE_POST);
  12318. }
  12319. };
  12320. /**
  12321. * Internal method that allocate a cache for the given group.
  12322. * Caching is made using a collection of MapTexture where many groups have their bitmap cache stored inside.
  12323. * @param group The group to allocate the cache of.
  12324. * @return custom type with the PackedRect instance giving information about the cache location into the texture and also the MapTexture instance that stores the cache.
  12325. */
  12326. Canvas2D.prototype._allocateGroupCache = function (group, parent, minSize, useMipMap, anisotropicLevel) {
  12327. if (useMipMap === void 0) { useMipMap = false; }
  12328. if (anisotropicLevel === void 0) { anisotropicLevel = 1; }
  12329. var key = (useMipMap ? "MipMap" : "NoMipMap") + "_" + anisotropicLevel;
  12330. var rd = group._renderableData;
  12331. var noResizeScale = rd._noResizeOnScale;
  12332. var isCanvas = parent == null;
  12333. var scale;
  12334. if (noResizeScale) {
  12335. scale = isCanvas ? Canvas2D._unS : group.parent.actualScale;
  12336. }
  12337. else {
  12338. scale = group.actualScale;
  12339. }
  12340. // Determine size
  12341. var size = group.actualSize;
  12342. size = new BABYLON.Size(Math.ceil(size.width * scale.x), Math.ceil(size.height * scale.y));
  12343. if (minSize) {
  12344. size.width = Math.max(minSize.width, size.width);
  12345. size.height = Math.max(minSize.height, size.height);
  12346. }
  12347. var mapArray = this._groupCacheMaps.getOrAddWithFactory(key, function () { return new Array(); });
  12348. // Try to find a spot in one of the cached texture
  12349. var res = null;
  12350. var map;
  12351. for (var _i = 0, mapArray_1 = mapArray; _i < mapArray_1.length; _i++) {
  12352. var _map = mapArray_1[_i];
  12353. map = _map;
  12354. var node = map.allocateRect(size);
  12355. if (node) {
  12356. res = { node: node, texture: map };
  12357. break;
  12358. }
  12359. }
  12360. // Couldn't find a map that could fit the rect, create a new map for it
  12361. if (!res) {
  12362. var mapSize = new BABYLON.Size(Canvas2D._groupTextureCacheSize, Canvas2D._groupTextureCacheSize);
  12363. // Check if the predefined size would fit, other create a custom size using the nearest bigger power of 2
  12364. if (size.width > mapSize.width || size.height > mapSize.height) {
  12365. mapSize.width = Math.pow(2, Math.ceil(Math.log(size.width) / Math.log(2)));
  12366. mapSize.height = Math.pow(2, Math.ceil(Math.log(size.height) / Math.log(2)));
  12367. }
  12368. var id = "groupsMapChache" + this._mapCounter++ + "forCanvas" + this.id;
  12369. map = new BABYLON.MapTexture(id, this._scene, mapSize, useMipMap ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : BABYLON.Texture.BILINEAR_SAMPLINGMODE, useMipMap);
  12370. map.hasAlpha = true;
  12371. map.anisotropicFilteringLevel = 4;
  12372. mapArray.splice(0, 0, map);
  12373. var node = map.allocateRect(size);
  12374. res = { node: node, texture: map };
  12375. }
  12376. // Check if we have to create a Sprite that will display the content of the Canvas which is cached.
  12377. // Don't do it in case of the group being a worldspace canvas (because its texture is bound to a WorldSpaceCanvas node)
  12378. if (group !== this || this._isScreenSpace) {
  12379. var node = res.node;
  12380. // Special case if the canvas is entirely cached: create a group that will have a single sprite it will be rendered specifically at the very end of the rendering process
  12381. var sprite = void 0;
  12382. if (this._cachingStrategy === Canvas2D.CACHESTRATEGY_CANVAS) {
  12383. this._cachedCanvasGroup = BABYLON.Group2D._createCachedCanvasGroup(this);
  12384. sprite = new BABYLON.Sprite2D(map, { parent: this._cachedCanvasGroup, id: "__cachedCanvasSprite__", spriteSize: node.contentSize, spriteLocation: node.pos });
  12385. sprite.zOrder = 1;
  12386. sprite.origin = BABYLON.Vector2.Zero();
  12387. }
  12388. else {
  12389. sprite = new BABYLON.Sprite2D(map, { parent: parent, id: "__cachedSpriteOfGroup__" + group.id, x: group.actualPosition.x, y: group.actualPosition.y, spriteSize: node.contentSize, spriteLocation: node.pos, dontInheritParentScale: true });
  12390. sprite.origin = group.origin.clone();
  12391. sprite.addExternalData("__cachedGroup__", group);
  12392. sprite.pointerEventObservable.add(function (e, s) {
  12393. if (group.pointerEventObservable !== null) {
  12394. group.pointerEventObservable.notifyObservers(e, s.mask);
  12395. }
  12396. });
  12397. res.sprite = sprite;
  12398. }
  12399. if (sprite && noResizeScale) {
  12400. var relScale = isCanvas ? group.actualScale : group.actualScale.divide(group.parent.actualScale);
  12401. sprite.scaleX = relScale.x;
  12402. sprite.scaleY = relScale.y;
  12403. }
  12404. }
  12405. return res;
  12406. };
  12407. /**
  12408. * Internal method used to register a Scene Node to track position for the given group
  12409. * Do not invoke this method, for internal purpose only.
  12410. * @param group the group to track its associated Scene Node
  12411. */
  12412. Canvas2D.prototype._registerTrackedNode = function (group) {
  12413. if (group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  12414. return;
  12415. }
  12416. this._trackedGroups.push(group);
  12417. group._setFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  12418. };
  12419. /**
  12420. * Internal method used to unregister a tracked Scene Node
  12421. * Do not invoke this method, it's for internal purpose only.
  12422. * @param group the group to unregister its tracked Scene Node from.
  12423. */
  12424. Canvas2D.prototype._unregisterTrackedNode = function (group) {
  12425. if (!group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  12426. return;
  12427. }
  12428. var i = this._trackedGroups.indexOf(group);
  12429. if (i !== -1) {
  12430. this._trackedGroups.splice(i, 1);
  12431. }
  12432. group._clearFlags(BABYLON.SmartPropertyPrim.flagTrackedGroup);
  12433. };
  12434. /**
  12435. * Get a Solid Color Brush instance matching the given color.
  12436. * @param color The color to retrieve
  12437. * @return A shared instance of the SolidColorBrush2D class that use the given color
  12438. */
  12439. Canvas2D.GetSolidColorBrush = function (color) {
  12440. return Canvas2D._solidColorBrushes.getOrAddWithFactory(color.toHexString(), function () { return new BABYLON.SolidColorBrush2D(color.clone(), true); });
  12441. };
  12442. /**
  12443. * Get a Solid Color Brush instance matching the given color expressed as a CSS formatted hexadecimal value.
  12444. * @param color The color to retrieve
  12445. * @return A shared instance of the SolidColorBrush2D class that uses the given color
  12446. */
  12447. Canvas2D.GetSolidColorBrushFromHex = function (hexValue) {
  12448. return Canvas2D._solidColorBrushes.getOrAddWithFactory(hexValue, function () { return new BABYLON.SolidColorBrush2D(BABYLON.Color4.FromHexString(hexValue), true); });
  12449. };
  12450. /**
  12451. * Get a Gradient Color Brush
  12452. * @param color1 starting color
  12453. * @param color2 engine color
  12454. * @param translation translation vector to apply. default is [0;0]
  12455. * @param rotation rotation in radian to apply to the brush, initial direction is top to bottom. rotation is counter clockwise. default is 0.
  12456. * @param scale scaling factor to apply. default is 1.
  12457. */
  12458. Canvas2D.GetGradientColorBrush = function (color1, color2, translation, rotation, scale) {
  12459. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  12460. if (rotation === void 0) { rotation = 0; }
  12461. if (scale === void 0) { scale = 1; }
  12462. return Canvas2D._gradientColorBrushes.getOrAddWithFactory(BABYLON.GradientColorBrush2D.BuildKey(color1, color2, translation, rotation, scale), function () { return new BABYLON.GradientColorBrush2D(color1, color2, translation, rotation, scale, true); });
  12463. };
  12464. /**
  12465. * Create a solid or gradient brush from a string value.
  12466. * @param brushString should be either
  12467. * - "solid: #RRGGBBAA" or "#RRGGBBAA"
  12468. * - "gradient: #FF808080, #FFFFFFF[, [10:20], 180, 1]" for color1, color2, translation, rotation (degree), scale. The last three are optionals, but if specified must be is this order. "gradient:" can be omitted.
  12469. */
  12470. Canvas2D.GetBrushFromString = function (brushString) {
  12471. // Note: yes, I hate/don't know RegEx.. Feel free to add your contribution to the cause!
  12472. brushString = brushString.trim();
  12473. var split = brushString.split(",");
  12474. // Solid, formatted as: "[solid:]#FF808080"
  12475. if (split.length === 1) {
  12476. var value = null;
  12477. if (brushString.indexOf("solid:") === 0) {
  12478. value = brushString.substr(6).trim();
  12479. }
  12480. else if (brushString.indexOf("#") === 0) {
  12481. value = brushString;
  12482. }
  12483. else {
  12484. return null;
  12485. }
  12486. return Canvas2D.GetSolidColorBrushFromHex(value);
  12487. }
  12488. else {
  12489. if (split[0].indexOf("gradient:") === 0) {
  12490. split[0] = split[0].substr(9).trim();
  12491. }
  12492. try {
  12493. var start = BABYLON.Color4.FromHexString(split[0].trim());
  12494. var end = BABYLON.Color4.FromHexString(split[1].trim());
  12495. var t = BABYLON.Vector2.Zero();
  12496. if (split.length > 2) {
  12497. var v = split[2].trim();
  12498. if (v.charAt(0) !== "[" || v.charAt(v.length - 1) !== "]") {
  12499. return null;
  12500. }
  12501. var sep = v.indexOf(":");
  12502. var x = parseFloat(v.substr(1, sep));
  12503. var y = parseFloat(v.substr(sep + 1, v.length - (sep + 1)));
  12504. t = new BABYLON.Vector2(x, y);
  12505. }
  12506. var r = 0;
  12507. if (split.length > 3) {
  12508. r = BABYLON.Tools.ToRadians(parseFloat(split[3].trim()));
  12509. }
  12510. var s = 1;
  12511. if (split.length > 4) {
  12512. s = parseFloat(split[4].trim());
  12513. }
  12514. return Canvas2D.GetGradientColorBrush(start, end, t, r, s);
  12515. }
  12516. catch (e) {
  12517. return null;
  12518. }
  12519. }
  12520. };
  12521. /**
  12522. * In this strategy only the direct children groups of the Canvas will be cached, their whole content (whatever the sub groups they have) into a single bitmap.
  12523. * This strategy doesn't allow primitives added directly as children of the Canvas.
  12524. * You typically want to use this strategy of a screenSpace fullscreen canvas: you don't want a bitmap cache taking the whole screen resolution but still want the main contents (say UI in the topLeft and rightBottom for instance) to be efficiently cached.
  12525. */
  12526. Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS = 1;
  12527. /**
  12528. * In this strategy each group will have its own cache bitmap (except if a given group explicitly defines the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors).
  12529. * This strategy is typically used if the canvas has some groups that are frequently animated. Unchanged ones will have a steady cache and the others will be refreshed when they change, reducing the redraw operation count to their content only.
  12530. * When using this strategy, group instances can rely on the DONTCACHEOVERRIDE or CACHEINPARENTGROUP behaviors to minimize the amount of cached bitmaps.
  12531. * Note that in this mode the Canvas itself is not cached, it only contains the sprites of its direct children group to render, there's no point to cache the whole canvas, sprites will be rendered pretty efficiently, the memory cost would be too great for the value of it.
  12532. */
  12533. Canvas2D.CACHESTRATEGY_ALLGROUPS = 2;
  12534. /**
  12535. * In this strategy the whole canvas is cached into a single bitmap containing every primitives it owns, at the exception of the ones that are owned by a group having the DONTCACHEOVERRIDE behavior (these primitives will be directly drawn to the viewport at each render for screenSpace Canvas or be part of the Canvas cache bitmap for worldSpace Canvas).
  12536. */
  12537. Canvas2D.CACHESTRATEGY_CANVAS = 3;
  12538. /**
  12539. * This strategy is used to recompose/redraw the canvas entirely at each viewport render.
  12540. * Use this strategy if memory is a concern above rendering performances and/or if the canvas is frequently animated (hence reducing the benefits of caching).
  12541. * Note that you can't use this strategy for WorldSpace Canvas, they need at least a top level group caching.
  12542. */
  12543. Canvas2D.CACHESTRATEGY_DONTCACHE = 4;
  12544. /**
  12545. * Observable Mask to be notified before rendering is made
  12546. */
  12547. Canvas2D.RENDEROBSERVABLE_PRE = 1;
  12548. /**
  12549. * Observable Mask to be notified after rendering is made
  12550. */
  12551. Canvas2D.RENDEROBSERVABLE_POST = 2;
  12552. Canvas2D._INSTANCES = [];
  12553. Canvas2D._zMinDelta = 1 / (Math.pow(2, 24) - 1);
  12554. Canvas2D._interInfo = new BABYLON.IntersectInfo2D();
  12555. Canvas2D._v = BABYLON.Vector3.Zero(); // Must stay zero
  12556. Canvas2D._m = BABYLON.Matrix.Identity();
  12557. Canvas2D._mI = BABYLON.Matrix.Identity(); // Must stay identity
  12558. Canvas2D._unS = new BABYLON.Vector2(1, 1);
  12559. /**
  12560. * Define the default size used for both the width and height of a MapTexture to allocate.
  12561. * Note that some MapTexture might be bigger than this size if the first node to allocate is bigger in width or height
  12562. */
  12563. Canvas2D._groupTextureCacheSize = 1024;
  12564. Canvas2D._solidColorBrushes = new BABYLON.StringDictionary();
  12565. Canvas2D._gradientColorBrushes = new BABYLON.StringDictionary();
  12566. Canvas2D = __decorate([
  12567. BABYLON.className("Canvas2D", "BABYLON")
  12568. ], Canvas2D);
  12569. return Canvas2D;
  12570. }(BABYLON.Group2D));
  12571. BABYLON.Canvas2D = Canvas2D;
  12572. var WorldSpaceCanvas2D = (function (_super) {
  12573. __extends(WorldSpaceCanvas2D, _super);
  12574. /**
  12575. * Create a new 2D WorldSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a world transformation information to place it in the world space.
  12576. * This kind of canvas can't have its Primitives directly drawn in the Viewport, they need to be cached in a bitmap at some point, as a consequence the DONT_CACHE strategy is unavailable. For now only CACHESTRATEGY_CANVAS is supported, but the remaining strategies will be soon.
  12577. * @param scene the Scene that owns the Canvas
  12578. * @param size the dimension of the Canvas in World Space
  12579. * @param settings a combination of settings, possible ones are
  12580. * - children: an array of direct children primitives
  12581. * - id: a text identifier, for information purpose only, default is null.
  12582. * - worldPosition the position of the Canvas in World Space, default is [0,0,0]
  12583. * - worldRotation the rotation of the Canvas in World Space, default is Quaternion.Identity()
  12584. * - sideOrientation: Unexpected behavior occur if the value is different from Mesh.DEFAULTSIDE right now, so please use this one, which is the default.
  12585. * - cachingStrategy Must be CACHESTRATEGY_CANVAS for now, which is the default.
  12586. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is false (the opposite of ScreenSpace).
  12587. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  12588. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  12589. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  12590. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see Canvas2D.GetBrushFromString) or a IBrush2D instance.
  12591. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  12592. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  12593. * - maxAdaptiveCanvasSize: set the max size (width and height) of the bitmap that will contain the cached version of the WorldSpace Canvas. Default is 1024 or less if it's not supported. In any case the value you give will be clipped by the maximum that WebGL supports on the running device. You can set any size, more than 1024 if you want, but testing proved it's a good max value for non "retina" like screens.
  12594. * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  12595. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  12596. * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  12597. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
  12598. * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
  12599. */
  12600. function WorldSpaceCanvas2D(scene, size, settings) {
  12601. var _this = this;
  12602. BABYLON.Prim2DBase._isCanvasInit = true;
  12603. var s = settings;
  12604. s.isScreenSpace = false;
  12605. s.size = size.clone();
  12606. settings.cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_CANVAS : settings.cachingStrategy;
  12607. if (settings.cachingStrategy !== Canvas2D.CACHESTRATEGY_CANVAS) {
  12608. throw new Error("Right now only the CACHESTRATEGY_CANVAS cache Strategy is supported for WorldSpace Canvas. More will come soon!");
  12609. }
  12610. _super.call(this, scene, settings);
  12611. BABYLON.Prim2DBase._isCanvasInit = false;
  12612. this._renderableData._useMipMap = true;
  12613. this._renderableData._anisotropicLevel = 8;
  12614. //if (cachingStrategy === Canvas2D.CACHESTRATEGY_DONTCACHE) {
  12615. // throw new Error("CACHESTRATEGY_DONTCACHE cache Strategy can't be used for WorldSpace Canvas");
  12616. //}
  12617. var createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
  12618. var id = settings ? settings.id || null : null;
  12619. // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
  12620. var capMaxTextSize = this.engine.getCaps().maxRenderTextureSize;
  12621. var defaultTextSize = (Math.min(capMaxTextSize, 1024)); // Default is 4K if allowed otherwise the max allowed
  12622. if (settings.maxAdaptiveCanvasSize == null) {
  12623. this._maxAdaptiveWorldSpaceCanvasSize = defaultTextSize;
  12624. }
  12625. else {
  12626. // We still clip the given value with the max allowed, the user may not be aware of these limitations
  12627. this._maxAdaptiveWorldSpaceCanvasSize = Math.min(settings.maxAdaptiveCanvasSize, capMaxTextSize);
  12628. }
  12629. if (createWorldSpaceNode) {
  12630. var plane = new BABYLON.WorldSpaceCanvas2DNode(id, scene, this);
  12631. var vertexData = BABYLON.VertexData.CreatePlane({
  12632. width: size.width,
  12633. height: size.height,
  12634. sideOrientation: settings && settings.sideOrientation || BABYLON.Mesh.DEFAULTSIDE
  12635. });
  12636. var mtl = new BABYLON.StandardMaterial(id + "_Material", scene);
  12637. this.applyCachedTexture(vertexData, mtl);
  12638. vertexData.applyToMesh(plane, true);
  12639. mtl.specularColor = new BABYLON.Color3(0, 0, 0);
  12640. mtl.disableLighting = true;
  12641. mtl.useAlphaFromDiffuseTexture = true;
  12642. plane.position = settings && settings.worldPosition || BABYLON.Vector3.Zero();
  12643. plane.rotationQuaternion = settings && settings.worldRotation || BABYLON.Quaternion.Identity();
  12644. plane.material = mtl;
  12645. this._worldSpaceNode = plane;
  12646. }
  12647. else {
  12648. this._worldSpaceNode = settings.customWorldSpaceNode;
  12649. this.applyCachedTexture(null, null);
  12650. }
  12651. this.propertyChanged.add(function (e, st) {
  12652. var mesh = _this._worldSpaceNode;
  12653. if (mesh) {
  12654. mesh.isVisible = _this.isVisible;
  12655. }
  12656. }, BABYLON.Prim2DBase.isVisibleProperty.flagId);
  12657. }
  12658. WorldSpaceCanvas2D = __decorate([
  12659. BABYLON.className("WorldSpaceCanvas2D", "BABYLON")
  12660. ], WorldSpaceCanvas2D);
  12661. return WorldSpaceCanvas2D;
  12662. }(Canvas2D));
  12663. BABYLON.WorldSpaceCanvas2D = WorldSpaceCanvas2D;
  12664. var ScreenSpaceCanvas2D = (function (_super) {
  12665. __extends(ScreenSpaceCanvas2D, _super);
  12666. /**
  12667. * Create a new 2D ScreenSpace Rendering Canvas, it is a 2D rectangle that has a size (width/height) and a position relative to the bottom/left corner of the screen.
  12668. * ScreenSpace Canvas will be drawn in the Viewport as a 2D Layer lying to the top of the 3D Scene. Typically used for traditional UI.
  12669. * All caching strategies will be available.
  12670. * PLEASE NOTE: the origin of a Screen Space Canvas is set to [0;0] (bottom/left) which is different than the default origin of a Primitive which is centered [0.5;0.5]
  12671. * @param scene the Scene that owns the Canvas
  12672. * @param settings a combination of settings, possible ones are
  12673. * - children: an array of direct children primitives
  12674. * - id: a text identifier, for information purpose only
  12675. * - x: the position along the x axis (horizontal), relative to the left edge of the viewport. you can alternatively use the position setting.
  12676. * - y: the position along the y axis (vertically), relative to the bottom edge of the viewport. you can alternatively use the position setting.
  12677. * - position: the position of the canvas, relative from the bottom/left of the scene's viewport. Alternatively you can set the x and y properties directly. Default value is [0, 0]
  12678. * - width: the width of the Canvas. you can alternatively use the size setting.
  12679. * - height: the height of the Canvas. you can alternatively use the size setting.
  12680. * - size: the Size of the canvas. Alternatively the width and height properties can be set. If null two behaviors depend on the cachingStrategy: if it's CACHESTRATEGY_CACHECANVAS then it will always auto-fit the rendering device, in all the other modes it will fit the content of the Canvas
  12681. * - designSize: if you want to set the canvas content based on fixed coordinates whatever the final canvas dimension would be, set this. For instance a designSize of 360*640 will give you the possibility to specify all the children element in this frame. The Canvas' true size will be the HTMLCanvas' size: for instance it could be 720*1280, then a uniform scale of 2 will be applied on the Canvas to keep the absolute coordinates working as expecting. If the ratios of the designSize and the true Canvas size are not the same, then the scale is computed following the designUseHorizAxis member by using either the size of the horizontal axis or the vertical axis.
  12682. * - designUseHorizAxis: you can set this member if you use designSize to specify which axis is priority to compute the scale when the ratio of the canvas' size is different from the designSize's one.
  12683. * - cachingStrategy: either CACHESTRATEGY_TOPLEVELGROUPS, CACHESTRATEGY_ALLGROUPS, CACHESTRATEGY_CANVAS, CACHESTRATEGY_DONTCACHE. Please refer to their respective documentation for more information. Default is Canvas2D.CACHESTRATEGY_DONTCACHE
  12684. * - enableInteraction: if true the pointer events will be listened and rerouted to the appropriate primitives of the Canvas2D through the Prim2DBase.onPointerEventObservable observable property. Default is true.
  12685. * - isVisible: true if the canvas must be visible, false for hidden. Default is true.
  12686. * - backgroundRoundRadius: the round radius of the background, either backgroundFill or backgroundBorder must be specified.
  12687. * - backgroundFill: the brush to use to create a background fill for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  12688. * - backgroundBorder: the brush to use to create a background border for the canvas. can be a string value (see BABYLON.Canvas2D.GetBrushFromString) or a IBrush2D instance.
  12689. * - backgroundBorderThickness: if a backgroundBorder is specified, its thickness can be set using this property
  12690. * - customWorldSpaceNode: if specified the Canvas will be rendered in this given Node. But it's the responsibility of the caller to set the "worldSpaceToNodeLocal" property to compute the hit of the mouse ray into the node (in world coordinate system) as well as rendering the cached bitmap in the node itself. The properties cachedRect and cachedTexture of Group2D will give you what you need to do that.
  12691. * - paddingTop: top padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  12692. * - paddingLeft: left padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  12693. * - paddingRight: right padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  12694. * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see BABYLON.PrimitiveThickness.fromString)
  12695. * - padding: top, left, right and bottom padding formatted as a single string (see BABYLON.PrimitiveThickness.fromString)
  12696. */
  12697. function ScreenSpaceCanvas2D(scene, settings) {
  12698. BABYLON.Prim2DBase._isCanvasInit = true;
  12699. _super.call(this, scene, settings);
  12700. }
  12701. ScreenSpaceCanvas2D = __decorate([
  12702. BABYLON.className("ScreenSpaceCanvas2D", "BABYLON")
  12703. ], ScreenSpaceCanvas2D);
  12704. return ScreenSpaceCanvas2D;
  12705. }(Canvas2D));
  12706. BABYLON.ScreenSpaceCanvas2D = ScreenSpaceCanvas2D;
  12707. })(BABYLON || (BABYLON = {}));
  12708. var BABYLON;
  12709. (function (BABYLON) {
  12710. /**
  12711. * This is the class that is used to display a World Space Canvas into a 3D scene
  12712. */
  12713. var WorldSpaceCanvas2DNode = (function (_super) {
  12714. __extends(WorldSpaceCanvas2DNode, _super);
  12715. function WorldSpaceCanvas2DNode(name, scene, canvas) {
  12716. _super.call(this, name, scene);
  12717. this._canvas = canvas;
  12718. }
  12719. WorldSpaceCanvas2DNode.prototype.dispose = function () {
  12720. _super.prototype.dispose.call(this);
  12721. if (this._canvas) {
  12722. this._canvas.dispose();
  12723. this._canvas = null;
  12724. }
  12725. };
  12726. return WorldSpaceCanvas2DNode;
  12727. }(BABYLON.Mesh));
  12728. BABYLON.WorldSpaceCanvas2DNode = WorldSpaceCanvas2DNode;
  12729. })(BABYLON || (BABYLON = {}));
  12730. var BABYLON;
  12731. (function (BABYLON) {
  12732. var Command = (function () {
  12733. function Command(execute, canExecute) {
  12734. if (!execute) {
  12735. throw Error("At least an execute lambda must be given at Command creation time");
  12736. }
  12737. this._canExecuteChanged = null;
  12738. this._lastCanExecuteResult = null;
  12739. this.execute = execute;
  12740. this.canExecute = canExecute;
  12741. }
  12742. Command.prototype.canExecute = function (parameter) {
  12743. var res = true;
  12744. if (this._canExecute) {
  12745. res = this._canExecute(parameter);
  12746. }
  12747. if (res !== this._lastCanExecuteResult) {
  12748. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  12749. this._canExecuteChanged.notifyObservers(null);
  12750. }
  12751. this._lastCanExecuteResult = res;
  12752. }
  12753. return res;
  12754. };
  12755. Command.prototype.execute = function (parameter) {
  12756. this._execute(parameter);
  12757. };
  12758. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  12759. get: function () {
  12760. if (!this._canExecuteChanged) {
  12761. this._canExecuteChanged = new BABYLON.Observable();
  12762. }
  12763. return this._canExecuteChanged;
  12764. },
  12765. enumerable: true,
  12766. configurable: true
  12767. });
  12768. return Command;
  12769. }());
  12770. BABYLON.Command = Command;
  12771. var UIElement = (function (_super) {
  12772. __extends(UIElement, _super);
  12773. function UIElement(settings) {
  12774. _super.call(this);
  12775. if (!settings) {
  12776. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  12777. }
  12778. var type = BABYLON.Tools.getFullClassName(this);
  12779. this._ownerWindow = null;
  12780. this._parent = null;
  12781. this._visualPlaceholder = null;
  12782. this._visualTemplateRoot = null;
  12783. this._visualChildrenPlaceholder = null;
  12784. this._hierarchyDepth = 0;
  12785. this._style = (settings.styleName != null) ? UIElementStyleManager.getStyle(type, settings.styleName) : null;
  12786. this._flags = 0;
  12787. this._id = (settings.id != null) ? settings.id : null;
  12788. this._uid = null;
  12789. this._width = (settings.width != null) ? settings.width : null;
  12790. this._height = (settings.height != null) ? settings.height : null;
  12791. this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  12792. this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  12793. this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  12794. this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  12795. this._margin = null;
  12796. this._padding = null;
  12797. this._marginAlignment = null;
  12798. this._isEnabled = true;
  12799. this._isFocused = false;
  12800. this._isMouseOver = false;
  12801. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  12802. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  12803. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  12804. // Set the layout/margin stuffs
  12805. if (settings.marginTop) {
  12806. this.margin.setTop(settings.marginTop);
  12807. }
  12808. if (settings.marginLeft) {
  12809. this.margin.setLeft(settings.marginLeft);
  12810. }
  12811. if (settings.marginRight) {
  12812. this.margin.setRight(settings.marginRight);
  12813. }
  12814. if (settings.marginBottom) {
  12815. this.margin.setBottom(settings.marginBottom);
  12816. }
  12817. if (settings.margin) {
  12818. if (typeof settings.margin === "string") {
  12819. this.margin.fromString(settings.margin);
  12820. }
  12821. else {
  12822. this.margin.fromUniformPixels(settings.margin);
  12823. }
  12824. }
  12825. if (settings.marginHAlignment) {
  12826. this.marginAlignment.horizontal = settings.marginHAlignment;
  12827. }
  12828. if (settings.marginVAlignment) {
  12829. this.marginAlignment.vertical = settings.marginVAlignment;
  12830. }
  12831. if (settings.marginAlignment) {
  12832. this.marginAlignment.fromString(settings.marginAlignment);
  12833. }
  12834. if (settings.paddingTop) {
  12835. this.padding.setTop(settings.paddingTop);
  12836. }
  12837. if (settings.paddingLeft) {
  12838. this.padding.setLeft(settings.paddingLeft);
  12839. }
  12840. if (settings.paddingRight) {
  12841. this.padding.setRight(settings.paddingRight);
  12842. }
  12843. if (settings.paddingBottom) {
  12844. this.padding.setBottom(settings.paddingBottom);
  12845. }
  12846. if (settings.padding) {
  12847. this.padding.fromString(settings.padding);
  12848. }
  12849. this._assignTemplate(settings.templateName);
  12850. if (settings.parent != null) {
  12851. this._parent = settings.parent;
  12852. this._hierarchyDepth = this._parent._hierarchyDepth + 1;
  12853. }
  12854. }
  12855. UIElement.prototype.dispose = function () {
  12856. if (this.isDisposed) {
  12857. return false;
  12858. }
  12859. if (this._renderingTemplate) {
  12860. this._renderingTemplate.detach();
  12861. this._renderingTemplate = null;
  12862. }
  12863. _super.prototype.dispose.call(this);
  12864. // Don't set to null, it may upset somebody...
  12865. this.animations.splice(0);
  12866. return true;
  12867. };
  12868. /**
  12869. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  12870. * Look at Sprite2D for more information
  12871. */
  12872. UIElement.prototype.getAnimatables = function () {
  12873. return new Array();
  12874. };
  12875. Object.defineProperty(UIElement.prototype, "ownerWindows", {
  12876. // TODO
  12877. // PROPERTIES
  12878. // Style
  12879. // Id
  12880. // Parent/Children
  12881. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  12882. // Alignment/Margin
  12883. // Visibility, IsVisible
  12884. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  12885. // CacheMode of Visual Elements
  12886. // Focusable/IsFocused
  12887. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  12888. // ContextMenu
  12889. // Cursor
  12890. // DesiredSize
  12891. // IsInputEnable ?
  12892. // Opacity, OpacityMask ?
  12893. // SnapToDevicePixels
  12894. // Tag
  12895. // ToolTip
  12896. // METHODS
  12897. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  12898. // Capture/ReleaseCapture (mouse, touch, stylus)
  12899. // Focus
  12900. // PointFrom/ToScreen to translate coordinates
  12901. // EVENTS
  12902. // ContextMenuOpening/Closing/Changed
  12903. // DragEnter/LeaveOver, Drop
  12904. // Got/LostFocus
  12905. // IsEnabledChanged
  12906. // IsPointerOver/DirectlyOverChanged
  12907. // IsVisibleChanged
  12908. // KeyDown/Up
  12909. // LayoutUpdated ?
  12910. // Pointer related events
  12911. // SizeChanged
  12912. // ToolTipOpening/Closing
  12913. get: function () {
  12914. return this._ownerWindow;
  12915. },
  12916. enumerable: true,
  12917. configurable: true
  12918. });
  12919. Object.defineProperty(UIElement.prototype, "style", {
  12920. get: function () {
  12921. if (!this.style) {
  12922. return UIElementStyleManager.DefaultStyleName;
  12923. }
  12924. return this._style.name;
  12925. },
  12926. set: function (value) {
  12927. if (this._style && (this._style.name === value)) {
  12928. return;
  12929. }
  12930. var newStyle = null;
  12931. if (value) {
  12932. newStyle = UIElementStyleManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  12933. if (!newStyle) {
  12934. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  12935. }
  12936. }
  12937. if (this._style) {
  12938. this._style.removeStyle(this);
  12939. }
  12940. if (newStyle) {
  12941. newStyle.applyStyle(this);
  12942. }
  12943. this._style = newStyle;
  12944. },
  12945. enumerable: true,
  12946. configurable: true
  12947. });
  12948. Object.defineProperty(UIElement.prototype, "id", {
  12949. /**
  12950. * A string that identifies the UIElement.
  12951. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  12952. */
  12953. get: function () {
  12954. return this._id;
  12955. },
  12956. set: function (value) {
  12957. if (this._id === value) {
  12958. return;
  12959. }
  12960. this._id = value;
  12961. },
  12962. enumerable: true,
  12963. configurable: true
  12964. });
  12965. Object.defineProperty(UIElement.prototype, "uid", {
  12966. /**
  12967. * Return a unique id automatically generated.
  12968. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  12969. */
  12970. get: function () {
  12971. if (!this._uid) {
  12972. this._uid = BABYLON.Tools.RandomId();
  12973. }
  12974. return this._uid;
  12975. },
  12976. enumerable: true,
  12977. configurable: true
  12978. });
  12979. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  12980. get: function () {
  12981. return this._hierarchyDepth;
  12982. },
  12983. enumerable: true,
  12984. configurable: true
  12985. });
  12986. Object.defineProperty(UIElement.prototype, "parent", {
  12987. get: function () {
  12988. return this._parent;
  12989. },
  12990. set: function (value) {
  12991. this._parent = value;
  12992. },
  12993. enumerable: true,
  12994. configurable: true
  12995. });
  12996. Object.defineProperty(UIElement.prototype, "width", {
  12997. get: function () {
  12998. return this._width;
  12999. },
  13000. set: function (value) {
  13001. this._width = value;
  13002. },
  13003. enumerable: true,
  13004. configurable: true
  13005. });
  13006. Object.defineProperty(UIElement.prototype, "height", {
  13007. get: function () {
  13008. return this._height;
  13009. },
  13010. set: function (value) {
  13011. this._height = value;
  13012. },
  13013. enumerable: true,
  13014. configurable: true
  13015. });
  13016. Object.defineProperty(UIElement.prototype, "minWidth", {
  13017. get: function () {
  13018. return this._minWidth;
  13019. },
  13020. set: function (value) {
  13021. this._minWidth = value;
  13022. },
  13023. enumerable: true,
  13024. configurable: true
  13025. });
  13026. Object.defineProperty(UIElement.prototype, "minHheight", {
  13027. get: function () {
  13028. return this._minHeight;
  13029. },
  13030. enumerable: true,
  13031. configurable: true
  13032. });
  13033. Object.defineProperty(UIElement.prototype, "minHeight", {
  13034. set: function (value) {
  13035. this._minHeight = value;
  13036. },
  13037. enumerable: true,
  13038. configurable: true
  13039. });
  13040. Object.defineProperty(UIElement.prototype, "maxWidth", {
  13041. get: function () {
  13042. return this._maxWidth;
  13043. },
  13044. set: function (value) {
  13045. this._maxWidth = value;
  13046. },
  13047. enumerable: true,
  13048. configurable: true
  13049. });
  13050. Object.defineProperty(UIElement.prototype, "maxHeight", {
  13051. get: function () {
  13052. return this._maxHeight;
  13053. },
  13054. set: function (value) {
  13055. this._maxHeight = value;
  13056. },
  13057. enumerable: true,
  13058. configurable: true
  13059. });
  13060. Object.defineProperty(UIElement.prototype, "actualWidth", {
  13061. get: function () {
  13062. return this._actualWidth;
  13063. },
  13064. set: function (value) {
  13065. this._actualWidth = value;
  13066. },
  13067. enumerable: true,
  13068. configurable: true
  13069. });
  13070. Object.defineProperty(UIElement.prototype, "actualHeight", {
  13071. get: function () {
  13072. return this._actualHeight;
  13073. },
  13074. set: function (value) {
  13075. this._actualHeight = value;
  13076. },
  13077. enumerable: true,
  13078. configurable: true
  13079. });
  13080. Object.defineProperty(UIElement.prototype, "margin", {
  13081. get: function () {
  13082. var _this = this;
  13083. if (!this._margin) {
  13084. this._margin = new BABYLON.PrimitiveThickness(function () {
  13085. if (!_this.parent) {
  13086. return null;
  13087. }
  13088. return _this.parent.margin;
  13089. });
  13090. }
  13091. return this._margin;
  13092. },
  13093. set: function (value) {
  13094. this.margin.copyFrom(value);
  13095. },
  13096. enumerable: true,
  13097. configurable: true
  13098. });
  13099. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  13100. get: function () {
  13101. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13102. },
  13103. enumerable: true,
  13104. configurable: true
  13105. });
  13106. Object.defineProperty(UIElement.prototype, "padding", {
  13107. get: function () {
  13108. var _this = this;
  13109. if (!this._padding) {
  13110. this._padding = new BABYLON.PrimitiveThickness(function () {
  13111. if (!_this.parent) {
  13112. return null;
  13113. }
  13114. return _this.parent.padding;
  13115. });
  13116. }
  13117. return this._padding;
  13118. },
  13119. set: function (value) {
  13120. this.padding.copyFrom(value);
  13121. },
  13122. enumerable: true,
  13123. configurable: true
  13124. });
  13125. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  13126. get: function () {
  13127. return this._padding !== null && !this._padding.isDefault;
  13128. },
  13129. enumerable: true,
  13130. configurable: true
  13131. });
  13132. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  13133. get: function () {
  13134. if (!this._marginAlignment) {
  13135. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  13136. }
  13137. return this._marginAlignment;
  13138. },
  13139. set: function (value) {
  13140. this.marginAlignment.copyFrom(value);
  13141. },
  13142. enumerable: true,
  13143. configurable: true
  13144. });
  13145. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  13146. /**
  13147. * Check if there a marginAlignment specified (non null and not default)
  13148. */
  13149. get: function () {
  13150. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  13151. },
  13152. enumerable: true,
  13153. configurable: true
  13154. });
  13155. Object.defineProperty(UIElement.prototype, "isEnabled", {
  13156. get: function () {
  13157. return this._isEnabled;
  13158. },
  13159. set: function (value) {
  13160. this._isEnabled = value;
  13161. },
  13162. enumerable: true,
  13163. configurable: true
  13164. });
  13165. Object.defineProperty(UIElement.prototype, "isFocused", {
  13166. get: function () {
  13167. return this._isFocused;
  13168. },
  13169. set: function (value) {
  13170. this._isFocused = value;
  13171. },
  13172. enumerable: true,
  13173. configurable: true
  13174. });
  13175. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  13176. get: function () {
  13177. return this._isMouseOver;
  13178. },
  13179. set: function (value) {
  13180. this._isMouseOver = value;
  13181. },
  13182. enumerable: true,
  13183. configurable: true
  13184. });
  13185. /**
  13186. * Check if a given flag is set
  13187. * @param flag the flag value
  13188. * @return true if set, false otherwise
  13189. */
  13190. UIElement.prototype._isFlagSet = function (flag) {
  13191. return (this._flags & flag) !== 0;
  13192. };
  13193. /**
  13194. * Check if all given flags are set
  13195. * @param flags the flags ORed
  13196. * @return true if all the flags are set, false otherwise
  13197. */
  13198. UIElement.prototype._areAllFlagsSet = function (flags) {
  13199. return (this._flags & flags) === flags;
  13200. };
  13201. /**
  13202. * Check if at least one flag of the given flags is set
  13203. * @param flags the flags ORed
  13204. * @return true if at least one flag is set, false otherwise
  13205. */
  13206. UIElement.prototype._areSomeFlagsSet = function (flags) {
  13207. return (this._flags & flags) !== 0;
  13208. };
  13209. /**
  13210. * Clear the given flags
  13211. * @param flags the flags to clear
  13212. */
  13213. UIElement.prototype._clearFlags = function (flags) {
  13214. this._flags &= ~flags;
  13215. };
  13216. /**
  13217. * Set the given flags to true state
  13218. * @param flags the flags ORed to set
  13219. * @return the flags state before this call
  13220. */
  13221. UIElement.prototype._setFlags = function (flags) {
  13222. var cur = this._flags;
  13223. this._flags |= flags;
  13224. return cur;
  13225. };
  13226. /**
  13227. * Change the state of the given flags
  13228. * @param flags the flags ORed to change
  13229. * @param state true to set them, false to clear them
  13230. */
  13231. UIElement.prototype._changeFlags = function (flags, state) {
  13232. if (state) {
  13233. this._flags |= flags;
  13234. }
  13235. else {
  13236. this._flags &= ~flags;
  13237. }
  13238. };
  13239. UIElement.prototype._assignTemplate = function (templateName) {
  13240. if (!templateName) {
  13241. templateName = UIElementRenderingTemplateManager.DefaultTemplateName;
  13242. }
  13243. var className = BABYLON.Tools.getFullClassName(this);
  13244. if (!className) {
  13245. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  13246. }
  13247. var factory = UIElementRenderingTemplateManager.getRenderingTemplate(className, templateName);
  13248. if (!factory) {
  13249. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  13250. }
  13251. this._renderingTemplate = factory();
  13252. this._renderingTemplate.attach(this);
  13253. };
  13254. UIElement.prototype._createVisualTree = function () {
  13255. var parentPrim = this.ownerWindows.canvas;
  13256. if (this.parent) {
  13257. parentPrim = this.parent.visualChildrenPlaceholder;
  13258. }
  13259. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI Visual Placeholder of " + this.id });
  13260. var p = this._visualPlaceholder;
  13261. p.addExternalData("_GUIOwnerElement_", this);
  13262. p.dataSource = this;
  13263. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  13264. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  13265. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  13266. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  13267. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  13268. p.createSimpleDataBinding(BABYLON.Prim2DBase.paddingProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  13269. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  13270. this.createVisualTree();
  13271. };
  13272. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  13273. if (ownerWindow) {
  13274. if (!this._ownerWindow) {
  13275. ownerWindow._registerVisualToBuild(this);
  13276. }
  13277. this._ownerWindow = ownerWindow;
  13278. }
  13279. this._parent = parent;
  13280. if (parent) {
  13281. this._hierarchyDepth = parent.hierarchyDepth + 1;
  13282. }
  13283. var children = this._getChildren();
  13284. if (children) {
  13285. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  13286. var curChild = children_1[_i];
  13287. curChild._patchUIElement(ownerWindow, this);
  13288. }
  13289. }
  13290. };
  13291. // Overload the SmartPropertyBase's method to provide the additional logic of returning the parent's dataSource if there's no dataSource specified at this level.
  13292. UIElement.prototype._getDataSource = function () {
  13293. var levelDS = _super.prototype._getDataSource.call(this);
  13294. if (levelDS != null) {
  13295. return levelDS;
  13296. }
  13297. var p = this.parent;
  13298. if (p != null) {
  13299. return p.dataSource;
  13300. }
  13301. return null;
  13302. };
  13303. UIElement.prototype.createVisualTree = function () {
  13304. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  13305. this._visualTemplateRoot = res.root;
  13306. this._visualChildrenPlaceholder = res.contentPlaceholder;
  13307. };
  13308. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  13309. get: function () {
  13310. return this._visualPlaceholder;
  13311. },
  13312. enumerable: true,
  13313. configurable: true
  13314. });
  13315. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  13316. get: function () {
  13317. return this._visualTemplateRoot;
  13318. },
  13319. enumerable: true,
  13320. configurable: true
  13321. });
  13322. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  13323. get: function () {
  13324. return this._visualChildrenPlaceholder;
  13325. },
  13326. enumerable: true,
  13327. configurable: true
  13328. });
  13329. Object.defineProperty(UIElement.prototype, "_position", {
  13330. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  13331. ,
  13332. enumerable: true,
  13333. configurable: true
  13334. });
  13335. UIElement.UIELEMENT_PROPCOUNT = 15;
  13336. UIElement.flagVisualToBuild = 0x0000001; // set if the UIElement visual must be updated
  13337. __decorate([
  13338. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  13339. ], UIElement.prototype, "parent", null);
  13340. __decorate([
  13341. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  13342. ], UIElement.prototype, "width", null);
  13343. __decorate([
  13344. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  13345. ], UIElement.prototype, "height", null);
  13346. __decorate([
  13347. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  13348. ], UIElement.prototype, "minWidth", null);
  13349. __decorate([
  13350. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  13351. ], UIElement.prototype, "minHheight", null);
  13352. __decorate([
  13353. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  13354. ], UIElement.prototype, "maxWidth", null);
  13355. __decorate([
  13356. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  13357. ], UIElement.prototype, "maxHeight", null);
  13358. __decorate([
  13359. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  13360. ], UIElement.prototype, "actualWidth", null);
  13361. __decorate([
  13362. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  13363. ], UIElement.prototype, "actualHeight", null);
  13364. __decorate([
  13365. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  13366. ], UIElement.prototype, "margin", null);
  13367. __decorate([
  13368. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  13369. ], UIElement.prototype, "padding", null);
  13370. __decorate([
  13371. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  13372. ], UIElement.prototype, "marginAlignment", null);
  13373. __decorate([
  13374. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.isEnabledProperty = pi; })
  13375. ], UIElement.prototype, "isEnabled", null);
  13376. __decorate([
  13377. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isFocusedProperty = pi; })
  13378. ], UIElement.prototype, "isFocused", null);
  13379. __decorate([
  13380. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isMouseOverProperty = pi; })
  13381. ], UIElement.prototype, "isMouseOver", null);
  13382. return UIElement;
  13383. }(BABYLON.SmartPropertyBase));
  13384. BABYLON.UIElement = UIElement;
  13385. var UIElementStyle = (function () {
  13386. function UIElementStyle() {
  13387. }
  13388. Object.defineProperty(UIElementStyle.prototype, "name", {
  13389. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  13390. ,
  13391. enumerable: true,
  13392. configurable: true
  13393. });
  13394. return UIElementStyle;
  13395. }());
  13396. BABYLON.UIElementStyle = UIElementStyle;
  13397. var UIElementStyleManager = (function () {
  13398. function UIElementStyleManager() {
  13399. }
  13400. UIElementStyleManager.getStyle = function (uiElType, styleName) {
  13401. var styles = UIElementStyleManager.stylesByUIElement.get(uiElType);
  13402. if (!styles) {
  13403. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  13404. }
  13405. var style = styles.get(styleName);
  13406. if (!style) {
  13407. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  13408. }
  13409. return style;
  13410. };
  13411. UIElementStyleManager.registerStyle = function (uiElType, templateName, style) {
  13412. var templates = UIElementStyleManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  13413. if (templates.contains(templateName)) {
  13414. templates[templateName] = style;
  13415. }
  13416. else {
  13417. templates.add(templateName, style);
  13418. }
  13419. };
  13420. Object.defineProperty(UIElementStyleManager, "DefaultStyleName", {
  13421. get: function () {
  13422. return UIElementStyleManager._defaultStyleName;
  13423. },
  13424. set: function (value) {
  13425. UIElementStyleManager._defaultStyleName = value;
  13426. },
  13427. enumerable: true,
  13428. configurable: true
  13429. });
  13430. UIElementStyleManager.stylesByUIElement = new BABYLON.StringDictionary();
  13431. UIElementStyleManager._defaultStyleName = "Default";
  13432. return UIElementStyleManager;
  13433. }());
  13434. BABYLON.UIElementStyleManager = UIElementStyleManager;
  13435. var UIElementRenderingTemplateManager = (function () {
  13436. function UIElementRenderingTemplateManager() {
  13437. }
  13438. UIElementRenderingTemplateManager.getRenderingTemplate = function (uiElType, templateName) {
  13439. var templates = UIElementRenderingTemplateManager.renderingTemplatesByUIElement.get(uiElType);
  13440. if (!templates) {
  13441. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  13442. }
  13443. var templateFactory = templates.get(templateName);
  13444. if (!templateFactory) {
  13445. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  13446. }
  13447. return templateFactory;
  13448. };
  13449. UIElementRenderingTemplateManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  13450. var templates = UIElementRenderingTemplateManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  13451. if (templates.contains(templateName)) {
  13452. templates[templateName] = factory;
  13453. }
  13454. else {
  13455. templates.add(templateName, factory);
  13456. }
  13457. };
  13458. Object.defineProperty(UIElementRenderingTemplateManager, "DefaultTemplateName", {
  13459. get: function () {
  13460. return UIElementRenderingTemplateManager._defaultTemplateName;
  13461. },
  13462. set: function (value) {
  13463. UIElementRenderingTemplateManager._defaultTemplateName = value;
  13464. },
  13465. enumerable: true,
  13466. configurable: true
  13467. });
  13468. UIElementRenderingTemplateManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  13469. UIElementRenderingTemplateManager._defaultTemplateName = "Default";
  13470. return UIElementRenderingTemplateManager;
  13471. }());
  13472. BABYLON.UIElementRenderingTemplateManager = UIElementRenderingTemplateManager;
  13473. var UIElementRenderingTemplateBase = (function () {
  13474. function UIElementRenderingTemplateBase() {
  13475. }
  13476. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  13477. this._owner = owner;
  13478. };
  13479. UIElementRenderingTemplateBase.prototype.detach = function () {
  13480. };
  13481. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  13482. get: function () {
  13483. return this._owner;
  13484. },
  13485. enumerable: true,
  13486. configurable: true
  13487. });
  13488. return UIElementRenderingTemplateBase;
  13489. }());
  13490. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  13491. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  13492. return function () {
  13493. UIElementRenderingTemplateManager.registerRenderingTemplate(uiElType, templateName, factory);
  13494. };
  13495. }
  13496. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  13497. })(BABYLON || (BABYLON = {}));
  13498. var BABYLON;
  13499. (function (BABYLON) {
  13500. var Control = (function (_super) {
  13501. __extends(Control, _super);
  13502. function Control(settings) {
  13503. _super.call(this, settings);
  13504. }
  13505. Object.defineProperty(Control.prototype, "background", {
  13506. get: function () {
  13507. if (!this._background) {
  13508. this._background = new BABYLON.ObservableStringDictionary(false);
  13509. }
  13510. return this._background;
  13511. },
  13512. set: function (value) {
  13513. this.background.copyFrom(value);
  13514. },
  13515. enumerable: true,
  13516. configurable: true
  13517. });
  13518. Object.defineProperty(Control.prototype, "border", {
  13519. get: function () {
  13520. return this._border;
  13521. },
  13522. set: function (value) {
  13523. this._border = value;
  13524. },
  13525. enumerable: true,
  13526. configurable: true
  13527. });
  13528. Object.defineProperty(Control.prototype, "borderThickness", {
  13529. get: function () {
  13530. return this._borderThickness;
  13531. },
  13532. set: function (value) {
  13533. this._borderThickness = value;
  13534. },
  13535. enumerable: true,
  13536. configurable: true
  13537. });
  13538. Object.defineProperty(Control.prototype, "fontName", {
  13539. get: function () {
  13540. return this._fontName;
  13541. },
  13542. set: function (value) {
  13543. this._fontName = value;
  13544. },
  13545. enumerable: true,
  13546. configurable: true
  13547. });
  13548. Object.defineProperty(Control.prototype, "foreground", {
  13549. get: function () {
  13550. return this._foreground;
  13551. },
  13552. set: function (value) {
  13553. this._foreground = value;
  13554. },
  13555. enumerable: true,
  13556. configurable: true
  13557. });
  13558. Control.CONTROL_PROPCOUNT = BABYLON.UIElement.UIELEMENT_PROPCOUNT + 5;
  13559. __decorate([
  13560. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 0, function (pi) { return Control.backgroundProperty = pi; })
  13561. ], Control.prototype, "background", null);
  13562. __decorate([
  13563. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 1, function (pi) { return Control.borderProperty = pi; })
  13564. ], Control.prototype, "border", null);
  13565. __decorate([
  13566. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 2, function (pi) { return Control.borderThicknessProperty = pi; })
  13567. ], Control.prototype, "borderThickness", null);
  13568. __decorate([
  13569. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 3, function (pi) { return Control.fontNameProperty = pi; })
  13570. ], Control.prototype, "fontName", null);
  13571. __decorate([
  13572. BABYLON.dependencyProperty(BABYLON.UIElement.UIELEMENT_PROPCOUNT + 4, function (pi) { return Control.foregroundProperty = pi; })
  13573. ], Control.prototype, "foreground", null);
  13574. Control = __decorate([
  13575. BABYLON.className("Control", "BABYLON")
  13576. ], Control);
  13577. return Control;
  13578. }(BABYLON.UIElement));
  13579. BABYLON.Control = Control;
  13580. var ContentControl = (function (_super) {
  13581. __extends(ContentControl, _super);
  13582. function ContentControl(settings) {
  13583. if (!settings) {
  13584. settings = {};
  13585. }
  13586. _super.call(this, settings);
  13587. if (settings.content != null) {
  13588. this._content = settings.content;
  13589. }
  13590. if (settings.contentAlignment != null) {
  13591. this.contentAlignment.fromString(settings.contentAlignment);
  13592. }
  13593. }
  13594. ContentControl.prototype.dispose = function () {
  13595. if (this.isDisposed) {
  13596. return false;
  13597. }
  13598. if (this.content && this.content.dispose) {
  13599. this.content.dispose();
  13600. this.content = null;
  13601. }
  13602. if (this.__contentUIElement) {
  13603. this.__contentUIElement.dispose();
  13604. this.__contentUIElement = null;
  13605. }
  13606. _super.prototype.dispose.call(this);
  13607. return true;
  13608. };
  13609. Object.defineProperty(ContentControl.prototype, "content", {
  13610. get: function () {
  13611. return this._content;
  13612. },
  13613. set: function (value) {
  13614. this._content = value;
  13615. },
  13616. enumerable: true,
  13617. configurable: true
  13618. });
  13619. Object.defineProperty(ContentControl.prototype, "contentAlignment", {
  13620. get: function () {
  13621. if (!this._contentAlignment) {
  13622. this._contentAlignment = new BABYLON.PrimitiveAlignment();
  13623. }
  13624. return this._contentAlignment;
  13625. },
  13626. set: function (value) {
  13627. this.contentAlignment.copyFrom(value);
  13628. },
  13629. enumerable: true,
  13630. configurable: true
  13631. });
  13632. Object.defineProperty(ContentControl.prototype, "_hasContentAlignment", {
  13633. /**
  13634. * Check if there a contentAlignment specified (non null and not default)
  13635. */
  13636. get: function () {
  13637. return (this._contentAlignment !== null && !this._contentAlignment.isDefault);
  13638. },
  13639. enumerable: true,
  13640. configurable: true
  13641. });
  13642. Object.defineProperty(ContentControl.prototype, "_contentUIElement", {
  13643. get: function () {
  13644. if (!this.__contentUIElement) {
  13645. this._buildContentUIElement();
  13646. }
  13647. return this.__contentUIElement;
  13648. },
  13649. enumerable: true,
  13650. configurable: true
  13651. });
  13652. ContentControl.prototype._buildContentUIElement = function () {
  13653. var c = this._content;
  13654. this.__contentUIElement = null;
  13655. // Already a UIElement
  13656. if (c instanceof BABYLON.UIElement) {
  13657. this.__contentUIElement = c;
  13658. }
  13659. else if ((typeof c === "string") || (typeof c === "boolean") || (typeof c === "number")) {
  13660. var l = new BABYLON.Label({ parent: this, id: "Content of " + this.id });
  13661. var binding = new BABYLON.DataBinding();
  13662. binding.propertyPathName = "content";
  13663. binding.stringFormat = function (v) { return ("" + v); };
  13664. binding.dataSource = this;
  13665. l.createDataBinding(BABYLON.Label.textProperty, binding);
  13666. binding = new BABYLON.DataBinding();
  13667. binding.propertyPathName = "contentAlignment";
  13668. binding.dataSource = this;
  13669. l.createDataBinding(BABYLON.Label.marginAlignmentProperty, binding);
  13670. this.__contentUIElement = l;
  13671. }
  13672. else {
  13673. }
  13674. if (this.__contentUIElement) {
  13675. this.__contentUIElement._patchUIElement(this.ownerWindows, this);
  13676. }
  13677. };
  13678. ContentControl.prototype._getChildren = function () {
  13679. var children = new Array();
  13680. if (this.content) {
  13681. children.push(this._contentUIElement);
  13682. }
  13683. return children;
  13684. };
  13685. ContentControl.CONTENTCONTROL_PROPCOUNT = Control.CONTROL_PROPCOUNT + 2;
  13686. __decorate([
  13687. BABYLON.dependencyProperty(Control.CONTROL_PROPCOUNT + 0, function (pi) { return ContentControl.contentProperty = pi; })
  13688. ], ContentControl.prototype, "content", null);
  13689. __decorate([
  13690. BABYLON.dependencyProperty(Control.CONTROL_PROPCOUNT + 1, function (pi) { return ContentControl.contentAlignmentProperty = pi; })
  13691. ], ContentControl.prototype, "contentAlignment", null);
  13692. ContentControl = __decorate([
  13693. BABYLON.className("ContentControl", "BABYLON")
  13694. ], ContentControl);
  13695. return ContentControl;
  13696. }(Control));
  13697. BABYLON.ContentControl = ContentControl;
  13698. })(BABYLON || (BABYLON = {}));
  13699. var BABYLON;
  13700. (function (BABYLON) {
  13701. var Window = (function (_super) {
  13702. __extends(Window, _super);
  13703. function Window(scene, settings) {
  13704. var _this = this;
  13705. if (!settings) {
  13706. settings = {};
  13707. }
  13708. _super.call(this, settings);
  13709. if (!this._UIElementVisualToBuildList) {
  13710. this._UIElementVisualToBuildList = new Array();
  13711. }
  13712. // Patch the owner and also the parent property through the whole tree
  13713. this._patchUIElement(this, null);
  13714. // Screen Space UI
  13715. if (!settings.worldPosition && !settings.worldRotation) {
  13716. this._canvas = Window.getScreenCanvas(scene);
  13717. this._isWorldSpaceCanvas = false;
  13718. this._left = (settings.left != null) ? settings.left : 0;
  13719. this._bottom = (settings.bottom != null) ? settings.bottom : 0;
  13720. }
  13721. else {
  13722. var w = (settings.width == null) ? 100 : settings.width;
  13723. var h = (settings.height == null) ? 100 : settings.height;
  13724. var wpos = (settings.worldPosition == null) ? BABYLON.Vector3.Zero() : settings.worldPosition;
  13725. var wrot = (settings.worldRotation == null) ? BABYLON.Quaternion.Identity() : settings.worldRotation;
  13726. this._canvas = new BABYLON.WorldSpaceCanvas2D(scene, new BABYLON.Size(w, h), { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE, worldPosition: wpos, worldRotation: wrot });
  13727. this._isWorldSpaceCanvas = true;
  13728. }
  13729. this._renderObserver = this._canvas.renderObservable.add(function (e, s) { return _this._canvasPreRender(); }, BABYLON.Canvas2D.RENDEROBSERVABLE_PRE);
  13730. this._disposeObserver = this._canvas.disposeObservable.add(function (e, s) { return _this._canvasDisposed(); });
  13731. this._canvas.propertyChanged.add(function (e, s) {
  13732. if (e.propertyName === "overPrim") {
  13733. _this._overPrimChanged(e.oldValue, e.newValue);
  13734. }
  13735. });
  13736. this._mouseOverUIElement = null;
  13737. }
  13738. Object.defineProperty(Window.prototype, "canvas", {
  13739. get: function () {
  13740. return this._canvas;
  13741. },
  13742. enumerable: true,
  13743. configurable: true
  13744. });
  13745. Object.defineProperty(Window.prototype, "left", {
  13746. get: function () {
  13747. return this._left;
  13748. },
  13749. set: function (value) {
  13750. var old = new BABYLON.Vector2(this._left, this._bottom);
  13751. this._left = value;
  13752. this.onPropertyChanged("_position", old, this._position);
  13753. },
  13754. enumerable: true,
  13755. configurable: true
  13756. });
  13757. Object.defineProperty(Window.prototype, "bottom", {
  13758. get: function () {
  13759. return this._bottom;
  13760. },
  13761. set: function (value) {
  13762. var old = new BABYLON.Vector2(this._left, this._bottom);
  13763. this._bottom = value;
  13764. this.onPropertyChanged("_position", old, this._position);
  13765. },
  13766. enumerable: true,
  13767. configurable: true
  13768. });
  13769. Object.defineProperty(Window.prototype, "position", {
  13770. get: function () {
  13771. return this._position;
  13772. },
  13773. set: function (value) {
  13774. this._left = value.x;
  13775. this._bottom = value.y;
  13776. },
  13777. enumerable: true,
  13778. configurable: true
  13779. });
  13780. Object.defineProperty(Window.prototype, "_position", {
  13781. get: function () {
  13782. return new BABYLON.Vector2(this.left, this.bottom);
  13783. },
  13784. enumerable: true,
  13785. configurable: true
  13786. });
  13787. Window.prototype.createVisualTree = function () {
  13788. _super.prototype.createVisualTree.call(this);
  13789. var p = this._visualPlaceholder;
  13790. p.createSimpleDataBinding(BABYLON.Group2D.positionProperty, "position");
  13791. };
  13792. Window.prototype._registerVisualToBuild = function (uiel) {
  13793. if (uiel._isFlagSet(BABYLON.UIElement.flagVisualToBuild)) {
  13794. return;
  13795. }
  13796. if (!this._UIElementVisualToBuildList) {
  13797. this._UIElementVisualToBuildList = new Array();
  13798. }
  13799. this._UIElementVisualToBuildList.push(uiel);
  13800. uiel._setFlags(BABYLON.UIElement.flagVisualToBuild);
  13801. };
  13802. Window.prototype._overPrimChanged = function (oldPrim, newPrim) {
  13803. var curOverEl = this._mouseOverUIElement;
  13804. var newOverEl = null;
  13805. var curGroup = newPrim ? newPrim.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  13806. while (curGroup) {
  13807. var uiel = curGroup.getExternalData("_GUIOwnerElement_");
  13808. if (uiel) {
  13809. newOverEl = uiel;
  13810. break;
  13811. }
  13812. curGroup = curGroup.parent ? curGroup.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D; }) : null;
  13813. }
  13814. if (curOverEl === newOverEl) {
  13815. return;
  13816. }
  13817. if (curOverEl) {
  13818. curOverEl.isMouseOver = false;
  13819. }
  13820. if (newOverEl) {
  13821. newOverEl.isMouseOver = true;
  13822. }
  13823. this._mouseOverUIElement = newOverEl;
  13824. };
  13825. Window.prototype._canvasPreRender = function () {
  13826. // Check if we have visual to create
  13827. if (this._UIElementVisualToBuildList.length > 0) {
  13828. // Sort the UI Element to get the highest (so lowest hierarchy depth) in the hierarchy tree first
  13829. var sortedElementList = this._UIElementVisualToBuildList.sort(function (a, b) { return a.hierarchyDepth - b.hierarchyDepth; });
  13830. for (var _i = 0, sortedElementList_1 = sortedElementList; _i < sortedElementList_1.length; _i++) {
  13831. var el = sortedElementList_1[_i];
  13832. el._createVisualTree();
  13833. }
  13834. this._UIElementVisualToBuildList.splice(0);
  13835. }
  13836. };
  13837. Window.prototype._canvasDisposed = function () {
  13838. this._canvas.disposeObservable.remove(this._disposeObserver);
  13839. this._canvas.renderObservable.remove(this._renderObserver);
  13840. };
  13841. Window.getScreenCanvas = function (scene) {
  13842. var canvas = BABYLON.Tools.first(Window._screenCanvasList, function (c) { return c.scene === scene; });
  13843. if (canvas) {
  13844. return canvas;
  13845. }
  13846. canvas = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "GUI Canvas", cachingStrategy: BABYLON.Canvas2D.CACHESTRATEGY_DONTCACHE });
  13847. Window._screenCanvasList.push(canvas);
  13848. return canvas;
  13849. };
  13850. Window.WINDOW_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2;
  13851. Window._screenCanvasList = new Array();
  13852. __decorate([
  13853. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 0, function (pi) { return Window.leftProperty = pi; })
  13854. ], Window.prototype, "left", null);
  13855. __decorate([
  13856. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 1, function (pi) { return Window.bottomProperty = pi; })
  13857. ], Window.prototype, "bottom", null);
  13858. __decorate([
  13859. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 2, function (pi) { return Window.positionProperty = pi; })
  13860. ], Window.prototype, "position", null);
  13861. Window = __decorate([
  13862. BABYLON.className("Window", "BABYLON")
  13863. ], Window);
  13864. return Window;
  13865. }(BABYLON.ContentControl));
  13866. BABYLON.Window = Window;
  13867. var DefaultWindowRenderingTemplate = (function (_super) {
  13868. __extends(DefaultWindowRenderingTemplate, _super);
  13869. function DefaultWindowRenderingTemplate() {
  13870. _super.apply(this, arguments);
  13871. }
  13872. DefaultWindowRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  13873. var r = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#808080FF" });
  13874. return { root: r, contentPlaceholder: r };
  13875. };
  13876. DefaultWindowRenderingTemplate = __decorate([
  13877. BABYLON.registerWindowRenderingTemplate("BABYLON.Window", "Default", function () { return new DefaultWindowRenderingTemplate(); })
  13878. ], DefaultWindowRenderingTemplate);
  13879. return DefaultWindowRenderingTemplate;
  13880. }(BABYLON.UIElementRenderingTemplateBase));
  13881. BABYLON.DefaultWindowRenderingTemplate = DefaultWindowRenderingTemplate;
  13882. })(BABYLON || (BABYLON = {}));
  13883. var BABYLON;
  13884. (function (BABYLON) {
  13885. var Label = (function (_super) {
  13886. __extends(Label, _super);
  13887. function Label(settings) {
  13888. if (!settings) {
  13889. settings = {};
  13890. }
  13891. _super.call(this, settings);
  13892. if (settings.text != null) {
  13893. this.text = settings.text;
  13894. }
  13895. }
  13896. Object.defineProperty(Label.prototype, "_position", {
  13897. get: function () {
  13898. return BABYLON.Vector2.Zero();
  13899. },
  13900. enumerable: true,
  13901. configurable: true
  13902. });
  13903. Label.prototype._getChildren = function () {
  13904. return Label._emptyArray;
  13905. };
  13906. Label.prototype.createVisualTree = function () {
  13907. _super.prototype.createVisualTree.call(this);
  13908. var p = this._visualChildrenPlaceholder;
  13909. };
  13910. Object.defineProperty(Label.prototype, "text", {
  13911. get: function () {
  13912. return this._text;
  13913. },
  13914. set: function (value) {
  13915. this._text = value;
  13916. },
  13917. enumerable: true,
  13918. configurable: true
  13919. });
  13920. Label._emptyArray = new Array();
  13921. __decorate([
  13922. BABYLON.dependencyProperty(BABYLON.Control.CONTROL_PROPCOUNT + 0, function (pi) { return Label.textProperty = pi; })
  13923. ], Label.prototype, "text", null);
  13924. Label = __decorate([
  13925. BABYLON.className("Label", "BABYLON")
  13926. ], Label);
  13927. return Label;
  13928. }(BABYLON.Control));
  13929. BABYLON.Label = Label;
  13930. var DefaultLabelRenderingTemplate = (function (_super) {
  13931. __extends(DefaultLabelRenderingTemplate, _super);
  13932. function DefaultLabelRenderingTemplate() {
  13933. _super.apply(this, arguments);
  13934. }
  13935. DefaultLabelRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  13936. var r = new BABYLON.Text2D("", { parent: visualPlaceholder });
  13937. r.createSimpleDataBinding(BABYLON.Text2D.textProperty, "text");
  13938. r.dataSource = owner;
  13939. return { root: r, contentPlaceholder: r };
  13940. };
  13941. DefaultLabelRenderingTemplate = __decorate([
  13942. BABYLON.registerWindowRenderingTemplate("BABYLON.Label", "Default", function () { return new DefaultLabelRenderingTemplate(); })
  13943. ], DefaultLabelRenderingTemplate);
  13944. return DefaultLabelRenderingTemplate;
  13945. }(BABYLON.UIElementRenderingTemplateBase));
  13946. BABYLON.DefaultLabelRenderingTemplate = DefaultLabelRenderingTemplate;
  13947. })(BABYLON || (BABYLON = {}));
  13948. var BABYLON;
  13949. (function (BABYLON) {
  13950. var Button = (function (_super) {
  13951. __extends(Button, _super);
  13952. function Button(settings) {
  13953. if (!settings) {
  13954. settings = {};
  13955. }
  13956. _super.call(this, settings);
  13957. // For a button the default contentAlignemnt is center/center
  13958. if (settings.contentAlignment == null) {
  13959. this.contentAlignment.horizontal = BABYLON.PrimitiveAlignment.AlignCenter;
  13960. this.contentAlignment.vertical = BABYLON.PrimitiveAlignment.AlignCenter;
  13961. }
  13962. this.normalEnabledBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#337AB7FF");
  13963. this.normalDisabledBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#7BA9D0FF");
  13964. this.normalMouseOverBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#286090FF");
  13965. this.normalPushedBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#1E496EFF");
  13966. this.normalEnabledBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E6DA4FF");
  13967. this.normalDisabledBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#77A0C4FF");
  13968. this.normalMouseOverBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#204D74FF");
  13969. this.normalPushedBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#2E5D9EFF");
  13970. this.defaultEnabledBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF");
  13971. this.defaultDisabledBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#FFFFFFFF");
  13972. this.defaultMouseOverBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#E6E6E6FF");
  13973. this.defaultPushedBackground = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#D4D4D4FF");
  13974. this.defaultEnabledBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#CCCCCCFF");
  13975. this.defaultDisabledBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#DEDEDEFF");
  13976. this.defaultMouseOverBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#ADADADFF");
  13977. this.defaultPushedBorder = BABYLON.Canvas2D.GetSolidColorBrushFromHex("#6C8EC5FF");
  13978. }
  13979. Object.defineProperty(Button.prototype, "isPushed", {
  13980. get: function () {
  13981. return this._isPushed;
  13982. },
  13983. set: function (value) {
  13984. this._isPushed = value;
  13985. },
  13986. enumerable: true,
  13987. configurable: true
  13988. });
  13989. Object.defineProperty(Button.prototype, "isDefault", {
  13990. get: function () {
  13991. return this._isDefault;
  13992. },
  13993. set: function (value) {
  13994. this._isDefault = value;
  13995. },
  13996. enumerable: true,
  13997. configurable: true
  13998. });
  13999. Object.defineProperty(Button.prototype, "isOutline", {
  14000. get: function () {
  14001. return this._isOutline;
  14002. },
  14003. set: function (value) {
  14004. this._isOutline = value;
  14005. },
  14006. enumerable: true,
  14007. configurable: true
  14008. });
  14009. Object.defineProperty(Button.prototype, "clickObservable", {
  14010. get: function () {
  14011. if (!this._clickObservable) {
  14012. this._clickObservable = new BABYLON.Observable();
  14013. }
  14014. return this._clickObservable;
  14015. },
  14016. enumerable: true,
  14017. configurable: true
  14018. });
  14019. Button.prototype._raiseClick = function () {
  14020. console.log("click");
  14021. };
  14022. Button.prototype.createVisualTree = function () {
  14023. var _this = this;
  14024. _super.prototype.createVisualTree.call(this);
  14025. var p = this._visualPlaceholder;
  14026. p.pointerEventObservable.add(function (e, s) {
  14027. // We reject an event coming from the placeholder because it means it's on an empty spot, so it's not valid.
  14028. if (e.relatedTarget === _this._visualPlaceholder) {
  14029. return;
  14030. }
  14031. if (s.mask === BABYLON.PrimitivePointerInfo.PointerUp) {
  14032. _this._raiseClick();
  14033. _this.isPushed = false;
  14034. }
  14035. else if (s.mask === BABYLON.PrimitivePointerInfo.PointerDown) {
  14036. _this.isPushed = true;
  14037. }
  14038. }, BABYLON.PrimitivePointerInfo.PointerUp | BABYLON.PrimitivePointerInfo.PointerDown);
  14039. };
  14040. Object.defineProperty(Button.prototype, "_position", {
  14041. get: function () {
  14042. return BABYLON.Vector2.Zero();
  14043. },
  14044. enumerable: true,
  14045. configurable: true
  14046. });
  14047. Button.BUTTON_PROPCOUNT = BABYLON.ContentControl.CONTENTCONTROL_PROPCOUNT + 3;
  14048. __decorate([
  14049. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 0, function (pi) { return Button.isPushedProperty = pi; })
  14050. ], Button.prototype, "isPushed", null);
  14051. __decorate([
  14052. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 1, function (pi) { return Button.isDefaultProperty = pi; })
  14053. ], Button.prototype, "isDefault", null);
  14054. __decorate([
  14055. BABYLON.dependencyProperty(BABYLON.ContentControl.CONTROL_PROPCOUNT + 2, function (pi) { return Button.isOutlineProperty = pi; })
  14056. ], Button.prototype, "isOutline", null);
  14057. Button = __decorate([
  14058. BABYLON.className("Button", "BABYLON")
  14059. ], Button);
  14060. return Button;
  14061. }(BABYLON.ContentControl));
  14062. BABYLON.Button = Button;
  14063. var DefaultButtonRenderingTemplate = (function (_super) {
  14064. __extends(DefaultButtonRenderingTemplate, _super);
  14065. function DefaultButtonRenderingTemplate() {
  14066. _super.apply(this, arguments);
  14067. }
  14068. DefaultButtonRenderingTemplate.prototype.createVisualTree = function (owner, visualPlaceholder) {
  14069. this._rect = new BABYLON.Rectangle2D({ parent: visualPlaceholder, fill: "#FF8080FF", border: "#FF8080FF", roundRadius: 10, borderThickness: 2 });
  14070. this.stateChange();
  14071. return { root: this._rect, contentPlaceholder: this._rect };
  14072. };
  14073. DefaultButtonRenderingTemplate.prototype.attach = function (owner) {
  14074. var _this = this;
  14075. _super.prototype.attach.call(this, owner);
  14076. this.owner.propertyChanged.add(function (e, s) { return _this.stateChange(); }, BABYLON.UIElement.isEnabledProperty.flagId |
  14077. BABYLON.UIElement.isFocusedProperty.flagId |
  14078. BABYLON.UIElement.isMouseOverProperty.flagId |
  14079. Button.isDefaultProperty.flagId |
  14080. Button.isOutlineProperty.flagId |
  14081. Button.isPushedProperty.flagId);
  14082. };
  14083. DefaultButtonRenderingTemplate.prototype.stateChange = function () {
  14084. var b = this.owner;
  14085. var bg = b.isDefault ? b.defaultEnabledBackground : b.normalEnabledBackground;
  14086. var bd = b.isDefault ? b.defaultEnabledBorder : b.normalEnabledBorder;
  14087. if (b.isPushed) {
  14088. if (b.isDefault) {
  14089. bg = b.defaultPushedBackground;
  14090. bd = b.defaultPushedBorder;
  14091. }
  14092. else {
  14093. bg = b.normalPushedBackground;
  14094. bd = b.normalPushedBorder;
  14095. }
  14096. }
  14097. else if (b.isMouseOver) {
  14098. console.log("MouseOver Style");
  14099. if (b.isDefault) {
  14100. bg = b.defaultMouseOverBackground;
  14101. bd = b.defaultMouseOverBorder;
  14102. }
  14103. else {
  14104. bg = b.normalMouseOverBackground;
  14105. bd = b.normalMouseOverBorder;
  14106. }
  14107. }
  14108. else if (!b.isEnabled) {
  14109. if (b.isDefault) {
  14110. bg = b.defaultDisabledBackground;
  14111. bd = b.defaultDisabledBorder;
  14112. }
  14113. else {
  14114. bg = b.normalDisabledBackground;
  14115. bd = b.normalDisabledBorder;
  14116. }
  14117. }
  14118. this._rect.fill = bg;
  14119. this._rect.border = bd;
  14120. };
  14121. DefaultButtonRenderingTemplate = __decorate([
  14122. BABYLON.registerWindowRenderingTemplate("BABYLON.Button", "Default", function () { return new DefaultButtonRenderingTemplate(); })
  14123. ], DefaultButtonRenderingTemplate);
  14124. return DefaultButtonRenderingTemplate;
  14125. }(BABYLON.UIElementRenderingTemplateBase));
  14126. BABYLON.DefaultButtonRenderingTemplate = DefaultButtonRenderingTemplate;
  14127. })(BABYLON || (BABYLON = {}));
  14128. BABYLON.Effect.ShadersStore['ellipse2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  14129. BABYLON.Effect.ShadersStore['ellipse2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef Border\natt float borderThickness;\n#endif\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n\natt vec3 properties;\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nfloat ms=properties.z;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<ms) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=ms;\n}\nfloat angle=TWOPI*segi/ms;\npos2.x=(cos(angle)/2.0)+0.5;\npos2.y=(sin(angle)/2.0)+0.5;\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse {\nfloat ms=properties.z;\nfloat angle=TWOPI*(index-1.0)/ms;\npos2.x=(cos(angle)/2.0)+0.5;\npos2.y=(sin(angle)/2.0)+0.5;\n}\n#endif\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4(pos2.xy,1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4(pos2.xy,1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=pos2.xy*properties.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  14130. BABYLON.Effect.ShadersStore['lines2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  14131. BABYLON.Effect.ShadersStore['lines2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute vec2 position;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec2 boundingMin;\natt vec2 boundingMax;\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4((position.xy-boundingMin)/(boundingMax-boundingMin),1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4((position.xy-boundingMin)/(boundingMax-boundingMin),1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=position.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  14132. BABYLON.Effect.ShadersStore['rect2dPixelShader'] = "varying vec4 vColor;\nvoid main(void) {\ngl_FragColor=vColor;\n}";
  14133. BABYLON.Effect.ShadersStore['rect2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n#ifdef Border\natt float borderThickness;\n#endif\n#ifdef FillSolid\natt vec4 fillSolidColor;\n#endif\n#ifdef BorderSolid\natt vec4 borderSolidColor;\n#endif\n#ifdef FillGradient\natt vec4 fillGradientColor1;\natt vec4 fillGradientColor2;\natt vec4 fillGradientTY;\n#endif\n#ifdef BorderGradient\natt vec4 borderGradientColor1;\natt vec4 borderGradientColor2;\natt vec4 borderGradientTY;\n#endif\n\natt vec3 properties;\n\n#define rsub0 17.0\n#define rsub1 33.0\n#define rsub2 49.0\n#define rsub3 65.0\n#define rsub 64.0\n#define TWOPI 6.28318530\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n\nif (properties.z == 0.0) {\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<4.0) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=4.0;\n}\nif (segi == 0.0) {\npos2=vec2(1.0,1.0);\n} \nelse if (segi == 1.0) {\npos2=vec2(1.0,0.0);\n}\nelse if (segi == 2.0) {\npos2=vec2(0.0,0.0);\n} \nelse {\npos2=vec2(0.0,1.0);\n}\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse if (index == 1.0) {\npos2=vec2(1.0,1.0);\n}\nelse if (index == 2.0) {\npos2=vec2(1.0,0.0);\n}\nelse if (index == 3.0) {\npos2=vec2(0.0,0.0);\n}\nelse {\npos2=vec2(0.0,1.0);\n}\n#endif\n}\nelse\n{\n#ifdef Border\nfloat w=properties.x;\nfloat h=properties.y;\nfloat r=properties.z;\nfloat nru=r/w;\nfloat nrv=r/h;\nvec2 borderOffset=vec2(1.0,1.0);\nfloat segi=index;\nif (index<rsub) {\nborderOffset=vec2(1.0-(borderThickness*2.0/w),1.0-(borderThickness*2.0/h));\n}\nelse {\nsegi-=rsub;\n}\n\nif (segi<rsub0) {\npos2=vec2(1.0-nru,nrv);\n}\n\nelse if (segi<rsub1) {\npos2=vec2(nru,nrv);\n}\n\nelse if (segi<rsub2) {\npos2=vec2(nru,1.0-nrv);\n}\n\nelse {\npos2=vec2(1.0-nru,1.0-nrv);\n}\nfloat angle=TWOPI-((index-1.0)*TWOPI/(rsub-0.5));\npos2.x+=cos(angle)*nru;\npos2.y+=sin(angle)*nrv;\npos2.x=((pos2.x-0.5)*borderOffset.x)+0.5;\npos2.y=((pos2.y-0.5)*borderOffset.y)+0.5;\n#else\nif (index == 0.0) {\npos2=vec2(0.5,0.5);\n}\nelse {\nfloat w=properties.x;\nfloat h=properties.y;\nfloat r=properties.z;\nfloat nru=r/w;\nfloat nrv=r/h;\n\nif (index<rsub0) {\npos2=vec2(1.0-nru,nrv);\n}\n\nelse if (index<rsub1) {\npos2=vec2(nru,nrv);\n}\n\nelse if (index<rsub2) {\npos2=vec2(nru,1.0-nrv);\n}\n\nelse {\npos2=vec2(1.0-nru,1.0-nrv);\n}\nfloat angle=TWOPI-((index-1.0)*TWOPI/(rsub-0.5));\npos2.x+=cos(angle)*nru;\npos2.y+=sin(angle)*nrv;\n}\n#endif\n}\n#ifdef FillSolid\nvColor=fillSolidColor;\n#endif\n#ifdef BorderSolid\nvColor=borderSolidColor;\n#endif\n#ifdef FillGradient\nfloat v=dot(vec4(pos2.xy,1,1),fillGradientTY);\nvColor=mix(fillGradientColor2,fillGradientColor1,v); \n#endif\n#ifdef BorderGradient\nfloat v=dot(vec4(pos2.xy,1,1),borderGradientTY);\nvColor=mix(borderGradientColor2,borderGradientColor1,v); \n#endif\nvColor.a*=opacity;\nvec4 pos;\npos.xy=pos2.xy*properties.xy;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  14134. BABYLON.Effect.ShadersStore['sprite2dPixelShader'] = "varying vec2 vUV;\nvarying float vOpacity;\nuniform bool alphaTest;\nuniform sampler2D diffuseSampler;\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\nif (alphaTest)\n{\nif (color.a<0.95) {\ndiscard;\n}\n}\ncolor.a*=vOpacity;\ngl_FragColor=color;\n}";
  14135. BABYLON.Effect.ShadersStore['sprite2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\n\nattribute float index;\natt vec2 topLeftUV;\natt vec2 sizeUV;\natt vec2 scaleFactor;\natt vec2 textureSize;\n\natt vec3 properties;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\n\n\nvarying vec2 vUV;\nvarying float vOpacity;\nvoid main(void) {\nvec2 pos2;\n\nvec2 off=vec2(0.0,0.0);\nvec2 sfSizeUV=sizeUV*scaleFactor;\nfloat frame=properties.x;\nfloat invertY=properties.y;\nfloat alignToPixel=properties.z;\n\nif (index == 0.0) {\npos2=vec2(0.0,0.0);\nvUV=vec2(topLeftUV.x+(frame*sfSizeUV.x)+off.x,topLeftUV.y-off.y);\n}\n\nelse if (index == 1.0) {\npos2=vec2(0.0,1.0);\nvUV=vec2(topLeftUV.x+(frame*sfSizeUV.x)+off.x,(topLeftUV.y+sfSizeUV.y));\n}\n\nelse if (index == 2.0) {\npos2=vec2( 1.0,1.0);\nvUV=vec2(topLeftUV.x+sfSizeUV.x+(frame*sfSizeUV.x),(topLeftUV.y+sfSizeUV.y));\n}\n\nelse if (index == 3.0) {\npos2=vec2( 1.0,0.0);\nvUV=vec2(topLeftUV.x+sfSizeUV.x+(frame*sfSizeUV.x),topLeftUV.y-off.y);\n}\nif (invertY == 1.0) {\nvUV.y=1.0-vUV.y;\n}\nvec4 pos;\nif (alignToPixel == 1.0)\n{\npos.xy=floor(pos2.xy*sizeUV*textureSize);\n} else {\npos.xy=pos2.xy*sizeUV*textureSize;\n}\nvOpacity=opacity;\npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n} ";
  14136. BABYLON.Effect.ShadersStore['text2dPixelShader'] = "varying vec4 vColor;\nvarying vec2 vUV;\n\nuniform sampler2D diffuseSampler;\nvoid main(void) {\nvec4 color=texture2D(diffuseSampler,vUV);\ngl_FragColor=color*vColor;\n}";
  14137. BABYLON.Effect.ShadersStore['text2dVertexShader'] = "\n#ifdef Instanced\n#define att attribute\n#else\n#define att uniform\n#endif\n\nattribute float index;\natt vec2 zBias;\natt vec4 transformX;\natt vec4 transformY;\natt float opacity;\natt vec2 topLeftUV;\natt vec2 sizeUV;\natt vec2 textureSize;\natt vec4 color;\natt float superSampleFactor;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvoid main(void) {\nvec2 pos2;\n\nif (index == 0.0) {\npos2=vec2(0.0,0.0);\nvUV=vec2(topLeftUV.x,topLeftUV.y+sizeUV.y);\n}\n\nelse if (index == 1.0) {\npos2=vec2(0.0,1.0);\nvUV=vec2(topLeftUV.x,topLeftUV.y);\n}\n\nelse if (index == 2.0) {\npos2=vec2(1.0,1.0);\nvUV=vec2(topLeftUV.x+sizeUV.x,topLeftUV.y);\n}\n\nelse if (index == 3.0) {\npos2=vec2(1.0,0.0);\nvUV=vec2(topLeftUV.x+sizeUV.x,topLeftUV.y+sizeUV.y);\n}\n\nvUV=(floor(vUV*textureSize)+vec2(0.0,0.0))/textureSize;\nvColor=color;\nvColor.a*=opacity;\nvec4 pos;\npos.xy=floor(pos2.xy*superSampleFactor*sizeUV*textureSize); \npos.z=1.0;\npos.w=1.0;\ngl_Position=vec4(dot(pos,transformX),dot(pos,transformY),zBias.x,1);\n}";
  14138. if (((typeof window != "undefined" && window.module) || (typeof module != "undefined")) && typeof module.exports != "undefined") {
  14139. module.exports = BABYLON;
  14140. };