babylon.inspector.js 167 KB

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