babylon.inspector.js 213 KB

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