babylon.inspector.js 212 KB

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