babylonjs.loaders.module.d.ts 187 KB

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