babylon.inspector.js 193 KB

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