babylon.inspector.js 222 KB

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