babylon.inspector.js 213 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926
  1. var INSPECTOR;
  2. (function (INSPECTOR) {
  3. var Inspector = /** @class */ (function () {
  4. /** The inspector is created with the given engine.
  5. * If the parameter 'popup' is false, the inspector is created as a right panel on the main window.
  6. * If the parameter 'popup' is true, the inspector is created in another popup.
  7. */
  8. function Inspector(scene, popup, initialTab, parentElement, newColors) {
  9. if (initialTab === void 0) { initialTab = 0; }
  10. if (parentElement === void 0) { parentElement = null; }
  11. var _this = this;
  12. /** True if the inspector is built as a popup tab */
  13. this._popupMode = false;
  14. // Load GUI library if not already done
  15. if (!BABYLON.GUI) {
  16. BABYLON.Tools.LoadScript("https://preview.babylonjs.com/gui/babylon.gui.js", function () {
  17. //Load properties of GUI objects now as BABYLON.GUI has to be declared before
  18. INSPECTOR.loadGUIProperties();
  19. }, function () {
  20. console.warn("Please add script https://preview.babylonjs.com/gui/babylon.gui.js to the HTML file");
  21. });
  22. }
  23. else {
  24. //Load properties of GUI objects now as BABYLON.GUI has to be declared before
  25. INSPECTOR.loadGUIProperties();
  26. }
  27. //get Tabbar initialTab
  28. this._initialTab = initialTab;
  29. //get parentElement of our Inspector
  30. this._parentElement = parentElement;
  31. // get canvas parent only if needed.
  32. this._scene = scene;
  33. // Save HTML document and window
  34. Inspector.DOCUMENT = window.document;
  35. Inspector.WINDOW = window;
  36. // POPUP MODE
  37. if (popup) {
  38. // Build the inspector in the given parent
  39. this.openPopup(true); // set to true in order to NOT dispose the inspector (done in openPopup), as it's not existing yet
  40. }
  41. else {
  42. // Get canvas and its DOM parent
  43. var canvas = this._scene.getEngine().getRenderingCanvas();
  44. var canvasParent = canvas.parentElement;
  45. // get canvas style
  46. var canvasComputedStyle = Inspector.WINDOW.getComputedStyle(canvas);
  47. this._canvasStyle = {
  48. width: INSPECTOR.Helpers.Css(canvas, 'width'),
  49. height: INSPECTOR.Helpers.Css(canvas, 'height'),
  50. position: canvasComputedStyle.position,
  51. top: canvasComputedStyle.top,
  52. bottom: canvasComputedStyle.bottom,
  53. left: canvasComputedStyle.left,
  54. right: canvasComputedStyle.right,
  55. padding: canvasComputedStyle.padding,
  56. paddingBottom: canvasComputedStyle.paddingBottom,
  57. paddingLeft: canvasComputedStyle.paddingLeft,
  58. paddingTop: canvasComputedStyle.paddingTop,
  59. paddingRight: canvasComputedStyle.paddingRight,
  60. margin: canvasComputedStyle.margin,
  61. marginBottom: canvasComputedStyle.marginBottom,
  62. marginLeft: canvasComputedStyle.marginLeft,
  63. marginTop: canvasComputedStyle.marginTop,
  64. marginRight: canvasComputedStyle.marginRight
  65. };
  66. if (this._parentElement) {
  67. // Build the inspector wrapper
  68. this._c2diwrapper = INSPECTOR.Helpers.CreateDiv('insp-wrapper', this._parentElement);
  69. this._c2diwrapper.style.width = '100%';
  70. this._c2diwrapper.style.height = '100%';
  71. this._c2diwrapper.style.paddingLeft = '5px';
  72. // add inspector
  73. var inspector = INSPECTOR.Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
  74. inspector.style.width = '100%';
  75. inspector.style.height = '100%';
  76. // and build it in the popup
  77. this._buildInspector(inspector);
  78. }
  79. else {
  80. // Create c2di wrapper
  81. this._c2diwrapper = INSPECTOR.Helpers.CreateDiv('insp-wrapper');
  82. // copy style from canvas to wrapper
  83. for (var prop in this._canvasStyle) {
  84. this._c2diwrapper.style[prop] = this._canvasStyle[prop];
  85. }
  86. if (!canvasComputedStyle.width || !canvasComputedStyle.height || !canvasComputedStyle.left) {
  87. return;
  88. }
  89. // Convert wrapper size in % (because getComputedStyle returns px only)
  90. var widthPx = parseFloat(canvasComputedStyle.width.substr(0, canvasComputedStyle.width.length - 2)) || 0;
  91. var heightPx = parseFloat(canvasComputedStyle.height.substr(0, canvasComputedStyle.height.length - 2)) || 0;
  92. // If the canvas position is absolute, restrain the wrapper width to the window width + left positionning
  93. if (canvasComputedStyle.position === "absolute" || canvasComputedStyle.position === "relative") {
  94. // compute only left as it takes predominance if right is also specified (and it will be for the wrapper)
  95. var leftPx = parseFloat(canvasComputedStyle.left.substr(0, canvasComputedStyle.left.length - 2)) || 0;
  96. if (widthPx + leftPx >= Inspector.WINDOW.innerWidth) {
  97. this._c2diwrapper.style.maxWidth = widthPx - leftPx + "px";
  98. }
  99. }
  100. // Check if the parent of the canvas is the body page. If yes, the size ratio is computed
  101. var parent_1 = this._getRelativeParent(canvas);
  102. var parentWidthPx = parent_1.clientWidth;
  103. var parentHeightPx = parent_1.clientHeight;
  104. var pWidth = widthPx / parentWidthPx * 100;
  105. var pheight = heightPx / parentHeightPx * 100;
  106. this._c2diwrapper.style.width = pWidth + "%";
  107. this._c2diwrapper.style.height = pheight + "%";
  108. // reset canvas style
  109. canvas.style.position = "static";
  110. canvas.style.width = "100%";
  111. canvas.style.height = "100%";
  112. canvas.style.paddingBottom = "0";
  113. canvas.style.paddingLeft = "0";
  114. canvas.style.paddingTop = "0";
  115. canvas.style.paddingRight = "0";
  116. canvas.style.margin = "0";
  117. canvas.style.marginBottom = "0";
  118. canvas.style.marginLeft = "0";
  119. canvas.style.marginTop = "0";
  120. canvas.style.marginRight = "0";
  121. // Replace canvas with the wrapper...
  122. if (canvasParent) {
  123. canvasParent.replaceChild(this._c2diwrapper, canvas);
  124. }
  125. // ... and add canvas to the wrapper
  126. this._c2diwrapper.appendChild(canvas);
  127. // add inspector
  128. var inspector = INSPECTOR.Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
  129. // Add split bar
  130. if (!this._parentElement) {
  131. Split([canvas, inspector], {
  132. direction: 'horizontal',
  133. sizes: [75, 25],
  134. onDrag: function () {
  135. INSPECTOR.Helpers.SEND_EVENT('resize');
  136. if (_this._tabbar) {
  137. _this._tabbar.updateWidth();
  138. }
  139. }
  140. });
  141. }
  142. // Build the inspector
  143. this._buildInspector(inspector);
  144. }
  145. // Send resize event to the window
  146. INSPECTOR.Helpers.SEND_EVENT('resize');
  147. this._tabbar.updateWidth();
  148. }
  149. // Refresh the inspector if the browser is not edge
  150. if (!INSPECTOR.Helpers.IsBrowserEdge()) {
  151. this.refresh();
  152. }
  153. // Check custom css colors
  154. if (newColors) {
  155. var bColor = newColors.backgroundColor || '#242424';
  156. var bColorl1 = newColors.backgroundColorLighter || '#2c2c2c';
  157. var bColorl2 = newColors.backgroundColorLighter2 || '#383838';
  158. var bColorl3 = newColors.backgroundColorLighter3 || '#454545';
  159. var color = newColors.color || '#ccc';
  160. var colorTop = newColors.colorTop || '#f29766';
  161. var colorBot = newColors.colorBot || '#5db0d7';
  162. var styles = Inspector.DOCUMENT.querySelectorAll('style');
  163. for (var s = 0; s < styles.length; s++) {
  164. var style = styles[s];
  165. if (style.innerHTML.indexOf('insp-wrapper') != -1) {
  166. styles[s].innerHTML = styles[s].innerHTML
  167. .replace(/#242424/g, bColor) // background color
  168. .replace(/#2c2c2c/g, bColorl1) // background-lighter
  169. .replace(/#383838/g, bColorl2) // background-lighter2
  170. .replace(/#454545/g, bColorl3) // background-lighter3
  171. .replace(/#ccc/g, color) // color
  172. .replace(/#f29766/g, colorTop) // color-top
  173. .replace(/#5db0d7/g, colorBot); // color-bot
  174. }
  175. }
  176. }
  177. }
  178. /**
  179. * If the given element has a position 'asbolute' or 'relative',
  180. * returns the first parent of the given element that has a position 'relative' or 'absolute'.
  181. * If the given element has no position, returns the first parent
  182. *
  183. */
  184. Inspector.prototype._getRelativeParent = function (elem, lookForAbsoluteOrRelative) {
  185. // If the elem has no parent, returns himself
  186. if (!elem.parentElement) {
  187. return elem;
  188. }
  189. var computedStyle = Inspector.WINDOW.getComputedStyle(elem);
  190. // looking for the first element absolute or relative
  191. if (lookForAbsoluteOrRelative) {
  192. // if found, return this one
  193. if (computedStyle.position === "relative" || computedStyle.position === "absolute") {
  194. return elem;
  195. }
  196. else {
  197. // otherwise keep looking
  198. return this._getRelativeParent(elem.parentElement, true);
  199. }
  200. }
  201. else {
  202. if (computedStyle.position == "static") {
  203. return elem.parentElement;
  204. }
  205. else {
  206. // the elem has a position relative or absolute, look for the closest relative/absolute parent
  207. return this._getRelativeParent(elem.parentElement, true);
  208. }
  209. }
  210. };
  211. /** Build the inspector panel in the given HTML element */
  212. Inspector.prototype._buildInspector = function (parent) {
  213. // tabbar
  214. this._tabbar = new INSPECTOR.TabBar(this, this._initialTab);
  215. // Top panel
  216. this._topPanel = INSPECTOR.Helpers.CreateDiv('top-panel', parent);
  217. // Add tabbar
  218. this._topPanel.appendChild(this._tabbar.toHtml());
  219. this._tabbar.updateWidth();
  220. // Tab panel
  221. this._tabPanel = INSPECTOR.Helpers.CreateDiv('tab-panel-content', this._topPanel);
  222. };
  223. Object.defineProperty(Inspector.prototype, "scene", {
  224. get: function () {
  225. return this._scene;
  226. },
  227. enumerable: true,
  228. configurable: true
  229. });
  230. Object.defineProperty(Inspector.prototype, "popupMode", {
  231. get: function () {
  232. return this._popupMode;
  233. },
  234. enumerable: true,
  235. configurable: true
  236. });
  237. /**
  238. * Filter the list of item present in the tree.
  239. * All item returned should have the given filter contained in the item id.
  240. */
  241. Inspector.prototype.filterItem = function (filter) {
  242. var tab = this._tabbar.getActiveTab();
  243. if (tab) {
  244. tab.filter(filter);
  245. }
  246. };
  247. /** Display the mesh tab on the given object */
  248. Inspector.prototype.displayObjectDetails = function (mesh) {
  249. this._tabbar.switchMeshTab(mesh);
  250. };
  251. /** Clean the whole tree of item and rebuilds it */
  252. Inspector.prototype.refresh = function () {
  253. // Clean top panel
  254. INSPECTOR.Helpers.CleanDiv(this._tabPanel);
  255. // Get the active tab and its items
  256. var activeTab = this._tabbar.getActiveTab();
  257. if (!activeTab) {
  258. return;
  259. }
  260. activeTab.update();
  261. this._tabPanel.appendChild(activeTab.getPanel());
  262. INSPECTOR.Helpers.SEND_EVENT('resize');
  263. };
  264. /** Remove the inspector panel when it's built as a right panel:
  265. * remove the right panel and remove the wrapper
  266. */
  267. Inspector.prototype.dispose = function () {
  268. if (!this._popupMode) {
  269. var activeTab = this._tabbar.getActiveTab();
  270. if (activeTab) {
  271. activeTab.dispose();
  272. }
  273. // Get canvas
  274. var canvas = this._scene.getEngine().getRenderingCanvas();
  275. // restore canvas style
  276. for (var prop in this._canvasStyle) {
  277. canvas.style[prop] = this._canvasStyle[prop];
  278. }
  279. // Get parent of the wrapper
  280. if (canvas.parentElement) {
  281. var canvasParent = canvas.parentElement.parentElement;
  282. if (canvasParent) {
  283. canvasParent.insertBefore(canvas, this._c2diwrapper);
  284. // Remove wrapper
  285. INSPECTOR.Helpers.CleanDiv(this._c2diwrapper);
  286. this._c2diwrapper.remove();
  287. // Send resize event to the window
  288. INSPECTOR.Helpers.SEND_EVENT('resize');
  289. }
  290. }
  291. }
  292. };
  293. /** Open the inspector in a new popup
  294. * Set 'firstTime' to true if there is no inspector created beforehands
  295. */
  296. Inspector.prototype.openPopup = function (firstTime) {
  297. var _this = this;
  298. if (INSPECTOR.Helpers.IsBrowserEdge()) {
  299. console.warn('Inspector - Popup mode is disabled in Edge, as the popup DOM cannot be updated from the main window for security reasons');
  300. }
  301. else {
  302. // Create popup
  303. var popup = window.open('', 'Babylon.js INSPECTOR', 'toolbar=no,resizable=yes,menubar=no,width=750,height=1000');
  304. if (!popup) {
  305. return;
  306. }
  307. popup.document.title = 'Babylon.js INSPECTOR';
  308. // Get the inspector style
  309. var styles = Inspector.DOCUMENT.querySelectorAll('style');
  310. for (var s = 0; s < styles.length; s++) {
  311. popup.document.body.appendChild(styles[s].cloneNode(true));
  312. }
  313. var links = document.querySelectorAll('link');
  314. for (var l = 0; l < links.length; l++) {
  315. var link = popup.document.createElement("link");
  316. link.rel = "stylesheet";
  317. link.href = links[l].href;
  318. popup.document.head.appendChild(link);
  319. }
  320. // Dispose the right panel if existing
  321. if (!firstTime) {
  322. this.dispose();
  323. }
  324. // set the mode as popup
  325. this._popupMode = true;
  326. // Save the HTML document
  327. Inspector.DOCUMENT = popup.document;
  328. Inspector.WINDOW = popup;
  329. // Build the inspector wrapper
  330. this._c2diwrapper = INSPECTOR.Helpers.CreateDiv('insp-wrapper', popup.document.body);
  331. // add inspector
  332. var inspector = INSPECTOR.Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
  333. inspector.classList.add('popupmode');
  334. // and build it in the popup
  335. this._buildInspector(inspector);
  336. // Rebuild it
  337. this.refresh();
  338. popup.addEventListener('resize', function () {
  339. if (_this._tabbar) {
  340. _this._tabbar.updateWidth();
  341. }
  342. });
  343. }
  344. };
  345. Inspector.prototype.getActiveTabIndex = function () {
  346. return this._tabbar.getActiveTabIndex();
  347. };
  348. return Inspector;
  349. }());
  350. INSPECTOR.Inspector = Inspector;
  351. })(INSPECTOR || (INSPECTOR = {}));
  352. //# sourceMappingURL=Inspector.js.map
  353. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  354. var INSPECTOR;
  355. (function (INSPECTOR) {
  356. INSPECTOR.PROPERTIES = {
  357. /** Format the given object :
  358. * If a format function exists, returns the result of this function.
  359. * If this function doesn't exists, return the object type instead */
  360. format: function (obj) {
  361. var type = INSPECTOR.Helpers.GET_TYPE(obj) || 'type_not_defined';
  362. if (INSPECTOR.PROPERTIES[type] && INSPECTOR.PROPERTIES[type].format) {
  363. return INSPECTOR.PROPERTIES[type].format(obj);
  364. }
  365. else {
  366. return INSPECTOR.Helpers.GET_TYPE(obj);
  367. }
  368. },
  369. 'type_not_defined': {
  370. properties: new Array(),
  371. format: function () { return ''; }
  372. },
  373. 'Vector2': {
  374. type: BABYLON.Vector2,
  375. format: function (vec) { return "x:" + INSPECTOR.Helpers.Trunc(vec.x) + ", y:" + INSPECTOR.Helpers.Trunc(vec.y); }
  376. },
  377. 'Vector3': {
  378. type: BABYLON.Vector3,
  379. format: function (vec) { return "x:" + INSPECTOR.Helpers.Trunc(vec.x) + ", y:" + INSPECTOR.Helpers.Trunc(vec.y) + ", z:" + INSPECTOR.Helpers.Trunc(vec.z); }
  380. },
  381. 'Color3': {
  382. type: BABYLON.Color3,
  383. format: function (color) { return "R:" + color.r + ", G:" + color.g + ", B:" + color.b; },
  384. slider: {
  385. r: { min: 0, max: 1, step: 0.01 },
  386. g: { min: 0, max: 1, step: 0.01 },
  387. b: { min: 0, max: 1, step: 0.01 }
  388. }
  389. },
  390. 'Color4': {
  391. type: BABYLON.Color4,
  392. format: function (color) { return "R:" + color.r + ", G:" + color.g + ", B:" + color.b; },
  393. slider: {
  394. r: { min: 0, max: 1, step: 0.01 },
  395. g: { min: 0, max: 1, step: 0.01 },
  396. b: { min: 0, max: 1, step: 0.01 }
  397. }
  398. },
  399. 'Quaternion': {
  400. type: BABYLON.Quaternion
  401. },
  402. 'Size': {
  403. type: BABYLON.Size,
  404. format: function (size) { return "Size - w:" + INSPECTOR.Helpers.Trunc(size.width) + ", h:" + INSPECTOR.Helpers.Trunc(size.height); }
  405. },
  406. 'Texture': {
  407. type: BABYLON.Texture,
  408. format: function (tex) { return tex.name; }
  409. },
  410. 'RenderTargetTexture': {
  411. type: BABYLON.RenderTargetTexture
  412. },
  413. 'DynamicTexture': {
  414. type: BABYLON.DynamicTexture
  415. },
  416. 'BaseTexture': {
  417. type: BABYLON.BaseTexture
  418. },
  419. 'CubeTexture': {
  420. type: BABYLON.CubeTexture
  421. },
  422. 'HDRCubeTexture': {
  423. type: BABYLON.HDRCubeTexture
  424. },
  425. 'Sound': {
  426. type: BABYLON.Sound
  427. },
  428. 'ArcRotateCamera': {
  429. type: BABYLON.ArcRotateCamera,
  430. slider: {
  431. alpha: { min: 0, max: 2 * Math.PI, step: 0.01 },
  432. beta: { min: -Math.PI, max: Math.PI, step: 0.01 },
  433. fov: { min: 0, max: 180, step: 1 }
  434. }
  435. },
  436. 'FreeCamera': {
  437. type: BABYLON.FreeCamera,
  438. slider: {
  439. fov: { min: 0, max: 180, step: 1 }
  440. }
  441. },
  442. 'Scene': {
  443. type: BABYLON.Scene,
  444. },
  445. 'TransformNode': {
  446. type: BABYLON.TransformNode,
  447. format: function (m) { return m.name; }
  448. },
  449. 'AbstractMesh': {
  450. type: BABYLON.AbstractMesh,
  451. format: function (m) { return m.name; }
  452. },
  453. 'Mesh': {
  454. type: BABYLON.Mesh,
  455. format: function (m) { return m.name; },
  456. slider: {
  457. visibility: { min: 0, max: 1, step: 0.1 }
  458. }
  459. },
  460. 'StandardMaterial': {
  461. type: BABYLON.StandardMaterial,
  462. format: function (mat) { return mat.name; },
  463. slider: {
  464. alpha: { min: 0, max: 1, step: 0.01 }
  465. }
  466. },
  467. 'PBRMaterial': {
  468. type: BABYLON.PBRMaterial,
  469. slider: {
  470. alpha: { min: 0, max: 1, step: 0.01 }
  471. }
  472. },
  473. 'PhysicsImpostor': {
  474. type: BABYLON.PhysicsImpostor
  475. },
  476. };
  477. })(INSPECTOR || (INSPECTOR = {}));
  478. //# sourceMappingURL=properties.js.map
  479. /// <reference path="../../dist/preview release/gui/babylon.gui.d.ts"/>
  480. var INSPECTOR;
  481. (function (INSPECTOR) {
  482. /**
  483. * Function that add gui objects properties to the variable PROPERTIES
  484. */
  485. function loadGUIProperties() {
  486. var PROPERTIES_GUI = {
  487. 'ValueAndUnit': {
  488. type: BABYLON.GUI.ValueAndUnit,
  489. properties: ['_value', 'unit'],
  490. format: function (valueAndUnit) { return valueAndUnit; }
  491. },
  492. 'Control': {
  493. type: BABYLON.GUI.Control,
  494. properties: [
  495. '_alpha',
  496. '_fontFamily',
  497. '_color',
  498. '_scaleX',
  499. '_scaleY',
  500. '_rotation',
  501. '_currentMeasure',
  502. '_width',
  503. '_height',
  504. '_left',
  505. '_top',
  506. '_linkedMesh',
  507. 'isHitTestVisible',
  508. 'isPointerBlocker',
  509. ],
  510. format: function (control) { return control.name; }
  511. },
  512. 'Button': {
  513. type: BABYLON.GUI.Button,
  514. properties: new Array(),
  515. format: function (button) { return button.name; }
  516. },
  517. 'ColorPicker': {
  518. type: BABYLON.GUI.ColorPicker,
  519. properties: ['_value'],
  520. format: function (colorPicker) { return colorPicker.name; }
  521. },
  522. 'Checkbox': {
  523. type: BABYLON.GUI.Checkbox,
  524. properties: ['_isChecked', '_background'],
  525. format: function (checkbox) { return checkbox.name; }
  526. },
  527. 'Ellipse': {
  528. type: BABYLON.GUI.Ellipse,
  529. properties: ['_thickness'],
  530. format: function (ellipse) { return ellipse.name; }
  531. },
  532. 'Image': {
  533. type: BABYLON.GUI.Image,
  534. properties: [
  535. '_imageWidth',
  536. '_imageHeight',
  537. '_loaded',
  538. '_source',
  539. ],
  540. format: function (image) { return image.name; }
  541. },
  542. 'Line': {
  543. type: BABYLON.GUI.Line,
  544. properties: ['_lineWidth',
  545. '_background',
  546. '_x1',
  547. '_y1',
  548. '_x2',
  549. '_y2',
  550. ],
  551. format: function (line) { return line.name; }
  552. },
  553. 'RadioButton': {
  554. type: BABYLON.GUI.RadioButton,
  555. properties: ['_isChecked', '_background'],
  556. format: function (radioButton) { return radioButton.name; }
  557. },
  558. 'Rectangle': {
  559. type: BABYLON.GUI.Rectangle,
  560. properties: ['_thickness', '_cornerRadius'],
  561. format: function (rectangle) { return rectangle.name; }
  562. },
  563. 'Slider': {
  564. type: BABYLON.GUI.Slider,
  565. properties: [
  566. '_minimum',
  567. '_maximum',
  568. '_value',
  569. '_background',
  570. '_borderColor',
  571. ],
  572. format: function (slider) { return slider.name; }
  573. },
  574. 'StackPanel': {
  575. type: BABYLON.GUI.StackPanel,
  576. properties: ['_isVertical'],
  577. format: function (stackPanel) { return stackPanel.name; }
  578. },
  579. 'TextBlock': {
  580. type: BABYLON.GUI.TextBlock,
  581. properties: ['_text', '_textWrapping'],
  582. format: function (textBlock) { return textBlock.name; }
  583. },
  584. 'Container': {
  585. type: BABYLON.GUI.Container,
  586. properties: ['_background'],
  587. format: function (container) { return container.name; }
  588. },
  589. };
  590. for (var prop in PROPERTIES_GUI) {
  591. INSPECTOR.PROPERTIES[prop] = PROPERTIES_GUI[prop];
  592. }
  593. }
  594. INSPECTOR.loadGUIProperties = loadGUIProperties;
  595. })(INSPECTOR || (INSPECTOR = {}));
  596. //# sourceMappingURL=properties_gui.js.map
  597. var INSPECTOR;
  598. (function (INSPECTOR) {
  599. /**
  600. * Represents a html div element.
  601. * The div is built when an instance of BasicElement is created.
  602. */
  603. var BasicElement = /** @class */ (function () {
  604. function BasicElement() {
  605. this._div = INSPECTOR.Helpers.CreateDiv();
  606. }
  607. /**
  608. * Returns the div element
  609. */
  610. BasicElement.prototype.toHtml = function () {
  611. return this._div;
  612. };
  613. /**
  614. * Build the html element
  615. */
  616. BasicElement.prototype._build = function () { };
  617. ;
  618. /** Default dispose method if needed */
  619. BasicElement.prototype.dispose = function () { };
  620. ;
  621. return BasicElement;
  622. }());
  623. INSPECTOR.BasicElement = BasicElement;
  624. })(INSPECTOR || (INSPECTOR = {}));
  625. //# sourceMappingURL=BasicElement.js.map
  626. var INSPECTOR;
  627. (function (INSPECTOR) {
  628. var Adapter = /** @class */ (function () {
  629. function Adapter(obj) {
  630. this._obj = obj;
  631. }
  632. /** Returns true if the given object correspond to this */
  633. Adapter.prototype.correspondsTo = function (obj) {
  634. return obj === this._obj;
  635. };
  636. Object.defineProperty(Adapter.prototype, "name", {
  637. /** Returns the adapter unique name */
  638. get: function () {
  639. return Adapter._name;
  640. },
  641. enumerable: true,
  642. configurable: true
  643. });
  644. Object.defineProperty(Adapter.prototype, "object", {
  645. /**
  646. * Returns the actual object used for this adapter
  647. */
  648. get: function () {
  649. return this._obj;
  650. },
  651. enumerable: true,
  652. configurable: true
  653. });
  654. // a unique name for this adapter, to retrieve its own key in the local storage
  655. Adapter._name = BABYLON.Geometry.RandomId();
  656. return Adapter;
  657. }());
  658. INSPECTOR.Adapter = Adapter;
  659. })(INSPECTOR || (INSPECTOR = {}));
  660. //# sourceMappingURL=Adapter.js.map
  661. var __extends = (this && this.__extends) || (function () {
  662. var extendStatics = Object.setPrototypeOf ||
  663. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  664. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  665. return function (d, b) {
  666. extendStatics(d, b);
  667. function __() { this.constructor = d; }
  668. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  669. };
  670. })();
  671. var INSPECTOR;
  672. (function (INSPECTOR) {
  673. var CameraAdapter = /** @class */ (function (_super) {
  674. __extends(CameraAdapter, _super);
  675. function CameraAdapter(obj) {
  676. return _super.call(this, obj) || this;
  677. }
  678. /** Returns the name displayed in the tree */
  679. CameraAdapter.prototype.id = function () {
  680. var str = '';
  681. if (this._obj.name) {
  682. str = this._obj.name;
  683. } // otherwise nothing displayed
  684. return str;
  685. };
  686. /** Returns the type of this object - displayed in the tree */
  687. CameraAdapter.prototype.type = function () {
  688. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  689. };
  690. /** Returns the list of properties to be displayed for this adapter */
  691. CameraAdapter.prototype.getProperties = function () {
  692. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  693. };
  694. CameraAdapter.prototype.getTools = function () {
  695. var tools = [];
  696. // tools.push(new Checkbox(this));
  697. tools.push(new INSPECTOR.CameraPOV(this));
  698. return tools;
  699. };
  700. CameraAdapter.prototype.setPOV = function () {
  701. this._obj.getScene().activeCamera = this._obj;
  702. };
  703. return CameraAdapter;
  704. }(INSPECTOR.Adapter));
  705. INSPECTOR.CameraAdapter = CameraAdapter;
  706. })(INSPECTOR || (INSPECTOR = {}));
  707. //# sourceMappingURL=CameraAdapter.js.map
  708. var __extends = (this && this.__extends) || (function () {
  709. var extendStatics = Object.setPrototypeOf ||
  710. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  711. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  712. return function (d, b) {
  713. extendStatics(d, b);
  714. function __() { this.constructor = d; }
  715. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  716. };
  717. })();
  718. var INSPECTOR;
  719. (function (INSPECTOR) {
  720. var PhysicsImpostorAdapter = /** @class */ (function (_super) {
  721. __extends(PhysicsImpostorAdapter, _super);
  722. function PhysicsImpostorAdapter(obj, viewer) {
  723. var _this = _super.call(this, obj) || this;
  724. _this._isVisible = false;
  725. _this._viewer = viewer;
  726. return _this;
  727. }
  728. /** Returns the name displayed in the tree */
  729. PhysicsImpostorAdapter.prototype.id = function () {
  730. var str = '';
  731. var physicsImposter = this._obj;
  732. if (physicsImposter && physicsImposter.object) {
  733. str = physicsImposter.object.name || "";
  734. } // otherwise nothing displayed
  735. return str;
  736. };
  737. /** Returns the type of this object - displayed in the tree */
  738. PhysicsImpostorAdapter.prototype.type = function () {
  739. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  740. };
  741. /** Returns the list of properties to be displayed for this adapter */
  742. PhysicsImpostorAdapter.prototype.getProperties = function () {
  743. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  744. };
  745. PhysicsImpostorAdapter.prototype.getTools = function () {
  746. var tools = [];
  747. tools.push(new INSPECTOR.Checkbox(this));
  748. return tools;
  749. };
  750. PhysicsImpostorAdapter.prototype.setVisible = function (b) {
  751. this._isVisible = b;
  752. if (b) {
  753. this._viewer.showImpostor(this._obj);
  754. }
  755. else {
  756. this._viewer.hideImpostor(this._obj);
  757. }
  758. };
  759. PhysicsImpostorAdapter.prototype.isVisible = function () {
  760. return this._isVisible;
  761. };
  762. return PhysicsImpostorAdapter;
  763. }(INSPECTOR.Adapter));
  764. INSPECTOR.PhysicsImpostorAdapter = PhysicsImpostorAdapter;
  765. })(INSPECTOR || (INSPECTOR = {}));
  766. //# sourceMappingURL=PhysicsImpostorAdapter.js.map
  767. var __extends = (this && this.__extends) || (function () {
  768. var extendStatics = Object.setPrototypeOf ||
  769. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  770. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  771. return function (d, b) {
  772. extendStatics(d, b);
  773. function __() { this.constructor = d; }
  774. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  775. };
  776. })();
  777. var INSPECTOR;
  778. (function (INSPECTOR) {
  779. var GUIAdapter = /** @class */ (function (_super) {
  780. __extends(GUIAdapter, _super);
  781. function GUIAdapter(obj) {
  782. return _super.call(this, obj) || this;
  783. }
  784. /** Returns the name displayed in the tree */
  785. GUIAdapter.prototype.id = function () {
  786. var str = '';
  787. if (this._obj.name) {
  788. str = this._obj.name;
  789. } // otherwise nothing displayed
  790. return str;
  791. };
  792. /** Returns the type of this object - displayed in the tree */
  793. GUIAdapter.prototype.type = function () {
  794. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  795. };
  796. /** Returns the list of properties to be displayed for this adapter */
  797. GUIAdapter.prototype.getProperties = function () {
  798. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  799. };
  800. GUIAdapter.prototype.getTools = function () {
  801. var tools = [];
  802. tools.push(new INSPECTOR.Checkbox(this));
  803. return tools;
  804. };
  805. GUIAdapter.prototype.setVisible = function (b) {
  806. this._obj.isVisible = b;
  807. };
  808. GUIAdapter.prototype.isVisible = function () {
  809. return this._obj.isVisible;
  810. };
  811. return GUIAdapter;
  812. }(INSPECTOR.Adapter));
  813. INSPECTOR.GUIAdapter = GUIAdapter;
  814. })(INSPECTOR || (INSPECTOR = {}));
  815. //# sourceMappingURL=GUIAdapter.js.map
  816. var __extends = (this && this.__extends) || (function () {
  817. var extendStatics = Object.setPrototypeOf ||
  818. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  819. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  820. return function (d, b) {
  821. extendStatics(d, b);
  822. function __() { this.constructor = d; }
  823. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  824. };
  825. })();
  826. var INSPECTOR;
  827. (function (INSPECTOR) {
  828. var SoundAdapter = /** @class */ (function (_super) {
  829. __extends(SoundAdapter, _super);
  830. function SoundAdapter(obj) {
  831. return _super.call(this, obj) || this;
  832. }
  833. /** Returns the name displayed in the tree */
  834. SoundAdapter.prototype.id = function () {
  835. var str = '';
  836. if (this._obj.name) {
  837. str = this._obj.name;
  838. } // otherwise nothing displayed
  839. return str;
  840. };
  841. /** Returns the type of this object - displayed in the tree */
  842. SoundAdapter.prototype.type = function () {
  843. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  844. };
  845. /** Returns the list of properties to be displayed for this adapter */
  846. SoundAdapter.prototype.getProperties = function () {
  847. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  848. };
  849. SoundAdapter.prototype.getTools = function () {
  850. var tools = [];
  851. tools.push(new INSPECTOR.SoundInteractions(this));
  852. return tools;
  853. };
  854. SoundAdapter.prototype.setPlaying = function (callback) {
  855. if (this._obj.isPlaying) {
  856. this._obj.pause();
  857. }
  858. else {
  859. this._obj.play();
  860. }
  861. this._obj.onended = function () {
  862. callback();
  863. };
  864. };
  865. return SoundAdapter;
  866. }(INSPECTOR.Adapter));
  867. INSPECTOR.SoundAdapter = SoundAdapter;
  868. })(INSPECTOR || (INSPECTOR = {}));
  869. //# sourceMappingURL=SoundAdapter.js.map
  870. var __extends = (this && this.__extends) || (function () {
  871. var extendStatics = Object.setPrototypeOf ||
  872. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  873. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  874. return function (d, b) {
  875. extendStatics(d, b);
  876. function __() { this.constructor = d; }
  877. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  878. };
  879. })();
  880. var INSPECTOR;
  881. (function (INSPECTOR) {
  882. var TextureAdapter = /** @class */ (function (_super) {
  883. __extends(TextureAdapter, _super);
  884. function TextureAdapter(obj) {
  885. return _super.call(this, obj) || this;
  886. }
  887. /** Returns the name displayed in the tree */
  888. TextureAdapter.prototype.id = function () {
  889. var str = '';
  890. if (this._obj.name) {
  891. str = this._obj.name;
  892. } // otherwise nothing displayed
  893. return str;
  894. };
  895. /** Returns the type of this object - displayed in the tree */
  896. TextureAdapter.prototype.type = function () {
  897. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  898. };
  899. /** Returns the list of properties to be displayed for this adapter */
  900. TextureAdapter.prototype.getProperties = function () {
  901. // Not used in this tab
  902. return [];
  903. };
  904. TextureAdapter.prototype.getTools = function () {
  905. var tools = new Array();
  906. // tools.push(new CameraPOV(this));
  907. return tools;
  908. };
  909. return TextureAdapter;
  910. }(INSPECTOR.Adapter));
  911. INSPECTOR.TextureAdapter = TextureAdapter;
  912. })(INSPECTOR || (INSPECTOR = {}));
  913. //# sourceMappingURL=TextureAdapter.js.map
  914. var __extends = (this && this.__extends) || (function () {
  915. var extendStatics = Object.setPrototypeOf ||
  916. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  917. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  918. return function (d, b) {
  919. extendStatics(d, b);
  920. function __() { this.constructor = d; }
  921. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  922. };
  923. })();
  924. var INSPECTOR;
  925. (function (INSPECTOR) {
  926. var LightAdapter = /** @class */ (function (_super) {
  927. __extends(LightAdapter, _super);
  928. function LightAdapter(obj) {
  929. return _super.call(this, obj) || this;
  930. }
  931. /** Returns the name displayed in the tree */
  932. LightAdapter.prototype.id = function () {
  933. var str = '';
  934. if (this._obj.name) {
  935. str = this._obj.name;
  936. } // otherwise nothing displayed
  937. return str;
  938. };
  939. /** Returns the type of this object - displayed in the tree */
  940. LightAdapter.prototype.type = function () {
  941. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  942. };
  943. /** Returns the list of properties to be displayed for this adapter */
  944. LightAdapter.prototype.getProperties = function () {
  945. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  946. };
  947. LightAdapter.prototype.getTools = function () {
  948. var tools = [];
  949. tools.push(new INSPECTOR.Checkbox(this));
  950. return tools;
  951. };
  952. LightAdapter.prototype.setVisible = function (b) {
  953. this._obj.setEnabled(b);
  954. };
  955. LightAdapter.prototype.isVisible = function () {
  956. return this._obj.isEnabled();
  957. };
  958. return LightAdapter;
  959. }(INSPECTOR.Adapter));
  960. INSPECTOR.LightAdapter = LightAdapter;
  961. })(INSPECTOR || (INSPECTOR = {}));
  962. //# sourceMappingURL=LightAdapter.js.map
  963. var __extends = (this && this.__extends) || (function () {
  964. var extendStatics = Object.setPrototypeOf ||
  965. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  966. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  967. return function (d, b) {
  968. extendStatics(d, b);
  969. function __() { this.constructor = d; }
  970. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  971. };
  972. })();
  973. var INSPECTOR;
  974. (function (INSPECTOR) {
  975. var MaterialAdapter = /** @class */ (function (_super) {
  976. __extends(MaterialAdapter, _super);
  977. function MaterialAdapter(obj) {
  978. return _super.call(this, obj) || this;
  979. }
  980. /** Returns the name displayed in the tree */
  981. MaterialAdapter.prototype.id = function () {
  982. var str = '';
  983. if (this._obj.name) {
  984. str = this._obj.name;
  985. } // otherwise nothing displayed
  986. return str;
  987. };
  988. /** Returns the type of this object - displayed in the tree */
  989. MaterialAdapter.prototype.type = function () {
  990. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  991. };
  992. /** Returns the list of properties to be displayed for this adapter */
  993. MaterialAdapter.prototype.getProperties = function () {
  994. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  995. };
  996. /** No tools for a material adapter */
  997. MaterialAdapter.prototype.getTools = function () {
  998. return [];
  999. };
  1000. return MaterialAdapter;
  1001. }(INSPECTOR.Adapter));
  1002. INSPECTOR.MaterialAdapter = MaterialAdapter;
  1003. })(INSPECTOR || (INSPECTOR = {}));
  1004. //# sourceMappingURL=MaterialAdapter.js.map
  1005. var __extends = (this && this.__extends) || (function () {
  1006. var extendStatics = Object.setPrototypeOf ||
  1007. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1008. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1009. return function (d, b) {
  1010. extendStatics(d, b);
  1011. function __() { this.constructor = d; }
  1012. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1013. };
  1014. })();
  1015. var INSPECTOR;
  1016. (function (INSPECTOR) {
  1017. var MeshAdapter = /** @class */ (function (_super) {
  1018. __extends(MeshAdapter, _super);
  1019. function MeshAdapter(mesh) {
  1020. return _super.call(this, mesh) || this;
  1021. }
  1022. /** Returns the name displayed in the tree */
  1023. MeshAdapter.prototype.id = function () {
  1024. var str = '';
  1025. if (this._obj.name) {
  1026. str = this._obj.name;
  1027. } // otherwise nothing displayed
  1028. return str;
  1029. };
  1030. /** Returns the type of this object - displayed in the tree */
  1031. MeshAdapter.prototype.type = function () {
  1032. return INSPECTOR.Helpers.GET_TYPE(this._obj);
  1033. };
  1034. /** Returns the list of properties to be displayed for this adapter */
  1035. MeshAdapter.prototype.getProperties = function () {
  1036. return INSPECTOR.Helpers.GetAllLinesProperties(this._obj);
  1037. };
  1038. MeshAdapter.prototype.getTools = function () {
  1039. var tools = [];
  1040. tools.push(new INSPECTOR.Checkbox(this));
  1041. tools.push(new INSPECTOR.DebugArea(this));
  1042. if (this._obj instanceof BABYLON.AbstractMesh) {
  1043. if (this._obj.getTotalVertices() > 0) {
  1044. tools.push(new INSPECTOR.BoundingBox(this));
  1045. }
  1046. }
  1047. tools.push(new INSPECTOR.Info(this));
  1048. return tools;
  1049. };
  1050. MeshAdapter.prototype.setVisible = function (b) {
  1051. this._obj.setEnabled(b);
  1052. this._obj.isVisible = b;
  1053. };
  1054. MeshAdapter.prototype.isVisible = function () {
  1055. return this._obj.isEnabled() && (this._obj.isVisible === undefined || this._obj.isVisible);
  1056. };
  1057. MeshAdapter.prototype.isBoxVisible = function () {
  1058. return this._obj.showBoundingBox;
  1059. };
  1060. MeshAdapter.prototype.setBoxVisible = function (b) {
  1061. return this._obj.showBoundingBox = b;
  1062. };
  1063. MeshAdapter.prototype.debug = function (enable) {
  1064. // Draw axis the first time
  1065. if (!this._axesViewer) {
  1066. this._drawAxis();
  1067. }
  1068. // Display or hide axis
  1069. if (!enable && this._axesViewer) {
  1070. var mesh = this._obj;
  1071. mesh.getScene().onBeforeRenderObservable.remove(this.onBeforeRenderObserver);
  1072. this._axesViewer.dispose();
  1073. this._axesViewer = null;
  1074. }
  1075. };
  1076. /** Returns some information about this mesh */
  1077. MeshAdapter.prototype.getInfo = function () {
  1078. if (this._obj instanceof BABYLON.AbstractMesh) {
  1079. return this._obj.getTotalVertices() + " vertices";
  1080. }
  1081. return '0 vertices';
  1082. };
  1083. /** Draw X, Y and Z axis for the actual object if this adapter.
  1084. * Should be called only one time as it will fill this._axis
  1085. */
  1086. MeshAdapter.prototype._drawAxis = function () {
  1087. var _this = this;
  1088. this._obj.computeWorldMatrix();
  1089. // Axis
  1090. var x = new BABYLON.Vector3(1, 0, 0);
  1091. var y = new BABYLON.Vector3(0, 1, 0);
  1092. var z = new BABYLON.Vector3(0, 0, 1);
  1093. this._axesViewer = new BABYLON.Debug.AxesViewer(this._obj.getScene());
  1094. var mesh = this._obj;
  1095. this.onBeforeRenderObserver = mesh.getScene().onBeforeRenderObservable.add(function () {
  1096. var matrix = mesh.getWorldMatrix();
  1097. var extend = new BABYLON.Vector3(1, 1, 1);
  1098. if (mesh instanceof BABYLON.AbstractMesh) {
  1099. extend = mesh.getBoundingInfo().boundingBox.extendSizeWorld;
  1100. }
  1101. _this._axesViewer.scaleLines = Math.max(extend.x, extend.y, extend.z) * 2;
  1102. _this._axesViewer.update(_this._obj.position, BABYLON.Vector3.TransformNormal(x, matrix), BABYLON.Vector3.TransformNormal(y, matrix), BABYLON.Vector3.TransformNormal(z, matrix));
  1103. });
  1104. };
  1105. return MeshAdapter;
  1106. }(INSPECTOR.Adapter));
  1107. INSPECTOR.MeshAdapter = MeshAdapter;
  1108. })(INSPECTOR || (INSPECTOR = {}));
  1109. //# sourceMappingURL=MeshAdapter.js.map
  1110. var __extends = (this && this.__extends) || (function () {
  1111. var extendStatics = Object.setPrototypeOf ||
  1112. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1113. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1114. return function (d, b) {
  1115. extendStatics(d, b);
  1116. function __() { this.constructor = d; }
  1117. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1118. };
  1119. })();
  1120. var INSPECTOR;
  1121. (function (INSPECTOR) {
  1122. var DetailPanel = /** @class */ (function (_super) {
  1123. __extends(DetailPanel, _super);
  1124. function DetailPanel(dr) {
  1125. var _this = _super.call(this) || this;
  1126. // Contains all details rows that belongs to the item above
  1127. _this._detailRows = [];
  1128. // Store the sort direction of each header column
  1129. _this._sortDirection = {};
  1130. _this._build();
  1131. if (dr) {
  1132. _this._detailRows = dr;
  1133. _this.update();
  1134. }
  1135. return _this;
  1136. }
  1137. Object.defineProperty(DetailPanel.prototype, "details", {
  1138. set: function (detailsRow) {
  1139. this.clean();
  1140. this._detailRows = detailsRow;
  1141. // Refresh HTML
  1142. this.update();
  1143. },
  1144. enumerable: true,
  1145. configurable: true
  1146. });
  1147. DetailPanel.prototype._build = function () {
  1148. this._div.className = 'insp-details';
  1149. this._div.id = 'insp-details';
  1150. // Create header row
  1151. this._createHeaderRow();
  1152. this._div.appendChild(this._headerRow);
  1153. };
  1154. /** Updates the HTML of the detail panel */
  1155. DetailPanel.prototype.update = function () {
  1156. this._sortDetails('name', 1);
  1157. this._addDetails();
  1158. };
  1159. /** Add all lines in the html div. Does not sort them! */
  1160. DetailPanel.prototype._addDetails = function () {
  1161. var details = INSPECTOR.Helpers.CreateDiv('details', this._div);
  1162. for (var _i = 0, _a = this._detailRows; _i < _a.length; _i++) {
  1163. var row = _a[_i];
  1164. details.appendChild(row.toHtml());
  1165. }
  1166. };
  1167. /**
  1168. * Sort the details row by comparing the given property of each row
  1169. */
  1170. DetailPanel.prototype._sortDetails = function (property, _direction) {
  1171. // Clean header
  1172. var elems = INSPECTOR.Inspector.DOCUMENT.querySelectorAll('.sort-direction');
  1173. for (var e = 0; e < elems.length; e++) {
  1174. elems[e].classList.remove('fa-chevron-up');
  1175. elems[e].classList.remove('fa-chevron-down');
  1176. }
  1177. if (_direction || !this._sortDirection[property]) {
  1178. this._sortDirection[property] = _direction || 1;
  1179. }
  1180. else {
  1181. this._sortDirection[property] *= -1;
  1182. }
  1183. var direction = this._sortDirection[property];
  1184. var query = this._headerRow.querySelector("#sort-direction-" + property);
  1185. if (query) {
  1186. if (direction == 1) {
  1187. query.classList.remove('fa-chevron-down');
  1188. query.classList.add('fa-chevron-up');
  1189. }
  1190. else {
  1191. query.classList.remove('fa-chevron-up');
  1192. query.classList.add('fa-chevron-down');
  1193. }
  1194. }
  1195. var isString = function (s) {
  1196. return typeof (s) === 'string' || s instanceof String;
  1197. };
  1198. this._detailRows.forEach(function (property) {
  1199. property.closeDetails();
  1200. });
  1201. this._detailRows.sort(function (detail1, detail2) {
  1202. var str1 = String(detail1[property]);
  1203. var str2 = String(detail2[property]);
  1204. if (!isString(str1)) {
  1205. str1 = detail1[property].toString();
  1206. }
  1207. if (!isString(str2)) {
  1208. str2 = detail2[property].toString();
  1209. }
  1210. // Compare numbers as numbers and string as string with 'numeric=true'
  1211. return str1.localeCompare(str2, [], { numeric: true }) * direction;
  1212. });
  1213. };
  1214. /**
  1215. * Removes all data in the detail panel but keep the header row
  1216. */
  1217. DetailPanel.prototype.clean = function () {
  1218. // Delete all details row
  1219. for (var _i = 0, _a = this._detailRows; _i < _a.length; _i++) {
  1220. var pline = _a[_i];
  1221. pline.dispose();
  1222. }
  1223. INSPECTOR.Helpers.CleanDiv(this._div);
  1224. // Header row
  1225. this._div.appendChild(this._headerRow);
  1226. };
  1227. /** Overrides basicelement.dispose */
  1228. DetailPanel.prototype.dispose = function () {
  1229. // Delete all details row
  1230. for (var _i = 0, _a = this._detailRows; _i < _a.length; _i++) {
  1231. var pline = _a[_i];
  1232. pline.dispose();
  1233. }
  1234. };
  1235. /**
  1236. * Creates the header row : name, value, id
  1237. */
  1238. DetailPanel.prototype._createHeaderRow = function () {
  1239. var _this = this;
  1240. this._headerRow = INSPECTOR.Helpers.CreateDiv('header-row');
  1241. var createDiv = function (name, cssClass) {
  1242. var div = INSPECTOR.Helpers.CreateDiv(cssClass + ' header-col');
  1243. // Column title - first letter in uppercase
  1244. var spanName = INSPECTOR.Inspector.DOCUMENT.createElement('span');
  1245. spanName.textContent = name.charAt(0).toUpperCase() + name.slice(1);
  1246. // sort direction
  1247. var spanDirection = INSPECTOR.Inspector.DOCUMENT.createElement('i');
  1248. spanDirection.className = 'sort-direction fa';
  1249. spanDirection.id = 'sort-direction-' + name;
  1250. div.appendChild(spanName);
  1251. div.appendChild(spanDirection);
  1252. div.addEventListener('click', function (e) {
  1253. _this._sortDetails(name);
  1254. _this._addDetails();
  1255. });
  1256. return div;
  1257. };
  1258. this._headerRow.appendChild(createDiv('name', 'prop-name'));
  1259. this._headerRow.appendChild(createDiv('value', 'prop-value'));
  1260. };
  1261. return DetailPanel;
  1262. }(INSPECTOR.BasicElement));
  1263. INSPECTOR.DetailPanel = DetailPanel;
  1264. })(INSPECTOR || (INSPECTOR = {}));
  1265. //# sourceMappingURL=DetailPanel.js.map
  1266. var INSPECTOR;
  1267. (function (INSPECTOR) {
  1268. /**
  1269. * A property is a link between a data (string) and an object.
  1270. */
  1271. var Property = /** @class */ (function () {
  1272. function Property(prop, obj) {
  1273. this._property = prop;
  1274. this._obj = obj;
  1275. }
  1276. Object.defineProperty(Property.prototype, "name", {
  1277. get: function () {
  1278. return this._property;
  1279. },
  1280. enumerable: true,
  1281. configurable: true
  1282. });
  1283. Object.defineProperty(Property.prototype, "value", {
  1284. get: function () {
  1285. return this._obj[this._property];
  1286. },
  1287. set: function (newValue) {
  1288. this._obj[this._property] = newValue;
  1289. },
  1290. enumerable: true,
  1291. configurable: true
  1292. });
  1293. Object.defineProperty(Property.prototype, "type", {
  1294. get: function () {
  1295. return INSPECTOR.Helpers.GET_TYPE(this.value);
  1296. },
  1297. enumerable: true,
  1298. configurable: true
  1299. });
  1300. Object.defineProperty(Property.prototype, "obj", {
  1301. get: function () {
  1302. return this._obj;
  1303. },
  1304. set: function (newObj) {
  1305. this._obj = newObj;
  1306. },
  1307. enumerable: true,
  1308. configurable: true
  1309. });
  1310. return Property;
  1311. }());
  1312. INSPECTOR.Property = Property;
  1313. })(INSPECTOR || (INSPECTOR = {}));
  1314. //# sourceMappingURL=Property.js.map
  1315. var INSPECTOR;
  1316. (function (INSPECTOR) {
  1317. var PropertyFormatter = /** @class */ (function () {
  1318. function PropertyFormatter() {
  1319. }
  1320. /**
  1321. * Format the value of the given property of the given object.
  1322. */
  1323. PropertyFormatter.format = function (obj, prop) {
  1324. // Get original value;
  1325. var value = obj[prop];
  1326. // test if type PrimitiveAlignment is available (only included in canvas2d)
  1327. return value;
  1328. };
  1329. return PropertyFormatter;
  1330. }());
  1331. INSPECTOR.PropertyFormatter = PropertyFormatter;
  1332. /**
  1333. * A property line represents a line in the detail panel. This line is composed of :
  1334. * - a name (the property name)
  1335. * - a value if this property is of a type 'simple' : string, number, boolean, color, texture
  1336. * - the type of the value if this property is of a complex type (Vector2, Size, ...)
  1337. * - a ID if defined (otherwise an empty string is displayed)
  1338. * The original object is sent to the value object who will update it at will.
  1339. *
  1340. * A property line can contain OTHER property line objects in the case of a complex type.
  1341. * If this instance has no link to other instances, its type is ALWAYS a simple one (see above).
  1342. *
  1343. */
  1344. var PropertyLine = /** @class */ (function () {
  1345. function PropertyLine(prop, parent, level) {
  1346. if (parent === void 0) { parent = null; }
  1347. if (level === void 0) { level = 0; }
  1348. // If the type is complex, this property will have child to update
  1349. this._children = [];
  1350. /** The list of viewer element displayed at the end of the line (color, texture...) */
  1351. this._elements = [];
  1352. this._property = prop;
  1353. this._level = level;
  1354. this._parent = parent;
  1355. this._div = INSPECTOR.Helpers.CreateDiv('row');
  1356. this._div.style.marginLeft = this._level + "px";
  1357. // Property name
  1358. var propName = INSPECTOR.Helpers.CreateDiv('prop-name', this._div);
  1359. propName.textContent = "" + this.name;
  1360. // Value
  1361. this._valueDiv = INSPECTOR.Helpers.CreateDiv('prop-value', this._div);
  1362. if (typeof this.value !== 'boolean' && !this._isSliderType()) {
  1363. this._valueDiv.textContent = this._displayValueContent() || '-'; // Init value text node
  1364. }
  1365. this._createElements();
  1366. for (var _i = 0, _a = this._elements; _i < _a.length; _i++) {
  1367. var elem = _a[_i];
  1368. this._valueDiv.appendChild(elem.toHtml());
  1369. }
  1370. this._updateValue();
  1371. // If the property type is not simple, add click event to unfold its children
  1372. if (typeof this.value === 'boolean') {
  1373. this._checkboxInput();
  1374. }
  1375. else if (this._isSliderType()) {
  1376. this._rangeInput();
  1377. }
  1378. else if (!this._isSimple()) {
  1379. this._valueDiv.classList.add('clickable');
  1380. this._valueDiv.addEventListener('click', this._addDetails.bind(this));
  1381. }
  1382. else {
  1383. this._initInput();
  1384. this._valueDiv.addEventListener('click', this._displayInputHandler);
  1385. this._input.addEventListener('focusout', this._focusOutInputHandler);
  1386. this._input.addEventListener('keydown', this._validateInputHandler);
  1387. this._input.addEventListener('keydown', this._escapeInputHandler);
  1388. }
  1389. // Add this property to the scheduler
  1390. INSPECTOR.Scheduler.getInstance().add(this);
  1391. }
  1392. /**
  1393. * Init the input element and al its handler :
  1394. * - a click in the window remove the input and restore the old property value
  1395. * - enters updates the property
  1396. */
  1397. PropertyLine.prototype._initInput = function () {
  1398. // Create the input element
  1399. this._input = document.createElement('input');
  1400. this._input.setAttribute('type', 'text');
  1401. // if the property is 'simple', add an event listener to create an input
  1402. this._displayInputHandler = this._displayInput.bind(this);
  1403. this._validateInputHandler = this._validateInput.bind(this);
  1404. this._escapeInputHandler = this._escapeInput.bind(this);
  1405. this._focusOutInputHandler = this.update.bind(this);
  1406. this._onMouseDownHandler = this._onMouseDown.bind(this);
  1407. this._onMouseDragHandler = this._onMouseDrag.bind(this);
  1408. this._onMouseUpHandler = this._onMouseUp.bind(this);
  1409. };
  1410. /**
  1411. * On enter : validates the new value and removes the input
  1412. * On escape : removes the input
  1413. */
  1414. PropertyLine.prototype._validateInput = function (e) {
  1415. this._input.removeEventListener('focusout', this._focusOutInputHandler);
  1416. if (e.keyCode == 13) {
  1417. this.validateInput(this._input.value);
  1418. }
  1419. else if (e.keyCode == 9) {
  1420. e.preventDefault();
  1421. this.validateInput(this._input.value);
  1422. }
  1423. else if (e.keyCode == 27) {
  1424. // Esc : remove input
  1425. this.update();
  1426. }
  1427. };
  1428. PropertyLine.prototype.validateInput = function (value, forceupdate) {
  1429. if (forceupdate === void 0) { forceupdate = true; }
  1430. this.updateObject();
  1431. if (typeof this._property.value === 'number') {
  1432. this._property.value = parseFloat(value);
  1433. }
  1434. else {
  1435. this._property.value = value;
  1436. }
  1437. // Remove input
  1438. if (forceupdate) {
  1439. this.update();
  1440. // resume scheduler
  1441. INSPECTOR.Scheduler.getInstance().pause = false;
  1442. }
  1443. };
  1444. /**
  1445. * On escape : removes the input
  1446. */
  1447. PropertyLine.prototype._escapeInput = function (e) {
  1448. // Remove focus out handler
  1449. this._input.removeEventListener('focusout', this._focusOutInputHandler);
  1450. if (e.keyCode == 27) {
  1451. // Esc : remove input
  1452. this.update();
  1453. }
  1454. };
  1455. /** Removes the input without validating the new value */
  1456. PropertyLine.prototype._removeInputWithoutValidating = function () {
  1457. INSPECTOR.Helpers.CleanDiv(this._valueDiv);
  1458. if (typeof this.value !== 'boolean' && !this._isSliderType()) {
  1459. this._valueDiv.textContent = "-";
  1460. }
  1461. // restore elements
  1462. for (var _i = 0, _a = this._elements; _i < _a.length; _i++) {
  1463. var elem = _a[_i];
  1464. this._valueDiv.appendChild(elem.toHtml());
  1465. }
  1466. if (typeof this.value !== 'boolean' && !this._isSliderType()) {
  1467. this._valueDiv.addEventListener('click', this._displayInputHandler);
  1468. }
  1469. };
  1470. /** Replaces the default display with an input */
  1471. PropertyLine.prototype._displayInput = function (e) {
  1472. // Remove the displayInput event listener
  1473. this._valueDiv.removeEventListener('click', this._displayInputHandler);
  1474. // Set input value
  1475. var valueTxt = this._valueDiv.textContent;
  1476. this._valueDiv.textContent = "";
  1477. this._input.value = valueTxt || "";
  1478. this._valueDiv.appendChild(this._input);
  1479. this._input.focus();
  1480. if (typeof this.value !== 'boolean' && !this._isSliderType()) {
  1481. this._input.addEventListener('focusout', this._focusOutInputHandler);
  1482. }
  1483. else if (typeof this.value === 'number') {
  1484. this._input.addEventListener('mousedown', this._onMouseDownHandler);
  1485. }
  1486. // Pause the scheduler
  1487. INSPECTOR.Scheduler.getInstance().pause = true;
  1488. };
  1489. /** Retrieve the correct object from its parent.
  1490. * If no parent exists, returns the property value.
  1491. * This method is used at each update in case the property object is removed from the original object
  1492. * (example : mesh.position = new BABYLON.Vector3 ; the original vector3 object is deleted from the mesh).
  1493. */
  1494. PropertyLine.prototype.updateObject = function () {
  1495. if (this._parent) {
  1496. this._property.obj = this._parent.updateObject();
  1497. }
  1498. return this._property.value;
  1499. };
  1500. Object.defineProperty(PropertyLine.prototype, "name", {
  1501. // Returns the property name
  1502. get: function () {
  1503. // let arrayName = Helpers.Capitalize(this._property.name).match(/[A-Z][a-z]+|[0-9]+/g)
  1504. // if (arrayName) {
  1505. // return arrayName.join(" ");
  1506. // }
  1507. return this._property.name;
  1508. },
  1509. enumerable: true,
  1510. configurable: true
  1511. });
  1512. Object.defineProperty(PropertyLine.prototype, "value", {
  1513. // Returns the value of the property
  1514. get: function () {
  1515. return PropertyFormatter.format(this._property.obj, this._property.name);
  1516. },
  1517. enumerable: true,
  1518. configurable: true
  1519. });
  1520. Object.defineProperty(PropertyLine.prototype, "type", {
  1521. // Returns the type of the property
  1522. get: function () {
  1523. return this._property.type;
  1524. },
  1525. enumerable: true,
  1526. configurable: true
  1527. });
  1528. /**
  1529. * Creates elements that wil be displayed on a property line, depending on the
  1530. * type of the property.
  1531. */
  1532. PropertyLine.prototype._createElements = function () {
  1533. // Colors
  1534. if (this.type == 'Color3' || this.type == 'Color4') {
  1535. this._elements.push(new INSPECTOR.ColorPickerElement(this.value, this));
  1536. //this._elements.push(new ColorElement(this.value));
  1537. }
  1538. // Texture
  1539. if (this.type == 'Texture') {
  1540. this._elements.push(new INSPECTOR.TextureElement(this.value));
  1541. }
  1542. // HDR Texture
  1543. if (this.type == 'HDRCubeTexture') {
  1544. this._elements.push(new INSPECTOR.HDRCubeTextureElement(this.value));
  1545. }
  1546. if (this.type == 'CubeTexture') {
  1547. this._elements.push(new INSPECTOR.CubeTextureElement(this.value));
  1548. }
  1549. };
  1550. // Returns the text displayed on the left of the property name :
  1551. // - If the type is simple, display its value
  1552. // - If the type is complex, but instance of Vector2, Size, display the type and its tostring
  1553. // - If the type is another one, display the Type
  1554. PropertyLine.prototype._displayValueContent = function () {
  1555. var value = this.value;
  1556. // If the value is a number, truncate it if needed
  1557. if (typeof value === 'number') {
  1558. return INSPECTOR.Helpers.Trunc(value);
  1559. }
  1560. // If it's a string or a boolean, display its value
  1561. if (typeof value === 'string' || typeof value === 'boolean') {
  1562. return value;
  1563. }
  1564. return INSPECTOR.PROPERTIES.format(value);
  1565. };
  1566. /** Delete properly this property line.
  1567. * Removes itself from the scheduler.
  1568. * Dispose all viewer element (color, texture...)
  1569. */
  1570. PropertyLine.prototype.dispose = function () {
  1571. // console.log('delete properties', this.name);
  1572. INSPECTOR.Scheduler.getInstance().remove(this);
  1573. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1574. var child = _a[_i];
  1575. // console.log('delete properties', child.name);
  1576. INSPECTOR.Scheduler.getInstance().remove(child);
  1577. }
  1578. for (var _b = 0, _c = this._elements; _b < _c.length; _b++) {
  1579. var elem = _c[_b];
  1580. elem.dispose();
  1581. }
  1582. this._elements = [];
  1583. };
  1584. /** Updates the content of _valueDiv with the value of the property,
  1585. * and all HTML element correpsonding to this type.
  1586. * Elements are updated as well
  1587. */
  1588. PropertyLine.prototype._updateValue = function () {
  1589. // Update the property object first
  1590. this.updateObject();
  1591. // Then update its value
  1592. // this._valueDiv.textContent = " "; // TOFIX this removes the elements after
  1593. if (typeof this.value === 'boolean') {
  1594. this._checkboxInput();
  1595. }
  1596. else if (this._isSliderType()) {
  1597. this._rangeInput();
  1598. }
  1599. else {
  1600. this._valueDiv.childNodes[0].nodeValue = this._displayValueContent();
  1601. }
  1602. for (var _i = 0, _a = this._elements; _i < _a.length; _i++) {
  1603. var elem = _a[_i];
  1604. elem.update(this.value);
  1605. }
  1606. };
  1607. /**
  1608. * Update the property division with the new property value.
  1609. * If this property is complex, update its child, otherwise update its text content
  1610. */
  1611. PropertyLine.prototype.update = function () {
  1612. this._removeInputWithoutValidating();
  1613. this._updateValue();
  1614. };
  1615. /**
  1616. * Returns true if the type of this property is simple, false otherwise.
  1617. * Returns true if the value is null
  1618. */
  1619. PropertyLine.prototype._isSimple = function () {
  1620. if (this.value != null && this.type !== 'type_not_defined') {
  1621. if (PropertyLine._SIMPLE_TYPE.indexOf(this.type) == -1) {
  1622. // complex type : return the type name
  1623. return false;
  1624. }
  1625. else {
  1626. // simple type : return value
  1627. return true;
  1628. }
  1629. }
  1630. else {
  1631. return true;
  1632. }
  1633. };
  1634. PropertyLine.prototype.toHtml = function () {
  1635. return this._div;
  1636. };
  1637. PropertyLine.prototype.closeDetails = function () {
  1638. if (this._div.classList.contains('unfolded')) {
  1639. // Remove class unfolded
  1640. this._div.classList.remove('unfolded');
  1641. // remove html children
  1642. if (this._div.parentNode) {
  1643. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1644. var child = _a[_i];
  1645. this._div.parentNode.removeChild(child.toHtml());
  1646. }
  1647. }
  1648. }
  1649. };
  1650. /**
  1651. * Add sub properties in case of a complex type
  1652. */
  1653. PropertyLine.prototype._addDetails = function () {
  1654. if (this._div.classList.contains('unfolded')) {
  1655. // Remove class unfolded
  1656. this._div.classList.remove('unfolded');
  1657. // remove html children
  1658. if (this._div.parentNode) {
  1659. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1660. var child = _a[_i];
  1661. this._div.parentNode.removeChild(child.toHtml());
  1662. }
  1663. }
  1664. }
  1665. else {
  1666. // if children does not exists, generate it
  1667. this._div.classList.toggle('unfolded');
  1668. if (this._children.length == 0) {
  1669. var objToDetail = this.value;
  1670. // Display all properties that are not functions
  1671. var propToDisplay = INSPECTOR.Helpers.GetAllLinesPropertiesAsString(objToDetail);
  1672. propToDisplay.sort().reverse();
  1673. for (var _b = 0, propToDisplay_1 = propToDisplay; _b < propToDisplay_1.length; _b++) {
  1674. var prop = propToDisplay_1[_b];
  1675. var infos = new INSPECTOR.Property(prop, this._property.value);
  1676. var child = new PropertyLine(infos, this, this._level + PropertyLine._MARGIN_LEFT);
  1677. this._children.push(child);
  1678. }
  1679. }
  1680. // otherwise display it
  1681. if (this._div.parentNode) {
  1682. for (var _c = 0, _d = this._children; _c < _d.length; _c++) {
  1683. var child = _d[_c];
  1684. this._div.parentNode.insertBefore(child.toHtml(), this._div.nextSibling);
  1685. }
  1686. }
  1687. }
  1688. };
  1689. /**
  1690. * Refresh mouse position on y axis
  1691. * @param e
  1692. */
  1693. PropertyLine.prototype._onMouseDrag = function (e) {
  1694. var diff = this._prevY - e.clientY;
  1695. this._input.value = (this._preValue + diff).toString();
  1696. };
  1697. /**
  1698. * Save new value from slider
  1699. * @param e
  1700. */
  1701. PropertyLine.prototype._onMouseUp = function (e) {
  1702. window.removeEventListener('mousemove', this._onMouseDragHandler);
  1703. window.removeEventListener('mouseup', this._onMouseUpHandler);
  1704. this._prevY = e.clientY;
  1705. };
  1706. /**
  1707. * Start record mouse position
  1708. * @param e
  1709. */
  1710. PropertyLine.prototype._onMouseDown = function (e) {
  1711. this._prevY = e.clientY;
  1712. this._preValue = this.value;
  1713. window.addEventListener('mousemove', this._onMouseDragHandler);
  1714. window.addEventListener('mouseup', this._onMouseUpHandler);
  1715. };
  1716. /**
  1717. * Create input entry
  1718. */
  1719. PropertyLine.prototype._checkboxInput = function () {
  1720. var _this = this;
  1721. if (this._valueDiv.childElementCount < 1) {
  1722. this._input = INSPECTOR.Helpers.CreateInput('checkbox-element', this._valueDiv);
  1723. this._input.type = 'checkbox';
  1724. this._input.checked = this.value;
  1725. this._input.addEventListener('change', function () {
  1726. INSPECTOR.Scheduler.getInstance().pause = true;
  1727. _this.validateInput(!_this.value);
  1728. });
  1729. }
  1730. };
  1731. PropertyLine.prototype._rangeInput = function () {
  1732. if (this._valueDiv.childElementCount < 1) {
  1733. this._input = INSPECTOR.Helpers.CreateInput('slider-element', this._valueDiv);
  1734. this._input.type = 'range';
  1735. this._input.style.display = 'inline-block';
  1736. this._input.min = this._getSliderProperty().min;
  1737. this._input.max = this._getSliderProperty().max;
  1738. this._input.step = this._getSliderProperty().step;
  1739. this._input.value = this.value;
  1740. this._validateInputHandler = this._rangeHandler.bind(this);
  1741. this._input.addEventListener('input', this._validateInputHandler);
  1742. this._input.addEventListener('change', function () {
  1743. INSPECTOR.Scheduler.getInstance().pause = false;
  1744. });
  1745. this._textValue = INSPECTOR.Helpers.CreateDiv('value-text', this._valueDiv);
  1746. this._textValue.innerText = INSPECTOR.Helpers.Trunc(this.value).toString();
  1747. this._textValue.style.paddingLeft = '10px';
  1748. this._textValue.style.display = 'inline-block';
  1749. }
  1750. };
  1751. PropertyLine.prototype._rangeHandler = function () {
  1752. INSPECTOR.Scheduler.getInstance().pause = true;
  1753. //this._input.style.backgroundSize = ((parseFloat(this._input.value) - parseFloat(this._input.min)) * 100 / ( parseFloat(this._input.max) - parseFloat(this._input.min))) + '% 100%'
  1754. this._textValue.innerText = this._input.value;
  1755. this.validateInput(this._input.value, false);
  1756. };
  1757. PropertyLine.prototype._isSliderType = function () {
  1758. return this._property &&
  1759. INSPECTOR.PROPERTIES.hasOwnProperty(this._property.obj.constructor.name) &&
  1760. INSPECTOR.PROPERTIES[this._property.obj.constructor.name].hasOwnProperty('slider') &&
  1761. INSPECTOR.PROPERTIES[this._property.obj.constructor.name].slider.hasOwnProperty(this.name);
  1762. };
  1763. PropertyLine.prototype._getSliderProperty = function () {
  1764. return INSPECTOR.PROPERTIES[this._property.obj.constructor.name].slider[this.name];
  1765. };
  1766. // Array representing the simple type. All others are considered 'complex'
  1767. PropertyLine._SIMPLE_TYPE = ['number', 'string', 'boolean'];
  1768. // The number of pixel at each children step
  1769. PropertyLine._MARGIN_LEFT = 15;
  1770. return PropertyLine;
  1771. }());
  1772. INSPECTOR.PropertyLine = PropertyLine;
  1773. })(INSPECTOR || (INSPECTOR = {}));
  1774. //# sourceMappingURL=PropertyLine.js.map
  1775. var __extends = (this && this.__extends) || (function () {
  1776. var extendStatics = Object.setPrototypeOf ||
  1777. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1778. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1779. return function (d, b) {
  1780. extendStatics(d, b);
  1781. function __() { this.constructor = d; }
  1782. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1783. };
  1784. })();
  1785. var INSPECTOR;
  1786. (function (INSPECTOR) {
  1787. /**
  1788. * Display a very small div corresponding to the given color
  1789. */
  1790. var ColorElement = /** @class */ (function (_super) {
  1791. __extends(ColorElement, _super);
  1792. // The color as hexadecimal string
  1793. function ColorElement(color) {
  1794. var _this = _super.call(this) || this;
  1795. _this._div.className = 'color-element';
  1796. _this._div.style.backgroundColor = _this._toRgba(color);
  1797. return _this;
  1798. }
  1799. ColorElement.prototype.update = function (color) {
  1800. if (color) {
  1801. this._div.style.backgroundColor = this._toRgba(color);
  1802. }
  1803. };
  1804. ColorElement.prototype._toRgba = function (color) {
  1805. if (color) {
  1806. var r = (color.r * 255) | 0;
  1807. var g = (color.g * 255) | 0;
  1808. var b = (color.b * 255) | 0;
  1809. var a = 1;
  1810. if (color instanceof BABYLON.Color4) {
  1811. a = color.a;
  1812. }
  1813. return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
  1814. }
  1815. else {
  1816. return '';
  1817. }
  1818. };
  1819. return ColorElement;
  1820. }(INSPECTOR.BasicElement));
  1821. INSPECTOR.ColorElement = ColorElement;
  1822. })(INSPECTOR || (INSPECTOR = {}));
  1823. var __extends = (this && this.__extends) || (function () {
  1824. var extendStatics = Object.setPrototypeOf ||
  1825. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1826. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1827. return function (d, b) {
  1828. extendStatics(d, b);
  1829. function __() { this.constructor = d; }
  1830. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1831. };
  1832. })();
  1833. var INSPECTOR;
  1834. (function (INSPECTOR) {
  1835. /**
  1836. * Represents a html div element.
  1837. * The div is built when an instance of BasicElement is created.
  1838. */
  1839. var ColorPickerElement = /** @class */ (function (_super) {
  1840. __extends(ColorPickerElement, _super);
  1841. function ColorPickerElement(color, propertyLine) {
  1842. var _this = _super.call(this) || this;
  1843. var scheduler = INSPECTOR.Scheduler.getInstance();
  1844. _this._div.className = 'color-element';
  1845. _this._div.style.backgroundColor = _this._toRgba(color);
  1846. _this.pline = propertyLine;
  1847. _this._input = INSPECTOR.Helpers.CreateInput();
  1848. _this._input.type = 'color';
  1849. _this._input.style.opacity = "0";
  1850. _this._input.style.width = '10px';
  1851. _this._input.style.height = '15px';
  1852. _this._input.value = color.toHexString();
  1853. _this._input.addEventListener('input', function (e) {
  1854. var color = BABYLON.Color3.FromHexString(_this._input.value);
  1855. color.r = parseFloat(color.r.toPrecision(2));
  1856. color.g = parseFloat(color.g.toPrecision(2));
  1857. color.b = parseFloat(color.b.toPrecision(2));
  1858. _this.pline.validateInput(color);
  1859. scheduler.pause = false;
  1860. });
  1861. _this._div.appendChild(_this._input);
  1862. _this._input.addEventListener('click', function (e) {
  1863. scheduler.pause = true;
  1864. });
  1865. return _this;
  1866. }
  1867. ColorPickerElement.prototype.update = function (color) {
  1868. if (color) {
  1869. this._div.style.backgroundColor = this._toRgba(color);
  1870. this._input.value = color.toHexString();
  1871. }
  1872. };
  1873. ColorPickerElement.prototype._toRgba = function (color) {
  1874. if (color) {
  1875. var r = (color.r * 255) | 0;
  1876. var g = (color.g * 255) | 0;
  1877. var b = (color.b * 255) | 0;
  1878. var a = 1;
  1879. if (color instanceof BABYLON.Color4) {
  1880. a = color.a;
  1881. }
  1882. return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
  1883. }
  1884. else {
  1885. return '';
  1886. }
  1887. };
  1888. return ColorPickerElement;
  1889. }(INSPECTOR.BasicElement));
  1890. INSPECTOR.ColorPickerElement = ColorPickerElement;
  1891. })(INSPECTOR || (INSPECTOR = {}));
  1892. var __extends = (this && this.__extends) || (function () {
  1893. var extendStatics = Object.setPrototypeOf ||
  1894. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1895. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1896. return function (d, b) {
  1897. extendStatics(d, b);
  1898. function __() { this.constructor = d; }
  1899. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1900. };
  1901. })();
  1902. var INSPECTOR;
  1903. (function (INSPECTOR) {
  1904. /**
  1905. * Display a very small div. A new canvas is created, with a new Babylon.js scene, containing only the
  1906. * cube texture in a cube
  1907. */
  1908. var CubeTextureElement = /** @class */ (function (_super) {
  1909. __extends(CubeTextureElement, _super);
  1910. /** The texture given as a parameter should be cube. */
  1911. function CubeTextureElement(tex) {
  1912. var _this = _super.call(this) || this;
  1913. // On pause the engine will not render anything
  1914. _this._pause = false;
  1915. _this._div.className = 'fa fa-search texture-element';
  1916. // Create the texture viewer
  1917. _this._textureDiv = INSPECTOR.Helpers.CreateDiv('texture-viewer', _this._div);
  1918. // canvas
  1919. _this._canvas = INSPECTOR.Helpers.CreateElement('canvas', 'texture-viewer-img', _this._textureDiv);
  1920. if (tex) {
  1921. _this._textureUrl = tex.name;
  1922. }
  1923. _this._div.addEventListener('mouseover', _this._showViewer.bind(_this, 'flex'));
  1924. _this._div.addEventListener('mouseout', _this._showViewer.bind(_this, 'none'));
  1925. return _this;
  1926. }
  1927. CubeTextureElement.prototype.update = function (tex) {
  1928. if (tex && tex.url === this._textureUrl) {
  1929. // Nothing to do, as the old texture is the same as the old one
  1930. }
  1931. else {
  1932. if (tex) {
  1933. this._textureUrl = tex.name;
  1934. }
  1935. if (this._engine) {
  1936. // Dispose old material and cube
  1937. if (this._cube.material) {
  1938. this._cube.material.dispose(true, true);
  1939. }
  1940. this._cube.dispose();
  1941. }
  1942. else {
  1943. this._initEngine();
  1944. }
  1945. // and create it again
  1946. this._populateScene();
  1947. }
  1948. };
  1949. /** Creates the box */
  1950. CubeTextureElement.prototype._populateScene = function () {
  1951. var _this = this;
  1952. // Create the hdr texture
  1953. var hdrTexture = new BABYLON.CubeTexture(this._textureUrl, this._scene);
  1954. hdrTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  1955. this._cube = BABYLON.Mesh.CreateBox("hdrSkyBox", 10.0, this._scene);
  1956. var hdrSkyboxMaterial = new BABYLON.StandardMaterial("skyBox", this._scene);
  1957. hdrSkyboxMaterial.backFaceCulling = false;
  1958. hdrSkyboxMaterial.reflectionTexture = hdrTexture;
  1959. hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  1960. hdrSkyboxMaterial.disableLighting = true;
  1961. this._cube.material = hdrSkyboxMaterial;
  1962. this._cube.registerBeforeRender(function () {
  1963. _this._cube.rotation.y += 0.01;
  1964. });
  1965. };
  1966. /** Init the babylon engine */
  1967. CubeTextureElement.prototype._initEngine = function () {
  1968. var _this = this;
  1969. this._engine = new BABYLON.Engine(this._canvas);
  1970. this._scene = new BABYLON.Scene(this._engine);
  1971. this._scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
  1972. this._engine.runRenderLoop(function () {
  1973. if (!_this._pause) {
  1974. _this._scene.render();
  1975. }
  1976. });
  1977. this._canvas.setAttribute('width', '110');
  1978. this._canvas.setAttribute('height', '110');
  1979. };
  1980. CubeTextureElement.prototype._showViewer = function (mode) {
  1981. // If displaying...
  1982. if (mode != 'none') {
  1983. // ... and the canvas is not initialized
  1984. if (!this._engine) {
  1985. this._initEngine();
  1986. this._populateScene();
  1987. }
  1988. // In every cases, unpause the engine
  1989. this._pause = false;
  1990. }
  1991. else {
  1992. // hide : pause the engine
  1993. this._pause = true;
  1994. }
  1995. this._textureDiv.style.display = mode;
  1996. };
  1997. /** Removes properly the babylon engine */
  1998. CubeTextureElement.prototype.dispose = function () {
  1999. if (this._engine) {
  2000. this._engine.dispose();
  2001. this._engine = null;
  2002. }
  2003. };
  2004. return CubeTextureElement;
  2005. }(INSPECTOR.BasicElement));
  2006. INSPECTOR.CubeTextureElement = CubeTextureElement;
  2007. })(INSPECTOR || (INSPECTOR = {}));
  2008. var __extends = (this && this.__extends) || (function () {
  2009. var extendStatics = Object.setPrototypeOf ||
  2010. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2011. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2012. return function (d, b) {
  2013. extendStatics(d, b);
  2014. function __() { this.constructor = d; }
  2015. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2016. };
  2017. })();
  2018. var INSPECTOR;
  2019. (function (INSPECTOR) {
  2020. /**
  2021. * Display a very small div. A new canvas is created, with a new Babylon.js scene, containing only the
  2022. * cube texture in a cube
  2023. */
  2024. var HDRCubeTextureElement = /** @class */ (function (_super) {
  2025. __extends(HDRCubeTextureElement, _super);
  2026. /** The texture given as a parameter should be cube. */
  2027. function HDRCubeTextureElement(tex) {
  2028. return _super.call(this, tex) || this;
  2029. }
  2030. /** Creates the box */
  2031. HDRCubeTextureElement.prototype._populateScene = function () {
  2032. var _this = this;
  2033. // Create the hdr texture
  2034. var hdrTexture = new BABYLON.HDRCubeTexture(this._textureUrl, this._scene, 512);
  2035. hdrTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  2036. this._cube = BABYLON.Mesh.CreateBox("hdrSkyBox", 10.0, this._scene);
  2037. var hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", this._scene);
  2038. hdrSkyboxMaterial.backFaceCulling = false;
  2039. hdrSkyboxMaterial.reflectionTexture = hdrTexture;
  2040. hdrSkyboxMaterial.microSurface = 1.0;
  2041. hdrSkyboxMaterial.disableLighting = true;
  2042. this._cube.material = hdrSkyboxMaterial;
  2043. this._cube.registerBeforeRender(function () {
  2044. _this._cube.rotation.y += 0.01;
  2045. });
  2046. };
  2047. return HDRCubeTextureElement;
  2048. }(INSPECTOR.CubeTextureElement));
  2049. INSPECTOR.HDRCubeTextureElement = HDRCubeTextureElement;
  2050. })(INSPECTOR || (INSPECTOR = {}));
  2051. var __extends = (this && this.__extends) || (function () {
  2052. var extendStatics = Object.setPrototypeOf ||
  2053. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2054. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2055. return function (d, b) {
  2056. extendStatics(d, b);
  2057. function __() { this.constructor = d; }
  2058. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2059. };
  2060. })();
  2061. var INSPECTOR;
  2062. (function (INSPECTOR) {
  2063. /**
  2064. * A search bar can be used to filter elements in the tree panel.
  2065. * At each keypress on the input, the treepanel will be filtered.
  2066. */
  2067. var SearchBar = /** @class */ (function (_super) {
  2068. __extends(SearchBar, _super);
  2069. function SearchBar(tab) {
  2070. var _this = _super.call(this) || this;
  2071. _this._tab = tab;
  2072. _this._div.classList.add('searchbar');
  2073. var filter = INSPECTOR.Inspector.DOCUMENT.createElement('i');
  2074. filter.className = 'fa fa-search';
  2075. _this._div.appendChild(filter);
  2076. // Create input
  2077. _this._inputElement = INSPECTOR.Inspector.DOCUMENT.createElement('input');
  2078. _this._inputElement.placeholder = 'Filter by name...';
  2079. _this._div.appendChild(_this._inputElement);
  2080. _this._inputElement.addEventListener('keyup', function (evt) {
  2081. var filter = _this._inputElement.value;
  2082. _this._tab.filter(filter);
  2083. });
  2084. return _this;
  2085. }
  2086. /** Delete all characters typped in the input element */
  2087. SearchBar.prototype.reset = function () {
  2088. this._inputElement.value = '';
  2089. };
  2090. SearchBar.prototype.update = function () {
  2091. // Nothing to update
  2092. };
  2093. return SearchBar;
  2094. }(INSPECTOR.BasicElement));
  2095. INSPECTOR.SearchBar = SearchBar;
  2096. })(INSPECTOR || (INSPECTOR = {}));
  2097. var __extends = (this && this.__extends) || (function () {
  2098. var extendStatics = Object.setPrototypeOf ||
  2099. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2100. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2101. return function (d, b) {
  2102. extendStatics(d, b);
  2103. function __() { this.constructor = d; }
  2104. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2105. };
  2106. })();
  2107. var INSPECTOR;
  2108. (function (INSPECTOR) {
  2109. /**
  2110. * Display a very small div corresponding to the given texture. On mouse over, display the full image
  2111. */
  2112. var TextureElement = /** @class */ (function (_super) {
  2113. __extends(TextureElement, _super);
  2114. function TextureElement(tex) {
  2115. var _this = _super.call(this) || this;
  2116. _this._div.className = 'fa fa-search texture-element';
  2117. // Create the texture viewer
  2118. _this._textureDiv = INSPECTOR.Helpers.CreateDiv('texture-viewer', _this._div);
  2119. // Img
  2120. var imgDiv = INSPECTOR.Helpers.CreateDiv('texture-viewer-img', _this._textureDiv);
  2121. // Texture size
  2122. var sizeDiv = INSPECTOR.Helpers.CreateDiv(null, _this._textureDiv);
  2123. if (tex) {
  2124. sizeDiv.textContent = tex.getBaseSize().width + "px x " + tex.getBaseSize().height + "px";
  2125. imgDiv.style.backgroundImage = "url('" + tex.url + "')";
  2126. imgDiv.style.width = tex.getBaseSize().width + "px";
  2127. imgDiv.style.height = tex.getBaseSize().height + "px";
  2128. }
  2129. _this._div.addEventListener('mouseover', _this._showViewer.bind(_this, 'flex'));
  2130. _this._div.addEventListener('mouseout', _this._showViewer.bind(_this, 'none'));
  2131. return _this;
  2132. }
  2133. TextureElement.prototype.update = function (tex) {
  2134. };
  2135. TextureElement.prototype._showViewer = function (mode) {
  2136. this._textureDiv.style.display = mode;
  2137. };
  2138. return TextureElement;
  2139. }(INSPECTOR.BasicElement));
  2140. INSPECTOR.TextureElement = TextureElement;
  2141. })(INSPECTOR || (INSPECTOR = {}));
  2142. var INSPECTOR;
  2143. (function (INSPECTOR) {
  2144. /**
  2145. * Creates a tooltip for the parent of the given html element
  2146. */
  2147. var Tooltip = /** @class */ (function () {
  2148. function Tooltip(elem, tip, attachTo) {
  2149. if (attachTo === void 0) { attachTo = null; }
  2150. var _this = this;
  2151. this._elem = elem;
  2152. if (!attachTo) {
  2153. attachTo = this._elem.parentElement;
  2154. }
  2155. this._infoDiv = INSPECTOR.Helpers.CreateDiv('tooltip', attachTo);
  2156. this._elem.addEventListener('mouseover', function () {
  2157. _this._infoDiv.textContent = tip;
  2158. _this._infoDiv.style.display = 'block';
  2159. });
  2160. this._elem.addEventListener('mouseout', function () { _this._infoDiv.style.display = 'none'; });
  2161. }
  2162. return Tooltip;
  2163. }());
  2164. INSPECTOR.Tooltip = Tooltip;
  2165. })(INSPECTOR || (INSPECTOR = {}));
  2166. var INSPECTOR;
  2167. (function (INSPECTOR) {
  2168. var Helpers = /** @class */ (function () {
  2169. function Helpers() {
  2170. }
  2171. /**
  2172. * Returns the type of the given object. First
  2173. * uses getClassName. If nothing is returned, used the type of the constructor
  2174. */
  2175. Helpers.GET_TYPE = function (obj) {
  2176. if (typeof obj === 'boolean') {
  2177. return 'boolean';
  2178. }
  2179. if (obj != null && obj != undefined) {
  2180. var classname = BABYLON.Tools.GetClassName(obj);
  2181. if (!classname || classname === 'object') {
  2182. classname = obj.constructor.name;
  2183. // classname is undefined in IE11
  2184. if (!classname) {
  2185. classname = this._GetFnName(obj.constructor);
  2186. }
  2187. }
  2188. // If the class name has no matching properties, check every type
  2189. if (!this._CheckIfTypeExists(classname)) {
  2190. return this._GetTypeFor(obj);
  2191. }
  2192. return classname;
  2193. }
  2194. else {
  2195. return 'type_not_defined';
  2196. }
  2197. };
  2198. /**
  2199. * Check if some properties are defined for the given type.
  2200. */
  2201. Helpers._CheckIfTypeExists = function (type) {
  2202. var properties = INSPECTOR.PROPERTIES[type];
  2203. if (properties) {
  2204. return true;
  2205. }
  2206. return false;
  2207. };
  2208. /**
  2209. * Returns true if the user browser is edge.
  2210. */
  2211. Helpers.IsBrowserEdge = function () {
  2212. //Detect if we are running on a faulty buggy OS.
  2213. var regexp = /Edge/;
  2214. return regexp.test(navigator.userAgent);
  2215. };
  2216. /**
  2217. * Returns the name of the type of the given object, where the name
  2218. * is in PROPERTIES constant.
  2219. * Returns 'Undefined' if no type exists for this object
  2220. */
  2221. Helpers._GetTypeFor = function (obj) {
  2222. for (var type in INSPECTOR.PROPERTIES) {
  2223. var typeBlock = INSPECTOR.PROPERTIES[type];
  2224. if (typeBlock.type) {
  2225. if (obj instanceof typeBlock.type) {
  2226. return type;
  2227. }
  2228. }
  2229. }
  2230. return 'type_not_defined';
  2231. };
  2232. /**
  2233. * Returns the name of a function (workaround to get object type for IE11)
  2234. */
  2235. Helpers._GetFnName = function (fn) {
  2236. var f = typeof fn == 'function';
  2237. var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
  2238. return (!f && 'not a function') || (s && s[1] || 'anonymous');
  2239. };
  2240. /** Send the event which name is given in parameter to the window */
  2241. Helpers.SEND_EVENT = function (eventName) {
  2242. var event;
  2243. if (INSPECTOR.Inspector.DOCUMENT.createEvent) {
  2244. event = INSPECTOR.Inspector.DOCUMENT.createEvent('HTMLEvents');
  2245. event.initEvent(eventName, true, true);
  2246. }
  2247. else {
  2248. event = new Event(eventName);
  2249. }
  2250. window.dispatchEvent(event);
  2251. };
  2252. /** Returns the given number with 2 decimal number max if a decimal part exists */
  2253. Helpers.Trunc = function (nb) {
  2254. if (typeof nb !== 'number') {
  2255. return 0;
  2256. }
  2257. if (Math.round(nb) !== nb) {
  2258. return nb.toFixed(2);
  2259. }
  2260. return nb;
  2261. };
  2262. ;
  2263. /**
  2264. * Useful function used to create a div
  2265. */
  2266. Helpers.CreateDiv = function (className, parent) {
  2267. if (className === void 0) { className = null; }
  2268. return Helpers.CreateElement('div', className, parent);
  2269. };
  2270. /**
  2271. * Useful function used to create a input
  2272. */
  2273. Helpers.CreateInput = function (className, parent) {
  2274. return Helpers.CreateElement('input', className, parent);
  2275. };
  2276. Helpers.CreateElement = function (element, className, parent) {
  2277. if (className === void 0) { className = null; }
  2278. var elem = INSPECTOR.Inspector.DOCUMENT.createElement(element);
  2279. if (className) {
  2280. elem.className = className;
  2281. }
  2282. if (parent) {
  2283. parent.appendChild(elem);
  2284. }
  2285. return elem;
  2286. };
  2287. /**
  2288. * Removes all children of the given div.
  2289. */
  2290. Helpers.CleanDiv = function (div) {
  2291. while (div.firstChild) {
  2292. div.removeChild(div.firstChild);
  2293. }
  2294. };
  2295. /**
  2296. * Returns the true value of the given CSS Attribute from the given element (in percentage or in pixel, as it was specified in the css)
  2297. */
  2298. Helpers.Css = function (elem, cssAttribute) {
  2299. var clone = elem.cloneNode(true);
  2300. var div = Helpers.CreateDiv('', INSPECTOR.Inspector.DOCUMENT.body);
  2301. div.style.display = 'none';
  2302. div.appendChild(clone);
  2303. var value = INSPECTOR.Inspector.WINDOW.getComputedStyle(clone)[cssAttribute];
  2304. if (div.parentNode) {
  2305. div.parentNode.removeChild(div);
  2306. }
  2307. return value;
  2308. };
  2309. Helpers.LoadScript = function () {
  2310. BABYLON.Tools.LoadFile("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js", function (elem) {
  2311. var script = Helpers.CreateElement('script', '', INSPECTOR.Inspector.DOCUMENT.body);
  2312. script.textContent = elem;
  2313. // Load glsl detection
  2314. BABYLON.Tools.LoadFile("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/languages/glsl.min.js", function (elem) {
  2315. var script = Helpers.CreateElement('script', '', INSPECTOR.Inspector.DOCUMENT.body);
  2316. script.textContent = elem;
  2317. // Load css style
  2318. BABYLON.Tools.LoadFile("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/zenburn.min.css", function (elem) {
  2319. var style = Helpers.CreateElement('style', '', INSPECTOR.Inspector.DOCUMENT.body);
  2320. style.textContent = elem;
  2321. });
  2322. }, undefined, undefined, undefined, function () {
  2323. console.log("erreur");
  2324. });
  2325. }, undefined, undefined, undefined, function () {
  2326. console.log("erreur");
  2327. });
  2328. };
  2329. Helpers.IsSystemName = function (name) {
  2330. if (name == null) {
  2331. return false;
  2332. }
  2333. return name.indexOf("###") === 0 && name.lastIndexOf("###") === (name.length - 3);
  2334. };
  2335. /**
  2336. * Return an array of PropertyLine for an obj
  2337. * @param obj
  2338. */
  2339. Helpers.GetAllLinesProperties = function (obj) {
  2340. var propertiesLines = [];
  2341. var props = Helpers.GetAllLinesPropertiesAsString(obj);
  2342. for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
  2343. var prop = props_1[_i];
  2344. var infos = new INSPECTOR.Property(prop, obj);
  2345. propertiesLines.push(new INSPECTOR.PropertyLine(infos));
  2346. }
  2347. return propertiesLines;
  2348. };
  2349. /**
  2350. * Returns an array of string corresponding to tjhe list of properties of the object to be displayed
  2351. * @param obj
  2352. */
  2353. Helpers.GetAllLinesPropertiesAsString = function (obj, dontTakeThis) {
  2354. if (dontTakeThis === void 0) { dontTakeThis = []; }
  2355. var props = [];
  2356. for (var prop in obj) {
  2357. //No private and no function
  2358. if (dontTakeThis.indexOf(prop) === -1 && prop.substring(0, 1) !== '_' && typeof obj[prop] !== 'function') {
  2359. props.push(prop);
  2360. }
  2361. }
  2362. return props;
  2363. };
  2364. Helpers.Capitalize = function (str) {
  2365. return str.charAt(0).toUpperCase() + str.slice(1);
  2366. };
  2367. return Helpers;
  2368. }());
  2369. INSPECTOR.Helpers = Helpers;
  2370. })(INSPECTOR || (INSPECTOR = {}));
  2371. var INSPECTOR;
  2372. (function (INSPECTOR) {
  2373. var Scheduler = /** @class */ (function () {
  2374. function Scheduler() {
  2375. /** Is this scheduler in pause ? */
  2376. this.pause = false;
  2377. /** The list of data to update */
  2378. this._updatableProperties = [];
  2379. setInterval(this._update.bind(this), Scheduler.REFRESH_TIME);
  2380. }
  2381. Scheduler.getInstance = function () {
  2382. if (!Scheduler._instance) {
  2383. Scheduler._instance = new Scheduler();
  2384. }
  2385. return Scheduler._instance;
  2386. };
  2387. /** Add a property line to be updated every X ms */
  2388. Scheduler.prototype.add = function (prop) {
  2389. this._updatableProperties.push(prop);
  2390. };
  2391. /** Removes the given property from the list of properties to update */
  2392. Scheduler.prototype.remove = function (prop) {
  2393. var index = this._updatableProperties.indexOf(prop);
  2394. if (index != -1) {
  2395. this._updatableProperties.splice(index, 1);
  2396. }
  2397. };
  2398. Scheduler.prototype._update = function () {
  2399. // If not in pause, update
  2400. if (!this.pause) {
  2401. for (var _i = 0, _a = this._updatableProperties; _i < _a.length; _i++) {
  2402. var prop = _a[_i];
  2403. prop.update();
  2404. }
  2405. }
  2406. };
  2407. /** All properties are refreshed every 250ms */
  2408. Scheduler.REFRESH_TIME = 250;
  2409. return Scheduler;
  2410. }());
  2411. INSPECTOR.Scheduler = Scheduler;
  2412. })(INSPECTOR || (INSPECTOR = {}));
  2413. var __extends = (this && this.__extends) || (function () {
  2414. var extendStatics = Object.setPrototypeOf ||
  2415. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2416. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2417. return function (d, b) {
  2418. extendStatics(d, b);
  2419. function __() { this.constructor = d; }
  2420. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2421. };
  2422. })();
  2423. var INSPECTOR;
  2424. (function (INSPECTOR) {
  2425. var Tab = /** @class */ (function (_super) {
  2426. __extends(Tab, _super);
  2427. function Tab(tabbar, name) {
  2428. var _this = _super.call(this) || this;
  2429. _this._isActive = false;
  2430. _this._tabbar = tabbar;
  2431. _this.name = name;
  2432. _this._build();
  2433. return _this;
  2434. }
  2435. /** True if the tab is active, false otherwise */
  2436. Tab.prototype.isActive = function () {
  2437. return this._isActive;
  2438. };
  2439. Tab.prototype._build = function () {
  2440. var _this = this;
  2441. this._div.className = 'tab';
  2442. this._div.textContent = this.name;
  2443. this._div.addEventListener('click', function (evt) {
  2444. // Set this tab as active
  2445. _this._tabbar.switchTab(_this);
  2446. });
  2447. };
  2448. /** Set this tab as active or not, depending on the current state */
  2449. Tab.prototype.active = function (b) {
  2450. if (b) {
  2451. this._div.classList.add('active');
  2452. }
  2453. else {
  2454. this._div.classList.remove('active');
  2455. }
  2456. this._isActive = b;
  2457. };
  2458. Tab.prototype.update = function () {
  2459. // Nothing for the moment
  2460. };
  2461. /** Creates the tab panel for this tab. */
  2462. Tab.prototype.getPanel = function () {
  2463. return this._panel;
  2464. };
  2465. /** Add this in the propertytab with the searchbar */
  2466. Tab.prototype.filter = function (str) { };
  2467. ;
  2468. /** Select an item in the tree */
  2469. Tab.prototype.select = function (item) {
  2470. // To define in subclasses if needed
  2471. };
  2472. /**
  2473. * Returns the total width in pixel of this tab, 0 by default
  2474. */
  2475. Tab.prototype.getPixelWidth = function () {
  2476. var style = INSPECTOR.Inspector.WINDOW.getComputedStyle(this._div);
  2477. if (!style.marginLeft || !style.marginRight) {
  2478. return 0;
  2479. }
  2480. var left = parseFloat(style.marginLeft.substr(0, style.marginLeft.length - 2)) || 0;
  2481. var right = parseFloat(style.marginRight.substr(0, style.marginRight.length - 2)) || 0;
  2482. return (this._div.clientWidth || 0) + left + right;
  2483. };
  2484. return Tab;
  2485. }(INSPECTOR.BasicElement));
  2486. INSPECTOR.Tab = Tab;
  2487. })(INSPECTOR || (INSPECTOR = {}));
  2488. var __extends = (this && this.__extends) || (function () {
  2489. var extendStatics = Object.setPrototypeOf ||
  2490. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2491. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2492. return function (d, b) {
  2493. extendStatics(d, b);
  2494. function __() { this.constructor = d; }
  2495. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2496. };
  2497. })();
  2498. var INSPECTOR;
  2499. (function (INSPECTOR) {
  2500. /**
  2501. * A Property tab can creates two panels:
  2502. * a tree panel and a detail panel,
  2503. * in which properties will be displayed.
  2504. * Both panels are separated by a resize bar
  2505. */
  2506. var PropertyTab = /** @class */ (function (_super) {
  2507. __extends(PropertyTab, _super);
  2508. function PropertyTab(tabbar, name, insp) {
  2509. var _this = _super.call(this, tabbar, name) || this;
  2510. _this._treeItems = [];
  2511. _this._inspector = insp;
  2512. // Build the properties panel : a div that will contains the tree and the detail panel
  2513. _this._panel = INSPECTOR.Helpers.CreateDiv('tab-panel');
  2514. _this._panel.classList.add('searchable');
  2515. // Search bar
  2516. _this._searchBar = new INSPECTOR.SearchBar(_this);
  2517. // Add searchbar
  2518. _this._panel.appendChild(_this._searchBar.toHtml());
  2519. // Build the treepanel
  2520. _this._treePanel = INSPECTOR.Helpers.CreateDiv('insp-tree', _this._panel);
  2521. // Build the detail panel
  2522. _this._detailsPanel = new INSPECTOR.DetailPanel();
  2523. _this._panel.appendChild(_this._detailsPanel.toHtml());
  2524. Split([_this._treePanel, _this._detailsPanel.toHtml()], {
  2525. blockDrag: _this._inspector.popupMode,
  2526. direction: 'vertical'
  2527. });
  2528. _this.update();
  2529. return _this;
  2530. }
  2531. /** Overrides dispose */
  2532. PropertyTab.prototype.dispose = function () {
  2533. this._detailsPanel.dispose();
  2534. };
  2535. PropertyTab.prototype.update = function (_items) {
  2536. var items;
  2537. if (_items) {
  2538. items = _items;
  2539. }
  2540. else {
  2541. // Rebuild the tree
  2542. this._treeItems = this._getTree();
  2543. items = this._treeItems;
  2544. }
  2545. // Clean the tree
  2546. INSPECTOR.Helpers.CleanDiv(this._treePanel);
  2547. // Clean the detail properties
  2548. this._detailsPanel.clean();
  2549. // Sort items alphabetically
  2550. items.sort(function (item1, item2) {
  2551. return item1.compareTo(item2);
  2552. });
  2553. // Display items
  2554. for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
  2555. var item = items_1[_i];
  2556. this._treePanel.appendChild(item.toHtml());
  2557. }
  2558. };
  2559. /** Display the details of the given item */
  2560. PropertyTab.prototype.displayDetails = function (item) {
  2561. // Remove active state on all items
  2562. this.activateNode(item);
  2563. // Update the detail panel
  2564. this._detailsPanel.details = item.getDetails();
  2565. };
  2566. /** Select an item in the tree */
  2567. PropertyTab.prototype.select = function (item) {
  2568. // Active the node
  2569. this.activateNode(item);
  2570. // Display its details
  2571. this.displayDetails(item);
  2572. };
  2573. /** Set the given item as active in the tree */
  2574. PropertyTab.prototype.activateNode = function (item) {
  2575. if (this._treeItems) {
  2576. for (var _i = 0, _a = this._treeItems; _i < _a.length; _i++) {
  2577. var node = _a[_i];
  2578. node.active(false);
  2579. }
  2580. }
  2581. item.getDiv().scrollIntoView();
  2582. item.active(true);
  2583. };
  2584. /** Returns the treeitem corersponding to the given obj, null if not found */
  2585. PropertyTab.prototype.getItemFor = function (_obj) {
  2586. var obj = _obj;
  2587. // Search recursively
  2588. var searchObjectInTree = function (object, treeItem) {
  2589. if (treeItem.correspondsTo(object)) {
  2590. return treeItem;
  2591. }
  2592. else {
  2593. if (treeItem.children.length > 0) {
  2594. for (var _i = 0, _a = treeItem.children; _i < _a.length; _i++) {
  2595. var item = _a[_i];
  2596. var it = searchObjectInTree(obj, item);
  2597. if (it) {
  2598. return it;
  2599. }
  2600. }
  2601. }
  2602. else {
  2603. return null;
  2604. }
  2605. }
  2606. return null;
  2607. };
  2608. for (var _i = 0, _a = this._treeItems; _i < _a.length; _i++) {
  2609. var item = _a[_i];
  2610. var it = searchObjectInTree(obj, item);
  2611. if (it) {
  2612. return it;
  2613. }
  2614. }
  2615. return null;
  2616. };
  2617. PropertyTab.prototype.filter = function (filter) {
  2618. var items = [];
  2619. for (var _i = 0, _a = this._treeItems; _i < _a.length; _i++) {
  2620. var item = _a[_i];
  2621. if (item.id.toLowerCase().indexOf(filter.toLowerCase()) != -1) {
  2622. items.push(item);
  2623. }
  2624. for (var _b = 0, _c = item.children; _b < _c.length; _b++) {
  2625. var child = _c[_b];
  2626. if (child.id.toLowerCase().indexOf(filter.toLowerCase()) != -1) {
  2627. items.push(item);
  2628. }
  2629. }
  2630. }
  2631. this.update(items);
  2632. };
  2633. return PropertyTab;
  2634. }(INSPECTOR.Tab));
  2635. INSPECTOR.PropertyTab = PropertyTab;
  2636. })(INSPECTOR || (INSPECTOR = {}));
  2637. var __extends = (this && this.__extends) || (function () {
  2638. var extendStatics = Object.setPrototypeOf ||
  2639. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2640. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2641. return function (d, b) {
  2642. extendStatics(d, b);
  2643. function __() { this.constructor = d; }
  2644. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2645. };
  2646. })();
  2647. var INSPECTOR;
  2648. (function (INSPECTOR) {
  2649. var CameraTab = /** @class */ (function (_super) {
  2650. __extends(CameraTab, _super);
  2651. function CameraTab(tabbar, inspector) {
  2652. return _super.call(this, tabbar, 'Camera', inspector) || this;
  2653. }
  2654. /* Overrides super */
  2655. CameraTab.prototype._getTree = function () {
  2656. var arr = [];
  2657. // get all cameras from the first scene
  2658. var instances = this._inspector.scene;
  2659. for (var _i = 0, _a = instances.cameras; _i < _a.length; _i++) {
  2660. var camera = _a[_i];
  2661. arr.push(new INSPECTOR.TreeItem(this, new INSPECTOR.CameraAdapter(camera)));
  2662. }
  2663. return arr;
  2664. };
  2665. return CameraTab;
  2666. }(INSPECTOR.PropertyTab));
  2667. INSPECTOR.CameraTab = CameraTab;
  2668. })(INSPECTOR || (INSPECTOR = {}));
  2669. var __extends = (this && this.__extends) || (function () {
  2670. var extendStatics = Object.setPrototypeOf ||
  2671. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2672. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2673. return function (d, b) {
  2674. extendStatics(d, b);
  2675. function __() { this.constructor = d; }
  2676. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2677. };
  2678. })();
  2679. var INSPECTOR;
  2680. (function (INSPECTOR) {
  2681. var GUITab = /** @class */ (function (_super) {
  2682. __extends(GUITab, _super);
  2683. function GUITab(tabbar, inspector) {
  2684. return _super.call(this, tabbar, 'GUI', inspector) || this;
  2685. }
  2686. /* Overrides super */
  2687. GUITab.prototype._getTree = function () {
  2688. var _this = this;
  2689. var arr = [];
  2690. // Recursive method building the tree panel
  2691. var createNode = function (obj) {
  2692. var descendants = obj.children;
  2693. if (descendants && descendants.length > 0) {
  2694. var node = new INSPECTOR.TreeItem(_this, new INSPECTOR.GUIAdapter(obj));
  2695. for (var _i = 0, descendants_1 = descendants; _i < descendants_1.length; _i++) {
  2696. var child = descendants_1[_i];
  2697. var n = createNode(child);
  2698. node.add(n);
  2699. }
  2700. node.update();
  2701. return node;
  2702. }
  2703. else {
  2704. return new INSPECTOR.TreeItem(_this, new INSPECTOR.GUIAdapter(obj));
  2705. }
  2706. };
  2707. // get all textures from the first scene
  2708. var instances = this._inspector.scene;
  2709. for (var _i = 0, _a = instances.textures; _i < _a.length; _i++) {
  2710. var tex = _a[_i];
  2711. //only get GUI's textures
  2712. if (tex instanceof BABYLON.GUI.AdvancedDynamicTexture) {
  2713. var node = createNode(tex._rootContainer);
  2714. arr.push(node);
  2715. }
  2716. }
  2717. return arr;
  2718. };
  2719. return GUITab;
  2720. }(INSPECTOR.PropertyTab));
  2721. INSPECTOR.GUITab = GUITab;
  2722. })(INSPECTOR || (INSPECTOR = {}));
  2723. var __extends = (this && this.__extends) || (function () {
  2724. var extendStatics = Object.setPrototypeOf ||
  2725. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2726. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2727. return function (d, b) {
  2728. extendStatics(d, b);
  2729. function __() { this.constructor = d; }
  2730. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2731. };
  2732. })();
  2733. var INSPECTOR;
  2734. (function (INSPECTOR) {
  2735. var PhysicsTab = /** @class */ (function (_super) {
  2736. __extends(PhysicsTab, _super);
  2737. function PhysicsTab(tabbar, inspector) {
  2738. return _super.call(this, tabbar, 'Physics', inspector) || this;
  2739. }
  2740. /* Overrides super */
  2741. PhysicsTab.prototype._getTree = function () {
  2742. var arr = new Array();
  2743. var scene = this._inspector.scene;
  2744. if (!scene.isPhysicsEnabled()) {
  2745. return arr;
  2746. }
  2747. if (!this.viewer) {
  2748. this.viewer = new BABYLON.Debug.PhysicsViewer(scene);
  2749. }
  2750. for (var _i = 0, _a = scene.meshes; _i < _a.length; _i++) {
  2751. var mesh = _a[_i];
  2752. if (mesh.physicsImpostor) {
  2753. arr.push(new INSPECTOR.TreeItem(this, new INSPECTOR.PhysicsImpostorAdapter(mesh.physicsImpostor, this.viewer)));
  2754. }
  2755. }
  2756. return arr;
  2757. };
  2758. return PhysicsTab;
  2759. }(INSPECTOR.PropertyTab));
  2760. INSPECTOR.PhysicsTab = PhysicsTab;
  2761. })(INSPECTOR || (INSPECTOR = {}));
  2762. var __extends = (this && this.__extends) || (function () {
  2763. var extendStatics = Object.setPrototypeOf ||
  2764. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2765. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2766. return function (d, b) {
  2767. extendStatics(d, b);
  2768. function __() { this.constructor = d; }
  2769. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2770. };
  2771. })();
  2772. var INSPECTOR;
  2773. (function (INSPECTOR) {
  2774. var SoundTab = /** @class */ (function (_super) {
  2775. __extends(SoundTab, _super);
  2776. function SoundTab(tabbar, inspector) {
  2777. return _super.call(this, tabbar, 'Audio', inspector) || this;
  2778. }
  2779. /* Overrides super */
  2780. SoundTab.prototype._getTree = function () {
  2781. var _this = this;
  2782. var arr = new Array();
  2783. // get all cameras from the first scene
  2784. var instances = this._inspector.scene;
  2785. for (var _i = 0, _a = instances.soundTracks; _i < _a.length; _i++) {
  2786. var sounds = _a[_i];
  2787. var sound = sounds.soundCollection;
  2788. sound.forEach(function (element) {
  2789. arr.push(new INSPECTOR.TreeItem(_this, new INSPECTOR.SoundAdapter(element)));
  2790. });
  2791. }
  2792. return arr;
  2793. };
  2794. return SoundTab;
  2795. }(INSPECTOR.PropertyTab));
  2796. INSPECTOR.SoundTab = SoundTab;
  2797. })(INSPECTOR || (INSPECTOR = {}));
  2798. var __extends = (this && this.__extends) || (function () {
  2799. var extendStatics = Object.setPrototypeOf ||
  2800. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2801. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2802. return function (d, b) {
  2803. extendStatics(d, b);
  2804. function __() { this.constructor = d; }
  2805. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2806. };
  2807. })();
  2808. var INSPECTOR;
  2809. (function (INSPECTOR) {
  2810. var TextureTab = /** @class */ (function (_super) {
  2811. __extends(TextureTab, _super);
  2812. function TextureTab(tabbar, inspector) {
  2813. var _this = _super.call(this, tabbar, 'Textures') || this;
  2814. _this._treeItems = [];
  2815. _this._inspector = inspector;
  2816. // Build the properties panel : a div that will contains the tree and the detail panel
  2817. _this._panel = INSPECTOR.Helpers.CreateDiv('tab-panel');
  2818. // Build the treepanel
  2819. _this._treePanel = INSPECTOR.Helpers.CreateDiv('insp-tree', _this._panel);
  2820. _this._imagePanel = INSPECTOR.Helpers.CreateDiv('insp-details', _this._panel);
  2821. Split([_this._treePanel, _this._imagePanel], {
  2822. blockDrag: _this._inspector.popupMode,
  2823. direction: 'vertical'
  2824. });
  2825. _this.update();
  2826. return _this;
  2827. }
  2828. TextureTab.prototype.dispose = function () {
  2829. // Nothing to dispose
  2830. };
  2831. TextureTab.prototype.update = function (_items) {
  2832. var items;
  2833. if (_items) {
  2834. items = _items;
  2835. }
  2836. else {
  2837. // Rebuild the tree
  2838. this._treeItems = this._getTree();
  2839. items = this._treeItems;
  2840. }
  2841. // Clean the tree
  2842. INSPECTOR.Helpers.CleanDiv(this._treePanel);
  2843. INSPECTOR.Helpers.CleanDiv(this._imagePanel);
  2844. // Sort items alphabetically
  2845. items.sort(function (item1, item2) {
  2846. return item1.compareTo(item2);
  2847. });
  2848. // Display items
  2849. for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
  2850. var item = items_1[_i];
  2851. this._treePanel.appendChild(item.toHtml());
  2852. }
  2853. };
  2854. /* Overrides super */
  2855. TextureTab.prototype._getTree = function () {
  2856. var arr = [];
  2857. // get all cameras from the first scene
  2858. var instances = this._inspector.scene;
  2859. for (var _i = 0, _a = instances.textures; _i < _a.length; _i++) {
  2860. var tex = _a[_i];
  2861. arr.push(new INSPECTOR.TreeItem(this, new INSPECTOR.TextureAdapter(tex)));
  2862. }
  2863. return arr;
  2864. };
  2865. /** Display the details of the given item */
  2866. TextureTab.prototype.displayDetails = function (item) {
  2867. // Remove active state on all items
  2868. this.activateNode(item);
  2869. INSPECTOR.Helpers.CleanDiv(this._imagePanel);
  2870. // Get the texture object
  2871. var texture = item.adapter.object;
  2872. var imgs = [];
  2873. var img = INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel);
  2874. imgs.push(img);
  2875. //Create five other images elements
  2876. for (var i = 0; i < 5; i++) {
  2877. imgs.push(INSPECTOR.Helpers.CreateElement('img', 'texture-image', this._imagePanel));
  2878. }
  2879. if (texture instanceof BABYLON.RenderTargetTexture) {
  2880. // RenderTarget textures
  2881. var scene = this._inspector.scene;
  2882. var engine_1 = scene.getEngine();
  2883. var size_1 = texture.getSize();
  2884. // Clone the texture
  2885. var screenShotTexture = texture.clone();
  2886. screenShotTexture.activeCamera = texture.activeCamera;
  2887. screenShotTexture.onBeforeRender = texture.onBeforeRender;
  2888. screenShotTexture.onAfterRender = texture.onAfterRender;
  2889. screenShotTexture.onBeforeRenderObservable = texture.onBeforeRenderObservable;
  2890. // To display the texture after rendering
  2891. screenShotTexture.onAfterRenderObservable.add(function (faceIndex) {
  2892. BABYLON.Tools.DumpFramebuffer(size_1.width, size_1.height, engine_1, function (data) { return imgs[faceIndex].src = data; });
  2893. });
  2894. // Render the texture
  2895. scene.incrementRenderId();
  2896. scene.resetCachedMaterial();
  2897. screenShotTexture.render();
  2898. screenShotTexture.dispose();
  2899. }
  2900. else if (texture instanceof BABYLON.CubeTexture) {
  2901. // Cannot open correctly DDS File
  2902. // Display all textures of the CubeTexture
  2903. var pixels = texture.readPixels();
  2904. var canvas = document.createElement('canvas');
  2905. canvas.id = "MyCanvas";
  2906. if (img.parentElement) {
  2907. img.parentElement.appendChild(canvas);
  2908. }
  2909. var ctx = canvas.getContext('2d');
  2910. var size = texture.getSize();
  2911. var tmp = pixels.buffer.slice(0, size.height * size.width * 4);
  2912. var u = new Uint8ClampedArray(tmp);
  2913. var colors = new ImageData(size.width * 6, size.height);
  2914. colors.data.set(u);
  2915. var imgData = ctx.createImageData(size.width * 6, size.height);
  2916. imgData.data.set(u);
  2917. // let data = imgData.data;
  2918. // for(let i = 0, len = size.height * size.width; i < len; i++) {
  2919. // data[i] = pixels[i];
  2920. // }
  2921. ctx.putImageData(imgData, 0, 0);
  2922. // let i: number = 0;
  2923. // for(let filename of (texture as BABYLON.CubeTexture)['_files']){
  2924. // imgs[i].src = filename;
  2925. // i++;
  2926. // }
  2927. }
  2928. else if (texture['_canvas']) {
  2929. // Dynamic texture
  2930. var base64Image = texture['_canvas'].toDataURL("image/png");
  2931. img.src = base64Image;
  2932. }
  2933. else if (texture.url) {
  2934. var pixels = texture.readPixels();
  2935. var canvas = document.createElement('canvas');
  2936. canvas.id = "MyCanvas";
  2937. if (img.parentElement) {
  2938. img.parentElement.appendChild(canvas);
  2939. }
  2940. var ctx = canvas.getContext('2d');
  2941. var size = texture.getSize();
  2942. var imgData = ctx.createImageData(size.width, size.height);
  2943. imgData.data.set(pixels);
  2944. ctx.putImageData(imgData, 0, 0);
  2945. // If an url is present, the texture is an image
  2946. // img.src = texture.url;
  2947. }
  2948. };
  2949. /** Select an item in the tree */
  2950. TextureTab.prototype.select = function (item) {
  2951. // Active the node
  2952. this.activateNode(item);
  2953. // Display its details
  2954. this.displayDetails(item);
  2955. };
  2956. /** Set the given item as active in the tree */
  2957. TextureTab.prototype.activateNode = function (item) {
  2958. if (this._treeItems) {
  2959. for (var _i = 0, _a = this._treeItems; _i < _a.length; _i++) {
  2960. var node = _a[_i];
  2961. node.active(false);
  2962. }
  2963. }
  2964. item.active(true);
  2965. };
  2966. return TextureTab;
  2967. }(INSPECTOR.Tab));
  2968. INSPECTOR.TextureTab = TextureTab;
  2969. })(INSPECTOR || (INSPECTOR = {}));
  2970. var __extends = (this && this.__extends) || (function () {
  2971. var extendStatics = Object.setPrototypeOf ||
  2972. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2973. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2974. return function (d, b) {
  2975. extendStatics(d, b);
  2976. function __() { this.constructor = d; }
  2977. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2978. };
  2979. })();
  2980. var INSPECTOR;
  2981. (function (INSPECTOR) {
  2982. var LightTab = /** @class */ (function (_super) {
  2983. __extends(LightTab, _super);
  2984. function LightTab(tabbar, inspector) {
  2985. return _super.call(this, tabbar, 'Light', inspector) || this;
  2986. }
  2987. /* Overrides super */
  2988. LightTab.prototype._getTree = function () {
  2989. var arr = [];
  2990. // get all lights from the first scene
  2991. var instances = this._inspector.scene;
  2992. for (var _i = 0, _a = instances.lights; _i < _a.length; _i++) {
  2993. var light = _a[_i];
  2994. arr.push(new INSPECTOR.TreeItem(this, new INSPECTOR.LightAdapter(light)));
  2995. }
  2996. return arr;
  2997. };
  2998. return LightTab;
  2999. }(INSPECTOR.PropertyTab));
  3000. INSPECTOR.LightTab = LightTab;
  3001. })(INSPECTOR || (INSPECTOR = {}));
  3002. var __extends = (this && this.__extends) || (function () {
  3003. var extendStatics = Object.setPrototypeOf ||
  3004. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3005. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3006. return function (d, b) {
  3007. extendStatics(d, b);
  3008. function __() { this.constructor = d; }
  3009. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3010. };
  3011. })();
  3012. var INSPECTOR;
  3013. (function (INSPECTOR) {
  3014. var MaterialTab = /** @class */ (function (_super) {
  3015. __extends(MaterialTab, _super);
  3016. function MaterialTab(tabbar, inspector) {
  3017. return _super.call(this, tabbar, 'Material', inspector) || this;
  3018. }
  3019. /* Overrides super */
  3020. MaterialTab.prototype._getTree = function () {
  3021. var arr = [];
  3022. // get all meshes from the first scene
  3023. var instances = this._inspector.scene;
  3024. for (var _i = 0, _a = instances.materials; _i < _a.length; _i++) {
  3025. var mat = _a[_i];
  3026. arr.push(new INSPECTOR.TreeItem(this, new INSPECTOR.MaterialAdapter(mat)));
  3027. }
  3028. return arr;
  3029. };
  3030. return MaterialTab;
  3031. }(INSPECTOR.PropertyTab));
  3032. INSPECTOR.MaterialTab = MaterialTab;
  3033. })(INSPECTOR || (INSPECTOR = {}));
  3034. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3035. var __extends = (this && this.__extends) || (function () {
  3036. var extendStatics = Object.setPrototypeOf ||
  3037. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3038. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3039. return function (d, b) {
  3040. extendStatics(d, b);
  3041. function __() { this.constructor = d; }
  3042. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3043. };
  3044. })();
  3045. var INSPECTOR;
  3046. (function (INSPECTOR) {
  3047. var MeshTab = /** @class */ (function (_super) {
  3048. __extends(MeshTab, _super);
  3049. function MeshTab(tabbar, inspector) {
  3050. return _super.call(this, tabbar, 'Mesh', inspector) || this;
  3051. }
  3052. /* Overrides super */
  3053. MeshTab.prototype._getTree = function () {
  3054. var _this = this;
  3055. var arr = new Array();
  3056. // Tab containing mesh already in results
  3057. var alreadyIn = new Array();
  3058. // Recursive method building the tree panel
  3059. var createNode = function (obj) {
  3060. var descendants = obj.getDescendants(true);
  3061. var node = new INSPECTOR.TreeItem(_this, new INSPECTOR.MeshAdapter(obj));
  3062. if (descendants.length > 0) {
  3063. for (var _i = 0, descendants_1 = descendants; _i < descendants_1.length; _i++) {
  3064. var child = descendants_1[_i];
  3065. if (child instanceof BABYLON.TransformNode) {
  3066. if (!INSPECTOR.Helpers.IsSystemName(child.name)) {
  3067. var n = createNode(child);
  3068. node.add(n);
  3069. }
  3070. }
  3071. }
  3072. node.update();
  3073. }
  3074. // Retrieve the root node if the mesh is actually child of another mesh
  3075. // This can hapen if the child mesh has been created before the parent mesh
  3076. if (obj.parent != null && alreadyIn.indexOf(obj) != -1) {
  3077. var i = 0;
  3078. var notFound = true;
  3079. // Find and delete the root node standing for this mesh
  3080. while (i < arr.length && notFound) {
  3081. if (obj.name === arr[i].id) {
  3082. arr.splice(i, 1);
  3083. notFound = false;
  3084. }
  3085. i++;
  3086. }
  3087. }
  3088. alreadyIn.push(obj);
  3089. return node;
  3090. };
  3091. // get all meshes from the first scene
  3092. var instances = this._inspector.scene;
  3093. // Find top of hierarchy for meshes...
  3094. var meshWithoutAnyParent = [];
  3095. for (var _i = 0, _a = instances.meshes; _i < _a.length; _i++) {
  3096. var mesh = _a[_i];
  3097. // Not already in the array, not system name and no parent
  3098. if (meshWithoutAnyParent.indexOf(mesh) == -1 && !INSPECTOR.Helpers.IsSystemName(mesh.name) && !mesh.parent) {
  3099. meshWithoutAnyParent.push(mesh);
  3100. }
  3101. }
  3102. // ... and for transforms
  3103. for (var _b = 0, _c = instances.transformNodes; _b < _c.length; _b++) {
  3104. var tn = _c[_b];
  3105. // Not already in the array, not system name and no parent
  3106. if (meshWithoutAnyParent.indexOf(tn) == -1 && !INSPECTOR.Helpers.IsSystemName(tn.name) && !tn.parent) {
  3107. meshWithoutAnyParent.push(tn);
  3108. }
  3109. }
  3110. for (var _d = 0, meshWithoutAnyParent_1 = meshWithoutAnyParent; _d < meshWithoutAnyParent_1.length; _d++) {
  3111. var mesh = meshWithoutAnyParent_1[_d];
  3112. if (alreadyIn.indexOf(mesh) == -1 && !INSPECTOR.Helpers.IsSystemName(mesh.name)) {
  3113. var node = createNode(mesh);
  3114. arr.push(node);
  3115. }
  3116. }
  3117. return arr;
  3118. };
  3119. return MeshTab;
  3120. }(INSPECTOR.PropertyTab));
  3121. INSPECTOR.MeshTab = MeshTab;
  3122. })(INSPECTOR || (INSPECTOR = {}));
  3123. var __extends = (this && this.__extends) || (function () {
  3124. var extendStatics = Object.setPrototypeOf ||
  3125. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3126. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3127. return function (d, b) {
  3128. extendStatics(d, b);
  3129. function __() { this.constructor = d; }
  3130. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3131. };
  3132. })();
  3133. var INSPECTOR;
  3134. (function (INSPECTOR) {
  3135. var SceneTab = /** @class */ (function (_super) {
  3136. __extends(SceneTab, _super);
  3137. function SceneTab(tabbar, insp) {
  3138. var _this = _super.call(this, tabbar, 'Scene') || this;
  3139. /** The list of skeleton viewer */
  3140. _this._skeletonViewers = [];
  3141. _this._inspector = insp;
  3142. // Build the properties panel : a div that will contains the tree and the detail panel
  3143. _this._panel = INSPECTOR.Helpers.CreateDiv('tab-panel');
  3144. _this._actions = INSPECTOR.Helpers.CreateDiv('scene-actions', _this._panel);
  3145. _this._detailsPanel = new INSPECTOR.DetailPanel();
  3146. _this._panel.appendChild(_this._detailsPanel.toHtml());
  3147. // build propertiesline
  3148. var details = [];
  3149. // Remove deprecated properties generating warning in console
  3150. var dontTakeThis = ['interFramePerfCounter', 'lastFramePerfCounter', 'evaluateActiveMeshesDurationPerfCounter', 'renderDurationPerfCounter', 'particlesDurationPerfCounter', 'spriteDuractionPerfCounter'];
  3151. var props = INSPECTOR.Helpers.GetAllLinesPropertiesAsString(_this._inspector.scene, dontTakeThis);
  3152. for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
  3153. var propString = props_1[_i];
  3154. var prop = new INSPECTOR.PropertyLine(new INSPECTOR.Property(propString, _this._inspector.scene));
  3155. details.push(prop);
  3156. }
  3157. _this._detailsPanel.details = details;
  3158. Split([_this._actions, _this._detailsPanel.toHtml()], {
  3159. blockDrag: _this._inspector.popupMode,
  3160. sizes: [50, 50],
  3161. direction: 'vertical'
  3162. });
  3163. // Build actions
  3164. {
  3165. // Rendering mode
  3166. var title = INSPECTOR.Helpers.CreateDiv('actions-title', _this._actions);
  3167. title.textContent = 'Rendering mode';
  3168. var point = INSPECTOR.Helpers.CreateDiv('action-radio', _this._actions);
  3169. var wireframe = INSPECTOR.Helpers.CreateDiv('action-radio', _this._actions);
  3170. var solid = INSPECTOR.Helpers.CreateDiv('action-radio', _this._actions);
  3171. point.textContent = 'Point';
  3172. wireframe.textContent = 'Wireframe';
  3173. solid.textContent = 'Solid';
  3174. if (_this._inspector.scene.forcePointsCloud) {
  3175. point.classList.add('active');
  3176. }
  3177. else if (_this._inspector.scene.forceWireframe) {
  3178. wireframe.classList.add('active');
  3179. }
  3180. else {
  3181. solid.classList.add('active');
  3182. }
  3183. _this._generateRadioAction([point, wireframe, solid]);
  3184. point.addEventListener('click', function () { _this._inspector.scene.forcePointsCloud = true; _this._inspector.scene.forceWireframe = false; });
  3185. wireframe.addEventListener('click', function () { _this._inspector.scene.forcePointsCloud = false; _this._inspector.scene.forceWireframe = true; });
  3186. solid.addEventListener('click', function () { _this._inspector.scene.forcePointsCloud = false; _this._inspector.scene.forceWireframe = false; });
  3187. // Textures
  3188. title = INSPECTOR.Helpers.CreateDiv('actions-title', _this._actions);
  3189. title.textContent = 'Textures channels';
  3190. _this._generateActionLine('Diffuse Texture', BABYLON.StandardMaterial.DiffuseTextureEnabled, function (b) { BABYLON.StandardMaterial.DiffuseTextureEnabled = b; });
  3191. _this._generateActionLine('Ambient Texture', BABYLON.StandardMaterial.AmbientTextureEnabled, function (b) { BABYLON.StandardMaterial.AmbientTextureEnabled = b; });
  3192. _this._generateActionLine('Specular Texture', BABYLON.StandardMaterial.SpecularTextureEnabled, function (b) { BABYLON.StandardMaterial.SpecularTextureEnabled = b; });
  3193. _this._generateActionLine('Emissive Texture', BABYLON.StandardMaterial.EmissiveTextureEnabled, function (b) { BABYLON.StandardMaterial.EmissiveTextureEnabled = b; });
  3194. _this._generateActionLine('Bump Texture', BABYLON.StandardMaterial.BumpTextureEnabled, function (b) { BABYLON.StandardMaterial.BumpTextureEnabled = b; });
  3195. _this._generateActionLine('Opacity Texture', BABYLON.StandardMaterial.OpacityTextureEnabled, function (b) { BABYLON.StandardMaterial.OpacityTextureEnabled = b; });
  3196. _this._generateActionLine('Reflection Texture', BABYLON.StandardMaterial.ReflectionTextureEnabled, function (b) { BABYLON.StandardMaterial.ReflectionTextureEnabled = b; });
  3197. _this._generateActionLine('Refraction Texture', BABYLON.StandardMaterial.RefractionTextureEnabled, function (b) { BABYLON.StandardMaterial.RefractionTextureEnabled = b; });
  3198. _this._generateActionLine('ColorGrading', BABYLON.StandardMaterial.ColorGradingTextureEnabled, function (b) { BABYLON.StandardMaterial.ColorGradingTextureEnabled = b; });
  3199. _this._generateActionLine('Lightmap Texture', BABYLON.StandardMaterial.LightmapTextureEnabled, function (b) { BABYLON.StandardMaterial.LightmapTextureEnabled = b; });
  3200. _this._generateActionLine('Fresnel', BABYLON.StandardMaterial.FresnelEnabled, function (b) { BABYLON.StandardMaterial.FresnelEnabled = b; });
  3201. // Options
  3202. title = INSPECTOR.Helpers.CreateDiv('actions-title', _this._actions);
  3203. title.textContent = 'Options';
  3204. _this._generateActionLine('Animations', _this._inspector.scene.animationsEnabled, function (b) { _this._inspector.scene.animationsEnabled = b; });
  3205. _this._generateActionLine('Collisions', _this._inspector.scene.collisionsEnabled, function (b) { _this._inspector.scene.collisionsEnabled = b; });
  3206. _this._generateActionLine('Fog', _this._inspector.scene.fogEnabled, function (b) { _this._inspector.scene.fogEnabled = b; });
  3207. _this._generateActionLine('Lens flares', _this._inspector.scene.lensFlaresEnabled, function (b) { _this._inspector.scene.lensFlaresEnabled = b; });
  3208. _this._generateActionLine('Lights', _this._inspector.scene.lightsEnabled, function (b) { _this._inspector.scene.lightsEnabled = b; });
  3209. _this._generateActionLine('Particles', _this._inspector.scene.particlesEnabled, function (b) { _this._inspector.scene.particlesEnabled = b; });
  3210. _this._generateActionLine('Post-processes', _this._inspector.scene.postProcessesEnabled, function (b) { _this._inspector.scene.postProcessesEnabled = b; });
  3211. _this._generateActionLine('Probes', _this._inspector.scene.probesEnabled, function (b) { _this._inspector.scene.probesEnabled = b; });
  3212. _this._generateActionLine('Procedural textures', _this._inspector.scene.proceduralTexturesEnabled, function (b) { _this._inspector.scene.proceduralTexturesEnabled = b; });
  3213. _this._generateActionLine('Render targets', _this._inspector.scene.renderTargetsEnabled, function (b) { _this._inspector.scene.renderTargetsEnabled = b; });
  3214. _this._generateActionLine('Shadows', _this._inspector.scene.shadowsEnabled, function (b) { _this._inspector.scene.shadowsEnabled = b; });
  3215. _this._generateActionLine('Skeletons', _this._inspector.scene.skeletonsEnabled, function (b) { _this._inspector.scene.skeletonsEnabled = b; });
  3216. _this._generateActionLine('Sprites', _this._inspector.scene.spritesEnabled, function (b) { _this._inspector.scene.spritesEnabled = b; });
  3217. _this._generateActionLine('Textures', _this._inspector.scene.texturesEnabled, function (b) { _this._inspector.scene.texturesEnabled = b; });
  3218. // Audio
  3219. title = INSPECTOR.Helpers.CreateDiv('actions-title', _this._actions);
  3220. title.textContent = 'Audio';
  3221. var headphones = INSPECTOR.Helpers.CreateDiv('action-radio', _this._actions);
  3222. var normalSpeaker = INSPECTOR.Helpers.CreateDiv('action-radio', _this._actions);
  3223. _this._generateActionLine('Disable audio', !_this._inspector.scene.audioEnabled, function (b) { _this._inspector.scene.audioEnabled = !b; });
  3224. headphones.textContent = 'Headphones';
  3225. normalSpeaker.textContent = 'Normal speakers';
  3226. _this._generateRadioAction([headphones, normalSpeaker]);
  3227. if (_this._inspector.scene.headphone) {
  3228. headphones.classList.add('active');
  3229. }
  3230. else {
  3231. normalSpeaker.classList.add('active');
  3232. }
  3233. headphones.addEventListener('click', function () { _this._inspector.scene.headphone = true; });
  3234. normalSpeaker.addEventListener('click', function () { _this._inspector.scene.headphone = false; });
  3235. // Viewers
  3236. title = INSPECTOR.Helpers.CreateDiv('actions-title', _this._actions);
  3237. title.textContent = 'Viewer';
  3238. _this._generateActionLine('Skeletons', false, function (b) {
  3239. if (b) {
  3240. for (var index = 0; index < _this._inspector.scene.meshes.length; index++) {
  3241. var mesh = _this._inspector.scene.meshes[index];
  3242. if (mesh.skeleton) {
  3243. var found = false;
  3244. for (var sIndex = 0; sIndex < _this._skeletonViewers.length; sIndex++) {
  3245. if (_this._skeletonViewers[sIndex].skeleton === mesh.skeleton) {
  3246. found = true;
  3247. break;
  3248. }
  3249. }
  3250. if (found) {
  3251. continue;
  3252. }
  3253. var viewer = new BABYLON.Debug.SkeletonViewer(mesh.skeleton, mesh, _this._inspector.scene);
  3254. viewer.isEnabled = true;
  3255. _this._skeletonViewers.push(viewer);
  3256. }
  3257. }
  3258. }
  3259. else {
  3260. for (var index = 0; index < _this._skeletonViewers.length; index++) {
  3261. _this._skeletonViewers[index].dispose();
  3262. }
  3263. _this._skeletonViewers = [];
  3264. }
  3265. });
  3266. }
  3267. return _this;
  3268. }
  3269. /** Overrides super.dispose */
  3270. SceneTab.prototype.dispose = function () {
  3271. this._detailsPanel.dispose();
  3272. };
  3273. /** generates a div which correspond to an option that can be activated/deactivated */
  3274. SceneTab.prototype._generateActionLine = function (name, initValue, action) {
  3275. var div = INSPECTOR.Helpers.CreateDiv('scene-actions', this._actions);
  3276. div.textContent = name;
  3277. div.classList.add('action');
  3278. if (initValue) {
  3279. div.classList.add('active');
  3280. }
  3281. div.addEventListener('click', function (e) {
  3282. div.classList.toggle('active');
  3283. var isActivated = div.classList.contains('active');
  3284. action(isActivated);
  3285. });
  3286. };
  3287. /**
  3288. * Add a click action for all given elements :
  3289. * the clicked element is set as active, all others elements are deactivated
  3290. */
  3291. SceneTab.prototype._generateRadioAction = function (arr) {
  3292. var active = function (elem, evt) {
  3293. for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
  3294. var e = arr_1[_i];
  3295. e.classList.remove('active');
  3296. }
  3297. elem.classList.add('active');
  3298. };
  3299. for (var _i = 0, arr_2 = arr; _i < arr_2.length; _i++) {
  3300. var elem = arr_2[_i];
  3301. elem.addEventListener('click', active.bind(this, elem));
  3302. }
  3303. };
  3304. return SceneTab;
  3305. }(INSPECTOR.Tab));
  3306. INSPECTOR.SceneTab = SceneTab;
  3307. })(INSPECTOR || (INSPECTOR = {}));
  3308. var __extends = (this && this.__extends) || (function () {
  3309. var extendStatics = Object.setPrototypeOf ||
  3310. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3311. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3312. return function (d, b) {
  3313. extendStatics(d, b);
  3314. function __() { this.constructor = d; }
  3315. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3316. };
  3317. })();
  3318. var INSPECTOR;
  3319. (function (INSPECTOR) {
  3320. /**
  3321. * The console tab will have two features :
  3322. * - hook all console.log call and display them in this panel (and in the browser console as well)
  3323. * - display all Babylon logs (called with Tools.Log...)
  3324. */
  3325. var ConsoleTab = /** @class */ (function (_super) {
  3326. __extends(ConsoleTab, _super);
  3327. function ConsoleTab(tabbar, insp) {
  3328. var _this = _super.call(this, tabbar, 'Console') || this;
  3329. _this._inspector = insp;
  3330. // Build the shaders panel : a div that will contains the shaders tree and both shaders panels
  3331. _this._panel = INSPECTOR.Helpers.CreateDiv('tab-panel');
  3332. var consolePanel = INSPECTOR.Helpers.CreateDiv('console-panel');
  3333. var bjsPanel = INSPECTOR.Helpers.CreateDiv('console-panel');
  3334. _this._panel.appendChild(consolePanel);
  3335. _this._panel.appendChild(bjsPanel);
  3336. Split([consolePanel, bjsPanel], {
  3337. blockDrag: _this._inspector.popupMode,
  3338. sizes: [50, 50],
  3339. direction: 'vertical'
  3340. });
  3341. // Titles
  3342. var title = INSPECTOR.Helpers.CreateDiv('console-panel-title', consolePanel);
  3343. title.textContent = 'Console logs';
  3344. title = INSPECTOR.Helpers.CreateDiv('console-panel-title', bjsPanel);
  3345. title.textContent = 'Babylon.js logs';
  3346. // Contents
  3347. _this._consolePanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', consolePanel);
  3348. _this._bjsPanelContent = INSPECTOR.Helpers.CreateDiv('console-panel-content', bjsPanel);
  3349. // Bjs logs
  3350. _this._bjsPanelContent.innerHTML = BABYLON.Tools.LogCache;
  3351. BABYLON.Tools.OnNewCacheEntry = function (entry) {
  3352. _this._bjsPanelContent.innerHTML += entry;
  3353. _this._bjsPanelContent.scrollTop = _this._bjsPanelContent.scrollHeight;
  3354. };
  3355. return _this;
  3356. // Testing
  3357. //console.log("This is a console.log message");
  3358. // console.log("That's right, console.log calls are hooked to be written in this window");
  3359. // console.log("Object are also stringify-ed", {width:10, height:30, shape:'rectangular'});
  3360. // console.warn("This is a console.warn message");
  3361. // console.error("This is a console.error message");
  3362. // BABYLON.Tools.Log("This is a message");
  3363. // BABYLON.Tools.Warn("This is a warning");
  3364. // BABYLON.Tools.Error("This is a error");
  3365. }
  3366. /** Overrides super.dispose */
  3367. ConsoleTab.prototype.dispose = function () {
  3368. console.log = this._oldConsoleLog;
  3369. console.warn = this._oldConsoleWarn;
  3370. console.error = this._oldConsoleError;
  3371. };
  3372. ConsoleTab.prototype.active = function (b) {
  3373. _super.prototype.active.call(this, b);
  3374. if (b) {
  3375. // save old console.log
  3376. this._oldConsoleLog = console.log;
  3377. this._oldConsoleWarn = console.warn;
  3378. this._oldConsoleError = console.error;
  3379. console.log = this._addConsoleLog.bind(this);
  3380. console.warn = this._addConsoleWarn.bind(this);
  3381. console.error = this._addConsoleError.bind(this);
  3382. }
  3383. };
  3384. ConsoleTab.prototype._message = function (type, message, caller) {
  3385. var callerLine = INSPECTOR.Helpers.CreateDiv('caller', this._consolePanelContent);
  3386. callerLine.textContent = caller;
  3387. var line = INSPECTOR.Helpers.CreateDiv(type, this._consolePanelContent);
  3388. line.textContent += message;
  3389. this._consolePanelContent.scrollTop = this._consolePanelContent.scrollHeight;
  3390. };
  3391. ConsoleTab.prototype._addConsoleLog = function () {
  3392. var params = [];
  3393. for (var _i = 0; _i < arguments.length; _i++) {
  3394. params[_i] = arguments[_i];
  3395. }
  3396. // Get caller name if not null
  3397. var callerFunc = this._addConsoleLog.caller;
  3398. var caller = callerFunc == null ? "Window" : "Function " + callerFunc['name'] + ": ";
  3399. for (var i = 0; i < params.length; i++) {
  3400. this._message('log', params[i], caller);
  3401. // Write again in console does not work on edge, as the console object
  3402. // is not instantiate if debugger tools is not open
  3403. if (!INSPECTOR.Helpers.IsBrowserEdge()) {
  3404. this._oldConsoleLog(params[i]);
  3405. }
  3406. }
  3407. };
  3408. ConsoleTab.prototype._addConsoleWarn = function () {
  3409. var params = [];
  3410. for (var _i = 0; _i < arguments.length; _i++) {
  3411. params[_i] = arguments[_i];
  3412. }
  3413. // Get caller name if not null
  3414. var callerFunc = this._addConsoleLog.caller;
  3415. var caller = callerFunc == null ? "Window" : callerFunc['name'];
  3416. for (var i = 0; i < params.length; i++) {
  3417. this._message('warn', params[i], caller);
  3418. // Write again in console does not work on edge, as the console object
  3419. // is not instantiate if debugger tools is not open
  3420. if (!INSPECTOR.Helpers.IsBrowserEdge()) {
  3421. this._oldConsoleWarn(params[i]);
  3422. }
  3423. }
  3424. };
  3425. ConsoleTab.prototype._addConsoleError = function () {
  3426. var params = [];
  3427. for (var _i = 0; _i < arguments.length; _i++) {
  3428. params[_i] = arguments[_i];
  3429. }
  3430. // Get caller name if not null
  3431. var callerFunc = this._addConsoleLog.caller;
  3432. var caller = callerFunc == null ? "Window" : callerFunc['name'];
  3433. for (var i = 0; i < params.length; i++) {
  3434. this._message('error', params[i], caller);
  3435. // Write again in console does not work on edge, as the console object
  3436. // is not instantiate if debugger tools is not open
  3437. if (!INSPECTOR.Helpers.IsBrowserEdge()) {
  3438. this._oldConsoleError(params[i]);
  3439. }
  3440. }
  3441. };
  3442. return ConsoleTab;
  3443. }(INSPECTOR.Tab));
  3444. INSPECTOR.ConsoleTab = ConsoleTab;
  3445. })(INSPECTOR || (INSPECTOR = {}));
  3446. var __extends = (this && this.__extends) || (function () {
  3447. var extendStatics = Object.setPrototypeOf ||
  3448. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3449. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3450. return function (d, b) {
  3451. extendStatics(d, b);
  3452. function __() { this.constructor = d; }
  3453. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3454. };
  3455. })();
  3456. var INSPECTOR;
  3457. (function (INSPECTOR) {
  3458. var StatsTab = /** @class */ (function (_super) {
  3459. __extends(StatsTab, _super);
  3460. function StatsTab(tabbar, insp) {
  3461. var _this = _super.call(this, tabbar, 'Stats') || this;
  3462. /**
  3463. * Properties in this array will be updated
  3464. * in a render loop - Mostly stats properties
  3465. */
  3466. _this._updatableProperties = [];
  3467. _this._inspector = insp;
  3468. _this._scene = _this._inspector.scene;
  3469. _this._engine = _this._scene.getEngine();
  3470. _this._glInfo = _this._engine.getGlInfo();
  3471. _this._connectToInstrumentation();
  3472. // Build the stats panel: a div that will contains all stats
  3473. _this._panel = INSPECTOR.Helpers.CreateDiv('tab-panel');
  3474. _this._panel.classList.add("stats-panel");
  3475. var title = INSPECTOR.Helpers.CreateDiv('stat-title1', _this._panel);
  3476. var fpsSpan = INSPECTOR.Helpers.CreateElement('span', 'stats-fps');
  3477. _this._updatableProperties.push({
  3478. elem: fpsSpan,
  3479. updateFct: function () { return BABYLON.Tools.Format(_this._inspector.scene.getEngine().getFps(), 0) + " fps"; }
  3480. });
  3481. var versionSpan = INSPECTOR.Helpers.CreateElement('span');
  3482. versionSpan.textContent = "Babylon.js v" + BABYLON.Engine.Version + " - ";
  3483. title.appendChild(versionSpan);
  3484. title.appendChild(fpsSpan);
  3485. _this._updateLoopHandler = _this._update.bind(_this);
  3486. // Count block
  3487. title = INSPECTOR.Helpers.CreateDiv('stat-title2', _this._panel);
  3488. title.textContent = "Count";
  3489. {
  3490. _this._createStatLabel("Total meshes", _this._panel);
  3491. var elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3492. _this._updatableProperties.push({
  3493. elem: elemValue,
  3494. updateFct: function () { return _this._scene.meshes.length.toString(); }
  3495. });
  3496. _this._createStatLabel("Draw calls", _this._panel);
  3497. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3498. _this._updatableProperties.push({
  3499. elem: elemValue,
  3500. updateFct: function () { return _this._sceneInstrumentation.drawCallsCounter.current.toString(); }
  3501. });
  3502. _this._createStatLabel("Total lights", _this._panel);
  3503. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3504. _this._updatableProperties.push({
  3505. elem: elemValue,
  3506. updateFct: function () { return _this._scene.lights.length.toString(); }
  3507. });
  3508. _this._createStatLabel("Total vertices", _this._panel);
  3509. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3510. _this._updatableProperties.push({
  3511. elem: elemValue,
  3512. updateFct: function () { return _this._scene.getTotalVertices().toString(); }
  3513. });
  3514. _this._createStatLabel("Total materials", _this._panel);
  3515. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3516. _this._updatableProperties.push({
  3517. elem: elemValue,
  3518. updateFct: function () { return _this._scene.materials.length.toString(); }
  3519. });
  3520. _this._createStatLabel("Total textures", _this._panel);
  3521. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3522. _this._updatableProperties.push({
  3523. elem: elemValue,
  3524. updateFct: function () { return _this._scene.textures.length.toString(); }
  3525. });
  3526. _this._createStatLabel("Active meshes", _this._panel);
  3527. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3528. _this._updatableProperties.push({
  3529. elem: elemValue,
  3530. updateFct: function () { return _this._scene.getActiveMeshes().length.toString(); }
  3531. });
  3532. _this._createStatLabel("Active indices", _this._panel);
  3533. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3534. _this._updatableProperties.push({
  3535. elem: elemValue,
  3536. updateFct: function () { return _this._scene.getActiveIndices().toString(); }
  3537. });
  3538. _this._createStatLabel("Active bones", _this._panel);
  3539. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3540. _this._updatableProperties.push({
  3541. elem: elemValue,
  3542. updateFct: function () { return _this._scene.getActiveBones().toString(); }
  3543. });
  3544. _this._createStatLabel("Active particles", _this._panel);
  3545. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3546. _this._updatableProperties.push({
  3547. elem: elemValue,
  3548. updateFct: function () { return _this._scene.getActiveParticles().toString(); }
  3549. });
  3550. }
  3551. title = INSPECTOR.Helpers.CreateDiv('stat-title2', _this._panel);
  3552. title.textContent = "Duration";
  3553. {
  3554. _this._createStatLabel("Meshes selection", _this._panel);
  3555. var elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3556. _this._updatableProperties.push({
  3557. elem: elemValue,
  3558. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.activeMeshesEvaluationTimeCounter.current); }
  3559. });
  3560. _this._createStatLabel("Render targets", _this._panel);
  3561. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3562. _this._updatableProperties.push({
  3563. elem: elemValue,
  3564. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.renderTargetsRenderTimeCounter.current); }
  3565. });
  3566. _this._createStatLabel("Particles", _this._panel);
  3567. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3568. _this._updatableProperties.push({
  3569. elem: elemValue,
  3570. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.particlesRenderTimeCounter.current); }
  3571. });
  3572. _this._createStatLabel("Sprites", _this._panel);
  3573. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3574. _this._updatableProperties.push({
  3575. elem: elemValue,
  3576. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.spritesRenderTimeCounter.current); }
  3577. });
  3578. _this._createStatLabel("Animations", _this._panel);
  3579. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3580. _this._updatableProperties.push({
  3581. elem: elemValue,
  3582. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.animationsTimeCounter.current); }
  3583. });
  3584. _this._createStatLabel("Physics", _this._panel);
  3585. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3586. _this._updatableProperties.push({
  3587. elem: elemValue,
  3588. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.physicsTimeCounter.current); }
  3589. });
  3590. _this._createStatLabel("Render", _this._panel);
  3591. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3592. _this._updatableProperties.push({
  3593. elem: elemValue,
  3594. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.renderTimeCounter.current); }
  3595. });
  3596. _this._createStatLabel("Frame", _this._panel);
  3597. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3598. _this._updatableProperties.push({
  3599. elem: elemValue,
  3600. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.frameTimeCounter.current); }
  3601. });
  3602. _this._createStatLabel("Inter-frame", _this._panel);
  3603. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3604. _this._updatableProperties.push({
  3605. elem: elemValue,
  3606. updateFct: function () { return BABYLON.Tools.Format(_this._sceneInstrumentation.interFrameTimeCounter.current); }
  3607. });
  3608. _this._createStatLabel("GPU Frame time", _this._panel);
  3609. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3610. _this._updatableProperties.push({
  3611. elem: elemValue,
  3612. updateFct: function () { return BABYLON.Tools.Format(_this._engineInstrumentation.gpuFrameTimeCounter.current * 0.000001); }
  3613. });
  3614. _this._createStatLabel("GPU Frame time (average)", _this._panel);
  3615. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3616. _this._updatableProperties.push({
  3617. elem: elemValue,
  3618. updateFct: function () { return BABYLON.Tools.Format(_this._engineInstrumentation.gpuFrameTimeCounter.average * 0.000001); }
  3619. });
  3620. _this._createStatLabel("Potential FPS", _this._panel);
  3621. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3622. _this._updatableProperties.push({
  3623. elem: elemValue,
  3624. updateFct: function () { return BABYLON.Tools.Format(1000.0 / _this._sceneInstrumentation.frameTimeCounter.current, 0); }
  3625. });
  3626. _this._createStatLabel("Resolution", _this._panel);
  3627. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3628. _this._updatableProperties.push({
  3629. elem: elemValue,
  3630. updateFct: function () { return _this._engine.getRenderWidth() + "x" + _this._engine.getRenderHeight(); }
  3631. });
  3632. }
  3633. title = INSPECTOR.Helpers.CreateDiv('stat-title2', _this._panel);
  3634. title.textContent = "Extensions";
  3635. {
  3636. _this._createStatLabel("Std derivatives", _this._panel);
  3637. var elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3638. _this._updatableProperties.push({
  3639. elem: elemValue,
  3640. updateFct: function () { return (_this._engine.getCaps().standardDerivatives ? "Yes" : "No"); }
  3641. });
  3642. _this._createStatLabel("Compressed textures", _this._panel);
  3643. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3644. _this._updatableProperties.push({
  3645. elem: elemValue,
  3646. updateFct: function () { return (_this._engine.getCaps().s3tc ? "Yes" : "No"); }
  3647. });
  3648. _this._createStatLabel("Hardware instances", _this._panel);
  3649. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3650. _this._updatableProperties.push({
  3651. elem: elemValue,
  3652. updateFct: function () { return (_this._engine.getCaps().instancedArrays ? "Yes" : "No"); }
  3653. });
  3654. _this._createStatLabel("Texture float", _this._panel);
  3655. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3656. _this._updatableProperties.push({
  3657. elem: elemValue,
  3658. updateFct: function () { return (_this._engine.getCaps().textureFloat ? "Yes" : "No"); }
  3659. });
  3660. _this._createStatLabel("32bits indices", _this._panel);
  3661. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3662. _this._updatableProperties.push({
  3663. elem: elemValue,
  3664. updateFct: function () { return (_this._engine.getCaps().uintIndices ? "Yes" : "No"); }
  3665. });
  3666. _this._createStatLabel("Fragment depth", _this._panel);
  3667. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3668. _this._updatableProperties.push({
  3669. elem: elemValue,
  3670. updateFct: function () { return (_this._engine.getCaps().fragmentDepthSupported ? "Yes" : "No"); }
  3671. });
  3672. _this._createStatLabel("High precision shaders", _this._panel);
  3673. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3674. _this._updatableProperties.push({
  3675. elem: elemValue,
  3676. updateFct: function () { return (_this._engine.getCaps().highPrecisionShaderSupported ? "Yes" : "No"); }
  3677. });
  3678. _this._createStatLabel("Draw buffers", _this._panel);
  3679. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3680. _this._updatableProperties.push({
  3681. elem: elemValue,
  3682. updateFct: function () { return (_this._engine.getCaps().drawBuffersExtension ? "Yes" : "No"); }
  3683. });
  3684. _this._createStatLabel("Vertex array object", _this._panel);
  3685. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3686. _this._updatableProperties.push({
  3687. elem: elemValue,
  3688. updateFct: function () { return (_this._engine.getCaps().vertexArrayObject ? "Yes" : "No"); }
  3689. });
  3690. _this._createStatLabel("Timer query", _this._panel);
  3691. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3692. _this._updatableProperties.push({
  3693. elem: elemValue,
  3694. updateFct: function () { return (_this._engine.getCaps().timerQuery ? "Yes" : "No"); }
  3695. });
  3696. }
  3697. title = INSPECTOR.Helpers.CreateDiv('stat-title2', _this._panel);
  3698. title.textContent = "Caps.";
  3699. {
  3700. _this._createStatLabel("Stencil", _this._panel);
  3701. var elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3702. _this._updatableProperties.push({
  3703. elem: elemValue,
  3704. updateFct: function () { return (_this._engine.isStencilEnable ? "Enabled" : "Disabled"); }
  3705. });
  3706. _this._createStatLabel("Max textures units", _this._panel);
  3707. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3708. _this._updatableProperties.push({
  3709. elem: elemValue,
  3710. updateFct: function () { return _this._engine.getCaps().maxTexturesImageUnits.toString(); }
  3711. });
  3712. _this._createStatLabel("Max textures size", _this._panel);
  3713. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3714. _this._updatableProperties.push({
  3715. elem: elemValue,
  3716. updateFct: function () { return _this._engine.getCaps().maxTextureSize.toString(); }
  3717. });
  3718. _this._createStatLabel("Max anisotropy", _this._panel);
  3719. elemValue = INSPECTOR.Helpers.CreateDiv('stat-value', _this._panel);
  3720. _this._updatableProperties.push({
  3721. elem: elemValue,
  3722. updateFct: function () { return _this._engine.getCaps().maxAnisotropy.toString(); }
  3723. });
  3724. }
  3725. title = INSPECTOR.Helpers.CreateDiv('stat-title2', _this._panel);
  3726. title.textContent = "Info";
  3727. {
  3728. var elemValue = INSPECTOR.Helpers.CreateDiv('stat-infos', _this._panel);
  3729. _this._updatableProperties.push({
  3730. elem: elemValue,
  3731. updateFct: function () { return "WebGL v" + _this._engine.webGLVersion + " - " + _this._glInfo.version + " - " + _this._glInfo.renderer; }
  3732. });
  3733. }
  3734. return _this;
  3735. }
  3736. StatsTab.prototype._connectToInstrumentation = function () {
  3737. if (this._sceneInstrumentation) {
  3738. return;
  3739. }
  3740. this._sceneInstrumentation = new BABYLON.SceneInstrumentation(this._scene);
  3741. this._sceneInstrumentation.captureActiveMeshesEvaluationTime = true;
  3742. this._sceneInstrumentation.captureRenderTargetsRenderTime = true;
  3743. this._sceneInstrumentation.captureFrameTime = true;
  3744. this._sceneInstrumentation.captureRenderTime = true;
  3745. this._sceneInstrumentation.captureInterFrameTime = true;
  3746. this._sceneInstrumentation.captureParticlesRenderTime = true;
  3747. this._sceneInstrumentation.captureSpritesRenderTime = true;
  3748. this._sceneInstrumentation.capturePhysicsTime = true;
  3749. this._sceneInstrumentation.captureAnimationsTime = true;
  3750. this._engineInstrumentation = new BABYLON.EngineInstrumentation(this._engine);
  3751. this._engineInstrumentation.captureGPUFrameTime = true;
  3752. };
  3753. StatsTab.prototype._createStatLabel = function (content, parent) {
  3754. var elem = INSPECTOR.Helpers.CreateDiv('stat-label', parent);
  3755. elem.textContent = content;
  3756. return elem;
  3757. };
  3758. /** Update each properties of the stats panel */
  3759. StatsTab.prototype._update = function () {
  3760. for (var _i = 0, _a = this._updatableProperties; _i < _a.length; _i++) {
  3761. var prop = _a[_i];
  3762. prop.elem.textContent = prop.updateFct();
  3763. }
  3764. };
  3765. StatsTab.prototype.dispose = function () {
  3766. this._scene.unregisterAfterRender(this._updateLoopHandler);
  3767. this._sceneInstrumentation.dispose();
  3768. this._sceneInstrumentation = null;
  3769. this._engineInstrumentation.dispose();
  3770. this._engineInstrumentation = null;
  3771. };
  3772. StatsTab.prototype.active = function (b) {
  3773. _super.prototype.active.call(this, b);
  3774. if (b) {
  3775. this._connectToInstrumentation();
  3776. this._scene.registerAfterRender(this._updateLoopHandler);
  3777. }
  3778. };
  3779. return StatsTab;
  3780. }(INSPECTOR.Tab));
  3781. INSPECTOR.StatsTab = StatsTab;
  3782. })(INSPECTOR || (INSPECTOR = {}));
  3783. var __extends = (this && this.__extends) || (function () {
  3784. var extendStatics = Object.setPrototypeOf ||
  3785. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3786. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3787. return function (d, b) {
  3788. extendStatics(d, b);
  3789. function __() { this.constructor = d; }
  3790. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3791. };
  3792. })();
  3793. var INSPECTOR;
  3794. (function (INSPECTOR) {
  3795. /**
  3796. * A tab bar will contains each view the inspector can have : Canvas2D, Meshes...
  3797. * The default active tab is the first one of the list.
  3798. */
  3799. var TabBar = /** @class */ (function (_super) {
  3800. __extends(TabBar, _super);
  3801. function TabBar(inspector, initialTab) {
  3802. var _this = _super.call(this) || this;
  3803. // The list of available tabs
  3804. _this._tabs = [];
  3805. /** The list of tab displayed by clicking on the remainingIcon */
  3806. _this._invisibleTabs = [];
  3807. /** The list of tabs visible, displayed in the tab bar */
  3808. _this._visibleTabs = [];
  3809. _this._inspector = inspector;
  3810. _this._tabs.push(new INSPECTOR.SceneTab(_this, _this._inspector));
  3811. _this._tabs.push(new INSPECTOR.ConsoleTab(_this, _this._inspector));
  3812. _this._tabs.push(new INSPECTOR.StatsTab(_this, _this._inspector));
  3813. _this._meshTab = new INSPECTOR.MeshTab(_this, _this._inspector);
  3814. _this._tabs.push(new INSPECTOR.TextureTab(_this, _this._inspector));
  3815. _this._tabs.push(_this._meshTab);
  3816. _this._tabs.push(new INSPECTOR.LightTab(_this, _this._inspector));
  3817. _this._tabs.push(new INSPECTOR.MaterialTab(_this, _this._inspector));
  3818. if (BABYLON.GUI) {
  3819. _this._tabs.push(new INSPECTOR.GUITab(_this, _this._inspector));
  3820. }
  3821. _this._tabs.push(new INSPECTOR.PhysicsTab(_this, _this._inspector));
  3822. _this._tabs.push(new INSPECTOR.CameraTab(_this, _this._inspector));
  3823. _this._tabs.push(new INSPECTOR.SoundTab(_this, _this._inspector));
  3824. _this._toolBar = new INSPECTOR.Toolbar(_this._inspector);
  3825. _this._build();
  3826. //Check initialTab is defined and between tabs bounds
  3827. if (!initialTab || initialTab < 0 || initialTab >= _this._tabs.length) {
  3828. initialTab = 0;
  3829. }
  3830. _this._tabs[initialTab].active(true);
  3831. // set all tab as visible
  3832. for (var _i = 0, _a = _this._tabs; _i < _a.length; _i++) {
  3833. var tab = _a[_i];
  3834. _this._visibleTabs.push(tab);
  3835. }
  3836. return _this;
  3837. }
  3838. // No update
  3839. TabBar.prototype.update = function () { };
  3840. TabBar.prototype._build = function () {
  3841. var _this = this;
  3842. this._div.className = 'tabbar';
  3843. this._div.appendChild(this._toolBar.toHtml());
  3844. for (var _i = 0, _a = this._tabs; _i < _a.length; _i++) {
  3845. var tab = _a[_i];
  3846. this._div.appendChild(tab.toHtml());
  3847. }
  3848. this._moreTabsIcon = INSPECTOR.Helpers.CreateElement('i', 'fa fa-angle-double-right more-tabs');
  3849. this._moreTabsPanel = INSPECTOR.Helpers.CreateDiv('more-tabs-panel');
  3850. this._moreTabsIcon.addEventListener('click', function () {
  3851. // Hide the 'more-tabs-panel' if already displayed
  3852. if (_this._moreTabsPanel.style.display == 'flex') {
  3853. _this._moreTabsPanel.style.display = 'none';
  3854. }
  3855. else {
  3856. // Attach more-tabs-panel if not attached yet
  3857. var topPanel = _this._div.parentNode;
  3858. if (!topPanel.contains(_this._moreTabsPanel)) {
  3859. topPanel.appendChild(_this._moreTabsPanel);
  3860. }
  3861. // Clean the 'more-tabs-panel'
  3862. INSPECTOR.Helpers.CleanDiv(_this._moreTabsPanel);
  3863. // Add each invisible tabs to this panel
  3864. for (var _i = 0, _a = _this._invisibleTabs; _i < _a.length; _i++) {
  3865. var tab = _a[_i];
  3866. _this._addInvisibleTabToPanel(tab);
  3867. }
  3868. // And display it
  3869. _this._moreTabsPanel.style.display = 'flex';
  3870. }
  3871. });
  3872. };
  3873. /**
  3874. * Add a tab to the 'more-tabs' panel, displayed by clicking on the
  3875. * 'more-tabs' icon
  3876. */
  3877. TabBar.prototype._addInvisibleTabToPanel = function (tab) {
  3878. var _this = this;
  3879. var div = INSPECTOR.Helpers.CreateDiv('invisible-tab', this._moreTabsPanel);
  3880. div.textContent = tab.name;
  3881. div.addEventListener('click', function () {
  3882. _this._moreTabsPanel.style.display = 'none';
  3883. _this.switchTab(tab);
  3884. });
  3885. };
  3886. /** Dispose the current tab, set the given tab as active, and refresh the treeview */
  3887. TabBar.prototype.switchTab = function (tab) {
  3888. // Dispose the active tab
  3889. var activeTab = this.getActiveTab();
  3890. if (activeTab) {
  3891. activeTab.dispose();
  3892. }
  3893. // Deactivate all tabs
  3894. for (var _i = 0, _a = this._tabs; _i < _a.length; _i++) {
  3895. var t = _a[_i];
  3896. t.active(false);
  3897. }
  3898. // activate the given tab
  3899. tab.active(true);
  3900. // Refresh the inspector
  3901. this._inspector.refresh();
  3902. };
  3903. /** Display the mesh tab.
  3904. * If a parameter is given, the given mesh details are displayed
  3905. */
  3906. TabBar.prototype.switchMeshTab = function (mesh) {
  3907. this.switchTab(this._meshTab);
  3908. if (mesh) {
  3909. var item = this._meshTab.getItemFor(mesh);
  3910. if (item) {
  3911. this._meshTab.select(item);
  3912. }
  3913. }
  3914. };
  3915. /** Returns the active tab */
  3916. TabBar.prototype.getActiveTab = function () {
  3917. for (var _i = 0, _a = this._tabs; _i < _a.length; _i++) {
  3918. var tab = _a[_i];
  3919. if (tab.isActive()) {
  3920. return tab;
  3921. }
  3922. }
  3923. return null;
  3924. };
  3925. TabBar.prototype.getActiveTabIndex = function () {
  3926. for (var i = 0; i < this._tabs.length; i++) {
  3927. if (this._tabs[i].isActive()) {
  3928. return i;
  3929. }
  3930. }
  3931. return 0;
  3932. };
  3933. Object.defineProperty(TabBar.prototype, "inspector", {
  3934. get: function () {
  3935. return this._inspector;
  3936. },
  3937. enumerable: true,
  3938. configurable: true
  3939. });
  3940. /**
  3941. * Returns the total width in pixel of the tabbar,
  3942. * that corresponds to the sum of the width of each visible tab + toolbar width
  3943. */
  3944. TabBar.prototype.getPixelWidth = function () {
  3945. var sum = 0;
  3946. for (var _i = 0, _a = this._visibleTabs; _i < _a.length; _i++) {
  3947. var tab = _a[_i];
  3948. sum += tab.getPixelWidth();
  3949. }
  3950. sum += this._toolBar.getPixelWidth();
  3951. if (this._div.contains(this._moreTabsIcon)) {
  3952. sum += 30; // $tabbarheight
  3953. }
  3954. return sum;
  3955. };
  3956. /** Display the remaining icon or not depending on the tabbar width.
  3957. * This function should be called each time the inspector width is updated
  3958. */
  3959. TabBar.prototype.updateWidth = function () {
  3960. if (!this._div.parentElement) {
  3961. return;
  3962. }
  3963. var parentSize = this._div.parentElement.clientWidth;
  3964. var lastTabWidth = 75;
  3965. var currentSize = this.getPixelWidth();
  3966. // Check if a tab should be removed : if the tab bar width is greater than
  3967. // its parent width
  3968. while (this._visibleTabs.length > 0 && currentSize > parentSize) {
  3969. // Start by the last element
  3970. var tab = this._visibleTabs.pop();
  3971. if (!tab) {
  3972. break;
  3973. }
  3974. // set it invisible
  3975. this._invisibleTabs.push(tab);
  3976. // and removes it from the DOM
  3977. this._div.removeChild(tab.toHtml());
  3978. currentSize = this.getPixelWidth() + lastTabWidth;
  3979. }
  3980. // Check if a tab can be added to the tab bar : if the tab bar width
  3981. // + 100 (at least 100px is needed to add a tab) is less than its parent width
  3982. if (this._invisibleTabs.length > 0) {
  3983. if (currentSize + lastTabWidth < parentSize) {
  3984. var lastTab = this._invisibleTabs.pop();
  3985. if (lastTab) {
  3986. this._div.appendChild(lastTab.toHtml());
  3987. this._visibleTabs.push(lastTab);
  3988. }
  3989. // Update more-tab icon in last position if needed
  3990. if (this._div.contains(this._moreTabsIcon)) {
  3991. this._div.removeChild(this._moreTabsIcon);
  3992. }
  3993. }
  3994. }
  3995. if (this._invisibleTabs.length > 0 && !this._div.contains(this._moreTabsIcon)) {
  3996. this._div.appendChild(this._moreTabsIcon);
  3997. }
  3998. };
  3999. return TabBar;
  4000. }(INSPECTOR.BasicElement));
  4001. INSPECTOR.TabBar = TabBar;
  4002. })(INSPECTOR || (INSPECTOR = {}));
  4003. var INSPECTOR;
  4004. (function (INSPECTOR) {
  4005. var AbstractTool = /** @class */ (function () {
  4006. function AbstractTool(icon, parent, inspector, tooltip) {
  4007. var _this = this;
  4008. this._inspector = inspector;
  4009. this._elem = INSPECTOR.Inspector.DOCUMENT.createElement('i');
  4010. this._elem.className = "tool fa " + icon;
  4011. parent.appendChild(this._elem);
  4012. this._elem.addEventListener('click', function (e) {
  4013. _this.action();
  4014. });
  4015. new INSPECTOR.Tooltip(this._elem, tooltip);
  4016. }
  4017. AbstractTool.prototype.toHtml = function () {
  4018. return this._elem;
  4019. };
  4020. /**
  4021. * Returns the total width in pixel of this tool, 0 by default
  4022. */
  4023. AbstractTool.prototype.getPixelWidth = function () {
  4024. var style = INSPECTOR.Inspector.WINDOW.getComputedStyle(this._elem);
  4025. if (!style.marginLeft || !style.marginRight) {
  4026. return 0;
  4027. }
  4028. var left = parseFloat(style.marginLeft.substr(0, style.marginLeft.length - 2)) || 0;
  4029. var right = parseFloat(style.marginRight.substr(0, style.marginRight.length - 2)) || 0;
  4030. return (this._elem.clientWidth || 0) + left + right;
  4031. };
  4032. /**
  4033. * Updates the icon of this tool with the given string
  4034. */
  4035. AbstractTool.prototype._updateIcon = function (icon) {
  4036. this._elem.className = "tool fa " + icon;
  4037. };
  4038. return AbstractTool;
  4039. }());
  4040. INSPECTOR.AbstractTool = AbstractTool;
  4041. })(INSPECTOR || (INSPECTOR = {}));
  4042. var __extends = (this && this.__extends) || (function () {
  4043. var extendStatics = Object.setPrototypeOf ||
  4044. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4045. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4046. return function (d, b) {
  4047. extendStatics(d, b);
  4048. function __() { this.constructor = d; }
  4049. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4050. };
  4051. })();
  4052. var INSPECTOR;
  4053. (function (INSPECTOR) {
  4054. var PauseScheduleTool = /** @class */ (function (_super) {
  4055. __extends(PauseScheduleTool, _super);
  4056. function PauseScheduleTool(parent, inspector) {
  4057. var _this = _super.call(this, 'fa-pause', parent, inspector, 'Pause the automatic update of properties') || this;
  4058. _this._isPause = false;
  4059. return _this;
  4060. }
  4061. // Action : refresh the whole panel
  4062. PauseScheduleTool.prototype.action = function () {
  4063. if (this._isPause) {
  4064. INSPECTOR.Scheduler.getInstance().pause = false;
  4065. this._updateIcon('fa-pause');
  4066. }
  4067. else {
  4068. INSPECTOR.Scheduler.getInstance().pause = true;
  4069. this._updateIcon('fa-play');
  4070. }
  4071. this._isPause = !this._isPause;
  4072. };
  4073. return PauseScheduleTool;
  4074. }(INSPECTOR.AbstractTool));
  4075. INSPECTOR.PauseScheduleTool = PauseScheduleTool;
  4076. })(INSPECTOR || (INSPECTOR = {}));
  4077. var __extends = (this && this.__extends) || (function () {
  4078. var extendStatics = Object.setPrototypeOf ||
  4079. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4080. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4081. return function (d, b) {
  4082. extendStatics(d, b);
  4083. function __() { this.constructor = d; }
  4084. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4085. };
  4086. })();
  4087. var INSPECTOR;
  4088. (function (INSPECTOR) {
  4089. var PickTool = /** @class */ (function (_super) {
  4090. __extends(PickTool, _super);
  4091. function PickTool(parent, inspector) {
  4092. var _this = _super.call(this, 'fa-mouse-pointer', parent, inspector, 'Select a mesh in the scene') || this;
  4093. _this._isActive = false;
  4094. // Create handler
  4095. _this._pickHandler = _this._pickMesh.bind(_this);
  4096. return _this;
  4097. }
  4098. // Action : find the corresponding tree item in the correct tab and display it
  4099. PickTool.prototype.action = function () {
  4100. if (this._isActive) {
  4101. this._deactivate();
  4102. }
  4103. else {
  4104. this.toHtml().classList.add('active');
  4105. // Add event handler : pick on a mesh in the scene
  4106. var canvas = this._inspector.scene.getEngine().getRenderingCanvas();
  4107. canvas.addEventListener('click', this._pickHandler);
  4108. this._isActive = true;
  4109. }
  4110. };
  4111. /** Deactivate this tool */
  4112. PickTool.prototype._deactivate = function () {
  4113. this.toHtml().classList.remove('active');
  4114. // Remove event handler
  4115. var canvas = this._inspector.scene.getEngine().getRenderingCanvas();
  4116. canvas.removeEventListener('click', this._pickHandler);
  4117. this._isActive = false;
  4118. };
  4119. /** Pick a mesh in the scene */
  4120. PickTool.prototype._pickMesh = function (evt) {
  4121. var pos = this._updatePointerPosition(evt);
  4122. var pi = this._inspector.scene.pick(pos.x, pos.y, function (mesh) { return true; });
  4123. if (pi && pi.pickedMesh) {
  4124. this._inspector.displayObjectDetails(pi.pickedMesh);
  4125. }
  4126. this._deactivate();
  4127. };
  4128. PickTool.prototype._updatePointerPosition = function (evt) {
  4129. var canvasRect = this._inspector.scene.getEngine().getRenderingCanvasClientRect();
  4130. var pointerX = evt.clientX - canvasRect.left;
  4131. var pointerY = evt.clientY - canvasRect.top;
  4132. return { x: pointerX, y: pointerY };
  4133. };
  4134. ;
  4135. return PickTool;
  4136. }(INSPECTOR.AbstractTool));
  4137. INSPECTOR.PickTool = PickTool;
  4138. })(INSPECTOR || (INSPECTOR = {}));
  4139. var __extends = (this && this.__extends) || (function () {
  4140. var extendStatics = Object.setPrototypeOf ||
  4141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4143. return function (d, b) {
  4144. extendStatics(d, b);
  4145. function __() { this.constructor = d; }
  4146. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4147. };
  4148. })();
  4149. var INSPECTOR;
  4150. (function (INSPECTOR) {
  4151. var PopupTool = /** @class */ (function (_super) {
  4152. __extends(PopupTool, _super);
  4153. function PopupTool(parent, inspector) {
  4154. return _super.call(this, 'fa-external-link', parent, inspector, 'Open the inspector in a popup') || this;
  4155. }
  4156. // Action : refresh the whole panel
  4157. PopupTool.prototype.action = function () {
  4158. this._inspector.openPopup();
  4159. };
  4160. return PopupTool;
  4161. }(INSPECTOR.AbstractTool));
  4162. INSPECTOR.PopupTool = PopupTool;
  4163. })(INSPECTOR || (INSPECTOR = {}));
  4164. var __extends = (this && this.__extends) || (function () {
  4165. var extendStatics = Object.setPrototypeOf ||
  4166. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4167. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4168. return function (d, b) {
  4169. extendStatics(d, b);
  4170. function __() { this.constructor = d; }
  4171. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4172. };
  4173. })();
  4174. var INSPECTOR;
  4175. (function (INSPECTOR) {
  4176. var RefreshTool = /** @class */ (function (_super) {
  4177. __extends(RefreshTool, _super);
  4178. function RefreshTool(parent, inspector) {
  4179. return _super.call(this, 'fa-refresh', parent, inspector, 'Refresh the current tab') || this;
  4180. }
  4181. // Action : refresh the whole panel
  4182. RefreshTool.prototype.action = function () {
  4183. this._inspector.refresh();
  4184. };
  4185. return RefreshTool;
  4186. }(INSPECTOR.AbstractTool));
  4187. INSPECTOR.RefreshTool = RefreshTool;
  4188. })(INSPECTOR || (INSPECTOR = {}));
  4189. var __extends = (this && this.__extends) || (function () {
  4190. var extendStatics = Object.setPrototypeOf ||
  4191. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4192. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4193. return function (d, b) {
  4194. extendStatics(d, b);
  4195. function __() { this.constructor = d; }
  4196. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4197. };
  4198. })();
  4199. var INSPECTOR;
  4200. (function (INSPECTOR) {
  4201. var LabelTool = /** @class */ (function (_super) {
  4202. __extends(LabelTool, _super);
  4203. function LabelTool(parent, inspector) {
  4204. var _this = _super.call(this, 'fa-tags', parent, inspector, 'Display mesh names on the canvas') || this;
  4205. /** True if label are displayed, false otherwise */
  4206. _this._isDisplayed = false;
  4207. _this._advancedTexture = null;
  4208. _this._labelInitialized = false;
  4209. _this._scene = null;
  4210. _this._guiLoaded = false;
  4211. _this._scene = inspector.scene;
  4212. return _this;
  4213. }
  4214. LabelTool.prototype.dispose = function () {
  4215. if (this._advancedTexture) {
  4216. this._advancedTexture.dispose();
  4217. }
  4218. };
  4219. LabelTool.prototype._checkGUILoaded = function () {
  4220. if (this._guiLoaded === true) {
  4221. return true;
  4222. }
  4223. if (BABYLON.GUI) {
  4224. this._guiLoaded = true;
  4225. }
  4226. return this._guiLoaded;
  4227. };
  4228. LabelTool.prototype._initializeLabels = function () {
  4229. var _this = this;
  4230. // Check if the label are already initialized and quit if it's the case
  4231. if (this._labelInitialized || !this._scene) {
  4232. return;
  4233. }
  4234. // Can't initialize them if the GUI lib is not loaded yet
  4235. if (!this._checkGUILoaded()) {
  4236. return;
  4237. }
  4238. // Create the canvas that will be used to display the labels
  4239. this._advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
  4240. // Create label for all the Meshes, Lights and Cameras
  4241. // Those that will be created/removed after this method is called will be taken care by the event handlers added below
  4242. for (var _i = 0, _a = this._scene.meshes; _i < _a.length; _i++) {
  4243. var m = _a[_i];
  4244. this._createLabel(m);
  4245. }
  4246. this._scene.onNewMeshAddedObservable.add(function (m, s) {
  4247. _this._createLabel(m);
  4248. });
  4249. this._scene.onMeshRemovedObservable.add(function (m, s) {
  4250. _this._removeLabel(m);
  4251. });
  4252. this._labelInitialized = true;
  4253. };
  4254. LabelTool.prototype._createLabel = function (mesh) {
  4255. // Don't create label for "system nodes" (starting and ending with ###)
  4256. var name = mesh.name;
  4257. if (INSPECTOR.Helpers.IsSystemName(name)) {
  4258. return;
  4259. }
  4260. if (mesh && this._advancedTexture) {
  4261. var rect1 = new BABYLON.GUI.Rectangle();
  4262. rect1.width = 4 + 10 * name.length + "px";
  4263. rect1.height = "22px";
  4264. rect1.background = "rgba(0,0,0,0.6)";
  4265. rect1.color = "black";
  4266. this._advancedTexture.addControl(rect1);
  4267. var label = new BABYLON.GUI.TextBlock();
  4268. label.text = name;
  4269. label.fontSize = 12;
  4270. rect1.addControl(label);
  4271. rect1.linkWithMesh(mesh);
  4272. }
  4273. };
  4274. LabelTool.prototype._removeLabel = function (mesh) {
  4275. if (!this._advancedTexture) {
  4276. return;
  4277. }
  4278. for (var _i = 0, _a = this._advancedTexture._rootContainer.children; _i < _a.length; _i++) {
  4279. var g = _a[_i];
  4280. var ed = g._linkedMesh;
  4281. if (ed === mesh) {
  4282. this._advancedTexture.removeControl(g);
  4283. break;
  4284. }
  4285. }
  4286. };
  4287. // Action : Display/hide mesh names on the canvas
  4288. LabelTool.prototype.action = function () {
  4289. // Don't toggle if the script is not loaded
  4290. if (!this._checkGUILoaded() || !this._advancedTexture) {
  4291. return;
  4292. }
  4293. // Toggle the label display state
  4294. this._isDisplayed = !this._isDisplayed;
  4295. // Check if we have to display the labels
  4296. if (this._isDisplayed) {
  4297. this._initializeLabels();
  4298. this._advancedTexture._rootContainer.isVisible = true;
  4299. }
  4300. else {
  4301. this._advancedTexture._rootContainer.isVisible = false;
  4302. }
  4303. };
  4304. return LabelTool;
  4305. }(INSPECTOR.AbstractTool));
  4306. INSPECTOR.LabelTool = LabelTool;
  4307. })(INSPECTOR || (INSPECTOR = {}));
  4308. var __extends = (this && this.__extends) || (function () {
  4309. var extendStatics = Object.setPrototypeOf ||
  4310. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4311. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4312. return function (d, b) {
  4313. extendStatics(d, b);
  4314. function __() { this.constructor = d; }
  4315. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4316. };
  4317. })();
  4318. var INSPECTOR;
  4319. (function (INSPECTOR) {
  4320. var Toolbar = /** @class */ (function (_super) {
  4321. __extends(Toolbar, _super);
  4322. function Toolbar(inspector) {
  4323. var _this = _super.call(this) || this;
  4324. _this._tools = [];
  4325. _this._inspector = inspector;
  4326. _this._build();
  4327. _this._addTools();
  4328. return _this;
  4329. }
  4330. // A toolbar cannot be updated
  4331. Toolbar.prototype.update = function () { };
  4332. ;
  4333. Toolbar.prototype._build = function () {
  4334. this._div.className = 'toolbar';
  4335. };
  4336. ;
  4337. Toolbar.prototype._addTools = function () {
  4338. // Refresh
  4339. this._tools.push(new INSPECTOR.RefreshTool(this._div, this._inspector));
  4340. // Display labels
  4341. this._tools.push(new INSPECTOR.LabelTool(this._div, this._inspector));
  4342. // Pick object
  4343. this._tools.push(new INSPECTOR.PickTool(this._div, this._inspector));
  4344. // Add the popup mode only if the inspector is not in popup mode and if the brower is not edge
  4345. // Edge is
  4346. if (!this._inspector.popupMode && !INSPECTOR.Helpers.IsBrowserEdge()) {
  4347. this._tools.push(new INSPECTOR.PopupTool(this._div, this._inspector));
  4348. }
  4349. // Pause schedule
  4350. this._tools.push(new INSPECTOR.PauseScheduleTool(this._div, this._inspector));
  4351. // Pause schedule
  4352. this._tools.push(new INSPECTOR.DisposeTool(this._div, this._inspector));
  4353. };
  4354. /**
  4355. * Returns the total width in pixel of the tabbar,
  4356. * that corresponds to the sum of the width of each tab + toolbar width
  4357. */
  4358. Toolbar.prototype.getPixelWidth = function () {
  4359. var sum = 0;
  4360. for (var _i = 0, _a = this._tools; _i < _a.length; _i++) {
  4361. var tool = _a[_i];
  4362. sum += tool.getPixelWidth();
  4363. }
  4364. return sum;
  4365. };
  4366. return Toolbar;
  4367. }(INSPECTOR.BasicElement));
  4368. INSPECTOR.Toolbar = Toolbar;
  4369. })(INSPECTOR || (INSPECTOR = {}));
  4370. var __extends = (this && this.__extends) || (function () {
  4371. var extendStatics = Object.setPrototypeOf ||
  4372. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4373. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4374. return function (d, b) {
  4375. extendStatics(d, b);
  4376. function __() { this.constructor = d; }
  4377. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4378. };
  4379. })();
  4380. var INSPECTOR;
  4381. (function (INSPECTOR) {
  4382. /**
  4383. * Removes the inspector panel
  4384. */
  4385. var DisposeTool = /** @class */ (function (_super) {
  4386. __extends(DisposeTool, _super);
  4387. function DisposeTool(parent, inspector) {
  4388. return _super.call(this, 'fa-times', parent, inspector, 'Close the inspector panel') || this;
  4389. }
  4390. // Action : refresh the whole panel
  4391. DisposeTool.prototype.action = function () {
  4392. this._inspector.dispose();
  4393. };
  4394. return DisposeTool;
  4395. }(INSPECTOR.AbstractTool));
  4396. INSPECTOR.DisposeTool = DisposeTool;
  4397. })(INSPECTOR || (INSPECTOR = {}));
  4398. var __extends = (this && this.__extends) || (function () {
  4399. var extendStatics = Object.setPrototypeOf ||
  4400. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4401. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4402. return function (d, b) {
  4403. extendStatics(d, b);
  4404. function __() { this.constructor = d; }
  4405. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4406. };
  4407. })();
  4408. var INSPECTOR;
  4409. (function (INSPECTOR) {
  4410. var TreeItem = /** @class */ (function (_super) {
  4411. __extends(TreeItem, _super);
  4412. function TreeItem(tab, obj) {
  4413. var _this = _super.call(this) || this;
  4414. _this.children = [];
  4415. _this._tab = tab;
  4416. _this._adapter = obj;
  4417. _this._tools = _this._adapter.getTools();
  4418. _this._build();
  4419. return _this;
  4420. }
  4421. Object.defineProperty(TreeItem.prototype, "id", {
  4422. /** Returns the item ID == its adapter ID */
  4423. get: function () {
  4424. return this._adapter.id();
  4425. },
  4426. enumerable: true,
  4427. configurable: true
  4428. });
  4429. /** Add the given item as a child of this one */
  4430. TreeItem.prototype.add = function (child) {
  4431. this.children.push(child);
  4432. this.update();
  4433. };
  4434. Object.defineProperty(TreeItem.prototype, "adapter", {
  4435. /**
  4436. * Returns the original adapter
  4437. */
  4438. get: function () {
  4439. return this._adapter;
  4440. },
  4441. enumerable: true,
  4442. configurable: true
  4443. });
  4444. /**
  4445. * Function used to compare this item to another tree item.
  4446. * Returns the alphabetical sort of the adapter ID
  4447. */
  4448. TreeItem.prototype.compareTo = function (item) {
  4449. var str1 = this.id;
  4450. var str2 = item.id;
  4451. return str1.localeCompare(str2, [], { numeric: true });
  4452. };
  4453. /** Returns true if the given obj correspond to the adapter linked to this tree item */
  4454. TreeItem.prototype.correspondsTo = function (obj) {
  4455. return this._adapter.correspondsTo(obj);
  4456. };
  4457. /** hide all children of this item */
  4458. TreeItem.prototype.fold = function () {
  4459. // Do nothing id no children
  4460. if (this.children.length > 0) {
  4461. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  4462. var elem = _a[_i];
  4463. elem.toHtml().style.display = 'none';
  4464. }
  4465. this._div.classList.add('folded');
  4466. this._div.classList.remove('unfolded');
  4467. }
  4468. };
  4469. /** Show all children of this item */
  4470. TreeItem.prototype.unfold = function () {
  4471. // Do nothing id no children
  4472. if (this.children.length > 0) {
  4473. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  4474. var elem = _a[_i];
  4475. elem.toHtml().style.display = 'block';
  4476. }
  4477. this._div.classList.add('unfolded');
  4478. this._div.classList.remove('folded');
  4479. }
  4480. };
  4481. /** Build the HTML of this item */
  4482. TreeItem.prototype._build = function () {
  4483. this._div.className = 'line';
  4484. // special class for transform node ONLY
  4485. if (this.adapter instanceof INSPECTOR.MeshAdapter) {
  4486. var obj = this.adapter.object;
  4487. if (obj instanceof BABYLON.TransformNode && !(obj instanceof BABYLON.AbstractMesh)) {
  4488. this._div.className += ' transformNode';
  4489. }
  4490. }
  4491. for (var _i = 0, _a = this._tools; _i < _a.length; _i++) {
  4492. var tool = _a[_i];
  4493. this._div.appendChild(tool.toHtml());
  4494. }
  4495. // Id
  4496. var text = INSPECTOR.Inspector.DOCUMENT.createElement('span');
  4497. text.textContent = this._adapter.id();
  4498. this._div.appendChild(text);
  4499. // Type
  4500. var type = INSPECTOR.Inspector.DOCUMENT.createElement('span');
  4501. type.className = 'property-type';
  4502. if (this._adapter.type() !== 'type_not_defined') {
  4503. type.textContent = ' - ' + this._adapter.type();
  4504. }
  4505. this._div.appendChild(type);
  4506. this._lineContent = INSPECTOR.Helpers.CreateDiv('line-content', this._div);
  4507. this._addEvent();
  4508. };
  4509. /**
  4510. * Returns one HTML element (.details) containing all details of this primitive
  4511. */
  4512. TreeItem.prototype.getDetails = function () {
  4513. return this._adapter.getProperties();
  4514. };
  4515. TreeItem.prototype.update = function () {
  4516. // Clean division holding all children
  4517. INSPECTOR.Helpers.CleanDiv(this._lineContent);
  4518. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  4519. var child = _a[_i];
  4520. var elem = child.toHtml();
  4521. this._lineContent.appendChild(elem);
  4522. }
  4523. if (this.children.length > 0) {
  4524. // Check if folded or not
  4525. if (!this._div.classList.contains('folded') && !this._div.classList.contains('unfolded')) {
  4526. this._div.classList.add('folded');
  4527. }
  4528. }
  4529. this.fold();
  4530. };
  4531. /**
  4532. * Add an event listener on the item :
  4533. * - one click display details
  4534. */
  4535. TreeItem.prototype._addEvent = function () {
  4536. var _this = this;
  4537. this._div.addEventListener('click', function (e) {
  4538. _this._tab.select(_this);
  4539. // Fold/unfold the tree
  4540. if (_this._isFolded()) {
  4541. _this.unfold();
  4542. }
  4543. else {
  4544. _this.fold();
  4545. }
  4546. e.stopPropagation();
  4547. });
  4548. };
  4549. /** Returns true if the node is folded, false otherwise */
  4550. TreeItem.prototype._isFolded = function () {
  4551. return !this._div.classList.contains('unfolded');
  4552. };
  4553. /** Set this item as active (background lighter) in the tree panel */
  4554. TreeItem.prototype.active = function (b) {
  4555. this._div.classList.remove('active');
  4556. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  4557. var child = _a[_i];
  4558. child.active(false);
  4559. }
  4560. if (b) {
  4561. this._div.classList.add('active');
  4562. }
  4563. };
  4564. TreeItem.prototype.getDiv = function () {
  4565. return this._div;
  4566. };
  4567. return TreeItem;
  4568. }(INSPECTOR.BasicElement));
  4569. INSPECTOR.TreeItem = TreeItem;
  4570. })(INSPECTOR || (INSPECTOR = {}));
  4571. var INSPECTOR;
  4572. (function (INSPECTOR) {
  4573. var AbstractTreeTool = /** @class */ (function () {
  4574. function AbstractTreeTool() {
  4575. /** Is the tool enabled ? */
  4576. this._on = false;
  4577. this._elem = INSPECTOR.Inspector.DOCUMENT.createElement('i');
  4578. this._elem.className = 'treeTool fa';
  4579. this._addEvents();
  4580. }
  4581. AbstractTreeTool.prototype.toHtml = function () {
  4582. return this._elem;
  4583. };
  4584. AbstractTreeTool.prototype._addEvents = function () {
  4585. var _this = this;
  4586. this._elem.addEventListener('click', function (e) {
  4587. _this.action();
  4588. e.stopPropagation();
  4589. });
  4590. };
  4591. /**
  4592. * Action launched when clicked on this element
  4593. * Should be overrided
  4594. */
  4595. AbstractTreeTool.prototype.action = function () {
  4596. this._on = !this._on;
  4597. };
  4598. return AbstractTreeTool;
  4599. }());
  4600. INSPECTOR.AbstractTreeTool = AbstractTreeTool;
  4601. })(INSPECTOR || (INSPECTOR = {}));
  4602. var __extends = (this && this.__extends) || (function () {
  4603. var extendStatics = Object.setPrototypeOf ||
  4604. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4605. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4606. return function (d, b) {
  4607. extendStatics(d, b);
  4608. function __() { this.constructor = d; }
  4609. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4610. };
  4611. })();
  4612. var INSPECTOR;
  4613. (function (INSPECTOR) {
  4614. /**
  4615. * Checkbox to display/hide the primitive
  4616. */
  4617. var BoundingBox = /** @class */ (function (_super) {
  4618. __extends(BoundingBox, _super);
  4619. function BoundingBox(obj) {
  4620. var _this = _super.call(this) || this;
  4621. _this._obj = obj;
  4622. _this._elem.classList.add('fa-square-o');
  4623. _this._on = _this._obj.isBoxVisible();
  4624. _this._check();
  4625. return _this;
  4626. }
  4627. // For a checkbox, set visible/invisible the corresponding prim
  4628. BoundingBox.prototype.action = function () {
  4629. _super.prototype.action.call(this);
  4630. // update object and gui according to the new status
  4631. this._check();
  4632. };
  4633. BoundingBox.prototype._check = function () {
  4634. if (this._on) {
  4635. // set icon eye
  4636. this._elem.classList.add('active');
  4637. }
  4638. else {
  4639. // set icon eye-slash
  4640. this._elem.classList.remove('active');
  4641. }
  4642. this._obj.setBoxVisible(this._on);
  4643. };
  4644. return BoundingBox;
  4645. }(INSPECTOR.AbstractTreeTool));
  4646. INSPECTOR.BoundingBox = BoundingBox;
  4647. })(INSPECTOR || (INSPECTOR = {}));
  4648. var __extends = (this && this.__extends) || (function () {
  4649. var extendStatics = Object.setPrototypeOf ||
  4650. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4651. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4652. return function (d, b) {
  4653. extendStatics(d, b);
  4654. function __() { this.constructor = d; }
  4655. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4656. };
  4657. })();
  4658. var INSPECTOR;
  4659. (function (INSPECTOR) {
  4660. /**
  4661. *
  4662. */
  4663. var CameraPOV = /** @class */ (function (_super) {
  4664. __extends(CameraPOV, _super);
  4665. function CameraPOV(camera) {
  4666. var _this = _super.call(this) || this;
  4667. _this.cameraPOV = camera;
  4668. _this._elem.classList.add('fa-video-camera');
  4669. return _this;
  4670. }
  4671. CameraPOV.prototype.action = function () {
  4672. _super.prototype.action.call(this);
  4673. this._gotoPOV();
  4674. };
  4675. CameraPOV.prototype._gotoPOV = function () {
  4676. var actives = INSPECTOR.Inspector.DOCUMENT.querySelectorAll(".fa-video-camera.active");
  4677. console.log(actives);
  4678. for (var i = 0; i < actives.length; i++) {
  4679. actives[i].classList.remove('active');
  4680. }
  4681. //if (this._on) {
  4682. // set icon camera
  4683. this._elem.classList.add('active');
  4684. //}
  4685. this.cameraPOV.setPOV();
  4686. };
  4687. return CameraPOV;
  4688. }(INSPECTOR.AbstractTreeTool));
  4689. INSPECTOR.CameraPOV = CameraPOV;
  4690. })(INSPECTOR || (INSPECTOR = {}));
  4691. var __extends = (this && this.__extends) || (function () {
  4692. var extendStatics = Object.setPrototypeOf ||
  4693. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4694. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4695. return function (d, b) {
  4696. extendStatics(d, b);
  4697. function __() { this.constructor = d; }
  4698. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4699. };
  4700. })();
  4701. var INSPECTOR;
  4702. (function (INSPECTOR) {
  4703. /**
  4704. *
  4705. */
  4706. var SoundInteractions = /** @class */ (function (_super) {
  4707. __extends(SoundInteractions, _super);
  4708. function SoundInteractions(playSound) {
  4709. var _this = _super.call(this) || this;
  4710. _this.playSound = playSound;
  4711. _this._elem.classList.add('fa-play');
  4712. return _this;
  4713. }
  4714. SoundInteractions.prototype.action = function () {
  4715. _super.prototype.action.call(this);
  4716. this._playSound();
  4717. };
  4718. SoundInteractions.prototype._playSound = function () {
  4719. var _this = this;
  4720. if (this._elem.classList.contains('fa-play')) {
  4721. this._elem.classList.remove('fa-play');
  4722. this._elem.classList.add('fa-pause');
  4723. }
  4724. else {
  4725. this._elem.classList.remove('fa-pause');
  4726. this._elem.classList.add('fa-play');
  4727. }
  4728. this.playSound.setPlaying(function () {
  4729. _this._elem.classList.remove('fa-pause');
  4730. _this._elem.classList.add('fa-play');
  4731. });
  4732. };
  4733. return SoundInteractions;
  4734. }(INSPECTOR.AbstractTreeTool));
  4735. INSPECTOR.SoundInteractions = SoundInteractions;
  4736. })(INSPECTOR || (INSPECTOR = {}));
  4737. var __extends = (this && this.__extends) || (function () {
  4738. var extendStatics = Object.setPrototypeOf ||
  4739. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4740. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4741. return function (d, b) {
  4742. extendStatics(d, b);
  4743. function __() { this.constructor = d; }
  4744. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4745. };
  4746. })();
  4747. var INSPECTOR;
  4748. (function (INSPECTOR) {
  4749. /**
  4750. * Checkbox to display/hide the primitive
  4751. */
  4752. var Checkbox = /** @class */ (function (_super) {
  4753. __extends(Checkbox, _super);
  4754. function Checkbox(obj) {
  4755. var _this = _super.call(this) || this;
  4756. _this._obj = obj;
  4757. _this._elem.classList.add('fa-eye');
  4758. _this._on = _this._obj.isVisible();
  4759. _this._check(true);
  4760. return _this;
  4761. }
  4762. // For a checkbox, set visible/invisible the corresponding prim
  4763. Checkbox.prototype.action = function () {
  4764. _super.prototype.action.call(this);
  4765. // update object and gui according to the new status
  4766. this._check();
  4767. };
  4768. Checkbox.prototype._check = function (dontEnable) {
  4769. if (this._on) {
  4770. // set icon eye
  4771. this._elem.classList.add('fa-eye');
  4772. this._elem.classList.add('active');
  4773. this._elem.classList.remove('fa-eye-slash');
  4774. }
  4775. else {
  4776. // set icon eye-slash
  4777. this._elem.classList.remove('fa-eye');
  4778. this._elem.classList.remove('active');
  4779. this._elem.classList.add('fa-eye-slash');
  4780. }
  4781. if (!dontEnable) {
  4782. this._obj.setVisible(this._on);
  4783. }
  4784. };
  4785. return Checkbox;
  4786. }(INSPECTOR.AbstractTreeTool));
  4787. INSPECTOR.Checkbox = Checkbox;
  4788. })(INSPECTOR || (INSPECTOR = {}));
  4789. var __extends = (this && this.__extends) || (function () {
  4790. var extendStatics = Object.setPrototypeOf ||
  4791. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4792. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4793. return function (d, b) {
  4794. extendStatics(d, b);
  4795. function __() { this.constructor = d; }
  4796. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4797. };
  4798. })();
  4799. var INSPECTOR;
  4800. (function (INSPECTOR) {
  4801. var DebugArea = /** @class */ (function (_super) {
  4802. __extends(DebugArea, _super);
  4803. function DebugArea(obj) {
  4804. var _this = _super.call(this) || this;
  4805. _this._obj = obj;
  4806. _this._elem.classList.add('fa-wrench');
  4807. return _this;
  4808. }
  4809. DebugArea.prototype.action = function () {
  4810. _super.prototype.action.call(this);
  4811. if (this._on) {
  4812. // set icon activated
  4813. this._elem.classList.add('active');
  4814. }
  4815. else {
  4816. // set icon deactivated
  4817. this._elem.classList.remove('active');
  4818. }
  4819. this._obj.debug(this._on);
  4820. };
  4821. return DebugArea;
  4822. }(INSPECTOR.AbstractTreeTool));
  4823. INSPECTOR.DebugArea = DebugArea;
  4824. })(INSPECTOR || (INSPECTOR = {}));
  4825. var __extends = (this && this.__extends) || (function () {
  4826. var extendStatics = Object.setPrototypeOf ||
  4827. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4828. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4829. return function (d, b) {
  4830. extendStatics(d, b);
  4831. function __() { this.constructor = d; }
  4832. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4833. };
  4834. })();
  4835. var INSPECTOR;
  4836. (function (INSPECTOR) {
  4837. /**
  4838. * Checkbox to display/hide the primitive
  4839. */
  4840. var Info = /** @class */ (function (_super) {
  4841. __extends(Info, _super);
  4842. function Info(obj) {
  4843. var _this = _super.call(this) || this;
  4844. _this._obj = obj;
  4845. _this._elem.classList.add('fa-info-circle');
  4846. new INSPECTOR.Tooltip(_this._elem, _this._obj.getInfo(), _this._elem);
  4847. return _this;
  4848. }
  4849. // Nothing to do on click
  4850. Info.prototype.action = function () {
  4851. _super.prototype.action.call(this);
  4852. };
  4853. return Info;
  4854. }(INSPECTOR.AbstractTreeTool));
  4855. INSPECTOR.Info = Info;
  4856. })(INSPECTOR || (INSPECTOR = {}));