babylon.inspector.js 214 KB

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