babylonjs.loaders.module.d.ts 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904
  1. declare module "babylonjs-loaders/glTF/glTFValidation" {
  2. import * as GLTF2 from 'babylonjs-gltf2interface';
  3. /**
  4. * Configuration for glTF validation
  5. */
  6. export interface IGLTFValidationConfiguration {
  7. /**
  8. * The url of the glTF validator.
  9. */
  10. url: string;
  11. }
  12. /**
  13. * glTF validation
  14. */
  15. export class GLTFValidation {
  16. /**
  17. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  18. */
  19. static Configuration: IGLTFValidationConfiguration;
  20. private static _LoadScriptPromise;
  21. /**
  22. * Validate a glTF asset using the glTF-Validator.
  23. * @param data The JSON of a glTF or the array buffer of a binary glTF
  24. * @param rootUrl The root url for the glTF
  25. * @param fileName The file name for the glTF
  26. * @param getExternalResource The callback to get external resources for the glTF validator
  27. * @returns A promise that resolves with the glTF validation results once complete
  28. */
  29. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<GLTF2.IGLTFValidationResults>;
  30. }
  31. }
  32. declare module "babylonjs-loaders/glTF/glTFFileLoader" {
  33. import * as GLTF2 from "babylonjs-gltf2interface";
  34. import { Nullable } from "babylonjs/types";
  35. import { Observable } from "babylonjs/Misc/observable";
  36. import { Camera } from "babylonjs/Cameras/camera";
  37. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  38. import { Skeleton } from "babylonjs/Bones/skeleton";
  39. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  40. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  41. import { Material } from "babylonjs/Materials/material";
  42. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  43. import { ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  44. import { AssetContainer } from "babylonjs/assetContainer";
  45. import { Scene, IDisposable } from "babylonjs/scene";
  46. import { WebRequest } from "babylonjs/Misc/webRequest";
  47. import { IFileRequest } from "babylonjs/Misc/fileRequest";
  48. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  49. import { Light } from 'babylonjs/Lights/light';
  50. import { TransformNode } from 'babylonjs/Meshes/transformNode';
  51. /**
  52. * Mode that determines the coordinate system to use.
  53. */
  54. export enum GLTFLoaderCoordinateSystemMode {
  55. /**
  56. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  57. */
  58. AUTO = 0,
  59. /**
  60. * Sets the useRightHandedSystem flag on the scene.
  61. */
  62. FORCE_RIGHT_HANDED = 1
  63. }
  64. /**
  65. * Mode that determines what animations will start.
  66. */
  67. export enum GLTFLoaderAnimationStartMode {
  68. /**
  69. * No animation will start.
  70. */
  71. NONE = 0,
  72. /**
  73. * The first animation will start.
  74. */
  75. FIRST = 1,
  76. /**
  77. * All animations will start.
  78. */
  79. ALL = 2
  80. }
  81. /**
  82. * Interface that contains the data for the glTF asset.
  83. */
  84. export interface IGLTFLoaderData {
  85. /**
  86. * The object that represents the glTF JSON.
  87. */
  88. json: Object;
  89. /**
  90. * The BIN chunk of a binary glTF.
  91. */
  92. bin: Nullable<IDataBuffer>;
  93. }
  94. /**
  95. * Interface for extending the loader.
  96. */
  97. export interface IGLTFLoaderExtension {
  98. /**
  99. * The name of this extension.
  100. */
  101. readonly name: string;
  102. /**
  103. * Defines whether this extension is enabled.
  104. */
  105. enabled: boolean;
  106. /**
  107. * Defines the order of this extension.
  108. * The loader sorts the extensions using these values when loading.
  109. */
  110. order?: number;
  111. }
  112. /**
  113. * Loader state.
  114. */
  115. export enum GLTFLoaderState {
  116. /**
  117. * The asset is loading.
  118. */
  119. LOADING = 0,
  120. /**
  121. * The asset is ready for rendering.
  122. */
  123. READY = 1,
  124. /**
  125. * The asset is completely loaded.
  126. */
  127. COMPLETE = 2
  128. }
  129. /** @hidden */
  130. export interface IImportMeshAsyncOutput {
  131. meshes: AbstractMesh[];
  132. particleSystems: IParticleSystem[];
  133. skeletons: Skeleton[];
  134. animationGroups: AnimationGroup[];
  135. lights: Light[];
  136. transformNodes: TransformNode[];
  137. }
  138. /** @hidden */
  139. export interface IGLTFLoader extends IDisposable {
  140. readonly state: Nullable<GLTFLoaderState>;
  141. importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<IImportMeshAsyncOutput>;
  142. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  143. }
  144. /**
  145. * File loader for loading glTF files into a scene.
  146. */
  147. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  148. /** @hidden */
  149. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  150. /** @hidden */
  151. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  152. /**
  153. * Raised when the asset has been parsed
  154. */
  155. onParsedObservable: Observable<IGLTFLoaderData>;
  156. private _onParsedObserver;
  157. /**
  158. * Raised when the asset has been parsed
  159. */
  160. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  161. /**
  162. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  163. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  164. * Defaults to true.
  165. * @hidden
  166. */
  167. static IncrementalLoading: boolean;
  168. /**
  169. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  170. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  171. * @hidden
  172. */
  173. static HomogeneousCoordinates: boolean;
  174. /**
  175. * The coordinate system mode. Defaults to AUTO.
  176. */
  177. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  178. /**
  179. * The animation start mode. Defaults to FIRST.
  180. */
  181. animationStartMode: GLTFLoaderAnimationStartMode;
  182. /**
  183. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  184. */
  185. compileMaterials: boolean;
  186. /**
  187. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  188. */
  189. useClipPlane: boolean;
  190. /**
  191. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  192. */
  193. compileShadowGenerators: boolean;
  194. /**
  195. * Defines if the Alpha blended materials are only applied as coverage.
  196. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  197. * If true, no extra effects are applied to transparent pixels.
  198. */
  199. transparencyAsCoverage: boolean;
  200. /**
  201. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  202. * Enabling will disable offline support and glTF validator.
  203. * Defaults to false.
  204. */
  205. useRangeRequests: boolean;
  206. /**
  207. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  208. */
  209. createInstances: boolean;
  210. /**
  211. * Function called before loading a url referenced by the asset.
  212. */
  213. preprocessUrlAsync: (url: string) => Promise<string>;
  214. /**
  215. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  216. */
  217. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  218. private _onMeshLoadedObserver;
  219. /**
  220. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  221. */
  222. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  223. /**
  224. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  225. */
  226. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  227. private _onTextureLoadedObserver;
  228. /**
  229. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  230. */
  231. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  232. /**
  233. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  234. */
  235. readonly onMaterialLoadedObservable: Observable<Material>;
  236. private _onMaterialLoadedObserver;
  237. /**
  238. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  239. */
  240. set onMaterialLoaded(callback: (material: Material) => void);
  241. /**
  242. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  243. */
  244. readonly onCameraLoadedObservable: Observable<Camera>;
  245. private _onCameraLoadedObserver;
  246. /**
  247. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  248. */
  249. set onCameraLoaded(callback: (camera: Camera) => void);
  250. /**
  251. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  252. * For assets with LODs, raised when all of the LODs are complete.
  253. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  254. */
  255. readonly onCompleteObservable: Observable<void>;
  256. private _onCompleteObserver;
  257. /**
  258. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  259. * For assets with LODs, raised when all of the LODs are complete.
  260. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  261. */
  262. set onComplete(callback: () => void);
  263. /**
  264. * Observable raised when an error occurs.
  265. */
  266. readonly onErrorObservable: Observable<any>;
  267. private _onErrorObserver;
  268. /**
  269. * Callback raised when an error occurs.
  270. */
  271. set onError(callback: (reason: any) => void);
  272. /**
  273. * Observable raised after the loader is disposed.
  274. */
  275. readonly onDisposeObservable: Observable<void>;
  276. private _onDisposeObserver;
  277. /**
  278. * Callback raised after the loader is disposed.
  279. */
  280. set onDispose(callback: () => void);
  281. /**
  282. * Observable raised after a loader extension is created.
  283. * Set additional options for a loader extension in this event.
  284. */
  285. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  286. private _onExtensionLoadedObserver;
  287. /**
  288. * Callback raised after a loader extension is created.
  289. */
  290. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  291. /**
  292. * Defines if the loader logging is enabled.
  293. */
  294. get loggingEnabled(): boolean;
  295. set loggingEnabled(value: boolean);
  296. /**
  297. * Defines if the loader should capture performance counters.
  298. */
  299. get capturePerformanceCounters(): boolean;
  300. set capturePerformanceCounters(value: boolean);
  301. /**
  302. * Defines if the loader should validate the asset.
  303. */
  304. validate: boolean;
  305. /**
  306. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  307. */
  308. readonly onValidatedObservable: Observable<GLTF2.IGLTFValidationResults>;
  309. private _onValidatedObserver;
  310. /**
  311. * Callback raised after a loader extension is created.
  312. */
  313. set onValidated(callback: (results: GLTF2.IGLTFValidationResults) => void);
  314. private _loader;
  315. /**
  316. * Name of the loader ("gltf")
  317. */
  318. name: string;
  319. /** @hidden */
  320. extensions: ISceneLoaderPluginExtensions;
  321. /**
  322. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  323. */
  324. dispose(): void;
  325. /** @hidden */
  326. _clear(): void;
  327. /** @hidden */
  328. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  329. /** @hidden */
  330. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  331. /** @hidden */
  332. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  333. meshes: AbstractMesh[];
  334. particleSystems: IParticleSystem[];
  335. skeletons: Skeleton[];
  336. animationGroups: AnimationGroup[];
  337. }>;
  338. /** @hidden */
  339. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  340. /** @hidden */
  341. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  342. /** @hidden */
  343. canDirectLoad(data: string): boolean;
  344. /** @hidden */
  345. directLoad(scene: Scene, data: string): any;
  346. /**
  347. * The callback that allows custom handling of the root url based on the response url.
  348. * @param rootUrl the original root url
  349. * @param responseURL the response url if available
  350. * @returns the new root url
  351. */
  352. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  353. /** @hidden */
  354. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  355. /**
  356. * The loader state or null if the loader is not active.
  357. */
  358. get loaderState(): Nullable<GLTFLoaderState>;
  359. /**
  360. * Returns a promise that resolves when the asset is completely loaded.
  361. * @returns a promise that resolves when the asset is completely loaded.
  362. */
  363. whenCompleteAsync(): Promise<void>;
  364. private _validate;
  365. private _getLoader;
  366. private _parseJson;
  367. private _unpackBinaryAsync;
  368. private _unpackBinaryV1Async;
  369. private _unpackBinaryV2Async;
  370. private static _parseVersion;
  371. private static _compareVersion;
  372. private static readonly _logSpaces;
  373. private _logIndentLevel;
  374. private _loggingEnabled;
  375. /** @hidden */
  376. _log: (message: string) => void;
  377. /** @hidden */
  378. _logOpen(message: string): void;
  379. /** @hidden */
  380. _logClose(): void;
  381. private _logEnabled;
  382. private _logDisabled;
  383. private _capturePerformanceCounters;
  384. /** @hidden */
  385. _startPerformanceCounter: (counterName: string) => void;
  386. /** @hidden */
  387. _endPerformanceCounter: (counterName: string) => void;
  388. private _startPerformanceCounterEnabled;
  389. private _startPerformanceCounterDisabled;
  390. private _endPerformanceCounterEnabled;
  391. private _endPerformanceCounterDisabled;
  392. }
  393. }
  394. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces" {
  395. import { Bone } from "babylonjs/Bones/bone";
  396. import { Skeleton } from "babylonjs/Bones/skeleton";
  397. import { Texture } from "babylonjs/Materials/Textures/texture";
  398. import { Node } from "babylonjs/node";
  399. import { Scene } from "babylonjs/scene";
  400. /**
  401. * Enums
  402. * @hidden
  403. */
  404. export enum EComponentType {
  405. BYTE = 5120,
  406. UNSIGNED_BYTE = 5121,
  407. SHORT = 5122,
  408. UNSIGNED_SHORT = 5123,
  409. FLOAT = 5126
  410. }
  411. /** @hidden */
  412. export enum EShaderType {
  413. FRAGMENT = 35632,
  414. VERTEX = 35633
  415. }
  416. /** @hidden */
  417. export enum EParameterType {
  418. BYTE = 5120,
  419. UNSIGNED_BYTE = 5121,
  420. SHORT = 5122,
  421. UNSIGNED_SHORT = 5123,
  422. INT = 5124,
  423. UNSIGNED_INT = 5125,
  424. FLOAT = 5126,
  425. FLOAT_VEC2 = 35664,
  426. FLOAT_VEC3 = 35665,
  427. FLOAT_VEC4 = 35666,
  428. INT_VEC2 = 35667,
  429. INT_VEC3 = 35668,
  430. INT_VEC4 = 35669,
  431. BOOL = 35670,
  432. BOOL_VEC2 = 35671,
  433. BOOL_VEC3 = 35672,
  434. BOOL_VEC4 = 35673,
  435. FLOAT_MAT2 = 35674,
  436. FLOAT_MAT3 = 35675,
  437. FLOAT_MAT4 = 35676,
  438. SAMPLER_2D = 35678
  439. }
  440. /** @hidden */
  441. export enum ETextureWrapMode {
  442. CLAMP_TO_EDGE = 33071,
  443. MIRRORED_REPEAT = 33648,
  444. REPEAT = 10497
  445. }
  446. /** @hidden */
  447. export enum ETextureFilterType {
  448. NEAREST = 9728,
  449. LINEAR = 9728,
  450. NEAREST_MIPMAP_NEAREST = 9984,
  451. LINEAR_MIPMAP_NEAREST = 9985,
  452. NEAREST_MIPMAP_LINEAR = 9986,
  453. LINEAR_MIPMAP_LINEAR = 9987
  454. }
  455. /** @hidden */
  456. export enum ETextureFormat {
  457. ALPHA = 6406,
  458. RGB = 6407,
  459. RGBA = 6408,
  460. LUMINANCE = 6409,
  461. LUMINANCE_ALPHA = 6410
  462. }
  463. /** @hidden */
  464. export enum ECullingType {
  465. FRONT = 1028,
  466. BACK = 1029,
  467. FRONT_AND_BACK = 1032
  468. }
  469. /** @hidden */
  470. export enum EBlendingFunction {
  471. ZERO = 0,
  472. ONE = 1,
  473. SRC_COLOR = 768,
  474. ONE_MINUS_SRC_COLOR = 769,
  475. DST_COLOR = 774,
  476. ONE_MINUS_DST_COLOR = 775,
  477. SRC_ALPHA = 770,
  478. ONE_MINUS_SRC_ALPHA = 771,
  479. DST_ALPHA = 772,
  480. ONE_MINUS_DST_ALPHA = 773,
  481. CONSTANT_COLOR = 32769,
  482. ONE_MINUS_CONSTANT_COLOR = 32770,
  483. CONSTANT_ALPHA = 32771,
  484. ONE_MINUS_CONSTANT_ALPHA = 32772,
  485. SRC_ALPHA_SATURATE = 776
  486. }
  487. /** @hidden */
  488. export interface IGLTFProperty {
  489. extensions?: {
  490. [key: string]: any;
  491. };
  492. extras?: Object;
  493. }
  494. /** @hidden */
  495. export interface IGLTFChildRootProperty extends IGLTFProperty {
  496. name?: string;
  497. }
  498. /** @hidden */
  499. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  500. bufferView: string;
  501. byteOffset: number;
  502. byteStride: number;
  503. count: number;
  504. type: string;
  505. componentType: EComponentType;
  506. max?: number[];
  507. min?: number[];
  508. name?: string;
  509. }
  510. /** @hidden */
  511. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  512. buffer: string;
  513. byteOffset: number;
  514. byteLength: number;
  515. byteStride: number;
  516. target?: number;
  517. }
  518. /** @hidden */
  519. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  520. uri: string;
  521. byteLength?: number;
  522. type?: string;
  523. }
  524. /** @hidden */
  525. export interface IGLTFShader extends IGLTFChildRootProperty {
  526. uri: string;
  527. type: EShaderType;
  528. }
  529. /** @hidden */
  530. export interface IGLTFProgram extends IGLTFChildRootProperty {
  531. attributes: string[];
  532. fragmentShader: string;
  533. vertexShader: string;
  534. }
  535. /** @hidden */
  536. export interface IGLTFTechniqueParameter {
  537. type: number;
  538. count?: number;
  539. semantic?: string;
  540. node?: string;
  541. value?: number | boolean | string | Array<any>;
  542. source?: string;
  543. babylonValue?: any;
  544. }
  545. /** @hidden */
  546. export interface IGLTFTechniqueCommonProfile {
  547. lightingModel: string;
  548. texcoordBindings: Object;
  549. parameters?: Array<any>;
  550. }
  551. /** @hidden */
  552. export interface IGLTFTechniqueStatesFunctions {
  553. blendColor?: number[];
  554. blendEquationSeparate?: number[];
  555. blendFuncSeparate?: number[];
  556. colorMask: boolean[];
  557. cullFace: number[];
  558. }
  559. /** @hidden */
  560. export interface IGLTFTechniqueStates {
  561. enable: number[];
  562. functions: IGLTFTechniqueStatesFunctions;
  563. }
  564. /** @hidden */
  565. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  566. parameters: {
  567. [key: string]: IGLTFTechniqueParameter;
  568. };
  569. program: string;
  570. attributes: {
  571. [key: string]: string;
  572. };
  573. uniforms: {
  574. [key: string]: string;
  575. };
  576. states: IGLTFTechniqueStates;
  577. }
  578. /** @hidden */
  579. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  580. technique?: string;
  581. values: string[];
  582. }
  583. /** @hidden */
  584. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  585. attributes: {
  586. [key: string]: string;
  587. };
  588. indices: string;
  589. material: string;
  590. mode?: number;
  591. }
  592. /** @hidden */
  593. export interface IGLTFMesh extends IGLTFChildRootProperty {
  594. primitives: IGLTFMeshPrimitive[];
  595. }
  596. /** @hidden */
  597. export interface IGLTFImage extends IGLTFChildRootProperty {
  598. uri: string;
  599. }
  600. /** @hidden */
  601. export interface IGLTFSampler extends IGLTFChildRootProperty {
  602. magFilter?: number;
  603. minFilter?: number;
  604. wrapS?: number;
  605. wrapT?: number;
  606. }
  607. /** @hidden */
  608. export interface IGLTFTexture extends IGLTFChildRootProperty {
  609. sampler: string;
  610. source: string;
  611. format?: ETextureFormat;
  612. internalFormat?: ETextureFormat;
  613. target?: number;
  614. type?: number;
  615. babylonTexture?: Texture;
  616. }
  617. /** @hidden */
  618. export interface IGLTFAmbienLight {
  619. color?: number[];
  620. }
  621. /** @hidden */
  622. export interface IGLTFDirectionalLight {
  623. color?: number[];
  624. }
  625. /** @hidden */
  626. export interface IGLTFPointLight {
  627. color?: number[];
  628. constantAttenuation?: number;
  629. linearAttenuation?: number;
  630. quadraticAttenuation?: number;
  631. }
  632. /** @hidden */
  633. export interface IGLTFSpotLight {
  634. color?: number[];
  635. constantAttenuation?: number;
  636. fallOfAngle?: number;
  637. fallOffExponent?: number;
  638. linearAttenuation?: number;
  639. quadraticAttenuation?: number;
  640. }
  641. /** @hidden */
  642. export interface IGLTFLight extends IGLTFChildRootProperty {
  643. type: string;
  644. }
  645. /** @hidden */
  646. export interface IGLTFCameraOrthographic {
  647. xmag: number;
  648. ymag: number;
  649. zfar: number;
  650. znear: number;
  651. }
  652. /** @hidden */
  653. export interface IGLTFCameraPerspective {
  654. aspectRatio: number;
  655. yfov: number;
  656. zfar: number;
  657. znear: number;
  658. }
  659. /** @hidden */
  660. export interface IGLTFCamera extends IGLTFChildRootProperty {
  661. type: string;
  662. }
  663. /** @hidden */
  664. export interface IGLTFAnimationChannelTarget {
  665. id: string;
  666. path: string;
  667. }
  668. /** @hidden */
  669. export interface IGLTFAnimationChannel {
  670. sampler: string;
  671. target: IGLTFAnimationChannelTarget;
  672. }
  673. /** @hidden */
  674. export interface IGLTFAnimationSampler {
  675. input: string;
  676. output: string;
  677. interpolation?: string;
  678. }
  679. /** @hidden */
  680. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  681. channels?: IGLTFAnimationChannel[];
  682. parameters?: {
  683. [key: string]: string;
  684. };
  685. samplers?: {
  686. [key: string]: IGLTFAnimationSampler;
  687. };
  688. }
  689. /** @hidden */
  690. export interface IGLTFNodeInstanceSkin {
  691. skeletons: string[];
  692. skin: string;
  693. meshes: string[];
  694. }
  695. /** @hidden */
  696. export interface IGLTFSkins extends IGLTFChildRootProperty {
  697. bindShapeMatrix: number[];
  698. inverseBindMatrices: string;
  699. jointNames: string[];
  700. babylonSkeleton?: Skeleton;
  701. }
  702. /** @hidden */
  703. export interface IGLTFNode extends IGLTFChildRootProperty {
  704. camera?: string;
  705. children: string[];
  706. skin?: string;
  707. jointName?: string;
  708. light?: string;
  709. matrix: number[];
  710. mesh?: string;
  711. meshes?: string[];
  712. rotation?: number[];
  713. scale?: number[];
  714. translation?: number[];
  715. babylonNode?: Node;
  716. }
  717. /** @hidden */
  718. export interface IGLTFScene extends IGLTFChildRootProperty {
  719. nodes: string[];
  720. }
  721. /** @hidden */
  722. export interface IGLTFRuntime {
  723. extensions: {
  724. [key: string]: any;
  725. };
  726. accessors: {
  727. [key: string]: IGLTFAccessor;
  728. };
  729. buffers: {
  730. [key: string]: IGLTFBuffer;
  731. };
  732. bufferViews: {
  733. [key: string]: IGLTFBufferView;
  734. };
  735. meshes: {
  736. [key: string]: IGLTFMesh;
  737. };
  738. lights: {
  739. [key: string]: IGLTFLight;
  740. };
  741. cameras: {
  742. [key: string]: IGLTFCamera;
  743. };
  744. nodes: {
  745. [key: string]: IGLTFNode;
  746. };
  747. images: {
  748. [key: string]: IGLTFImage;
  749. };
  750. textures: {
  751. [key: string]: IGLTFTexture;
  752. };
  753. shaders: {
  754. [key: string]: IGLTFShader;
  755. };
  756. programs: {
  757. [key: string]: IGLTFProgram;
  758. };
  759. samplers: {
  760. [key: string]: IGLTFSampler;
  761. };
  762. techniques: {
  763. [key: string]: IGLTFTechnique;
  764. };
  765. materials: {
  766. [key: string]: IGLTFMaterial;
  767. };
  768. animations: {
  769. [key: string]: IGLTFAnimation;
  770. };
  771. skins: {
  772. [key: string]: IGLTFSkins;
  773. };
  774. currentScene?: Object;
  775. scenes: {
  776. [key: string]: IGLTFScene;
  777. };
  778. extensionsUsed: string[];
  779. extensionsRequired?: string[];
  780. buffersCount: number;
  781. shaderscount: number;
  782. scene: Scene;
  783. rootUrl: string;
  784. loadedBufferCount: number;
  785. loadedBufferViews: {
  786. [name: string]: ArrayBufferView;
  787. };
  788. loadedShaderCount: number;
  789. importOnlyMeshes: boolean;
  790. importMeshesNames?: string[];
  791. dummyNodes: Node[];
  792. forAssetContainer: boolean;
  793. }
  794. /** @hidden */
  795. export interface INodeToRoot {
  796. bone: Bone;
  797. node: IGLTFNode;
  798. id: string;
  799. }
  800. /** @hidden */
  801. export interface IJointNode {
  802. node: IGLTFNode;
  803. id: string;
  804. }
  805. }
  806. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderUtils" {
  807. import { IGLTFTechniqueParameter, IGLTFAccessor, ETextureFilterType, IGLTFRuntime, IGLTFBufferView, EComponentType } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  808. import { Effect } from "babylonjs/Materials/effect";
  809. import { ShaderMaterial } from "babylonjs/Materials/shaderMaterial";
  810. import { Node } from "babylonjs/node";
  811. import { Scene } from "babylonjs/scene";
  812. /**
  813. * Utils functions for GLTF
  814. * @hidden
  815. */
  816. export class GLTFUtils {
  817. /**
  818. * Sets the given "parameter" matrix
  819. * @param scene: the Scene object
  820. * @param source: the source node where to pick the matrix
  821. * @param parameter: the GLTF technique parameter
  822. * @param uniformName: the name of the shader's uniform
  823. * @param shaderMaterial: the shader material
  824. */
  825. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  826. /**
  827. * Sets the given "parameter" matrix
  828. * @param shaderMaterial: the shader material
  829. * @param uniform: the name of the shader's uniform
  830. * @param value: the value of the uniform
  831. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  832. */
  833. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  834. /**
  835. * Returns the wrap mode of the texture
  836. * @param mode: the mode value
  837. */
  838. static GetWrapMode(mode: number): number;
  839. /**
  840. * Returns the byte stride giving an accessor
  841. * @param accessor: the GLTF accessor objet
  842. */
  843. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  844. /**
  845. * Returns the texture filter mode giving a mode value
  846. * @param mode: the filter mode value
  847. */
  848. static GetTextureFilterMode(mode: number): ETextureFilterType;
  849. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  850. /**
  851. * Returns a buffer from its accessor
  852. * @param gltfRuntime: the GLTF runtime
  853. * @param accessor: the GLTF accessor
  854. */
  855. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  856. /**
  857. * Decodes a buffer view into a string
  858. * @param view: the buffer view
  859. */
  860. static DecodeBufferToText(view: ArrayBufferView): string;
  861. /**
  862. * Returns the default material of gltf. Related to
  863. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  864. * @param scene: the Babylon.js scene
  865. */
  866. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  867. private static _DefaultMaterial;
  868. }
  869. }
  870. declare module "babylonjs-loaders/glTF/1.0/glTFLoader" {
  871. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  872. import { Nullable } from "babylonjs/types";
  873. import { Material } from "babylonjs/Materials/material";
  874. import { Texture } from "babylonjs/Materials/Textures/texture";
  875. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  876. import { Scene } from "babylonjs/scene";
  877. import { IGLTFLoader, GLTFLoaderState, IGLTFLoaderData, IImportMeshAsyncOutput } from "babylonjs-loaders/glTF/glTFFileLoader";
  878. /**
  879. * Implementation of the base glTF spec
  880. * @hidden
  881. */
  882. export class GLTFLoaderBase {
  883. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  884. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  885. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  886. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  887. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  888. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  889. }
  890. /**
  891. * glTF V1 Loader
  892. * @hidden
  893. */
  894. export class GLTFLoader implements IGLTFLoader {
  895. static Extensions: {
  896. [name: string]: GLTFLoaderExtension;
  897. };
  898. static RegisterExtension(extension: GLTFLoaderExtension): void;
  899. state: Nullable<GLTFLoaderState>;
  900. dispose(): void;
  901. private _importMeshAsync;
  902. /**
  903. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  904. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  905. * @param scene the scene the meshes should be added to
  906. * @param forAssetContainer defines if the entities must be stored in the scene
  907. * @param data gltf data containing information of the meshes in a loaded file
  908. * @param rootUrl root url to load from
  909. * @param onProgress event that fires when loading progress has occured
  910. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  911. */
  912. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<IImportMeshAsyncOutput>;
  913. private _loadAsync;
  914. /**
  915. * Imports all objects from a loaded gltf file and adds them to the scene
  916. * @param scene the scene the objects should be added to
  917. * @param data gltf data containing information of the meshes in a loaded file
  918. * @param rootUrl root url to load from
  919. * @param onProgress event that fires when loading progress has occured
  920. * @returns a promise which completes when objects have been loaded to the scene
  921. */
  922. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  923. private _loadShadersAsync;
  924. private _loadBuffersAsync;
  925. private _createNodes;
  926. }
  927. /** @hidden */
  928. export abstract class GLTFLoaderExtension {
  929. private _name;
  930. constructor(name: string);
  931. get name(): string;
  932. /**
  933. * Defines an override for loading the runtime
  934. * Return true to stop further extensions from loading the runtime
  935. */
  936. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  937. /**
  938. * Defines an onverride for creating gltf runtime
  939. * Return true to stop further extensions from creating the runtime
  940. */
  941. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  942. /**
  943. * Defines an override for loading buffers
  944. * Return true to stop further extensions from loading this buffer
  945. */
  946. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  947. /**
  948. * Defines an override for loading texture buffers
  949. * Return true to stop further extensions from loading this texture data
  950. */
  951. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  952. /**
  953. * Defines an override for creating textures
  954. * Return true to stop further extensions from loading this texture
  955. */
  956. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  957. /**
  958. * Defines an override for loading shader strings
  959. * Return true to stop further extensions from loading this shader data
  960. */
  961. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  962. /**
  963. * Defines an override for loading materials
  964. * Return true to stop further extensions from loading this material
  965. */
  966. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  967. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  968. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  969. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  970. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  971. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  972. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  973. private static LoadTextureBufferAsync;
  974. private static CreateTextureAsync;
  975. private static ApplyExtensions;
  976. }
  977. }
  978. declare module "babylonjs-loaders/glTF/1.0/glTFBinaryExtension" {
  979. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  980. import { Scene } from "babylonjs/scene";
  981. import { IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  982. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  983. /** @hidden */
  984. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  985. private _bin;
  986. constructor();
  987. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  988. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  989. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  990. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  991. }
  992. }
  993. declare module "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension" {
  994. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  995. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  996. import { Material } from "babylonjs/Materials/material";
  997. /** @hidden */
  998. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  999. constructor();
  1000. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  1001. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1002. private _loadTexture;
  1003. }
  1004. }
  1005. declare module "babylonjs-loaders/glTF/1.0/index" {
  1006. export * from "babylonjs-loaders/glTF/1.0/glTFBinaryExtension";
  1007. export * from "babylonjs-loaders/glTF/1.0/glTFLoader";
  1008. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  1009. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderUtils";
  1010. export * from "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension";
  1011. }
  1012. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces" {
  1013. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1014. import { Bone } from "babylonjs/Bones/bone";
  1015. import { Skeleton } from "babylonjs/Bones/skeleton";
  1016. import { Material } from "babylonjs/Materials/material";
  1017. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1018. import { Buffer, VertexBuffer } from "babylonjs/Meshes/buffer";
  1019. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1020. import { Mesh } from "babylonjs/Meshes/mesh";
  1021. import * as GLTF2 from "babylonjs-gltf2interface";
  1022. /**
  1023. * Loader interface with an index field.
  1024. */
  1025. export interface IArrayItem {
  1026. /**
  1027. * The index of this item in the array.
  1028. */
  1029. index: number;
  1030. }
  1031. /**
  1032. * Loader interface with additional members.
  1033. */
  1034. export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
  1035. /** @hidden */
  1036. _data?: Promise<ArrayBufferView>;
  1037. /** @hidden */
  1038. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1039. }
  1040. /**
  1041. * Loader interface with additional members.
  1042. */
  1043. export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
  1044. }
  1045. /** @hidden */
  1046. export interface _IAnimationSamplerData {
  1047. input: Float32Array;
  1048. interpolation: GLTF2.AnimationSamplerInterpolation;
  1049. output: Float32Array;
  1050. }
  1051. /**
  1052. * Loader interface with additional members.
  1053. */
  1054. export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
  1055. /** @hidden */
  1056. _data?: Promise<_IAnimationSamplerData>;
  1057. }
  1058. /**
  1059. * Loader interface with additional members.
  1060. */
  1061. export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
  1062. channels: IAnimationChannel[];
  1063. samplers: IAnimationSampler[];
  1064. /** @hidden */
  1065. _babylonAnimationGroup?: AnimationGroup;
  1066. }
  1067. /**
  1068. * Loader interface with additional members.
  1069. */
  1070. export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
  1071. /** @hidden */
  1072. _data?: Promise<ArrayBufferView>;
  1073. }
  1074. /**
  1075. * Loader interface with additional members.
  1076. */
  1077. export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
  1078. /** @hidden */
  1079. _data?: Promise<ArrayBufferView>;
  1080. /** @hidden */
  1081. _babylonBuffer?: Promise<Buffer>;
  1082. }
  1083. /**
  1084. * Loader interface with additional members.
  1085. */
  1086. export interface ICamera extends GLTF2.ICamera, IArrayItem {
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface IImage extends GLTF2.IImage, IArrayItem {
  1092. /** @hidden */
  1093. _data?: Promise<ArrayBufferView>;
  1094. }
  1095. /**
  1096. * Loader interface with additional members.
  1097. */
  1098. export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1099. }
  1100. /**
  1101. * Loader interface with additional members.
  1102. */
  1103. export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1104. }
  1105. /**
  1106. * Loader interface with additional members.
  1107. */
  1108. export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
  1109. baseColorTexture?: ITextureInfo;
  1110. metallicRoughnessTexture?: ITextureInfo;
  1111. }
  1112. /**
  1113. * Loader interface with additional members.
  1114. */
  1115. export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
  1116. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1117. normalTexture?: IMaterialNormalTextureInfo;
  1118. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1119. emissiveTexture?: ITextureInfo;
  1120. /** @hidden */
  1121. _data?: {
  1122. [babylonDrawMode: number]: {
  1123. babylonMaterial: Material;
  1124. babylonMeshes: AbstractMesh[];
  1125. promise: Promise<void>;
  1126. };
  1127. };
  1128. }
  1129. /**
  1130. * Loader interface with additional members.
  1131. */
  1132. export interface IMesh extends GLTF2.IMesh, IArrayItem {
  1133. primitives: IMeshPrimitive[];
  1134. }
  1135. /**
  1136. * Loader interface with additional members.
  1137. */
  1138. export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
  1139. /** @hidden */
  1140. _instanceData?: {
  1141. babylonSourceMesh: Mesh;
  1142. promise: Promise<any>;
  1143. };
  1144. }
  1145. /**
  1146. * Loader interface with additional members.
  1147. */
  1148. export interface INode extends GLTF2.INode, IArrayItem {
  1149. /**
  1150. * The parent glTF node.
  1151. */
  1152. parent?: INode;
  1153. /** @hidden */
  1154. _babylonTransformNode?: TransformNode;
  1155. /** @hidden */
  1156. _primitiveBabylonMeshes?: AbstractMesh[];
  1157. /** @hidden */
  1158. _babylonBones?: Bone[];
  1159. /** @hidden */
  1160. _numMorphTargets?: number;
  1161. }
  1162. /** @hidden */
  1163. export interface _ISamplerData {
  1164. noMipMaps: boolean;
  1165. samplingMode: number;
  1166. wrapU: number;
  1167. wrapV: number;
  1168. }
  1169. /**
  1170. * Loader interface with additional members.
  1171. */
  1172. export interface ISampler extends GLTF2.ISampler, IArrayItem {
  1173. /** @hidden */
  1174. _data?: _ISamplerData;
  1175. }
  1176. /**
  1177. * Loader interface with additional members.
  1178. */
  1179. export interface IScene extends GLTF2.IScene, IArrayItem {
  1180. }
  1181. /**
  1182. * Loader interface with additional members.
  1183. */
  1184. export interface ISkin extends GLTF2.ISkin, IArrayItem {
  1185. /** @hidden */
  1186. _data?: {
  1187. babylonSkeleton: Skeleton;
  1188. promise: Promise<void>;
  1189. };
  1190. }
  1191. /**
  1192. * Loader interface with additional members.
  1193. */
  1194. export interface ITexture extends GLTF2.ITexture, IArrayItem {
  1195. }
  1196. /**
  1197. * Loader interface with additional members.
  1198. */
  1199. export interface ITextureInfo extends GLTF2.ITextureInfo {
  1200. }
  1201. /**
  1202. * Loader interface with additional members.
  1203. */
  1204. export interface IGLTF extends GLTF2.IGLTF {
  1205. accessors?: IAccessor[];
  1206. animations?: IAnimation[];
  1207. buffers?: IBuffer[];
  1208. bufferViews?: IBufferView[];
  1209. cameras?: ICamera[];
  1210. images?: IImage[];
  1211. materials?: IMaterial[];
  1212. meshes?: IMesh[];
  1213. nodes?: INode[];
  1214. samplers?: ISampler[];
  1215. scenes?: IScene[];
  1216. skins?: ISkin[];
  1217. textures?: ITexture[];
  1218. }
  1219. }
  1220. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtension" {
  1221. import { Nullable } from "babylonjs/types";
  1222. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1223. import { Material } from "babylonjs/Materials/material";
  1224. import { Camera } from "babylonjs/Cameras/camera";
  1225. import { Geometry } from "babylonjs/Meshes/geometry";
  1226. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1227. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1228. import { Mesh } from "babylonjs/Meshes/mesh";
  1229. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1230. import { IDisposable } from "babylonjs/scene";
  1231. import { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation, IBufferView, IBuffer } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1232. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
  1233. import { IProperty } from 'babylonjs-gltf2interface';
  1234. /**
  1235. * Interface for a glTF loader extension.
  1236. */
  1237. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  1238. /**
  1239. * Called after the loader state changes to LOADING.
  1240. */
  1241. onLoading?(): void;
  1242. /**
  1243. * Called after the loader state changes to READY.
  1244. */
  1245. onReady?(): void;
  1246. /**
  1247. * Define this method to modify the default behavior when loading scenes.
  1248. * @param context The context when loading the asset
  1249. * @param scene The glTF scene property
  1250. * @returns A promise that resolves when the load is complete or null if not handled
  1251. */
  1252. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1253. /**
  1254. * Define this method to modify the default behavior when loading nodes.
  1255. * @param context The context when loading the asset
  1256. * @param node The glTF node property
  1257. * @param assign A function called synchronously after parsing the glTF properties
  1258. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1259. */
  1260. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1261. /**
  1262. * Define this method to modify the default behavior when loading cameras.
  1263. * @param context The context when loading the asset
  1264. * @param camera The glTF camera property
  1265. * @param assign A function called synchronously after parsing the glTF properties
  1266. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1267. */
  1268. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1269. /**
  1270. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1271. * @param context The context when loading the asset
  1272. * @param primitive The glTF mesh primitive property
  1273. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1274. */
  1275. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1276. /**
  1277. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1278. * @param context The context when loading the asset
  1279. * @param name The mesh name when loading the asset
  1280. * @param node The glTF node when loading the asset
  1281. * @param mesh The glTF mesh when loading the asset
  1282. * @param primitive The glTF mesh primitive property
  1283. * @param assign A function called synchronously after parsing the glTF properties
  1284. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1285. */
  1286. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1287. /**
  1288. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1289. * @param context The context when loading the asset
  1290. * @param material The glTF material property
  1291. * @param assign A function called synchronously after parsing the glTF properties
  1292. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1293. */
  1294. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1295. /**
  1296. * Define this method to modify the default behavior when creating materials.
  1297. * @param context The context when loading the asset
  1298. * @param material The glTF material property
  1299. * @param babylonDrawMode The draw mode for the Babylon material
  1300. * @returns The Babylon material or null if not handled
  1301. */
  1302. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1303. /**
  1304. * Define this method to modify the default behavior when loading material properties.
  1305. * @param context The context when loading the asset
  1306. * @param material The glTF material property
  1307. * @param babylonMaterial The Babylon material
  1308. * @returns A promise that resolves when the load is complete or null if not handled
  1309. */
  1310. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1311. /**
  1312. * Define this method to modify the default behavior when loading texture infos.
  1313. * @param context The context when loading the asset
  1314. * @param textureInfo The glTF texture info property
  1315. * @param assign A function called synchronously after parsing the glTF properties
  1316. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1317. */
  1318. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1319. /**
  1320. * Define this method to modify the default behavior when loading animations.
  1321. * @param context The context when loading the asset
  1322. * @param animation The glTF animation property
  1323. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1324. */
  1325. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1326. /**
  1327. * @hidden Define this method to modify the default behavior when loading skins.
  1328. * @param context The context when loading the asset
  1329. * @param node The glTF node property
  1330. * @param skin The glTF skin property
  1331. * @returns A promise that resolves when the load is complete or null if not handled
  1332. */
  1333. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1334. /**
  1335. * @hidden Define this method to modify the default behavior when loading uris.
  1336. * @param context The context when loading the asset
  1337. * @param property The glTF property associated with the uri
  1338. * @param uri The uri to load
  1339. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1340. */
  1341. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1342. /**
  1343. * Define this method to modify the default behavior when loading buffer views.
  1344. * @param context The context when loading the asset
  1345. * @param bufferView The glTF buffer view property
  1346. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1347. */
  1348. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1349. /**
  1350. * Define this method to modify the default behavior when loading buffers.
  1351. * @param context The context when loading the asset
  1352. * @param buffer The glTF buffer property
  1353. * @param byteOffset The byte offset to load
  1354. * @param byteLength The byte length to load
  1355. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1356. */
  1357. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1358. }
  1359. }
  1360. declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
  1361. import { Nullable } from "babylonjs/types";
  1362. import { Camera } from "babylonjs/Cameras/camera";
  1363. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1364. import { Material } from "babylonjs/Materials/material";
  1365. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1366. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1367. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1368. import { Mesh } from "babylonjs/Meshes/mesh";
  1369. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1370. import { Scene } from "babylonjs/scene";
  1371. import { IProperty } from "babylonjs-gltf2interface";
  1372. import { IGLTF, INode, IScene, IMesh, ICamera, IAnimation, IAnimationChannel, IBufferView, IMaterial, ITextureInfo, IImage, IMeshPrimitive, IArrayItem as IArrItem } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1373. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1374. import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData, IImportMeshAsyncOutput } from "babylonjs-loaders/glTF/glTFFileLoader";
  1375. import { IAnimatable } from 'babylonjs/Animations/animatable.interface';
  1376. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  1377. import { Light } from 'babylonjs/Lights/light';
  1378. /**
  1379. * Helper class for working with arrays when loading the glTF asset
  1380. */
  1381. export class ArrayItem {
  1382. /**
  1383. * Gets an item from the given array.
  1384. * @param context The context when loading the asset
  1385. * @param array The array to get the item from
  1386. * @param index The index to the array
  1387. * @returns The array item
  1388. */
  1389. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1390. /**
  1391. * Assign an `index` field to each item of the given array.
  1392. * @param array The array of items
  1393. */
  1394. static Assign(array?: IArrItem[]): void;
  1395. }
  1396. /**
  1397. * The glTF 2.0 loader
  1398. */
  1399. export class GLTFLoader implements IGLTFLoader {
  1400. /** @hidden */
  1401. _completePromises: Promise<any>[];
  1402. /** @hidden */
  1403. _forAssetContainer: boolean;
  1404. /** Storage */
  1405. _babylonLights: Light[];
  1406. private _disposed;
  1407. private _parent;
  1408. private _state;
  1409. private _extensions;
  1410. private _rootUrl;
  1411. private _fileName;
  1412. private _uniqueRootUrl;
  1413. private _gltf;
  1414. private _bin;
  1415. private _babylonScene;
  1416. private _rootBabylonMesh;
  1417. private _defaultBabylonMaterialData;
  1418. private _progressCallback?;
  1419. private _requests;
  1420. private static readonly _DefaultSampler;
  1421. private static _RegisteredExtensions;
  1422. /**
  1423. * Registers a loader extension.
  1424. * @param name The name of the loader extension.
  1425. * @param factory The factory function that creates the loader extension.
  1426. */
  1427. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1428. /**
  1429. * Unregisters a loader extension.
  1430. * @param name The name of the loader extension.
  1431. * @returns A boolean indicating whether the extension has been unregistered
  1432. */
  1433. static UnregisterExtension(name: string): boolean;
  1434. /**
  1435. * Gets the loader state.
  1436. */
  1437. get state(): Nullable<GLTFLoaderState>;
  1438. /**
  1439. * The object that represents the glTF JSON.
  1440. */
  1441. get gltf(): IGLTF;
  1442. /**
  1443. * The BIN chunk of a binary glTF.
  1444. */
  1445. get bin(): Nullable<IDataBuffer>;
  1446. /**
  1447. * The parent file loader.
  1448. */
  1449. get parent(): GLTFFileLoader;
  1450. /**
  1451. * The Babylon scene when loading the asset.
  1452. */
  1453. get babylonScene(): Scene;
  1454. /**
  1455. * The root Babylon mesh when loading the asset.
  1456. */
  1457. get rootBabylonMesh(): Mesh;
  1458. /** @hidden */
  1459. constructor(parent: GLTFFileLoader);
  1460. /** @hidden */
  1461. dispose(): void;
  1462. /** @hidden */
  1463. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<IImportMeshAsyncOutput>;
  1464. /** @hidden */
  1465. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1466. private _loadAsync;
  1467. private _loadData;
  1468. private _setupData;
  1469. private _loadExtensions;
  1470. private _checkExtensions;
  1471. private _setState;
  1472. private _createRootNode;
  1473. /**
  1474. * Loads a glTF scene.
  1475. * @param context The context when loading the asset
  1476. * @param scene The glTF scene property
  1477. * @returns A promise that resolves when the load is complete
  1478. */
  1479. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1480. private _forEachPrimitive;
  1481. private _getMeshes;
  1482. private _getTransformNodes;
  1483. private _getSkeletons;
  1484. private _getAnimationGroups;
  1485. private _startAnimations;
  1486. /**
  1487. * Loads a glTF node.
  1488. * @param context The context when loading the asset
  1489. * @param node The glTF node property
  1490. * @param assign A function called synchronously after parsing the glTF properties
  1491. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1492. */
  1493. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1494. private _loadMeshAsync;
  1495. /**
  1496. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1497. * @param context The context when loading the asset
  1498. * @param name The mesh name when loading the asset
  1499. * @param node The glTF node when loading the asset
  1500. * @param mesh The glTF mesh when loading the asset
  1501. * @param primitive The glTF mesh primitive property
  1502. * @param assign A function called synchronously after parsing the glTF properties
  1503. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1504. */
  1505. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1506. private _loadVertexDataAsync;
  1507. private _createMorphTargets;
  1508. private _loadMorphTargetsAsync;
  1509. private _loadMorphTargetVertexDataAsync;
  1510. private static _LoadTransform;
  1511. private _loadSkinAsync;
  1512. private _loadBones;
  1513. private _loadBone;
  1514. private _loadSkinInverseBindMatricesDataAsync;
  1515. private _updateBoneMatrices;
  1516. private _getNodeMatrix;
  1517. /**
  1518. * Loads a glTF camera.
  1519. * @param context The context when loading the asset
  1520. * @param camera The glTF camera property
  1521. * @param assign A function called synchronously after parsing the glTF properties
  1522. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1523. */
  1524. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1525. private _loadAnimationsAsync;
  1526. /**
  1527. * Loads a glTF animation.
  1528. * @param context The context when loading the asset
  1529. * @param animation The glTF animation property
  1530. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1531. */
  1532. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1533. /**
  1534. * @hidden Loads a glTF animation channel.
  1535. * @param context The context when loading the asset
  1536. * @param animationContext The context of the animation when loading the asset
  1537. * @param animation The glTF animation property
  1538. * @param channel The glTF animation channel property
  1539. * @param babylonAnimationGroup The babylon animation group property
  1540. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1541. * @returns A void promise when the channel load is complete
  1542. */
  1543. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1544. private _loadAnimationSamplerAsync;
  1545. private _loadBufferAsync;
  1546. /**
  1547. * Loads a glTF buffer view.
  1548. * @param context The context when loading the asset
  1549. * @param bufferView The glTF buffer view property
  1550. * @returns A promise that resolves with the loaded data when the load is complete
  1551. */
  1552. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1553. private _loadAccessorAsync;
  1554. private _loadFloatAccessorAsync;
  1555. private _loadIndicesAccessorAsync;
  1556. private _loadVertexBufferViewAsync;
  1557. private _loadVertexAccessorAsync;
  1558. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1559. /** @hidden */
  1560. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1561. private _createDefaultMaterial;
  1562. /**
  1563. * Creates a Babylon material from a glTF material.
  1564. * @param context The context when loading the asset
  1565. * @param material The glTF material property
  1566. * @param babylonDrawMode The draw mode for the Babylon material
  1567. * @returns The Babylon material
  1568. */
  1569. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1570. /**
  1571. * Loads properties from a glTF material into a Babylon material.
  1572. * @param context The context when loading the asset
  1573. * @param material The glTF material property
  1574. * @param babylonMaterial The Babylon material
  1575. * @returns A promise that resolves when the load is complete
  1576. */
  1577. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1578. /**
  1579. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1580. * @param context The context when loading the asset
  1581. * @param material The glTF material property
  1582. * @param babylonMaterial The Babylon material
  1583. * @returns A promise that resolves when the load is complete
  1584. */
  1585. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1586. /**
  1587. * Loads the alpha properties from a glTF material into a Babylon material.
  1588. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1589. * @param context The context when loading the asset
  1590. * @param material The glTF material property
  1591. * @param babylonMaterial The Babylon material
  1592. */
  1593. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1594. /**
  1595. * Loads a glTF texture info.
  1596. * @param context The context when loading the asset
  1597. * @param textureInfo The glTF texture info property
  1598. * @param assign A function called synchronously after parsing the glTF properties
  1599. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1600. */
  1601. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1602. private _loadTextureAsync;
  1603. private _loadSampler;
  1604. /**
  1605. * Loads a glTF image.
  1606. * @param context The context when loading the asset
  1607. * @param image The glTF image property
  1608. * @returns A promise that resolves with the loaded data when the load is complete
  1609. */
  1610. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1611. /**
  1612. * Loads a glTF uri.
  1613. * @param context The context when loading the asset
  1614. * @param property The glTF property associated with the uri
  1615. * @param uri The base64 or relative uri
  1616. * @returns A promise that resolves with the loaded data when the load is complete
  1617. */
  1618. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1619. private _onProgress;
  1620. /**
  1621. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1622. * @param babylonObject the Babylon object with metadata
  1623. * @param pointer the JSON pointer
  1624. */
  1625. static AddPointerMetadata(babylonObject: {
  1626. metadata: any;
  1627. }, pointer: string): void;
  1628. private static _GetTextureWrapMode;
  1629. private static _GetTextureSamplingMode;
  1630. private static _GetTypedArrayConstructor;
  1631. private static _GetTypedArray;
  1632. private static _GetNumComponents;
  1633. private static _ValidateUri;
  1634. private static _GetDrawMode;
  1635. private _compileMaterialsAsync;
  1636. private _compileShadowGeneratorsAsync;
  1637. private _forEachExtensions;
  1638. private _applyExtensions;
  1639. private _extensionsOnLoading;
  1640. private _extensionsOnReady;
  1641. private _extensionsLoadSceneAsync;
  1642. private _extensionsLoadNodeAsync;
  1643. private _extensionsLoadCameraAsync;
  1644. private _extensionsLoadVertexDataAsync;
  1645. private _extensionsLoadMeshPrimitiveAsync;
  1646. private _extensionsLoadMaterialAsync;
  1647. private _extensionsCreateMaterial;
  1648. private _extensionsLoadMaterialPropertiesAsync;
  1649. private _extensionsLoadTextureInfoAsync;
  1650. private _extensionsLoadAnimationAsync;
  1651. private _extensionsLoadSkinAsync;
  1652. private _extensionsLoadUriAsync;
  1653. private _extensionsLoadBufferViewAsync;
  1654. private _extensionsLoadBufferAsync;
  1655. /**
  1656. * Helper method called by a loader extension to load an glTF extension.
  1657. * @param context The context when loading the asset
  1658. * @param property The glTF property to load the extension from
  1659. * @param extensionName The name of the extension to load
  1660. * @param actionAsync The action to run
  1661. * @returns The promise returned by actionAsync or null if the extension does not exist
  1662. */
  1663. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1664. /**
  1665. * Helper method called by a loader extension to load a glTF extra.
  1666. * @param context The context when loading the asset
  1667. * @param property The glTF property to load the extra from
  1668. * @param extensionName The name of the extension to load
  1669. * @param actionAsync The action to run
  1670. * @returns The promise returned by actionAsync or null if the extra does not exist
  1671. */
  1672. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1673. /**
  1674. * Checks for presence of an extension.
  1675. * @param name The name of the extension to check
  1676. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1677. */
  1678. isExtensionUsed(name: string): boolean;
  1679. /**
  1680. * Increments the indentation level and logs a message.
  1681. * @param message The message to log
  1682. */
  1683. logOpen(message: string): void;
  1684. /**
  1685. * Decrements the indentation level.
  1686. */
  1687. logClose(): void;
  1688. /**
  1689. * Logs a message
  1690. * @param message The message to log
  1691. */
  1692. log(message: string): void;
  1693. /**
  1694. * Starts a performance counter.
  1695. * @param counterName The name of the performance counter
  1696. */
  1697. startPerformanceCounter(counterName: string): void;
  1698. /**
  1699. * Ends a performance counter.
  1700. * @param counterName The name of the performance counter
  1701. */
  1702. endPerformanceCounter(counterName: string): void;
  1703. }
  1704. }
  1705. declare module "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based" {
  1706. import { Nullable } from "babylonjs/types";
  1707. import { IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1708. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1709. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1710. /**
  1711. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1712. */
  1713. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1714. /**
  1715. * The name of this extension.
  1716. */
  1717. readonly name: string;
  1718. /**
  1719. * Defines whether this extension is enabled.
  1720. */
  1721. enabled: boolean;
  1722. private _loader;
  1723. private _lights?;
  1724. /** @hidden */
  1725. constructor(loader: GLTFLoader);
  1726. /** @hidden */
  1727. dispose(): void;
  1728. /** @hidden */
  1729. onLoading(): void;
  1730. /** @hidden */
  1731. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1732. private _loadLightAsync;
  1733. }
  1734. }
  1735. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression" {
  1736. import { DracoCompression } from "babylonjs/Meshes/Compression/dracoCompression";
  1737. import { Nullable } from "babylonjs/types";
  1738. import { Geometry } from "babylonjs/Meshes/geometry";
  1739. import { Mesh } from "babylonjs/Meshes/mesh";
  1740. import { IMeshPrimitive } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1741. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1742. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1743. /**
  1744. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1745. */
  1746. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1747. /**
  1748. * The name of this extension.
  1749. */
  1750. readonly name: string;
  1751. /**
  1752. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1753. */
  1754. dracoCompression?: DracoCompression;
  1755. /**
  1756. * Defines whether this extension is enabled.
  1757. */
  1758. enabled: boolean;
  1759. private _loader;
  1760. /** @hidden */
  1761. constructor(loader: GLTFLoader);
  1762. /** @hidden */
  1763. dispose(): void;
  1764. /** @hidden */
  1765. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1766. }
  1767. }
  1768. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual" {
  1769. import { Nullable } from "babylonjs/types";
  1770. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1771. import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1772. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1773. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1774. /**
  1775. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  1776. */
  1777. export class KHR_lights implements IGLTFLoaderExtension {
  1778. /**
  1779. * The name of this extension.
  1780. */
  1781. readonly name: string;
  1782. /**
  1783. * Defines whether this extension is enabled.
  1784. */
  1785. enabled: boolean;
  1786. private _loader;
  1787. private _lights?;
  1788. /** @hidden */
  1789. constructor(loader: GLTFLoader);
  1790. /** @hidden */
  1791. dispose(): void;
  1792. /** @hidden */
  1793. onLoading(): void;
  1794. /** @hidden */
  1795. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1796. }
  1797. }
  1798. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness" {
  1799. import { Nullable } from "babylonjs/types";
  1800. import { Material } from "babylonjs/Materials/material";
  1801. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1802. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1803. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1804. /**
  1805. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1806. */
  1807. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1808. /**
  1809. * The name of this extension.
  1810. */
  1811. readonly name: string;
  1812. /**
  1813. * Defines whether this extension is enabled.
  1814. */
  1815. enabled: boolean;
  1816. /**
  1817. * Defines a number that determines the order the extensions are applied.
  1818. */
  1819. order: number;
  1820. private _loader;
  1821. /** @hidden */
  1822. constructor(loader: GLTFLoader);
  1823. /** @hidden */
  1824. dispose(): void;
  1825. /** @hidden */
  1826. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1827. private _loadSpecularGlossinessPropertiesAsync;
  1828. }
  1829. }
  1830. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit" {
  1831. import { Nullable } from "babylonjs/types";
  1832. import { Material } from "babylonjs/Materials/material";
  1833. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1834. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1835. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1836. /**
  1837. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1838. */
  1839. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1840. /**
  1841. * The name of this extension.
  1842. */
  1843. readonly name: string;
  1844. /**
  1845. * Defines whether this extension is enabled.
  1846. */
  1847. enabled: boolean;
  1848. /**
  1849. * Defines a number that determines the order the extensions are applied.
  1850. */
  1851. order: number;
  1852. private _loader;
  1853. /** @hidden */
  1854. constructor(loader: GLTFLoader);
  1855. /** @hidden */
  1856. dispose(): void;
  1857. /** @hidden */
  1858. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1859. private _loadUnlitPropertiesAsync;
  1860. }
  1861. }
  1862. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat" {
  1863. import { Nullable } from "babylonjs/types";
  1864. import { Material } from "babylonjs/Materials/material";
  1865. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1866. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1867. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1868. /**
  1869. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1870. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1871. * !!! Experimental Extension Subject to Changes !!!
  1872. */
  1873. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1874. /**
  1875. * The name of this extension.
  1876. */
  1877. readonly name: string;
  1878. /**
  1879. * Defines whether this extension is enabled.
  1880. */
  1881. enabled: boolean;
  1882. /**
  1883. * Defines a number that determines the order the extensions are applied.
  1884. */
  1885. order: number;
  1886. private _loader;
  1887. /** @hidden */
  1888. constructor(loader: GLTFLoader);
  1889. /** @hidden */
  1890. dispose(): void;
  1891. /** @hidden */
  1892. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1893. private _loadClearCoatPropertiesAsync;
  1894. }
  1895. }
  1896. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen" {
  1897. import { Nullable } from "babylonjs/types";
  1898. import { Material } from "babylonjs/Materials/material";
  1899. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1900. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1901. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1902. /**
  1903. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1904. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1905. * !!! Experimental Extension Subject to Changes !!!
  1906. */
  1907. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1908. /**
  1909. * The name of this extension.
  1910. */
  1911. readonly name: string;
  1912. /**
  1913. * Defines whether this extension is enabled.
  1914. */
  1915. enabled: boolean;
  1916. /**
  1917. * Defines a number that determines the order the extensions are applied.
  1918. */
  1919. order: number;
  1920. private _loader;
  1921. /** @hidden */
  1922. constructor(loader: GLTFLoader);
  1923. /** @hidden */
  1924. dispose(): void;
  1925. /** @hidden */
  1926. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1927. private _loadSheenPropertiesAsync;
  1928. }
  1929. }
  1930. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular" {
  1931. import { Nullable } from "babylonjs/types";
  1932. import { Material } from "babylonjs/Materials/material";
  1933. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1934. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1935. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1936. /**
  1937. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1938. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1939. * !!! Experimental Extension Subject to Changes !!!
  1940. */
  1941. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1942. /**
  1943. * The name of this extension.
  1944. */
  1945. readonly name: string;
  1946. /**
  1947. * Defines whether this extension is enabled.
  1948. */
  1949. enabled: boolean;
  1950. /**
  1951. * Defines a number that determines the order the extensions are applied.
  1952. */
  1953. order: number;
  1954. private _loader;
  1955. /** @hidden */
  1956. constructor(loader: GLTFLoader);
  1957. /** @hidden */
  1958. dispose(): void;
  1959. /** @hidden */
  1960. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1961. private _loadSpecularPropertiesAsync;
  1962. }
  1963. }
  1964. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization" {
  1965. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1966. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1967. /**
  1968. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1969. */
  1970. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1971. /**
  1972. * The name of this extension.
  1973. */
  1974. readonly name: string;
  1975. /**
  1976. * Defines whether this extension is enabled.
  1977. */
  1978. enabled: boolean;
  1979. /** @hidden */
  1980. constructor(loader: GLTFLoader);
  1981. /** @hidden */
  1982. dispose(): void;
  1983. }
  1984. }
  1985. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform" {
  1986. import { Nullable } from "babylonjs/types";
  1987. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1988. import { ITextureInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1989. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1990. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1991. /**
  1992. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1993. */
  1994. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1995. /**
  1996. * The name of this extension.
  1997. */
  1998. readonly name: string;
  1999. /**
  2000. * Defines whether this extension is enabled.
  2001. */
  2002. enabled: boolean;
  2003. private _loader;
  2004. /** @hidden */
  2005. constructor(loader: GLTFLoader);
  2006. /** @hidden */
  2007. dispose(): void;
  2008. /** @hidden */
  2009. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2010. }
  2011. }
  2012. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter" {
  2013. import { Nullable } from "babylonjs/types";
  2014. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  2015. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2016. import { IScene, INode, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2017. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2018. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2019. /**
  2020. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2021. */
  2022. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2023. /**
  2024. * The name of this extension.
  2025. */
  2026. readonly name: string;
  2027. /**
  2028. * Defines whether this extension is enabled.
  2029. */
  2030. enabled: boolean;
  2031. private _loader;
  2032. private _clips;
  2033. private _emitters;
  2034. /** @hidden */
  2035. constructor(loader: GLTFLoader);
  2036. /** @hidden */
  2037. dispose(): void;
  2038. /** @hidden */
  2039. onLoading(): void;
  2040. /** @hidden */
  2041. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2042. /** @hidden */
  2043. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2044. /** @hidden */
  2045. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2046. private _loadClipAsync;
  2047. private _loadEmitterAsync;
  2048. private _getEventAction;
  2049. private _loadAnimationEventAsync;
  2050. }
  2051. }
  2052. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod" {
  2053. import { Nullable } from "babylonjs/types";
  2054. import { Observable } from "babylonjs/Misc/observable";
  2055. import { Material } from "babylonjs/Materials/material";
  2056. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2057. import { Mesh } from "babylonjs/Meshes/mesh";
  2058. import { INode, IMaterial, IBuffer, IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2059. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2060. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2061. import { IProperty } from 'babylonjs-gltf2interface';
  2062. /**
  2063. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2064. */
  2065. export class MSFT_lod implements IGLTFLoaderExtension {
  2066. /**
  2067. * The name of this extension.
  2068. */
  2069. readonly name: string;
  2070. /**
  2071. * Defines whether this extension is enabled.
  2072. */
  2073. enabled: boolean;
  2074. /**
  2075. * Defines a number that determines the order the extensions are applied.
  2076. */
  2077. order: number;
  2078. /**
  2079. * Maximum number of LODs to load, starting from the lowest LOD.
  2080. */
  2081. maxLODsToLoad: number;
  2082. /**
  2083. * Observable raised when all node LODs of one level are loaded.
  2084. * The event data is the index of the loaded LOD starting from zero.
  2085. * Dispose the loader to cancel the loading of the next level of LODs.
  2086. */
  2087. onNodeLODsLoadedObservable: Observable<number>;
  2088. /**
  2089. * Observable raised when all material LODs of one level are loaded.
  2090. * The event data is the index of the loaded LOD starting from zero.
  2091. * Dispose the loader to cancel the loading of the next level of LODs.
  2092. */
  2093. onMaterialLODsLoadedObservable: Observable<number>;
  2094. private _loader;
  2095. private _nodeIndexLOD;
  2096. private _nodeSignalLODs;
  2097. private _nodePromiseLODs;
  2098. private _materialIndexLOD;
  2099. private _materialSignalLODs;
  2100. private _materialPromiseLODs;
  2101. private _indexLOD;
  2102. private _bufferLODs;
  2103. /** @hidden */
  2104. constructor(loader: GLTFLoader);
  2105. /** @hidden */
  2106. dispose(): void;
  2107. /** @hidden */
  2108. onReady(): void;
  2109. /** @hidden */
  2110. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2111. /** @hidden */
  2112. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2113. /** @hidden */
  2114. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2115. /** @hidden */
  2116. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2117. /** @hidden */
  2118. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2119. private _loadBufferLOD;
  2120. /**
  2121. * Gets an array of LOD properties from lowest to highest.
  2122. */
  2123. private _getLODs;
  2124. private _disposeUnusedMaterials;
  2125. }
  2126. }
  2127. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh" {
  2128. import { Nullable } from "babylonjs/types";
  2129. import { Material } from "babylonjs/Materials/material";
  2130. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2131. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2132. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2133. /** @hidden */
  2134. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2135. readonly name: string;
  2136. enabled: boolean;
  2137. private _loader;
  2138. constructor(loader: GLTFLoader);
  2139. dispose(): void;
  2140. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2141. }
  2142. }
  2143. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors" {
  2144. import { Nullable } from "babylonjs/types";
  2145. import { Material } from "babylonjs/Materials/material";
  2146. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2147. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2148. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2149. /** @hidden */
  2150. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2151. readonly name: string;
  2152. enabled: boolean;
  2153. private _loader;
  2154. constructor(loader: GLTFLoader);
  2155. dispose(): void;
  2156. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2157. }
  2158. }
  2159. declare module "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata" {
  2160. import { Nullable } from "babylonjs/types";
  2161. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2162. import { Camera } from "babylonjs/Cameras/camera";
  2163. import { INode, ICamera, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2164. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2165. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2166. import { Material } from "babylonjs/Materials/material";
  2167. /**
  2168. * Store glTF extras (if present) in BJS objects' metadata
  2169. */
  2170. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2171. /**
  2172. * The name of this extension.
  2173. */
  2174. readonly name: string;
  2175. /**
  2176. * Defines whether this extension is enabled.
  2177. */
  2178. enabled: boolean;
  2179. private _loader;
  2180. private _assignExtras;
  2181. /** @hidden */
  2182. constructor(loader: GLTFLoader);
  2183. /** @hidden */
  2184. dispose(): void;
  2185. /** @hidden */
  2186. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2187. /** @hidden */
  2188. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2189. /** @hidden */
  2190. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2191. }
  2192. }
  2193. declare module "babylonjs-loaders/glTF/2.0/Extensions/index" {
  2194. export * from "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based";
  2195. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
  2196. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual";
  2197. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness";
  2198. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit";
  2199. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat";
  2200. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen";
  2201. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular";
  2202. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization";
  2203. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform";
  2204. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter";
  2205. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod";
  2206. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh";
  2207. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors";
  2208. export * from "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata";
  2209. }
  2210. declare module "babylonjs-loaders/glTF/2.0/index" {
  2211. export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2212. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2213. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2214. export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
  2215. }
  2216. declare module "babylonjs-loaders/glTF/index" {
  2217. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2218. export * from "babylonjs-loaders/glTF/glTFValidation";
  2219. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2220. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2221. export { GLTF1, GLTF2 };
  2222. }
  2223. declare module "babylonjs-loaders/OBJ/mtlFileLoader" {
  2224. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  2225. import { Scene } from "babylonjs/scene";
  2226. /**
  2227. * Class reading and parsing the MTL file bundled with the obj file.
  2228. */
  2229. export class MTLFileLoader {
  2230. /**
  2231. * Invert Y-Axis of referenced textures on load
  2232. */
  2233. static INVERT_TEXTURE_Y: boolean;
  2234. /**
  2235. * All material loaded from the mtl will be set here
  2236. */
  2237. materials: StandardMaterial[];
  2238. /**
  2239. * This function will read the mtl file and create each material described inside
  2240. * This function could be improve by adding :
  2241. * -some component missing (Ni, Tf...)
  2242. * -including the specific options available
  2243. *
  2244. * @param scene defines the scene the material will be created in
  2245. * @param data defines the mtl data to parse
  2246. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2247. * @param forAssetContainer defines if the material should be registered in the scene
  2248. */
  2249. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2250. /**
  2251. * Gets the texture for the material.
  2252. *
  2253. * If the material is imported from input file,
  2254. * We sanitize the url to ensure it takes the textre from aside the material.
  2255. *
  2256. * @param rootUrl The root url to load from
  2257. * @param value The value stored in the mtl
  2258. * @return The Texture
  2259. */
  2260. private static _getTexture;
  2261. }
  2262. }
  2263. declare module "babylonjs-loaders/OBJ/objFileLoader" {
  2264. import { Vector2 } from "babylonjs/Maths/math";
  2265. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  2266. import { Skeleton } from "babylonjs/Bones/skeleton";
  2267. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2268. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2269. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin } from "babylonjs/Loading/sceneLoader";
  2270. import { AssetContainer } from "babylonjs/assetContainer";
  2271. import { Scene } from "babylonjs/scene";
  2272. /**
  2273. * Options for loading OBJ/MTL files
  2274. */
  2275. type MeshLoadOptions = {
  2276. /**
  2277. * Defines if UVs are optimized by default during load.
  2278. */
  2279. OptimizeWithUV: boolean;
  2280. /**
  2281. * Defines custom scaling of UV coordinates of loaded meshes.
  2282. */
  2283. UVScaling: Vector2;
  2284. /**
  2285. * Invert model on y-axis (does a model scaling inversion)
  2286. */
  2287. InvertY: boolean;
  2288. /**
  2289. * Invert Y-Axis of referenced textures on load
  2290. */
  2291. InvertTextureY: boolean;
  2292. /**
  2293. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2294. */
  2295. ImportVertexColors: boolean;
  2296. /**
  2297. * Compute the normals for the model, even if normals are present in the file.
  2298. */
  2299. ComputeNormals: boolean;
  2300. /**
  2301. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2302. */
  2303. SkipMaterials: boolean;
  2304. /**
  2305. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2306. */
  2307. MaterialLoadingFailsSilently: boolean;
  2308. };
  2309. /**
  2310. * OBJ file type loader.
  2311. * This is a babylon scene loader plugin.
  2312. */
  2313. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2314. /**
  2315. * Defines if UVs are optimized by default during load.
  2316. */
  2317. static OPTIMIZE_WITH_UV: boolean;
  2318. /**
  2319. * Invert model on y-axis (does a model scaling inversion)
  2320. */
  2321. static INVERT_Y: boolean;
  2322. /**
  2323. * Invert Y-Axis of referenced textures on load
  2324. */
  2325. static get INVERT_TEXTURE_Y(): boolean;
  2326. static set INVERT_TEXTURE_Y(value: boolean);
  2327. /**
  2328. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2329. */
  2330. static IMPORT_VERTEX_COLORS: boolean;
  2331. /**
  2332. * Compute the normals for the model, even if normals are present in the file.
  2333. */
  2334. static COMPUTE_NORMALS: boolean;
  2335. /**
  2336. * Defines custom scaling of UV coordinates of loaded meshes.
  2337. */
  2338. static UV_SCALING: Vector2;
  2339. /**
  2340. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2341. */
  2342. static SKIP_MATERIALS: boolean;
  2343. /**
  2344. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2345. *
  2346. * Defaults to true for backwards compatibility.
  2347. */
  2348. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2349. /**
  2350. * Defines the name of the plugin.
  2351. */
  2352. name: string;
  2353. /**
  2354. * Defines the extension the plugin is able to load.
  2355. */
  2356. extensions: string;
  2357. /** @hidden */
  2358. obj: RegExp;
  2359. /** @hidden */
  2360. group: RegExp;
  2361. /** @hidden */
  2362. mtllib: RegExp;
  2363. /** @hidden */
  2364. usemtl: RegExp;
  2365. /** @hidden */
  2366. smooth: RegExp;
  2367. /** @hidden */
  2368. vertexPattern: RegExp;
  2369. /** @hidden */
  2370. normalPattern: RegExp;
  2371. /** @hidden */
  2372. uvPattern: RegExp;
  2373. /** @hidden */
  2374. facePattern1: RegExp;
  2375. /** @hidden */
  2376. facePattern2: RegExp;
  2377. /** @hidden */
  2378. facePattern3: RegExp;
  2379. /** @hidden */
  2380. facePattern4: RegExp;
  2381. /** @hidden */
  2382. facePattern5: RegExp;
  2383. private _forAssetContainer;
  2384. private _meshLoadOptions;
  2385. /**
  2386. * Creates loader for .OBJ files
  2387. *
  2388. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2389. */
  2390. constructor(meshLoadOptions?: MeshLoadOptions);
  2391. private static get currentMeshLoadOptions();
  2392. /**
  2393. * Calls synchronously the MTL file attached to this obj.
  2394. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2395. * Without this function materials are not displayed in the first frame (but displayed after).
  2396. * In consequence it is impossible to get material information in your HTML file
  2397. *
  2398. * @param url The URL of the MTL file
  2399. * @param rootUrl
  2400. * @param onSuccess Callback function to be called when the MTL file is loaded
  2401. * @private
  2402. */
  2403. private _loadMTL;
  2404. /**
  2405. * Instantiates a OBJ file loader plugin.
  2406. * @returns the created plugin
  2407. */
  2408. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2409. /**
  2410. * If the data string can be loaded directly.
  2411. *
  2412. * @param data string containing the file data
  2413. * @returns if the data can be loaded directly
  2414. */
  2415. canDirectLoad(data: string): boolean;
  2416. /**
  2417. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2418. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2419. * @param scene the scene the meshes should be added to
  2420. * @param data the OBJ data to load
  2421. * @param rootUrl root url to load from
  2422. * @param onProgress event that fires when loading progress has occured
  2423. * @param fileName Defines the name of the file to load
  2424. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2425. */
  2426. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2427. meshes: AbstractMesh[];
  2428. particleSystems: IParticleSystem[];
  2429. skeletons: Skeleton[];
  2430. animationGroups: AnimationGroup[];
  2431. }>;
  2432. /**
  2433. * Imports all objects from the loaded OBJ data and adds them to the scene
  2434. * @param scene the scene the objects should be added to
  2435. * @param data the OBJ data to load
  2436. * @param rootUrl root url to load from
  2437. * @param onProgress event that fires when loading progress has occured
  2438. * @param fileName Defines the name of the file to load
  2439. * @returns a promise which completes when objects have been loaded to the scene
  2440. */
  2441. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2442. /**
  2443. * Load into an asset container.
  2444. * @param scene The scene to load into
  2445. * @param data The data to import
  2446. * @param rootUrl The root url for scene and resources
  2447. * @param onProgress The callback when the load progresses
  2448. * @param fileName Defines the name of the file to load
  2449. * @returns The loaded asset container
  2450. */
  2451. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2452. /**
  2453. * Read the OBJ file and create an Array of meshes.
  2454. * Each mesh contains all information given by the OBJ and the MTL file.
  2455. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2456. *
  2457. * @param meshesNames
  2458. * @param scene Scene The scene where are displayed the data
  2459. * @param data String The content of the obj file
  2460. * @param rootUrl String The path to the folder
  2461. * @returns Array<AbstractMesh>
  2462. * @private
  2463. */
  2464. private _parseSolid;
  2465. }
  2466. }
  2467. declare module "babylonjs-loaders/OBJ/index" {
  2468. export * from "babylonjs-loaders/OBJ/mtlFileLoader";
  2469. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2470. }
  2471. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2472. import { Nullable } from "babylonjs/types";
  2473. import { Skeleton } from "babylonjs/Bones/skeleton";
  2474. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2475. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2476. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2477. import { AssetContainer } from "babylonjs/assetContainer";
  2478. import { Scene } from "babylonjs/scene";
  2479. /**
  2480. * STL file type loader.
  2481. * This is a babylon scene loader plugin.
  2482. */
  2483. export class STLFileLoader implements ISceneLoaderPlugin {
  2484. /** @hidden */
  2485. solidPattern: RegExp;
  2486. /** @hidden */
  2487. facetsPattern: RegExp;
  2488. /** @hidden */
  2489. normalPattern: RegExp;
  2490. /** @hidden */
  2491. vertexPattern: RegExp;
  2492. /**
  2493. * Defines the name of the plugin.
  2494. */
  2495. name: string;
  2496. /**
  2497. * Defines the extensions the stl loader is able to load.
  2498. * force data to come in as an ArrayBuffer
  2499. * we'll convert to string if it looks like it's an ASCII .stl
  2500. */
  2501. extensions: ISceneLoaderPluginExtensions;
  2502. /**
  2503. * Import meshes into a scene.
  2504. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2505. * @param scene The scene to import into
  2506. * @param data The data to import
  2507. * @param rootUrl The root url for scene and resources
  2508. * @param meshes The meshes array to import into
  2509. * @param particleSystems The particle systems array to import into
  2510. * @param skeletons The skeletons array to import into
  2511. * @param onError The callback when import fails
  2512. * @returns True if successful or false otherwise
  2513. */
  2514. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2515. /**
  2516. * Load into a scene.
  2517. * @param scene The scene to load into
  2518. * @param data The data to import
  2519. * @param rootUrl The root url for scene and resources
  2520. * @param onError The callback when import fails
  2521. * @returns true if successful or false otherwise
  2522. */
  2523. load(scene: Scene, data: any, rootUrl: string): boolean;
  2524. /**
  2525. * Load into an asset container.
  2526. * @param scene The scene to load into
  2527. * @param data The data to import
  2528. * @param rootUrl The root url for scene and resources
  2529. * @param onError The callback when import fails
  2530. * @returns The loaded asset container
  2531. */
  2532. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2533. private _isBinary;
  2534. private _parseBinary;
  2535. private _parseASCII;
  2536. }
  2537. }
  2538. declare module "babylonjs-loaders/STL/index" {
  2539. export * from "babylonjs-loaders/STL/stlFileLoader";
  2540. }
  2541. declare module "babylonjs-loaders/index" {
  2542. export * from "babylonjs-loaders/glTF/index";
  2543. export * from "babylonjs-loaders/OBJ/index";
  2544. export * from "babylonjs-loaders/STL/index";
  2545. }
  2546. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2547. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2548. export * from "babylonjs-loaders/glTF/glTFValidation";
  2549. }
  2550. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2551. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2552. export { GLTF1 };
  2553. }
  2554. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2555. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2556. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2557. }
  2558. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2559. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2560. export { GLTF2 };
  2561. }
  2562. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2563. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2564. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2565. }
  2566. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2567. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2568. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2569. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2570. }
  2571. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2572. export * from "babylonjs-loaders/OBJ/index";
  2573. }
  2574. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2575. export * from "babylonjs-loaders/STL/index";
  2576. }
  2577. declare module "babylonjs-loaders/legacy/legacy" {
  2578. import "babylonjs-loaders/index";
  2579. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2580. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2581. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2582. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2583. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2584. }
  2585. declare module "babylonjs-loaders" {
  2586. export * from "babylonjs-loaders/legacy/legacy";
  2587. }
  2588. declare module BABYLON {
  2589. /**
  2590. * Configuration for glTF validation
  2591. */
  2592. export interface IGLTFValidationConfiguration {
  2593. /**
  2594. * The url of the glTF validator.
  2595. */
  2596. url: string;
  2597. }
  2598. /**
  2599. * glTF validation
  2600. */
  2601. export class GLTFValidation {
  2602. /**
  2603. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  2604. */
  2605. static Configuration: IGLTFValidationConfiguration;
  2606. private static _LoadScriptPromise;
  2607. /**
  2608. * Validate a glTF asset using the glTF-Validator.
  2609. * @param data The JSON of a glTF or the array buffer of a binary glTF
  2610. * @param rootUrl The root url for the glTF
  2611. * @param fileName The file name for the glTF
  2612. * @param getExternalResource The callback to get external resources for the glTF validator
  2613. * @returns A promise that resolves with the glTF validation results once complete
  2614. */
  2615. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<BABYLON.GLTF2.IGLTFValidationResults>;
  2616. }
  2617. }
  2618. declare module BABYLON {
  2619. /**
  2620. * Mode that determines the coordinate system to use.
  2621. */
  2622. export enum GLTFLoaderCoordinateSystemMode {
  2623. /**
  2624. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2625. */
  2626. AUTO = 0,
  2627. /**
  2628. * Sets the useRightHandedSystem flag on the scene.
  2629. */
  2630. FORCE_RIGHT_HANDED = 1
  2631. }
  2632. /**
  2633. * Mode that determines what animations will start.
  2634. */
  2635. export enum GLTFLoaderAnimationStartMode {
  2636. /**
  2637. * No animation will start.
  2638. */
  2639. NONE = 0,
  2640. /**
  2641. * The first animation will start.
  2642. */
  2643. FIRST = 1,
  2644. /**
  2645. * All animations will start.
  2646. */
  2647. ALL = 2
  2648. }
  2649. /**
  2650. * Interface that contains the data for the glTF asset.
  2651. */
  2652. export interface IGLTFLoaderData {
  2653. /**
  2654. * The object that represents the glTF JSON.
  2655. */
  2656. json: Object;
  2657. /**
  2658. * The BIN chunk of a binary glTF.
  2659. */
  2660. bin: Nullable<IDataBuffer>;
  2661. }
  2662. /**
  2663. * Interface for extending the loader.
  2664. */
  2665. export interface IGLTFLoaderExtension {
  2666. /**
  2667. * The name of this extension.
  2668. */
  2669. readonly name: string;
  2670. /**
  2671. * Defines whether this extension is enabled.
  2672. */
  2673. enabled: boolean;
  2674. /**
  2675. * Defines the order of this extension.
  2676. * The loader sorts the extensions using these values when loading.
  2677. */
  2678. order?: number;
  2679. }
  2680. /**
  2681. * Loader state.
  2682. */
  2683. export enum GLTFLoaderState {
  2684. /**
  2685. * The asset is loading.
  2686. */
  2687. LOADING = 0,
  2688. /**
  2689. * The asset is ready for rendering.
  2690. */
  2691. READY = 1,
  2692. /**
  2693. * The asset is completely loaded.
  2694. */
  2695. COMPLETE = 2
  2696. }
  2697. /** @hidden */
  2698. export interface IImportMeshAsyncOutput {
  2699. meshes: AbstractMesh[];
  2700. particleSystems: IParticleSystem[];
  2701. skeletons: Skeleton[];
  2702. animationGroups: AnimationGroup[];
  2703. lights: Light[];
  2704. transformNodes: TransformNode[];
  2705. }
  2706. /** @hidden */
  2707. export interface IGLTFLoader extends IDisposable {
  2708. readonly state: Nullable<GLTFLoaderState>;
  2709. importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<IImportMeshAsyncOutput>;
  2710. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2711. }
  2712. /**
  2713. * File loader for loading glTF files into a scene.
  2714. */
  2715. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2716. /** @hidden */
  2717. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2718. /** @hidden */
  2719. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2720. /**
  2721. * Raised when the asset has been parsed
  2722. */
  2723. onParsedObservable: Observable<IGLTFLoaderData>;
  2724. private _onParsedObserver;
  2725. /**
  2726. * Raised when the asset has been parsed
  2727. */
  2728. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  2729. /**
  2730. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  2731. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2732. * Defaults to true.
  2733. * @hidden
  2734. */
  2735. static IncrementalLoading: boolean;
  2736. /**
  2737. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2738. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2739. * @hidden
  2740. */
  2741. static HomogeneousCoordinates: boolean;
  2742. /**
  2743. * The coordinate system mode. Defaults to AUTO.
  2744. */
  2745. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2746. /**
  2747. * The animation start mode. Defaults to FIRST.
  2748. */
  2749. animationStartMode: GLTFLoaderAnimationStartMode;
  2750. /**
  2751. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2752. */
  2753. compileMaterials: boolean;
  2754. /**
  2755. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2756. */
  2757. useClipPlane: boolean;
  2758. /**
  2759. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2760. */
  2761. compileShadowGenerators: boolean;
  2762. /**
  2763. * Defines if the Alpha blended materials are only applied as coverage.
  2764. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2765. * If true, no extra effects are applied to transparent pixels.
  2766. */
  2767. transparencyAsCoverage: boolean;
  2768. /**
  2769. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  2770. * Enabling will disable offline support and glTF validator.
  2771. * Defaults to false.
  2772. */
  2773. useRangeRequests: boolean;
  2774. /**
  2775. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  2776. */
  2777. createInstances: boolean;
  2778. /**
  2779. * Function called before loading a url referenced by the asset.
  2780. */
  2781. preprocessUrlAsync: (url: string) => Promise<string>;
  2782. /**
  2783. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2784. */
  2785. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2786. private _onMeshLoadedObserver;
  2787. /**
  2788. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2789. */
  2790. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  2791. /**
  2792. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2793. */
  2794. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2795. private _onTextureLoadedObserver;
  2796. /**
  2797. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2798. */
  2799. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  2800. /**
  2801. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2802. */
  2803. readonly onMaterialLoadedObservable: Observable<Material>;
  2804. private _onMaterialLoadedObserver;
  2805. /**
  2806. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2807. */
  2808. set onMaterialLoaded(callback: (material: Material) => void);
  2809. /**
  2810. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2811. */
  2812. readonly onCameraLoadedObservable: Observable<Camera>;
  2813. private _onCameraLoadedObserver;
  2814. /**
  2815. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2816. */
  2817. set onCameraLoaded(callback: (camera: Camera) => void);
  2818. /**
  2819. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2820. * For assets with LODs, raised when all of the LODs are complete.
  2821. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2822. */
  2823. readonly onCompleteObservable: Observable<void>;
  2824. private _onCompleteObserver;
  2825. /**
  2826. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2827. * For assets with LODs, raised when all of the LODs are complete.
  2828. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2829. */
  2830. set onComplete(callback: () => void);
  2831. /**
  2832. * Observable raised when an error occurs.
  2833. */
  2834. readonly onErrorObservable: Observable<any>;
  2835. private _onErrorObserver;
  2836. /**
  2837. * Callback raised when an error occurs.
  2838. */
  2839. set onError(callback: (reason: any) => void);
  2840. /**
  2841. * Observable raised after the loader is disposed.
  2842. */
  2843. readonly onDisposeObservable: Observable<void>;
  2844. private _onDisposeObserver;
  2845. /**
  2846. * Callback raised after the loader is disposed.
  2847. */
  2848. set onDispose(callback: () => void);
  2849. /**
  2850. * Observable raised after a loader extension is created.
  2851. * Set additional options for a loader extension in this event.
  2852. */
  2853. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2854. private _onExtensionLoadedObserver;
  2855. /**
  2856. * Callback raised after a loader extension is created.
  2857. */
  2858. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  2859. /**
  2860. * Defines if the loader logging is enabled.
  2861. */
  2862. get loggingEnabled(): boolean;
  2863. set loggingEnabled(value: boolean);
  2864. /**
  2865. * Defines if the loader should capture performance counters.
  2866. */
  2867. get capturePerformanceCounters(): boolean;
  2868. set capturePerformanceCounters(value: boolean);
  2869. /**
  2870. * Defines if the loader should validate the asset.
  2871. */
  2872. validate: boolean;
  2873. /**
  2874. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2875. */
  2876. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  2877. private _onValidatedObserver;
  2878. /**
  2879. * Callback raised after a loader extension is created.
  2880. */
  2881. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  2882. private _loader;
  2883. /**
  2884. * Name of the loader ("gltf")
  2885. */
  2886. name: string;
  2887. /** @hidden */
  2888. extensions: ISceneLoaderPluginExtensions;
  2889. /**
  2890. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2891. */
  2892. dispose(): void;
  2893. /** @hidden */
  2894. _clear(): void;
  2895. /** @hidden */
  2896. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2897. /** @hidden */
  2898. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2899. /** @hidden */
  2900. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2901. meshes: AbstractMesh[];
  2902. particleSystems: IParticleSystem[];
  2903. skeletons: Skeleton[];
  2904. animationGroups: AnimationGroup[];
  2905. }>;
  2906. /** @hidden */
  2907. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2908. /** @hidden */
  2909. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2910. /** @hidden */
  2911. canDirectLoad(data: string): boolean;
  2912. /** @hidden */
  2913. directLoad(scene: Scene, data: string): any;
  2914. /**
  2915. * The callback that allows custom handling of the root url based on the response url.
  2916. * @param rootUrl the original root url
  2917. * @param responseURL the response url if available
  2918. * @returns the new root url
  2919. */
  2920. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  2921. /** @hidden */
  2922. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2923. /**
  2924. * The loader state or null if the loader is not active.
  2925. */
  2926. get loaderState(): Nullable<GLTFLoaderState>;
  2927. /**
  2928. * Returns a promise that resolves when the asset is completely loaded.
  2929. * @returns a promise that resolves when the asset is completely loaded.
  2930. */
  2931. whenCompleteAsync(): Promise<void>;
  2932. private _validate;
  2933. private _getLoader;
  2934. private _parseJson;
  2935. private _unpackBinaryAsync;
  2936. private _unpackBinaryV1Async;
  2937. private _unpackBinaryV2Async;
  2938. private static _parseVersion;
  2939. private static _compareVersion;
  2940. private static readonly _logSpaces;
  2941. private _logIndentLevel;
  2942. private _loggingEnabled;
  2943. /** @hidden */
  2944. _log: (message: string) => void;
  2945. /** @hidden */
  2946. _logOpen(message: string): void;
  2947. /** @hidden */
  2948. _logClose(): void;
  2949. private _logEnabled;
  2950. private _logDisabled;
  2951. private _capturePerformanceCounters;
  2952. /** @hidden */
  2953. _startPerformanceCounter: (counterName: string) => void;
  2954. /** @hidden */
  2955. _endPerformanceCounter: (counterName: string) => void;
  2956. private _startPerformanceCounterEnabled;
  2957. private _startPerformanceCounterDisabled;
  2958. private _endPerformanceCounterEnabled;
  2959. private _endPerformanceCounterDisabled;
  2960. }
  2961. }
  2962. declare module BABYLON.GLTF1 {
  2963. /**
  2964. * Enums
  2965. * @hidden
  2966. */
  2967. export enum EComponentType {
  2968. BYTE = 5120,
  2969. UNSIGNED_BYTE = 5121,
  2970. SHORT = 5122,
  2971. UNSIGNED_SHORT = 5123,
  2972. FLOAT = 5126
  2973. }
  2974. /** @hidden */
  2975. export enum EShaderType {
  2976. FRAGMENT = 35632,
  2977. VERTEX = 35633
  2978. }
  2979. /** @hidden */
  2980. export enum EParameterType {
  2981. BYTE = 5120,
  2982. UNSIGNED_BYTE = 5121,
  2983. SHORT = 5122,
  2984. UNSIGNED_SHORT = 5123,
  2985. INT = 5124,
  2986. UNSIGNED_INT = 5125,
  2987. FLOAT = 5126,
  2988. FLOAT_VEC2 = 35664,
  2989. FLOAT_VEC3 = 35665,
  2990. FLOAT_VEC4 = 35666,
  2991. INT_VEC2 = 35667,
  2992. INT_VEC3 = 35668,
  2993. INT_VEC4 = 35669,
  2994. BOOL = 35670,
  2995. BOOL_VEC2 = 35671,
  2996. BOOL_VEC3 = 35672,
  2997. BOOL_VEC4 = 35673,
  2998. FLOAT_MAT2 = 35674,
  2999. FLOAT_MAT3 = 35675,
  3000. FLOAT_MAT4 = 35676,
  3001. SAMPLER_2D = 35678
  3002. }
  3003. /** @hidden */
  3004. export enum ETextureWrapMode {
  3005. CLAMP_TO_EDGE = 33071,
  3006. MIRRORED_REPEAT = 33648,
  3007. REPEAT = 10497
  3008. }
  3009. /** @hidden */
  3010. export enum ETextureFilterType {
  3011. NEAREST = 9728,
  3012. LINEAR = 9728,
  3013. NEAREST_MIPMAP_NEAREST = 9984,
  3014. LINEAR_MIPMAP_NEAREST = 9985,
  3015. NEAREST_MIPMAP_LINEAR = 9986,
  3016. LINEAR_MIPMAP_LINEAR = 9987
  3017. }
  3018. /** @hidden */
  3019. export enum ETextureFormat {
  3020. ALPHA = 6406,
  3021. RGB = 6407,
  3022. RGBA = 6408,
  3023. LUMINANCE = 6409,
  3024. LUMINANCE_ALPHA = 6410
  3025. }
  3026. /** @hidden */
  3027. export enum ECullingType {
  3028. FRONT = 1028,
  3029. BACK = 1029,
  3030. FRONT_AND_BACK = 1032
  3031. }
  3032. /** @hidden */
  3033. export enum EBlendingFunction {
  3034. ZERO = 0,
  3035. ONE = 1,
  3036. SRC_COLOR = 768,
  3037. ONE_MINUS_SRC_COLOR = 769,
  3038. DST_COLOR = 774,
  3039. ONE_MINUS_DST_COLOR = 775,
  3040. SRC_ALPHA = 770,
  3041. ONE_MINUS_SRC_ALPHA = 771,
  3042. DST_ALPHA = 772,
  3043. ONE_MINUS_DST_ALPHA = 773,
  3044. CONSTANT_COLOR = 32769,
  3045. ONE_MINUS_CONSTANT_COLOR = 32770,
  3046. CONSTANT_ALPHA = 32771,
  3047. ONE_MINUS_CONSTANT_ALPHA = 32772,
  3048. SRC_ALPHA_SATURATE = 776
  3049. }
  3050. /** @hidden */
  3051. export interface IGLTFProperty {
  3052. extensions?: {
  3053. [key: string]: any;
  3054. };
  3055. extras?: Object;
  3056. }
  3057. /** @hidden */
  3058. export interface IGLTFChildRootProperty extends IGLTFProperty {
  3059. name?: string;
  3060. }
  3061. /** @hidden */
  3062. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  3063. bufferView: string;
  3064. byteOffset: number;
  3065. byteStride: number;
  3066. count: number;
  3067. type: string;
  3068. componentType: EComponentType;
  3069. max?: number[];
  3070. min?: number[];
  3071. name?: string;
  3072. }
  3073. /** @hidden */
  3074. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  3075. buffer: string;
  3076. byteOffset: number;
  3077. byteLength: number;
  3078. byteStride: number;
  3079. target?: number;
  3080. }
  3081. /** @hidden */
  3082. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  3083. uri: string;
  3084. byteLength?: number;
  3085. type?: string;
  3086. }
  3087. /** @hidden */
  3088. export interface IGLTFShader extends IGLTFChildRootProperty {
  3089. uri: string;
  3090. type: EShaderType;
  3091. }
  3092. /** @hidden */
  3093. export interface IGLTFProgram extends IGLTFChildRootProperty {
  3094. attributes: string[];
  3095. fragmentShader: string;
  3096. vertexShader: string;
  3097. }
  3098. /** @hidden */
  3099. export interface IGLTFTechniqueParameter {
  3100. type: number;
  3101. count?: number;
  3102. semantic?: string;
  3103. node?: string;
  3104. value?: number | boolean | string | Array<any>;
  3105. source?: string;
  3106. babylonValue?: any;
  3107. }
  3108. /** @hidden */
  3109. export interface IGLTFTechniqueCommonProfile {
  3110. lightingModel: string;
  3111. texcoordBindings: Object;
  3112. parameters?: Array<any>;
  3113. }
  3114. /** @hidden */
  3115. export interface IGLTFTechniqueStatesFunctions {
  3116. blendColor?: number[];
  3117. blendEquationSeparate?: number[];
  3118. blendFuncSeparate?: number[];
  3119. colorMask: boolean[];
  3120. cullFace: number[];
  3121. }
  3122. /** @hidden */
  3123. export interface IGLTFTechniqueStates {
  3124. enable: number[];
  3125. functions: IGLTFTechniqueStatesFunctions;
  3126. }
  3127. /** @hidden */
  3128. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  3129. parameters: {
  3130. [key: string]: IGLTFTechniqueParameter;
  3131. };
  3132. program: string;
  3133. attributes: {
  3134. [key: string]: string;
  3135. };
  3136. uniforms: {
  3137. [key: string]: string;
  3138. };
  3139. states: IGLTFTechniqueStates;
  3140. }
  3141. /** @hidden */
  3142. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  3143. technique?: string;
  3144. values: string[];
  3145. }
  3146. /** @hidden */
  3147. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  3148. attributes: {
  3149. [key: string]: string;
  3150. };
  3151. indices: string;
  3152. material: string;
  3153. mode?: number;
  3154. }
  3155. /** @hidden */
  3156. export interface IGLTFMesh extends IGLTFChildRootProperty {
  3157. primitives: IGLTFMeshPrimitive[];
  3158. }
  3159. /** @hidden */
  3160. export interface IGLTFImage extends IGLTFChildRootProperty {
  3161. uri: string;
  3162. }
  3163. /** @hidden */
  3164. export interface IGLTFSampler extends IGLTFChildRootProperty {
  3165. magFilter?: number;
  3166. minFilter?: number;
  3167. wrapS?: number;
  3168. wrapT?: number;
  3169. }
  3170. /** @hidden */
  3171. export interface IGLTFTexture extends IGLTFChildRootProperty {
  3172. sampler: string;
  3173. source: string;
  3174. format?: ETextureFormat;
  3175. internalFormat?: ETextureFormat;
  3176. target?: number;
  3177. type?: number;
  3178. babylonTexture?: Texture;
  3179. }
  3180. /** @hidden */
  3181. export interface IGLTFAmbienLight {
  3182. color?: number[];
  3183. }
  3184. /** @hidden */
  3185. export interface IGLTFDirectionalLight {
  3186. color?: number[];
  3187. }
  3188. /** @hidden */
  3189. export interface IGLTFPointLight {
  3190. color?: number[];
  3191. constantAttenuation?: number;
  3192. linearAttenuation?: number;
  3193. quadraticAttenuation?: number;
  3194. }
  3195. /** @hidden */
  3196. export interface IGLTFSpotLight {
  3197. color?: number[];
  3198. constantAttenuation?: number;
  3199. fallOfAngle?: number;
  3200. fallOffExponent?: number;
  3201. linearAttenuation?: number;
  3202. quadraticAttenuation?: number;
  3203. }
  3204. /** @hidden */
  3205. export interface IGLTFLight extends IGLTFChildRootProperty {
  3206. type: string;
  3207. }
  3208. /** @hidden */
  3209. export interface IGLTFCameraOrthographic {
  3210. xmag: number;
  3211. ymag: number;
  3212. zfar: number;
  3213. znear: number;
  3214. }
  3215. /** @hidden */
  3216. export interface IGLTFCameraPerspective {
  3217. aspectRatio: number;
  3218. yfov: number;
  3219. zfar: number;
  3220. znear: number;
  3221. }
  3222. /** @hidden */
  3223. export interface IGLTFCamera extends IGLTFChildRootProperty {
  3224. type: string;
  3225. }
  3226. /** @hidden */
  3227. export interface IGLTFAnimationChannelTarget {
  3228. id: string;
  3229. path: string;
  3230. }
  3231. /** @hidden */
  3232. export interface IGLTFAnimationChannel {
  3233. sampler: string;
  3234. target: IGLTFAnimationChannelTarget;
  3235. }
  3236. /** @hidden */
  3237. export interface IGLTFAnimationSampler {
  3238. input: string;
  3239. output: string;
  3240. interpolation?: string;
  3241. }
  3242. /** @hidden */
  3243. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  3244. channels?: IGLTFAnimationChannel[];
  3245. parameters?: {
  3246. [key: string]: string;
  3247. };
  3248. samplers?: {
  3249. [key: string]: IGLTFAnimationSampler;
  3250. };
  3251. }
  3252. /** @hidden */
  3253. export interface IGLTFNodeInstanceSkin {
  3254. skeletons: string[];
  3255. skin: string;
  3256. meshes: string[];
  3257. }
  3258. /** @hidden */
  3259. export interface IGLTFSkins extends IGLTFChildRootProperty {
  3260. bindShapeMatrix: number[];
  3261. inverseBindMatrices: string;
  3262. jointNames: string[];
  3263. babylonSkeleton?: Skeleton;
  3264. }
  3265. /** @hidden */
  3266. export interface IGLTFNode extends IGLTFChildRootProperty {
  3267. camera?: string;
  3268. children: string[];
  3269. skin?: string;
  3270. jointName?: string;
  3271. light?: string;
  3272. matrix: number[];
  3273. mesh?: string;
  3274. meshes?: string[];
  3275. rotation?: number[];
  3276. scale?: number[];
  3277. translation?: number[];
  3278. babylonNode?: Node;
  3279. }
  3280. /** @hidden */
  3281. export interface IGLTFScene extends IGLTFChildRootProperty {
  3282. nodes: string[];
  3283. }
  3284. /** @hidden */
  3285. export interface IGLTFRuntime {
  3286. extensions: {
  3287. [key: string]: any;
  3288. };
  3289. accessors: {
  3290. [key: string]: IGLTFAccessor;
  3291. };
  3292. buffers: {
  3293. [key: string]: IGLTFBuffer;
  3294. };
  3295. bufferViews: {
  3296. [key: string]: IGLTFBufferView;
  3297. };
  3298. meshes: {
  3299. [key: string]: IGLTFMesh;
  3300. };
  3301. lights: {
  3302. [key: string]: IGLTFLight;
  3303. };
  3304. cameras: {
  3305. [key: string]: IGLTFCamera;
  3306. };
  3307. nodes: {
  3308. [key: string]: IGLTFNode;
  3309. };
  3310. images: {
  3311. [key: string]: IGLTFImage;
  3312. };
  3313. textures: {
  3314. [key: string]: IGLTFTexture;
  3315. };
  3316. shaders: {
  3317. [key: string]: IGLTFShader;
  3318. };
  3319. programs: {
  3320. [key: string]: IGLTFProgram;
  3321. };
  3322. samplers: {
  3323. [key: string]: IGLTFSampler;
  3324. };
  3325. techniques: {
  3326. [key: string]: IGLTFTechnique;
  3327. };
  3328. materials: {
  3329. [key: string]: IGLTFMaterial;
  3330. };
  3331. animations: {
  3332. [key: string]: IGLTFAnimation;
  3333. };
  3334. skins: {
  3335. [key: string]: IGLTFSkins;
  3336. };
  3337. currentScene?: Object;
  3338. scenes: {
  3339. [key: string]: IGLTFScene;
  3340. };
  3341. extensionsUsed: string[];
  3342. extensionsRequired?: string[];
  3343. buffersCount: number;
  3344. shaderscount: number;
  3345. scene: Scene;
  3346. rootUrl: string;
  3347. loadedBufferCount: number;
  3348. loadedBufferViews: {
  3349. [name: string]: ArrayBufferView;
  3350. };
  3351. loadedShaderCount: number;
  3352. importOnlyMeshes: boolean;
  3353. importMeshesNames?: string[];
  3354. dummyNodes: Node[];
  3355. forAssetContainer: boolean;
  3356. }
  3357. /** @hidden */
  3358. export interface INodeToRoot {
  3359. bone: Bone;
  3360. node: IGLTFNode;
  3361. id: string;
  3362. }
  3363. /** @hidden */
  3364. export interface IJointNode {
  3365. node: IGLTFNode;
  3366. id: string;
  3367. }
  3368. }
  3369. declare module BABYLON.GLTF1 {
  3370. /**
  3371. * Utils functions for GLTF
  3372. * @hidden
  3373. */
  3374. export class GLTFUtils {
  3375. /**
  3376. * Sets the given "parameter" matrix
  3377. * @param scene: the Scene object
  3378. * @param source: the source node where to pick the matrix
  3379. * @param parameter: the GLTF technique parameter
  3380. * @param uniformName: the name of the shader's uniform
  3381. * @param shaderMaterial: the shader material
  3382. */
  3383. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  3384. /**
  3385. * Sets the given "parameter" matrix
  3386. * @param shaderMaterial: the shader material
  3387. * @param uniform: the name of the shader's uniform
  3388. * @param value: the value of the uniform
  3389. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3390. */
  3391. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  3392. /**
  3393. * Returns the wrap mode of the texture
  3394. * @param mode: the mode value
  3395. */
  3396. static GetWrapMode(mode: number): number;
  3397. /**
  3398. * Returns the byte stride giving an accessor
  3399. * @param accessor: the GLTF accessor objet
  3400. */
  3401. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  3402. /**
  3403. * Returns the texture filter mode giving a mode value
  3404. * @param mode: the filter mode value
  3405. */
  3406. static GetTextureFilterMode(mode: number): ETextureFilterType;
  3407. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  3408. /**
  3409. * Returns a buffer from its accessor
  3410. * @param gltfRuntime: the GLTF runtime
  3411. * @param accessor: the GLTF accessor
  3412. */
  3413. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  3414. /**
  3415. * Decodes a buffer view into a string
  3416. * @param view: the buffer view
  3417. */
  3418. static DecodeBufferToText(view: ArrayBufferView): string;
  3419. /**
  3420. * Returns the default material of gltf. Related to
  3421. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3422. * @param scene: the Babylon.js scene
  3423. */
  3424. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  3425. private static _DefaultMaterial;
  3426. }
  3427. }
  3428. declare module BABYLON.GLTF1 {
  3429. /**
  3430. * Implementation of the base glTF spec
  3431. * @hidden
  3432. */
  3433. export class GLTFLoaderBase {
  3434. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  3435. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3436. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  3437. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3438. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  3439. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3440. }
  3441. /**
  3442. * glTF V1 Loader
  3443. * @hidden
  3444. */
  3445. export class GLTFLoader implements IGLTFLoader {
  3446. static Extensions: {
  3447. [name: string]: GLTFLoaderExtension;
  3448. };
  3449. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3450. state: Nullable<GLTFLoaderState>;
  3451. dispose(): void;
  3452. private _importMeshAsync;
  3453. /**
  3454. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3455. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3456. * @param scene the scene the meshes should be added to
  3457. * @param forAssetContainer defines if the entities must be stored in the scene
  3458. * @param data gltf data containing information of the meshes in a loaded file
  3459. * @param rootUrl root url to load from
  3460. * @param onProgress event that fires when loading progress has occured
  3461. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3462. */
  3463. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<IImportMeshAsyncOutput>;
  3464. private _loadAsync;
  3465. /**
  3466. * Imports all objects from a loaded gltf file and adds them to the scene
  3467. * @param scene the scene the objects should be added to
  3468. * @param data gltf data containing information of the meshes in a loaded file
  3469. * @param rootUrl root url to load from
  3470. * @param onProgress event that fires when loading progress has occured
  3471. * @returns a promise which completes when objects have been loaded to the scene
  3472. */
  3473. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3474. private _loadShadersAsync;
  3475. private _loadBuffersAsync;
  3476. private _createNodes;
  3477. }
  3478. /** @hidden */
  3479. export abstract class GLTFLoaderExtension {
  3480. private _name;
  3481. constructor(name: string);
  3482. get name(): string;
  3483. /**
  3484. * Defines an override for loading the runtime
  3485. * Return true to stop further extensions from loading the runtime
  3486. */
  3487. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3488. /**
  3489. * Defines an onverride for creating gltf runtime
  3490. * Return true to stop further extensions from creating the runtime
  3491. */
  3492. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3493. /**
  3494. * Defines an override for loading buffers
  3495. * Return true to stop further extensions from loading this buffer
  3496. */
  3497. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3498. /**
  3499. * Defines an override for loading texture buffers
  3500. * Return true to stop further extensions from loading this texture data
  3501. */
  3502. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3503. /**
  3504. * Defines an override for creating textures
  3505. * Return true to stop further extensions from loading this texture
  3506. */
  3507. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3508. /**
  3509. * Defines an override for loading shader strings
  3510. * Return true to stop further extensions from loading this shader data
  3511. */
  3512. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3513. /**
  3514. * Defines an override for loading materials
  3515. * Return true to stop further extensions from loading this material
  3516. */
  3517. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3518. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3519. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3520. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3521. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3522. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3523. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3524. private static LoadTextureBufferAsync;
  3525. private static CreateTextureAsync;
  3526. private static ApplyExtensions;
  3527. }
  3528. }
  3529. declare module BABYLON.GLTF1 {
  3530. /** @hidden */
  3531. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3532. private _bin;
  3533. constructor();
  3534. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3535. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3536. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3537. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3538. }
  3539. }
  3540. declare module BABYLON.GLTF1 {
  3541. /** @hidden */
  3542. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3543. constructor();
  3544. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3545. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3546. private _loadTexture;
  3547. }
  3548. }
  3549. declare module BABYLON.GLTF2.Loader {
  3550. /**
  3551. * Loader interface with an index field.
  3552. */
  3553. export interface IArrayItem {
  3554. /**
  3555. * The index of this item in the array.
  3556. */
  3557. index: number;
  3558. }
  3559. /**
  3560. * Loader interface with additional members.
  3561. */
  3562. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3563. /** @hidden */
  3564. _data?: Promise<ArrayBufferView>;
  3565. /** @hidden */
  3566. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3567. }
  3568. /**
  3569. * Loader interface with additional members.
  3570. */
  3571. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3572. }
  3573. /** @hidden */
  3574. export interface _IAnimationSamplerData {
  3575. input: Float32Array;
  3576. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3577. output: Float32Array;
  3578. }
  3579. /**
  3580. * Loader interface with additional members.
  3581. */
  3582. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3583. /** @hidden */
  3584. _data?: Promise<_IAnimationSamplerData>;
  3585. }
  3586. /**
  3587. * Loader interface with additional members.
  3588. */
  3589. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3590. channels: IAnimationChannel[];
  3591. samplers: IAnimationSampler[];
  3592. /** @hidden */
  3593. _babylonAnimationGroup?: AnimationGroup;
  3594. }
  3595. /**
  3596. * Loader interface with additional members.
  3597. */
  3598. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3599. /** @hidden */
  3600. _data?: Promise<ArrayBufferView>;
  3601. }
  3602. /**
  3603. * Loader interface with additional members.
  3604. */
  3605. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3606. /** @hidden */
  3607. _data?: Promise<ArrayBufferView>;
  3608. /** @hidden */
  3609. _babylonBuffer?: Promise<Buffer>;
  3610. }
  3611. /**
  3612. * Loader interface with additional members.
  3613. */
  3614. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3615. }
  3616. /**
  3617. * Loader interface with additional members.
  3618. */
  3619. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3620. /** @hidden */
  3621. _data?: Promise<ArrayBufferView>;
  3622. }
  3623. /**
  3624. * Loader interface with additional members.
  3625. */
  3626. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3627. }
  3628. /**
  3629. * Loader interface with additional members.
  3630. */
  3631. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3632. }
  3633. /**
  3634. * Loader interface with additional members.
  3635. */
  3636. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3637. baseColorTexture?: ITextureInfo;
  3638. metallicRoughnessTexture?: ITextureInfo;
  3639. }
  3640. /**
  3641. * Loader interface with additional members.
  3642. */
  3643. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3644. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3645. normalTexture?: IMaterialNormalTextureInfo;
  3646. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3647. emissiveTexture?: ITextureInfo;
  3648. /** @hidden */
  3649. _data?: {
  3650. [babylonDrawMode: number]: {
  3651. babylonMaterial: Material;
  3652. babylonMeshes: AbstractMesh[];
  3653. promise: Promise<void>;
  3654. };
  3655. };
  3656. }
  3657. /**
  3658. * Loader interface with additional members.
  3659. */
  3660. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3661. primitives: IMeshPrimitive[];
  3662. }
  3663. /**
  3664. * Loader interface with additional members.
  3665. */
  3666. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3667. /** @hidden */
  3668. _instanceData?: {
  3669. babylonSourceMesh: Mesh;
  3670. promise: Promise<any>;
  3671. };
  3672. }
  3673. /**
  3674. * Loader interface with additional members.
  3675. */
  3676. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3677. /**
  3678. * The parent glTF node.
  3679. */
  3680. parent?: INode;
  3681. /** @hidden */
  3682. _babylonTransformNode?: TransformNode;
  3683. /** @hidden */
  3684. _primitiveBabylonMeshes?: AbstractMesh[];
  3685. /** @hidden */
  3686. _babylonBones?: Bone[];
  3687. /** @hidden */
  3688. _numMorphTargets?: number;
  3689. }
  3690. /** @hidden */
  3691. export interface _ISamplerData {
  3692. noMipMaps: boolean;
  3693. samplingMode: number;
  3694. wrapU: number;
  3695. wrapV: number;
  3696. }
  3697. /**
  3698. * Loader interface with additional members.
  3699. */
  3700. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3701. /** @hidden */
  3702. _data?: _ISamplerData;
  3703. }
  3704. /**
  3705. * Loader interface with additional members.
  3706. */
  3707. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3708. }
  3709. /**
  3710. * Loader interface with additional members.
  3711. */
  3712. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3713. /** @hidden */
  3714. _data?: {
  3715. babylonSkeleton: Skeleton;
  3716. promise: Promise<void>;
  3717. };
  3718. }
  3719. /**
  3720. * Loader interface with additional members.
  3721. */
  3722. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3723. }
  3724. /**
  3725. * Loader interface with additional members.
  3726. */
  3727. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3728. }
  3729. /**
  3730. * Loader interface with additional members.
  3731. */
  3732. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3733. accessors?: IAccessor[];
  3734. animations?: IAnimation[];
  3735. buffers?: IBuffer[];
  3736. bufferViews?: IBufferView[];
  3737. cameras?: ICamera[];
  3738. images?: IImage[];
  3739. materials?: IMaterial[];
  3740. meshes?: IMesh[];
  3741. nodes?: INode[];
  3742. samplers?: ISampler[];
  3743. scenes?: IScene[];
  3744. skins?: ISkin[];
  3745. textures?: ITexture[];
  3746. }
  3747. }
  3748. declare module BABYLON.GLTF2 {
  3749. /**
  3750. * Interface for a glTF loader extension.
  3751. */
  3752. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3753. /**
  3754. * Called after the loader state changes to LOADING.
  3755. */
  3756. onLoading?(): void;
  3757. /**
  3758. * Called after the loader state changes to READY.
  3759. */
  3760. onReady?(): void;
  3761. /**
  3762. * Define this method to modify the default behavior when loading scenes.
  3763. * @param context The context when loading the asset
  3764. * @param scene The glTF scene property
  3765. * @returns A promise that resolves when the load is complete or null if not handled
  3766. */
  3767. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3768. /**
  3769. * Define this method to modify the default behavior when loading nodes.
  3770. * @param context The context when loading the asset
  3771. * @param node The glTF node property
  3772. * @param assign A function called synchronously after parsing the glTF properties
  3773. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3774. */
  3775. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3776. /**
  3777. * Define this method to modify the default behavior when loading cameras.
  3778. * @param context The context when loading the asset
  3779. * @param camera The glTF camera property
  3780. * @param assign A function called synchronously after parsing the glTF properties
  3781. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3782. */
  3783. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3784. /**
  3785. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3786. * @param context The context when loading the asset
  3787. * @param primitive The glTF mesh primitive property
  3788. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3789. */
  3790. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3791. /**
  3792. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3793. * @param context The context when loading the asset
  3794. * @param name The mesh name when loading the asset
  3795. * @param node The glTF node when loading the asset
  3796. * @param mesh The glTF mesh when loading the asset
  3797. * @param primitive The glTF mesh primitive property
  3798. * @param assign A function called synchronously after parsing the glTF properties
  3799. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3800. */
  3801. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3802. /**
  3803. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3804. * @param context The context when loading the asset
  3805. * @param material The glTF material property
  3806. * @param assign A function called synchronously after parsing the glTF properties
  3807. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3808. */
  3809. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3810. /**
  3811. * Define this method to modify the default behavior when creating materials.
  3812. * @param context The context when loading the asset
  3813. * @param material The glTF material property
  3814. * @param babylonDrawMode The draw mode for the Babylon material
  3815. * @returns The Babylon material or null if not handled
  3816. */
  3817. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3818. /**
  3819. * Define this method to modify the default behavior when loading material properties.
  3820. * @param context The context when loading the asset
  3821. * @param material The glTF material property
  3822. * @param babylonMaterial The Babylon material
  3823. * @returns A promise that resolves when the load is complete or null if not handled
  3824. */
  3825. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3826. /**
  3827. * Define this method to modify the default behavior when loading texture infos.
  3828. * @param context The context when loading the asset
  3829. * @param textureInfo The glTF texture info property
  3830. * @param assign A function called synchronously after parsing the glTF properties
  3831. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3832. */
  3833. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3834. /**
  3835. * Define this method to modify the default behavior when loading animations.
  3836. * @param context The context when loading the asset
  3837. * @param animation The glTF animation property
  3838. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3839. */
  3840. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3841. /**
  3842. * @hidden Define this method to modify the default behavior when loading skins.
  3843. * @param context The context when loading the asset
  3844. * @param node The glTF node property
  3845. * @param skin The glTF skin property
  3846. * @returns A promise that resolves when the load is complete or null if not handled
  3847. */
  3848. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  3849. /**
  3850. * @hidden Define this method to modify the default behavior when loading uris.
  3851. * @param context The context when loading the asset
  3852. * @param property The glTF property associated with the uri
  3853. * @param uri The uri to load
  3854. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3855. */
  3856. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  3857. /**
  3858. * Define this method to modify the default behavior when loading buffer views.
  3859. * @param context The context when loading the asset
  3860. * @param bufferView The glTF buffer view property
  3861. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3862. */
  3863. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  3864. /**
  3865. * Define this method to modify the default behavior when loading buffers.
  3866. * @param context The context when loading the asset
  3867. * @param buffer The glTF buffer property
  3868. * @param byteOffset The byte offset to load
  3869. * @param byteLength The byte length to load
  3870. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3871. */
  3872. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  3873. }
  3874. }
  3875. declare module BABYLON.GLTF2 {
  3876. /**
  3877. * Helper class for working with arrays when loading the glTF asset
  3878. */
  3879. export class ArrayItem {
  3880. /**
  3881. * Gets an item from the given array.
  3882. * @param context The context when loading the asset
  3883. * @param array The array to get the item from
  3884. * @param index The index to the array
  3885. * @returns The array item
  3886. */
  3887. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3888. /**
  3889. * Assign an `index` field to each item of the given array.
  3890. * @param array The array of items
  3891. */
  3892. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3893. }
  3894. /**
  3895. * The glTF 2.0 loader
  3896. */
  3897. export class GLTFLoader implements IGLTFLoader {
  3898. /** @hidden */
  3899. _completePromises: Promise<any>[];
  3900. /** @hidden */
  3901. _forAssetContainer: boolean;
  3902. /** Storage */
  3903. _babylonLights: Light[];
  3904. private _disposed;
  3905. private _parent;
  3906. private _state;
  3907. private _extensions;
  3908. private _rootUrl;
  3909. private _fileName;
  3910. private _uniqueRootUrl;
  3911. private _gltf;
  3912. private _bin;
  3913. private _babylonScene;
  3914. private _rootBabylonMesh;
  3915. private _defaultBabylonMaterialData;
  3916. private _progressCallback?;
  3917. private _requests;
  3918. private static readonly _DefaultSampler;
  3919. private static _RegisteredExtensions;
  3920. /**
  3921. * Registers a loader extension.
  3922. * @param name The name of the loader extension.
  3923. * @param factory The factory function that creates the loader extension.
  3924. */
  3925. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3926. /**
  3927. * Unregisters a loader extension.
  3928. * @param name The name of the loader extension.
  3929. * @returns A boolean indicating whether the extension has been unregistered
  3930. */
  3931. static UnregisterExtension(name: string): boolean;
  3932. /**
  3933. * Gets the loader state.
  3934. */
  3935. get state(): Nullable<GLTFLoaderState>;
  3936. /**
  3937. * The object that represents the glTF JSON.
  3938. */
  3939. get gltf(): IGLTF;
  3940. /**
  3941. * The BIN chunk of a binary glTF.
  3942. */
  3943. get bin(): Nullable<IDataBuffer>;
  3944. /**
  3945. * The parent file loader.
  3946. */
  3947. get parent(): GLTFFileLoader;
  3948. /**
  3949. * The Babylon scene when loading the asset.
  3950. */
  3951. get babylonScene(): Scene;
  3952. /**
  3953. * The root Babylon mesh when loading the asset.
  3954. */
  3955. get rootBabylonMesh(): Mesh;
  3956. /** @hidden */
  3957. constructor(parent: GLTFFileLoader);
  3958. /** @hidden */
  3959. dispose(): void;
  3960. /** @hidden */
  3961. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<IImportMeshAsyncOutput>;
  3962. /** @hidden */
  3963. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3964. private _loadAsync;
  3965. private _loadData;
  3966. private _setupData;
  3967. private _loadExtensions;
  3968. private _checkExtensions;
  3969. private _setState;
  3970. private _createRootNode;
  3971. /**
  3972. * Loads a glTF scene.
  3973. * @param context The context when loading the asset
  3974. * @param scene The glTF scene property
  3975. * @returns A promise that resolves when the load is complete
  3976. */
  3977. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3978. private _forEachPrimitive;
  3979. private _getMeshes;
  3980. private _getTransformNodes;
  3981. private _getSkeletons;
  3982. private _getAnimationGroups;
  3983. private _startAnimations;
  3984. /**
  3985. * Loads a glTF node.
  3986. * @param context The context when loading the asset
  3987. * @param node The glTF node property
  3988. * @param assign A function called synchronously after parsing the glTF properties
  3989. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3990. */
  3991. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3992. private _loadMeshAsync;
  3993. /**
  3994. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3995. * @param context The context when loading the asset
  3996. * @param name The mesh name when loading the asset
  3997. * @param node The glTF node when loading the asset
  3998. * @param mesh The glTF mesh when loading the asset
  3999. * @param primitive The glTF mesh primitive property
  4000. * @param assign A function called synchronously after parsing the glTF properties
  4001. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  4002. */
  4003. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  4004. private _loadVertexDataAsync;
  4005. private _createMorphTargets;
  4006. private _loadMorphTargetsAsync;
  4007. private _loadMorphTargetVertexDataAsync;
  4008. private static _LoadTransform;
  4009. private _loadSkinAsync;
  4010. private _loadBones;
  4011. private _loadBone;
  4012. private _loadSkinInverseBindMatricesDataAsync;
  4013. private _updateBoneMatrices;
  4014. private _getNodeMatrix;
  4015. /**
  4016. * Loads a glTF camera.
  4017. * @param context The context when loading the asset
  4018. * @param camera The glTF camera property
  4019. * @param assign A function called synchronously after parsing the glTF properties
  4020. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  4021. */
  4022. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  4023. private _loadAnimationsAsync;
  4024. /**
  4025. * Loads a glTF animation.
  4026. * @param context The context when loading the asset
  4027. * @param animation The glTF animation property
  4028. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  4029. */
  4030. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  4031. /**
  4032. * @hidden Loads a glTF animation channel.
  4033. * @param context The context when loading the asset
  4034. * @param animationContext The context of the animation when loading the asset
  4035. * @param animation The glTF animation property
  4036. * @param channel The glTF animation channel property
  4037. * @param babylonAnimationGroup The babylon animation group property
  4038. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  4039. * @returns A void promise when the channel load is complete
  4040. */
  4041. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  4042. private _loadAnimationSamplerAsync;
  4043. private _loadBufferAsync;
  4044. /**
  4045. * Loads a glTF buffer view.
  4046. * @param context The context when loading the asset
  4047. * @param bufferView The glTF buffer view property
  4048. * @returns A promise that resolves with the loaded data when the load is complete
  4049. */
  4050. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  4051. private _loadAccessorAsync;
  4052. private _loadFloatAccessorAsync;
  4053. private _loadIndicesAccessorAsync;
  4054. private _loadVertexBufferViewAsync;
  4055. private _loadVertexAccessorAsync;
  4056. private _loadMaterialMetallicRoughnessPropertiesAsync;
  4057. /** @hidden */
  4058. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  4059. private _createDefaultMaterial;
  4060. /**
  4061. * Creates a Babylon material from a glTF material.
  4062. * @param context The context when loading the asset
  4063. * @param material The glTF material property
  4064. * @param babylonDrawMode The draw mode for the Babylon material
  4065. * @returns The Babylon material
  4066. */
  4067. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  4068. /**
  4069. * Loads properties from a glTF material into a Babylon material.
  4070. * @param context The context when loading the asset
  4071. * @param material The glTF material property
  4072. * @param babylonMaterial The Babylon material
  4073. * @returns A promise that resolves when the load is complete
  4074. */
  4075. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4076. /**
  4077. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  4078. * @param context The context when loading the asset
  4079. * @param material The glTF material property
  4080. * @param babylonMaterial The Babylon material
  4081. * @returns A promise that resolves when the load is complete
  4082. */
  4083. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4084. /**
  4085. * Loads the alpha properties from a glTF material into a Babylon material.
  4086. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  4087. * @param context The context when loading the asset
  4088. * @param material The glTF material property
  4089. * @param babylonMaterial The Babylon material
  4090. */
  4091. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  4092. /**
  4093. * Loads a glTF texture info.
  4094. * @param context The context when loading the asset
  4095. * @param textureInfo The glTF texture info property
  4096. * @param assign A function called synchronously after parsing the glTF properties
  4097. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  4098. */
  4099. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  4100. private _loadTextureAsync;
  4101. private _loadSampler;
  4102. /**
  4103. * Loads a glTF image.
  4104. * @param context The context when loading the asset
  4105. * @param image The glTF image property
  4106. * @returns A promise that resolves with the loaded data when the load is complete
  4107. */
  4108. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  4109. /**
  4110. * Loads a glTF uri.
  4111. * @param context The context when loading the asset
  4112. * @param property The glTF property associated with the uri
  4113. * @param uri The base64 or relative uri
  4114. * @returns A promise that resolves with the loaded data when the load is complete
  4115. */
  4116. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  4117. private _onProgress;
  4118. /**
  4119. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  4120. * @param babylonObject the Babylon object with metadata
  4121. * @param pointer the JSON pointer
  4122. */
  4123. static AddPointerMetadata(babylonObject: {
  4124. metadata: any;
  4125. }, pointer: string): void;
  4126. private static _GetTextureWrapMode;
  4127. private static _GetTextureSamplingMode;
  4128. private static _GetTypedArrayConstructor;
  4129. private static _GetTypedArray;
  4130. private static _GetNumComponents;
  4131. private static _ValidateUri;
  4132. private static _GetDrawMode;
  4133. private _compileMaterialsAsync;
  4134. private _compileShadowGeneratorsAsync;
  4135. private _forEachExtensions;
  4136. private _applyExtensions;
  4137. private _extensionsOnLoading;
  4138. private _extensionsOnReady;
  4139. private _extensionsLoadSceneAsync;
  4140. private _extensionsLoadNodeAsync;
  4141. private _extensionsLoadCameraAsync;
  4142. private _extensionsLoadVertexDataAsync;
  4143. private _extensionsLoadMeshPrimitiveAsync;
  4144. private _extensionsLoadMaterialAsync;
  4145. private _extensionsCreateMaterial;
  4146. private _extensionsLoadMaterialPropertiesAsync;
  4147. private _extensionsLoadTextureInfoAsync;
  4148. private _extensionsLoadAnimationAsync;
  4149. private _extensionsLoadSkinAsync;
  4150. private _extensionsLoadUriAsync;
  4151. private _extensionsLoadBufferViewAsync;
  4152. private _extensionsLoadBufferAsync;
  4153. /**
  4154. * Helper method called by a loader extension to load an glTF extension.
  4155. * @param context The context when loading the asset
  4156. * @param property The glTF property to load the extension from
  4157. * @param extensionName The name of the extension to load
  4158. * @param actionAsync The action to run
  4159. * @returns The promise returned by actionAsync or null if the extension does not exist
  4160. */
  4161. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4162. /**
  4163. * Helper method called by a loader extension to load a glTF extra.
  4164. * @param context The context when loading the asset
  4165. * @param property The glTF property to load the extra from
  4166. * @param extensionName The name of the extension to load
  4167. * @param actionAsync The action to run
  4168. * @returns The promise returned by actionAsync or null if the extra does not exist
  4169. */
  4170. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4171. /**
  4172. * Checks for presence of an extension.
  4173. * @param name The name of the extension to check
  4174. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4175. */
  4176. isExtensionUsed(name: string): boolean;
  4177. /**
  4178. * Increments the indentation level and logs a message.
  4179. * @param message The message to log
  4180. */
  4181. logOpen(message: string): void;
  4182. /**
  4183. * Decrements the indentation level.
  4184. */
  4185. logClose(): void;
  4186. /**
  4187. * Logs a message
  4188. * @param message The message to log
  4189. */
  4190. log(message: string): void;
  4191. /**
  4192. * Starts a performance counter.
  4193. * @param counterName The name of the performance counter
  4194. */
  4195. startPerformanceCounter(counterName: string): void;
  4196. /**
  4197. * Ends a performance counter.
  4198. * @param counterName The name of the performance counter
  4199. */
  4200. endPerformanceCounter(counterName: string): void;
  4201. }
  4202. }
  4203. declare module BABYLON.GLTF2.Loader.Extensions {
  4204. /**
  4205. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  4206. */
  4207. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  4208. /**
  4209. * The name of this extension.
  4210. */
  4211. readonly name: string;
  4212. /**
  4213. * Defines whether this extension is enabled.
  4214. */
  4215. enabled: boolean;
  4216. private _loader;
  4217. private _lights?;
  4218. /** @hidden */
  4219. constructor(loader: GLTFLoader);
  4220. /** @hidden */
  4221. dispose(): void;
  4222. /** @hidden */
  4223. onLoading(): void;
  4224. /** @hidden */
  4225. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4226. private _loadLightAsync;
  4227. }
  4228. }
  4229. declare module BABYLON.GLTF2.Loader.Extensions {
  4230. /**
  4231. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4232. */
  4233. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  4234. /**
  4235. * The name of this extension.
  4236. */
  4237. readonly name: string;
  4238. /**
  4239. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  4240. */
  4241. dracoCompression?: DracoCompression;
  4242. /**
  4243. * Defines whether this extension is enabled.
  4244. */
  4245. enabled: boolean;
  4246. private _loader;
  4247. /** @hidden */
  4248. constructor(loader: GLTFLoader);
  4249. /** @hidden */
  4250. dispose(): void;
  4251. /** @hidden */
  4252. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  4253. }
  4254. }
  4255. declare module BABYLON.GLTF2.Loader.Extensions {
  4256. /**
  4257. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4258. */
  4259. export class KHR_lights implements IGLTFLoaderExtension {
  4260. /**
  4261. * The name of this extension.
  4262. */
  4263. readonly name: string;
  4264. /**
  4265. * Defines whether this extension is enabled.
  4266. */
  4267. enabled: boolean;
  4268. private _loader;
  4269. private _lights?;
  4270. /** @hidden */
  4271. constructor(loader: GLTFLoader);
  4272. /** @hidden */
  4273. dispose(): void;
  4274. /** @hidden */
  4275. onLoading(): void;
  4276. /** @hidden */
  4277. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4278. }
  4279. }
  4280. declare module BABYLON.GLTF2.Loader.Extensions {
  4281. /**
  4282. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4283. */
  4284. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  4285. /**
  4286. * The name of this extension.
  4287. */
  4288. readonly name: string;
  4289. /**
  4290. * Defines whether this extension is enabled.
  4291. */
  4292. enabled: boolean;
  4293. /**
  4294. * Defines a number that determines the order the extensions are applied.
  4295. */
  4296. order: number;
  4297. private _loader;
  4298. /** @hidden */
  4299. constructor(loader: GLTFLoader);
  4300. /** @hidden */
  4301. dispose(): void;
  4302. /** @hidden */
  4303. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4304. private _loadSpecularGlossinessPropertiesAsync;
  4305. }
  4306. }
  4307. declare module BABYLON.GLTF2.Loader.Extensions {
  4308. /**
  4309. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4310. */
  4311. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  4312. /**
  4313. * The name of this extension.
  4314. */
  4315. readonly name: string;
  4316. /**
  4317. * Defines whether this extension is enabled.
  4318. */
  4319. enabled: boolean;
  4320. /**
  4321. * Defines a number that determines the order the extensions are applied.
  4322. */
  4323. order: number;
  4324. private _loader;
  4325. /** @hidden */
  4326. constructor(loader: GLTFLoader);
  4327. /** @hidden */
  4328. dispose(): void;
  4329. /** @hidden */
  4330. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4331. private _loadUnlitPropertiesAsync;
  4332. }
  4333. }
  4334. declare module BABYLON.GLTF2.Loader.Extensions {
  4335. /**
  4336. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4337. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4338. * !!! Experimental Extension Subject to Changes !!!
  4339. */
  4340. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  4341. /**
  4342. * The name of this extension.
  4343. */
  4344. readonly name: string;
  4345. /**
  4346. * Defines whether this extension is enabled.
  4347. */
  4348. enabled: boolean;
  4349. /**
  4350. * Defines a number that determines the order the extensions are applied.
  4351. */
  4352. order: number;
  4353. private _loader;
  4354. /** @hidden */
  4355. constructor(loader: GLTFLoader);
  4356. /** @hidden */
  4357. dispose(): void;
  4358. /** @hidden */
  4359. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4360. private _loadClearCoatPropertiesAsync;
  4361. }
  4362. }
  4363. declare module BABYLON.GLTF2.Loader.Extensions {
  4364. /**
  4365. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4366. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4367. * !!! Experimental Extension Subject to Changes !!!
  4368. */
  4369. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  4370. /**
  4371. * The name of this extension.
  4372. */
  4373. readonly name: string;
  4374. /**
  4375. * Defines whether this extension is enabled.
  4376. */
  4377. enabled: boolean;
  4378. /**
  4379. * Defines a number that determines the order the extensions are applied.
  4380. */
  4381. order: number;
  4382. private _loader;
  4383. /** @hidden */
  4384. constructor(loader: GLTFLoader);
  4385. /** @hidden */
  4386. dispose(): void;
  4387. /** @hidden */
  4388. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4389. private _loadSheenPropertiesAsync;
  4390. }
  4391. }
  4392. declare module BABYLON.GLTF2.Loader.Extensions {
  4393. /**
  4394. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4395. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4396. * !!! Experimental Extension Subject to Changes !!!
  4397. */
  4398. export class KHR_materials_specular implements IGLTFLoaderExtension {
  4399. /**
  4400. * The name of this extension.
  4401. */
  4402. readonly name: string;
  4403. /**
  4404. * Defines whether this extension is enabled.
  4405. */
  4406. enabled: boolean;
  4407. /**
  4408. * Defines a number that determines the order the extensions are applied.
  4409. */
  4410. order: number;
  4411. private _loader;
  4412. /** @hidden */
  4413. constructor(loader: GLTFLoader);
  4414. /** @hidden */
  4415. dispose(): void;
  4416. /** @hidden */
  4417. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4418. private _loadSpecularPropertiesAsync;
  4419. }
  4420. }
  4421. declare module BABYLON.GLTF2.Loader.Extensions {
  4422. /**
  4423. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4424. */
  4425. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  4426. /**
  4427. * The name of this extension.
  4428. */
  4429. readonly name: string;
  4430. /**
  4431. * Defines whether this extension is enabled.
  4432. */
  4433. enabled: boolean;
  4434. /** @hidden */
  4435. constructor(loader: GLTFLoader);
  4436. /** @hidden */
  4437. dispose(): void;
  4438. }
  4439. }
  4440. declare module BABYLON.GLTF2.Loader.Extensions {
  4441. /**
  4442. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4443. */
  4444. export class KHR_texture_transform implements IGLTFLoaderExtension {
  4445. /**
  4446. * The name of this extension.
  4447. */
  4448. readonly name: string;
  4449. /**
  4450. * Defines whether this extension is enabled.
  4451. */
  4452. enabled: boolean;
  4453. private _loader;
  4454. /** @hidden */
  4455. constructor(loader: GLTFLoader);
  4456. /** @hidden */
  4457. dispose(): void;
  4458. /** @hidden */
  4459. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  4460. }
  4461. }
  4462. declare module BABYLON.GLTF2.Loader.Extensions {
  4463. /**
  4464. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4465. */
  4466. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  4467. /**
  4468. * The name of this extension.
  4469. */
  4470. readonly name: string;
  4471. /**
  4472. * Defines whether this extension is enabled.
  4473. */
  4474. enabled: boolean;
  4475. private _loader;
  4476. private _clips;
  4477. private _emitters;
  4478. /** @hidden */
  4479. constructor(loader: GLTFLoader);
  4480. /** @hidden */
  4481. dispose(): void;
  4482. /** @hidden */
  4483. onLoading(): void;
  4484. /** @hidden */
  4485. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4486. /** @hidden */
  4487. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4488. /** @hidden */
  4489. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  4490. private _loadClipAsync;
  4491. private _loadEmitterAsync;
  4492. private _getEventAction;
  4493. private _loadAnimationEventAsync;
  4494. }
  4495. }
  4496. declare module BABYLON.GLTF2.Loader.Extensions {
  4497. /**
  4498. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4499. */
  4500. export class MSFT_lod implements IGLTFLoaderExtension {
  4501. /**
  4502. * The name of this extension.
  4503. */
  4504. readonly name: string;
  4505. /**
  4506. * Defines whether this extension is enabled.
  4507. */
  4508. enabled: boolean;
  4509. /**
  4510. * Defines a number that determines the order the extensions are applied.
  4511. */
  4512. order: number;
  4513. /**
  4514. * Maximum number of LODs to load, starting from the lowest LOD.
  4515. */
  4516. maxLODsToLoad: number;
  4517. /**
  4518. * Observable raised when all node LODs of one level are loaded.
  4519. * The event data is the index of the loaded LOD starting from zero.
  4520. * Dispose the loader to cancel the loading of the next level of LODs.
  4521. */
  4522. onNodeLODsLoadedObservable: Observable<number>;
  4523. /**
  4524. * Observable raised when all material LODs of one level are loaded.
  4525. * The event data is the index of the loaded LOD starting from zero.
  4526. * Dispose the loader to cancel the loading of the next level of LODs.
  4527. */
  4528. onMaterialLODsLoadedObservable: Observable<number>;
  4529. private _loader;
  4530. private _nodeIndexLOD;
  4531. private _nodeSignalLODs;
  4532. private _nodePromiseLODs;
  4533. private _materialIndexLOD;
  4534. private _materialSignalLODs;
  4535. private _materialPromiseLODs;
  4536. private _indexLOD;
  4537. private _bufferLODs;
  4538. /** @hidden */
  4539. constructor(loader: GLTFLoader);
  4540. /** @hidden */
  4541. dispose(): void;
  4542. /** @hidden */
  4543. onReady(): void;
  4544. /** @hidden */
  4545. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4546. /** @hidden */
  4547. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4548. /** @hidden */
  4549. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  4550. /** @hidden */
  4551. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  4552. /** @hidden */
  4553. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  4554. private _loadBufferLOD;
  4555. /**
  4556. * Gets an array of LOD properties from lowest to highest.
  4557. */
  4558. private _getLODs;
  4559. private _disposeUnusedMaterials;
  4560. }
  4561. }
  4562. declare module BABYLON.GLTF2.Loader.Extensions {
  4563. /** @hidden */
  4564. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  4565. readonly name: string;
  4566. enabled: boolean;
  4567. private _loader;
  4568. constructor(loader: GLTFLoader);
  4569. dispose(): void;
  4570. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4571. }
  4572. }
  4573. declare module BABYLON.GLTF2.Loader.Extensions {
  4574. /** @hidden */
  4575. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  4576. readonly name: string;
  4577. enabled: boolean;
  4578. private _loader;
  4579. constructor(loader: GLTFLoader);
  4580. dispose(): void;
  4581. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4582. }
  4583. }
  4584. declare module BABYLON.GLTF2.Loader.Extensions {
  4585. /**
  4586. * Store glTF extras (if present) in BJS objects' metadata
  4587. */
  4588. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  4589. /**
  4590. * The name of this extension.
  4591. */
  4592. readonly name: string;
  4593. /**
  4594. * Defines whether this extension is enabled.
  4595. */
  4596. enabled: boolean;
  4597. private _loader;
  4598. private _assignExtras;
  4599. /** @hidden */
  4600. constructor(loader: GLTFLoader);
  4601. /** @hidden */
  4602. dispose(): void;
  4603. /** @hidden */
  4604. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4605. /** @hidden */
  4606. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  4607. /** @hidden */
  4608. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  4609. }
  4610. }
  4611. declare module BABYLON {
  4612. /**
  4613. * Class reading and parsing the MTL file bundled with the obj file.
  4614. */
  4615. export class MTLFileLoader {
  4616. /**
  4617. * Invert Y-Axis of referenced textures on load
  4618. */
  4619. static INVERT_TEXTURE_Y: boolean;
  4620. /**
  4621. * All material loaded from the mtl will be set here
  4622. */
  4623. materials: StandardMaterial[];
  4624. /**
  4625. * This function will read the mtl file and create each material described inside
  4626. * This function could be improve by adding :
  4627. * -some component missing (Ni, Tf...)
  4628. * -including the specific options available
  4629. *
  4630. * @param scene defines the scene the material will be created in
  4631. * @param data defines the mtl data to parse
  4632. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  4633. * @param forAssetContainer defines if the material should be registered in the scene
  4634. */
  4635. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  4636. /**
  4637. * Gets the texture for the material.
  4638. *
  4639. * If the material is imported from input file,
  4640. * We sanitize the url to ensure it takes the textre from aside the material.
  4641. *
  4642. * @param rootUrl The root url to load from
  4643. * @param value The value stored in the mtl
  4644. * @return The Texture
  4645. */
  4646. private static _getTexture;
  4647. }
  4648. }
  4649. declare module BABYLON {
  4650. /**
  4651. * Options for loading OBJ/MTL files
  4652. */
  4653. type MeshLoadOptions = {
  4654. /**
  4655. * Defines if UVs are optimized by default during load.
  4656. */
  4657. OptimizeWithUV: boolean;
  4658. /**
  4659. * Defines custom scaling of UV coordinates of loaded meshes.
  4660. */
  4661. UVScaling: Vector2;
  4662. /**
  4663. * Invert model on y-axis (does a model scaling inversion)
  4664. */
  4665. InvertY: boolean;
  4666. /**
  4667. * Invert Y-Axis of referenced textures on load
  4668. */
  4669. InvertTextureY: boolean;
  4670. /**
  4671. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4672. */
  4673. ImportVertexColors: boolean;
  4674. /**
  4675. * Compute the normals for the model, even if normals are present in the file.
  4676. */
  4677. ComputeNormals: boolean;
  4678. /**
  4679. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4680. */
  4681. SkipMaterials: boolean;
  4682. /**
  4683. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4684. */
  4685. MaterialLoadingFailsSilently: boolean;
  4686. };
  4687. /**
  4688. * OBJ file type loader.
  4689. * This is a babylon scene loader plugin.
  4690. */
  4691. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  4692. /**
  4693. * Defines if UVs are optimized by default during load.
  4694. */
  4695. static OPTIMIZE_WITH_UV: boolean;
  4696. /**
  4697. * Invert model on y-axis (does a model scaling inversion)
  4698. */
  4699. static INVERT_Y: boolean;
  4700. /**
  4701. * Invert Y-Axis of referenced textures on load
  4702. */
  4703. static get INVERT_TEXTURE_Y(): boolean;
  4704. static set INVERT_TEXTURE_Y(value: boolean);
  4705. /**
  4706. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4707. */
  4708. static IMPORT_VERTEX_COLORS: boolean;
  4709. /**
  4710. * Compute the normals for the model, even if normals are present in the file.
  4711. */
  4712. static COMPUTE_NORMALS: boolean;
  4713. /**
  4714. * Defines custom scaling of UV coordinates of loaded meshes.
  4715. */
  4716. static UV_SCALING: Vector2;
  4717. /**
  4718. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4719. */
  4720. static SKIP_MATERIALS: boolean;
  4721. /**
  4722. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4723. *
  4724. * Defaults to true for backwards compatibility.
  4725. */
  4726. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  4727. /**
  4728. * Defines the name of the plugin.
  4729. */
  4730. name: string;
  4731. /**
  4732. * Defines the extension the plugin is able to load.
  4733. */
  4734. extensions: string;
  4735. /** @hidden */
  4736. obj: RegExp;
  4737. /** @hidden */
  4738. group: RegExp;
  4739. /** @hidden */
  4740. mtllib: RegExp;
  4741. /** @hidden */
  4742. usemtl: RegExp;
  4743. /** @hidden */
  4744. smooth: RegExp;
  4745. /** @hidden */
  4746. vertexPattern: RegExp;
  4747. /** @hidden */
  4748. normalPattern: RegExp;
  4749. /** @hidden */
  4750. uvPattern: RegExp;
  4751. /** @hidden */
  4752. facePattern1: RegExp;
  4753. /** @hidden */
  4754. facePattern2: RegExp;
  4755. /** @hidden */
  4756. facePattern3: RegExp;
  4757. /** @hidden */
  4758. facePattern4: RegExp;
  4759. /** @hidden */
  4760. facePattern5: RegExp;
  4761. private _forAssetContainer;
  4762. private _meshLoadOptions;
  4763. /**
  4764. * Creates loader for .OBJ files
  4765. *
  4766. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  4767. */
  4768. constructor(meshLoadOptions?: MeshLoadOptions);
  4769. private static get currentMeshLoadOptions();
  4770. /**
  4771. * Calls synchronously the MTL file attached to this obj.
  4772. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  4773. * Without this function materials are not displayed in the first frame (but displayed after).
  4774. * In consequence it is impossible to get material information in your HTML file
  4775. *
  4776. * @param url The URL of the MTL file
  4777. * @param rootUrl
  4778. * @param onSuccess Callback function to be called when the MTL file is loaded
  4779. * @private
  4780. */
  4781. private _loadMTL;
  4782. /**
  4783. * Instantiates a OBJ file loader plugin.
  4784. * @returns the created plugin
  4785. */
  4786. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  4787. /**
  4788. * If the data string can be loaded directly.
  4789. *
  4790. * @param data string containing the file data
  4791. * @returns if the data can be loaded directly
  4792. */
  4793. canDirectLoad(data: string): boolean;
  4794. /**
  4795. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  4796. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  4797. * @param scene the scene the meshes should be added to
  4798. * @param data the OBJ data to load
  4799. * @param rootUrl root url to load from
  4800. * @param onProgress event that fires when loading progress has occured
  4801. * @param fileName Defines the name of the file to load
  4802. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4803. */
  4804. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4805. meshes: AbstractMesh[];
  4806. particleSystems: IParticleSystem[];
  4807. skeletons: Skeleton[];
  4808. animationGroups: AnimationGroup[];
  4809. }>;
  4810. /**
  4811. * Imports all objects from the loaded OBJ data and adds them to the scene
  4812. * @param scene the scene the objects should be added to
  4813. * @param data the OBJ data to load
  4814. * @param rootUrl root url to load from
  4815. * @param onProgress event that fires when loading progress has occured
  4816. * @param fileName Defines the name of the file to load
  4817. * @returns a promise which completes when objects have been loaded to the scene
  4818. */
  4819. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4820. /**
  4821. * Load into an asset container.
  4822. * @param scene The scene to load into
  4823. * @param data The data to import
  4824. * @param rootUrl The root url for scene and resources
  4825. * @param onProgress The callback when the load progresses
  4826. * @param fileName Defines the name of the file to load
  4827. * @returns The loaded asset container
  4828. */
  4829. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4830. /**
  4831. * Read the OBJ file and create an Array of meshes.
  4832. * Each mesh contains all information given by the OBJ and the MTL file.
  4833. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4834. *
  4835. * @param meshesNames
  4836. * @param scene Scene The scene where are displayed the data
  4837. * @param data String The content of the obj file
  4838. * @param rootUrl String The path to the folder
  4839. * @returns Array<AbstractMesh>
  4840. * @private
  4841. */
  4842. private _parseSolid;
  4843. }
  4844. }
  4845. declare module BABYLON {
  4846. /**
  4847. * STL file type loader.
  4848. * This is a babylon scene loader plugin.
  4849. */
  4850. export class STLFileLoader implements ISceneLoaderPlugin {
  4851. /** @hidden */
  4852. solidPattern: RegExp;
  4853. /** @hidden */
  4854. facetsPattern: RegExp;
  4855. /** @hidden */
  4856. normalPattern: RegExp;
  4857. /** @hidden */
  4858. vertexPattern: RegExp;
  4859. /**
  4860. * Defines the name of the plugin.
  4861. */
  4862. name: string;
  4863. /**
  4864. * Defines the extensions the stl loader is able to load.
  4865. * force data to come in as an ArrayBuffer
  4866. * we'll convert to string if it looks like it's an ASCII .stl
  4867. */
  4868. extensions: ISceneLoaderPluginExtensions;
  4869. /**
  4870. * Import meshes into a scene.
  4871. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4872. * @param scene The scene to import into
  4873. * @param data The data to import
  4874. * @param rootUrl The root url for scene and resources
  4875. * @param meshes The meshes array to import into
  4876. * @param particleSystems The particle systems array to import into
  4877. * @param skeletons The skeletons array to import into
  4878. * @param onError The callback when import fails
  4879. * @returns True if successful or false otherwise
  4880. */
  4881. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4882. /**
  4883. * Load into a scene.
  4884. * @param scene The scene to load into
  4885. * @param data The data to import
  4886. * @param rootUrl The root url for scene and resources
  4887. * @param onError The callback when import fails
  4888. * @returns true if successful or false otherwise
  4889. */
  4890. load(scene: Scene, data: any, rootUrl: string): boolean;
  4891. /**
  4892. * Load into an asset container.
  4893. * @param scene The scene to load into
  4894. * @param data The data to import
  4895. * @param rootUrl The root url for scene and resources
  4896. * @param onError The callback when import fails
  4897. * @returns The loaded asset container
  4898. */
  4899. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4900. private _isBinary;
  4901. private _parseBinary;
  4902. private _parseASCII;
  4903. }
  4904. }