babylon.inspector.js 198 KB

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