babylon.inspector.js 193 KB

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