babylon.inspector.js 246 KB

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