babylon.inspector.js 213 KB

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