babylon.inspector.js 194 KB

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