babylonjs.loaders.module.d.ts 170 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103
  1. declare module "babylonjs-loaders/glTF/glTFFileLoader" {
  2. import { IGLTFValidationResults } from "babylonjs-gltf2interface";
  3. import { Nullable } from "babylonjs/types";
  4. import { Observable } from "babylonjs/Misc/observable";
  5. import { Camera } from "babylonjs/Cameras/camera";
  6. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  7. import { Skeleton } from "babylonjs/Bones/skeleton";
  8. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  9. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  10. import { Material } from "babylonjs/Materials/material";
  11. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  12. import { ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  13. import { AssetContainer } from "babylonjs/assetContainer";
  14. import { Scene, IDisposable } from "babylonjs/scene";
  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<IGLTFValidationResults>;
  252. private _onValidatedObserver;
  253. /**
  254. * Callback raised after a loader extension is created.
  255. */
  256. onValidated: (results: 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 IGLTF2 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 IGLTF2.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 IGLTF2.IAnimationChannel, IArrayItem {
  1020. }
  1021. /** @hidden */
  1022. export interface _IAnimationSamplerData {
  1023. input: Float32Array;
  1024. interpolation: IGLTF2.AnimationSamplerInterpolation;
  1025. output: Float32Array;
  1026. }
  1027. /**
  1028. * Loader interface with additional members.
  1029. */
  1030. export interface IAnimationSampler extends IGLTF2.IAnimationSampler, IArrayItem {
  1031. /** @hidden */
  1032. _data?: Promise<_IAnimationSamplerData>;
  1033. }
  1034. /**
  1035. * Loader interface with additional members.
  1036. */
  1037. export interface IAnimation extends IGLTF2.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 IGLTF2.IBuffer, IArrayItem {
  1047. /** @hidden */
  1048. _data?: Promise<ArrayBufferView>;
  1049. }
  1050. /**
  1051. * Loader interface with additional members.
  1052. */
  1053. export interface IBufferView extends IGLTF2.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 IGLTF2.ICamera, IArrayItem {
  1063. }
  1064. /**
  1065. * Loader interface with additional members.
  1066. */
  1067. export interface IImage extends IGLTF2.IImage, IArrayItem {
  1068. /** @hidden */
  1069. _data?: Promise<ArrayBufferView>;
  1070. }
  1071. /**
  1072. * Loader interface with additional members.
  1073. */
  1074. export interface IMaterialNormalTextureInfo extends IGLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1075. }
  1076. /**
  1077. * Loader interface with additional members.
  1078. */
  1079. export interface IMaterialOcclusionTextureInfo extends IGLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1080. }
  1081. /**
  1082. * Loader interface with additional members.
  1083. */
  1084. export interface IMaterialPbrMetallicRoughness extends IGLTF2.IMaterialPbrMetallicRoughness {
  1085. baseColorTexture?: ITextureInfo;
  1086. metallicRoughnessTexture?: ITextureInfo;
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface IMaterial extends IGLTF2.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 IGLTF2.IMesh, IArrayItem {
  1109. primitives: IMeshPrimitive[];
  1110. }
  1111. /**
  1112. * Loader interface with additional members.
  1113. */
  1114. export interface IMeshPrimitive extends IGLTF2.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 IGLTF2.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 IGLTF2.ISampler, IArrayItem {
  1149. /** @hidden */
  1150. _data?: _ISamplerData;
  1151. }
  1152. /**
  1153. * Loader interface with additional members.
  1154. */
  1155. export interface IScene extends IGLTF2.IScene, IArrayItem {
  1156. }
  1157. /**
  1158. * Loader interface with additional members.
  1159. */
  1160. export interface ISkin extends IGLTF2.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 IGLTF2.ITexture, IArrayItem {
  1171. }
  1172. /**
  1173. * Loader interface with additional members.
  1174. */
  1175. export interface ITextureInfo extends IGLTF2.ITextureInfo {
  1176. }
  1177. /**
  1178. * Loader interface with additional members.
  1179. */
  1180. export interface IGLTF extends IGLTF2.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 { IDisposable } from "babylonjs/scene";
  1206. import { IScene, INode, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1207. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
  1208. /**
  1209. * Interface for a glTF loader extension.
  1210. */
  1211. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  1212. /**
  1213. * Called after the loader state changes to LOADING.
  1214. */
  1215. onLoading?(): void;
  1216. /**
  1217. * Called after the loader state changes to READY.
  1218. */
  1219. onReady?(): void;
  1220. /**
  1221. * Define this method to modify the default behavior when loading scenes.
  1222. * @param context The context when loading the asset
  1223. * @param scene The glTF scene property
  1224. * @returns A promise that resolves when the load is complete or null if not handled
  1225. */
  1226. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1227. /**
  1228. * Define this method to modify the default behavior when loading nodes.
  1229. * @param context The context when loading the asset
  1230. * @param node The glTF node property
  1231. * @param assign A function called synchronously after parsing the glTF properties
  1232. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1233. */
  1234. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1235. /**
  1236. * Define this method to modify the default behavior when loading cameras.
  1237. * @param context The context when loading the asset
  1238. * @param camera The glTF camera property
  1239. * @param assign A function called synchronously after parsing the glTF properties
  1240. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1241. */
  1242. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1243. /**
  1244. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1245. * @param context The context when loading the asset
  1246. * @param primitive The glTF mesh primitive property
  1247. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1248. */
  1249. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1250. /**
  1251. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1252. * @param context The context when loading the asset
  1253. * @param material The glTF material property
  1254. * @param assign A function called synchronously after parsing the glTF properties
  1255. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1256. */
  1257. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1258. /**
  1259. * Define this method to modify the default behavior when creating materials.
  1260. * @param context The context when loading the asset
  1261. * @param material The glTF material property
  1262. * @param babylonDrawMode The draw mode for the Babylon material
  1263. * @returns The Babylon material or null if not handled
  1264. */
  1265. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1266. /**
  1267. * Define this method to modify the default behavior when loading material properties.
  1268. * @param context The context when loading the asset
  1269. * @param material The glTF material property
  1270. * @param babylonMaterial The Babylon material
  1271. * @returns A promise that resolves when the load is complete or null if not handled
  1272. */
  1273. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1274. /**
  1275. * Define this method to modify the default behavior when loading texture infos.
  1276. * @param context The context when loading the asset
  1277. * @param textureInfo The glTF texture info property
  1278. * @param assign A function called synchronously after parsing the glTF properties
  1279. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1280. */
  1281. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1282. /**
  1283. * Define this method to modify the default behavior when loading animations.
  1284. * @param context The context when loading the asset
  1285. * @param animation The glTF animation property
  1286. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1287. */
  1288. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1289. /**
  1290. * Define this method to modify the default behavior when loading uris.
  1291. * @param context The context when loading the asset
  1292. * @param uri The uri to load
  1293. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1294. */
  1295. _loadUriAsync?(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1296. }
  1297. }
  1298. declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
  1299. import { Nullable } from "babylonjs/types";
  1300. import { Camera } from "babylonjs/Cameras/camera";
  1301. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1302. import { Skeleton } from "babylonjs/Bones/skeleton";
  1303. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1304. import { Material } from "babylonjs/Materials/material";
  1305. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1306. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1307. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1308. import { Mesh } from "babylonjs/Meshes/mesh";
  1309. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1310. import { Scene } from "babylonjs/scene";
  1311. import { IProperty } from "babylonjs-gltf2interface";
  1312. import { IGLTF, INode, IScene, ICamera, IAnimation, IBufferView, IMaterial, ITextureInfo, IImage, IArrayItem as IArrItem } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1313. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1314. import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  1315. /**
  1316. * Helper class for working with arrays when loading the glTF asset
  1317. */
  1318. export class ArrayItem {
  1319. /**
  1320. * Gets an item from the given array.
  1321. * @param context The context when loading the asset
  1322. * @param array The array to get the item from
  1323. * @param index The index to the array
  1324. * @returns The array item
  1325. */
  1326. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1327. /**
  1328. * Assign an `index` field to each item of the given array.
  1329. * @param array The array of items
  1330. */
  1331. static Assign(array?: IArrItem[]): void;
  1332. }
  1333. /**
  1334. * The glTF 2.0 loader
  1335. */
  1336. export class GLTFLoader implements IGLTFLoader {
  1337. /** The glTF object parsed from the JSON. */
  1338. gltf: IGLTF;
  1339. /** The Babylon scene when loading the asset. */
  1340. babylonScene: Scene;
  1341. /** @hidden */
  1342. _completePromises: Promise<any>[];
  1343. private _disposed;
  1344. private _parent;
  1345. private _state;
  1346. private _extensions;
  1347. private _rootUrl;
  1348. private _fileName;
  1349. private _uniqueRootUrl;
  1350. private _rootBabylonMesh;
  1351. private _defaultBabylonMaterialData;
  1352. private _progressCallback?;
  1353. private _requests;
  1354. private static readonly _DefaultSampler;
  1355. private static _ExtensionNames;
  1356. private static _ExtensionFactories;
  1357. /**
  1358. * Registers a loader extension.
  1359. * @param name The name of the loader extension.
  1360. * @param factory The factory function that creates the loader extension.
  1361. */
  1362. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1363. /**
  1364. * Unregisters a loader extension.
  1365. * @param name The name of the loader extenion.
  1366. * @returns A boolean indicating whether the extension has been unregistered
  1367. */
  1368. static UnregisterExtension(name: string): boolean;
  1369. /**
  1370. * Gets the loader state.
  1371. */
  1372. readonly state: Nullable<GLTFLoaderState>;
  1373. /** @hidden */
  1374. constructor(parent: GLTFFileLoader);
  1375. /** @hidden */
  1376. dispose(): void;
  1377. /** @hidden */
  1378. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1379. meshes: AbstractMesh[];
  1380. particleSystems: IParticleSystem[];
  1381. skeletons: Skeleton[];
  1382. animationGroups: AnimationGroup[];
  1383. }>;
  1384. /** @hidden */
  1385. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1386. private _loadAsync;
  1387. private _loadData;
  1388. private _setupData;
  1389. private _loadExtensions;
  1390. private _checkExtensions;
  1391. private _setState;
  1392. private _createRootNode;
  1393. /**
  1394. * Loads a glTF scene.
  1395. * @param context The context when loading the asset
  1396. * @param scene The glTF scene property
  1397. * @returns A promise that resolves when the load is complete
  1398. */
  1399. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1400. private _forEachPrimitive;
  1401. private _getMeshes;
  1402. private _getSkeletons;
  1403. private _getAnimationGroups;
  1404. private _startAnimations;
  1405. /**
  1406. * Loads a glTF node.
  1407. * @param context The context when loading the asset
  1408. * @param node The glTF node property
  1409. * @param assign A function called synchronously after parsing the glTF properties
  1410. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1411. */
  1412. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1413. private _loadMeshAsync;
  1414. private _loadMeshPrimitiveAsync;
  1415. private _loadVertexDataAsync;
  1416. private _createMorphTargets;
  1417. private _loadMorphTargetsAsync;
  1418. private _loadMorphTargetVertexDataAsync;
  1419. private static _LoadTransform;
  1420. private _loadSkinAsync;
  1421. private _loadBones;
  1422. private _loadBone;
  1423. private _loadSkinInverseBindMatricesDataAsync;
  1424. private _updateBoneMatrices;
  1425. private _getNodeMatrix;
  1426. /**
  1427. * Loads a glTF camera.
  1428. * @param context The context when loading the asset
  1429. * @param camera The glTF camera property
  1430. * @param assign A function called synchronously after parsing the glTF properties
  1431. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1432. */
  1433. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1434. private _loadAnimationsAsync;
  1435. /**
  1436. * Loads a glTF animation.
  1437. * @param context The context when loading the asset
  1438. * @param animation The glTF animation property
  1439. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1440. */
  1441. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1442. private _loadAnimationChannelAsync;
  1443. private _loadAnimationSamplerAsync;
  1444. private _loadBufferAsync;
  1445. /**
  1446. * Loads a glTF buffer view.
  1447. * @param context The context when loading the asset
  1448. * @param bufferView The glTF buffer view property
  1449. * @returns A promise that resolves with the loaded data when the load is complete
  1450. */
  1451. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1452. private _loadIndicesAccessorAsync;
  1453. private _loadFloatAccessorAsync;
  1454. private _loadVertexBufferViewAsync;
  1455. private _loadVertexAccessorAsync;
  1456. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1457. /** @hidden */
  1458. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1459. private _createDefaultMaterial;
  1460. /**
  1461. * Creates a Babylon material from a glTF material.
  1462. * @param context The context when loading the asset
  1463. * @param material The glTF material property
  1464. * @param babylonDrawMode The draw mode for the Babylon material
  1465. * @returns The Babylon material
  1466. */
  1467. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1468. /**
  1469. * Loads properties from a glTF material into a Babylon material.
  1470. * @param context The context when loading the asset
  1471. * @param material The glTF material property
  1472. * @param babylonMaterial The Babylon material
  1473. * @returns A promise that resolves when the load is complete
  1474. */
  1475. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1476. /**
  1477. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1478. * @param context The context when loading the asset
  1479. * @param material The glTF material property
  1480. * @param babylonMaterial The Babylon material
  1481. * @returns A promise that resolves when the load is complete
  1482. */
  1483. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1484. /**
  1485. * Loads the alpha properties from a glTF material into a Babylon material.
  1486. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1487. * @param context The context when loading the asset
  1488. * @param material The glTF material property
  1489. * @param babylonMaterial The Babylon material
  1490. */
  1491. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1492. /**
  1493. * Loads a glTF texture info.
  1494. * @param context The context when loading the asset
  1495. * @param textureInfo The glTF texture info property
  1496. * @param assign A function called synchronously after parsing the glTF properties
  1497. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1498. */
  1499. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1500. private _loadTextureAsync;
  1501. private _loadSampler;
  1502. /**
  1503. * Loads a glTF image.
  1504. * @param context The context when loading the asset
  1505. * @param image The glTF image property
  1506. * @returns A promise that resolves with the loaded data when the load is complete
  1507. */
  1508. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1509. /**
  1510. * Loads a glTF uri.
  1511. * @param context The context when loading the asset
  1512. * @param uri The base64 or relative uri
  1513. * @returns A promise that resolves with the loaded data when the load is complete
  1514. */
  1515. loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1516. private _onProgress;
  1517. /**
  1518. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1519. * @param babylonObject the Babylon object with metadata
  1520. * @param pointer the JSON pointer
  1521. */
  1522. static AddPointerMetadata(babylonObject: {
  1523. metadata: any;
  1524. }, pointer: string): void;
  1525. private static _GetTextureWrapMode;
  1526. private static _GetTextureSamplingMode;
  1527. private static _GetTypedArray;
  1528. private static _GetNumComponents;
  1529. private static _ValidateUri;
  1530. private static _GetDrawMode;
  1531. private _compileMaterialsAsync;
  1532. private _compileShadowGeneratorsAsync;
  1533. private _forEachExtensions;
  1534. private _applyExtensions;
  1535. private _extensionsOnLoading;
  1536. private _extensionsOnReady;
  1537. private _extensionsLoadSceneAsync;
  1538. private _extensionsLoadNodeAsync;
  1539. private _extensionsLoadCameraAsync;
  1540. private _extensionsLoadVertexDataAsync;
  1541. private _extensionsLoadMaterialAsync;
  1542. private _extensionsCreateMaterial;
  1543. private _extensionsLoadMaterialPropertiesAsync;
  1544. private _extensionsLoadTextureInfoAsync;
  1545. private _extensionsLoadAnimationAsync;
  1546. private _extensionsLoadUriAsync;
  1547. /**
  1548. * Helper method called by a loader extension to load an glTF extension.
  1549. * @param context The context when loading the asset
  1550. * @param property The glTF property to load the extension from
  1551. * @param extensionName The name of the extension to load
  1552. * @param actionAsync The action to run
  1553. * @returns The promise returned by actionAsync or null if the extension does not exist
  1554. */
  1555. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1556. /**
  1557. * Helper method called by a loader extension to load a glTF extra.
  1558. * @param context The context when loading the asset
  1559. * @param property The glTF property to load the extra from
  1560. * @param extensionName The name of the extension to load
  1561. * @param actionAsync The action to run
  1562. * @returns The promise returned by actionAsync or null if the extra does not exist
  1563. */
  1564. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1565. /**
  1566. * Increments the indentation level and logs a message.
  1567. * @param message The message to log
  1568. */
  1569. logOpen(message: string): void;
  1570. /**
  1571. * Decrements the indentation level.
  1572. */
  1573. logClose(): void;
  1574. /**
  1575. * Logs a message
  1576. * @param message The message to log
  1577. */
  1578. log(message: string): void;
  1579. /**
  1580. * Starts a performance counter.
  1581. * @param counterName The name of the performance counter
  1582. */
  1583. startPerformanceCounter(counterName: string): void;
  1584. /**
  1585. * Ends a performance counter.
  1586. * @param counterName The name of the performance counter
  1587. */
  1588. endPerformanceCounter(counterName: string): void;
  1589. }
  1590. }
  1591. declare module "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based" {
  1592. import { Nullable } from "babylonjs/types";
  1593. import { IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1594. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1595. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1596. /**
  1597. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1598. */
  1599. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1600. /** The name of this extension. */
  1601. readonly name: string;
  1602. /** Defines whether this extension is enabled. */
  1603. enabled: boolean;
  1604. private _loader;
  1605. private _lights?;
  1606. /** @hidden */
  1607. constructor(loader: GLTFLoader);
  1608. /** @hidden */
  1609. dispose(): void;
  1610. /** @hidden */
  1611. onLoading(): void;
  1612. /** @hidden */
  1613. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1614. private _loadLightAsync;
  1615. }
  1616. }
  1617. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression" {
  1618. import { Nullable } from "babylonjs/types";
  1619. import { Geometry } from "babylonjs/Meshes/geometry";
  1620. import { Mesh } from "babylonjs/Meshes/mesh";
  1621. import { IMeshPrimitive } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1622. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1623. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1624. /**
  1625. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1626. */
  1627. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1628. /** The name of this extension. */
  1629. readonly name: string;
  1630. /** Defines whether this extension is enabled. */
  1631. enabled: boolean;
  1632. private _loader;
  1633. private _dracoCompression?;
  1634. /** @hidden */
  1635. constructor(loader: GLTFLoader);
  1636. /** @hidden */
  1637. dispose(): void;
  1638. /** @hidden */
  1639. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1640. }
  1641. }
  1642. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual" {
  1643. import { Nullable } from "babylonjs/types";
  1644. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1645. import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1646. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1647. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1648. /**
  1649. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1650. */
  1651. export class KHR_lights implements IGLTFLoaderExtension {
  1652. /** The name of this extension. */
  1653. readonly name: string;
  1654. /** Defines whether this extension is enabled. */
  1655. enabled: boolean;
  1656. private _loader;
  1657. private _lights?;
  1658. /** @hidden */
  1659. constructor(loader: GLTFLoader);
  1660. /** @hidden */
  1661. dispose(): void;
  1662. /** @hidden */
  1663. onLoading(): void;
  1664. /** @hidden */
  1665. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1666. }
  1667. }
  1668. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness" {
  1669. import { Nullable } from "babylonjs/types";
  1670. import { Material } from "babylonjs/Materials/material";
  1671. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1672. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1673. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1674. /**
  1675. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1676. */
  1677. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1678. /** The name of this extension. */
  1679. readonly name: string;
  1680. /** Defines whether this extension is enabled. */
  1681. enabled: boolean;
  1682. private _loader;
  1683. /** @hidden */
  1684. constructor(loader: GLTFLoader);
  1685. /** @hidden */
  1686. dispose(): void;
  1687. /** @hidden */
  1688. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1689. private _loadSpecularGlossinessPropertiesAsync;
  1690. }
  1691. }
  1692. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit" {
  1693. import { Nullable } from "babylonjs/types";
  1694. import { Material } from "babylonjs/Materials/material";
  1695. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1696. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1697. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1698. /**
  1699. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1700. */
  1701. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1702. /** The name of this extension. */
  1703. readonly name: string;
  1704. /** Defines whether this extension is enabled. */
  1705. enabled: boolean;
  1706. private _loader;
  1707. /** @hidden */
  1708. constructor(loader: GLTFLoader);
  1709. /** @hidden */
  1710. dispose(): void;
  1711. /** @hidden */
  1712. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1713. private _loadUnlitPropertiesAsync;
  1714. }
  1715. }
  1716. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform" {
  1717. import { Nullable } from "babylonjs/types";
  1718. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1719. import { ITextureInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1720. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1721. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1722. /**
  1723. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1724. */
  1725. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1726. /** The name of this extension. */
  1727. readonly name: string;
  1728. /** Defines whether this extension is enabled. */
  1729. enabled: boolean;
  1730. private _loader;
  1731. /** @hidden */
  1732. constructor(loader: GLTFLoader);
  1733. /** @hidden */
  1734. dispose(): void;
  1735. /** @hidden */
  1736. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1737. }
  1738. }
  1739. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter" {
  1740. import { Nullable } from "babylonjs/types";
  1741. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1742. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1743. import { IScene, INode, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1744. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1745. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1746. /**
  1747. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1748. */
  1749. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1750. /** The name of this extension. */
  1751. readonly name: string;
  1752. /** Defines whether this extension is enabled. */
  1753. enabled: boolean;
  1754. private _loader;
  1755. private _clips;
  1756. private _emitters;
  1757. /** @hidden */
  1758. constructor(loader: GLTFLoader);
  1759. /** @hidden */
  1760. dispose(): void;
  1761. /** @hidden */
  1762. onLoading(): void;
  1763. /** @hidden */
  1764. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1765. /** @hidden */
  1766. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1767. /** @hidden */
  1768. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1769. private _loadClipAsync;
  1770. private _loadEmitterAsync;
  1771. private _getEventAction;
  1772. private _loadAnimationEventAsync;
  1773. }
  1774. }
  1775. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod" {
  1776. import { Nullable } from "babylonjs/types";
  1777. import { Observable } from "babylonjs/Misc/observable";
  1778. import { Material } from "babylonjs/Materials/material";
  1779. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1780. import { Mesh } from "babylonjs/Meshes/mesh";
  1781. import { INode, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1782. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1783. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1784. /**
  1785. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1786. */
  1787. export class MSFT_lod implements IGLTFLoaderExtension {
  1788. /** The name of this extension. */
  1789. readonly name: string;
  1790. /** Defines whether this extension is enabled. */
  1791. enabled: boolean;
  1792. /**
  1793. * Maximum number of LODs to load, starting from the lowest LOD.
  1794. */
  1795. maxLODsToLoad: number;
  1796. /**
  1797. * Observable raised when all node LODs of one level are loaded.
  1798. * The event data is the index of the loaded LOD starting from zero.
  1799. * Dispose the loader to cancel the loading of the next level of LODs.
  1800. */
  1801. onNodeLODsLoadedObservable: Observable<number>;
  1802. /**
  1803. * Observable raised when all material LODs of one level are loaded.
  1804. * The event data is the index of the loaded LOD starting from zero.
  1805. * Dispose the loader to cancel the loading of the next level of LODs.
  1806. */
  1807. onMaterialLODsLoadedObservable: Observable<number>;
  1808. private _loader;
  1809. private _nodeIndexLOD;
  1810. private _nodeSignalLODs;
  1811. private _nodePromiseLODs;
  1812. private _materialIndexLOD;
  1813. private _materialSignalLODs;
  1814. private _materialPromiseLODs;
  1815. /** @hidden */
  1816. constructor(loader: GLTFLoader);
  1817. /** @hidden */
  1818. dispose(): void;
  1819. /** @hidden */
  1820. onReady(): void;
  1821. /** @hidden */
  1822. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1823. /** @hidden */
  1824. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1825. /** @hidden */
  1826. _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1827. /**
  1828. * Gets an array of LOD properties from lowest to highest.
  1829. */
  1830. private _getLODs;
  1831. private _disposeUnusedMaterials;
  1832. }
  1833. }
  1834. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh" {
  1835. import { Nullable } from "babylonjs/types";
  1836. import { Material } from "babylonjs/Materials/material";
  1837. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1838. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1839. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1840. /** @hidden */
  1841. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1842. readonly name: string;
  1843. enabled: boolean;
  1844. private _loader;
  1845. constructor(loader: GLTFLoader);
  1846. dispose(): void;
  1847. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1848. }
  1849. }
  1850. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors" {
  1851. import { Nullable } from "babylonjs/types";
  1852. import { Material } from "babylonjs/Materials/material";
  1853. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1854. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1855. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1856. /** @hidden */
  1857. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1858. readonly name: string;
  1859. enabled: boolean;
  1860. private _loader;
  1861. constructor(loader: GLTFLoader);
  1862. dispose(): void;
  1863. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1864. }
  1865. }
  1866. declare module "babylonjs-loaders/glTF/2.0/Extensions/index" {
  1867. export * from "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based";
  1868. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
  1869. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual";
  1870. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness";
  1871. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit";
  1872. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform";
  1873. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter";
  1874. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod";
  1875. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh";
  1876. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors";
  1877. }
  1878. declare module "babylonjs-loaders/glTF/2.0/index" {
  1879. export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1880. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1881. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1882. export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
  1883. }
  1884. declare module "babylonjs-loaders/glTF/index" {
  1885. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  1886. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  1887. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  1888. export { GLTF1, GLTF2 };
  1889. }
  1890. declare module "babylonjs-loaders/OBJ/objFileLoader" {
  1891. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1892. import { Skeleton } from "babylonjs/Bones/skeleton";
  1893. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1894. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  1895. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1896. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1897. import { AssetContainer } from "babylonjs/assetContainer";
  1898. import { Scene } from "babylonjs/scene";
  1899. /**
  1900. * Class reading and parsing the MTL file bundled with the obj file.
  1901. */
  1902. export class MTLFileLoader {
  1903. /**
  1904. * All material loaded from the mtl will be set here
  1905. */
  1906. materials: StandardMaterial[];
  1907. /**
  1908. * This function will read the mtl file and create each material described inside
  1909. * This function could be improve by adding :
  1910. * -some component missing (Ni, Tf...)
  1911. * -including the specific options available
  1912. *
  1913. * @param scene defines the scene the material will be created in
  1914. * @param data defines the mtl data to parse
  1915. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1916. */
  1917. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1918. /**
  1919. * Gets the texture for the material.
  1920. *
  1921. * If the material is imported from input file,
  1922. * We sanitize the url to ensure it takes the textre from aside the material.
  1923. *
  1924. * @param rootUrl The root url to load from
  1925. * @param value The value stored in the mtl
  1926. * @return The Texture
  1927. */
  1928. private static _getTexture;
  1929. }
  1930. /**
  1931. * OBJ file type loader.
  1932. * This is a babylon scene loader plugin.
  1933. */
  1934. export class OBJFileLoader implements ISceneLoaderPluginAsync {
  1935. /**
  1936. * Defines if UVs are optimized by default during load.
  1937. */
  1938. static OPTIMIZE_WITH_UV: boolean;
  1939. /**
  1940. * Invert model on y-axis (does a model scaling inversion)
  1941. */
  1942. static INVERT_Y: boolean;
  1943. /**
  1944. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1945. */
  1946. static IMPORT_VERTEX_COLORS: boolean;
  1947. /**
  1948. * Compute the normals for the model, even if normals are present in the file
  1949. */
  1950. static COMPUTE_NORMALS: boolean;
  1951. /**
  1952. * Defines the name of the plugin.
  1953. */
  1954. name: string;
  1955. /**
  1956. * Defines the extension the plugin is able to load.
  1957. */
  1958. extensions: string;
  1959. /** @hidden */
  1960. obj: RegExp;
  1961. /** @hidden */
  1962. group: RegExp;
  1963. /** @hidden */
  1964. mtllib: RegExp;
  1965. /** @hidden */
  1966. usemtl: RegExp;
  1967. /** @hidden */
  1968. smooth: RegExp;
  1969. /** @hidden */
  1970. vertexPattern: RegExp;
  1971. /** @hidden */
  1972. normalPattern: RegExp;
  1973. /** @hidden */
  1974. uvPattern: RegExp;
  1975. /** @hidden */
  1976. facePattern1: RegExp;
  1977. /** @hidden */
  1978. facePattern2: RegExp;
  1979. /** @hidden */
  1980. facePattern3: RegExp;
  1981. /** @hidden */
  1982. facePattern4: RegExp;
  1983. /** @hidden */
  1984. facePattern5: RegExp;
  1985. /**
  1986. * Calls synchronously the MTL file attached to this obj.
  1987. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  1988. * Without this function materials are not displayed in the first frame (but displayed after).
  1989. * In consequence it is impossible to get material information in your HTML file
  1990. *
  1991. * @param url The URL of the MTL file
  1992. * @param rootUrl
  1993. * @param onSuccess Callback function to be called when the MTL file is loaded
  1994. * @private
  1995. */
  1996. private _loadMTL;
  1997. /**
  1998. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  1999. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2000. * @param scene the scene the meshes should be added to
  2001. * @param data the OBJ data to load
  2002. * @param rootUrl root url to load from
  2003. * @param onProgress event that fires when loading progress has occured
  2004. * @param fileName Defines the name of the file to load
  2005. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2006. */
  2007. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2008. meshes: AbstractMesh[];
  2009. particleSystems: IParticleSystem[];
  2010. skeletons: Skeleton[];
  2011. animationGroups: AnimationGroup[];
  2012. }>;
  2013. /**
  2014. * Imports all objects from the loaded OBJ data and adds them to the scene
  2015. * @param scene the scene the objects should be added to
  2016. * @param data the OBJ data to load
  2017. * @param rootUrl root url to load from
  2018. * @param onProgress event that fires when loading progress has occured
  2019. * @param fileName Defines the name of the file to load
  2020. * @returns a promise which completes when objects have been loaded to the scene
  2021. */
  2022. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2023. /**
  2024. * Load into an asset container.
  2025. * @param scene The scene to load into
  2026. * @param data The data to import
  2027. * @param rootUrl The root url for scene and resources
  2028. * @param onProgress The callback when the load progresses
  2029. * @param fileName Defines the name of the file to load
  2030. * @returns The loaded asset container
  2031. */
  2032. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2033. /**
  2034. * Read the OBJ file and create an Array of meshes.
  2035. * Each mesh contains all information given by the OBJ and the MTL file.
  2036. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2037. *
  2038. * @param meshesNames
  2039. * @param scene Scene The scene where are displayed the data
  2040. * @param data String The content of the obj file
  2041. * @param rootUrl String The path to the folder
  2042. * @returns Array<AbstractMesh>
  2043. * @private
  2044. */
  2045. private _parseSolid;
  2046. }
  2047. }
  2048. declare module "babylonjs-loaders/OBJ/index" {
  2049. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2050. }
  2051. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2052. import { Nullable } from "babylonjs/types";
  2053. import { Skeleton } from "babylonjs/Bones/skeleton";
  2054. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2055. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2056. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2057. import { AssetContainer } from "babylonjs/assetContainer";
  2058. import { Scene } from "babylonjs/scene";
  2059. /**
  2060. * STL file type loader.
  2061. * This is a babylon scene loader plugin.
  2062. */
  2063. export class STLFileLoader implements ISceneLoaderPlugin {
  2064. /** @hidden */
  2065. solidPattern: RegExp;
  2066. /** @hidden */
  2067. facetsPattern: RegExp;
  2068. /** @hidden */
  2069. normalPattern: RegExp;
  2070. /** @hidden */
  2071. vertexPattern: RegExp;
  2072. /**
  2073. * Defines the name of the plugin.
  2074. */
  2075. name: string;
  2076. /**
  2077. * Defines the extensions the stl loader is able to load.
  2078. * force data to come in as an ArrayBuffer
  2079. * we'll convert to string if it looks like it's an ASCII .stl
  2080. */
  2081. extensions: ISceneLoaderPluginExtensions;
  2082. /**
  2083. * Import meshes into a scene.
  2084. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2085. * @param scene The scene to import into
  2086. * @param data The data to import
  2087. * @param rootUrl The root url for scene and resources
  2088. * @param meshes The meshes array to import into
  2089. * @param particleSystems The particle systems array to import into
  2090. * @param skeletons The skeletons array to import into
  2091. * @param onError The callback when import fails
  2092. * @returns True if successful or false otherwise
  2093. */
  2094. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2095. /**
  2096. * Load into a scene.
  2097. * @param scene The scene to load into
  2098. * @param data The data to import
  2099. * @param rootUrl The root url for scene and resources
  2100. * @param onError The callback when import fails
  2101. * @returns true if successful or false otherwise
  2102. */
  2103. load(scene: Scene, data: any, rootUrl: string): boolean;
  2104. /**
  2105. * Load into an asset container.
  2106. * @param scene The scene to load into
  2107. * @param data The data to import
  2108. * @param rootUrl The root url for scene and resources
  2109. * @param onError The callback when import fails
  2110. * @returns The loaded asset container
  2111. */
  2112. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2113. private _isBinary;
  2114. private _parseBinary;
  2115. private _parseASCII;
  2116. }
  2117. }
  2118. declare module "babylonjs-loaders/STL/index" {
  2119. export * from "babylonjs-loaders/STL/stlFileLoader";
  2120. }
  2121. declare module "babylonjs-loaders/index" {
  2122. export * from "babylonjs-loaders/glTF/index";
  2123. export * from "babylonjs-loaders/OBJ/index";
  2124. export * from "babylonjs-loaders/STL/index";
  2125. }
  2126. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2127. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2128. }
  2129. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2130. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2131. export { GLTF1 };
  2132. }
  2133. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2134. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2135. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2136. }
  2137. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2138. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2139. export { GLTF2 };
  2140. }
  2141. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2142. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2143. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2144. }
  2145. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2146. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2147. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2148. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2149. }
  2150. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2151. export * from "babylonjs-loaders/OBJ/index";
  2152. }
  2153. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2154. export * from "babylonjs-loaders/STL/index";
  2155. }
  2156. declare module "babylonjs-loaders/legacy/legacy" {
  2157. import "babylonjs-loaders/index";
  2158. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2159. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2160. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2161. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2162. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2163. }
  2164. declare module "babylonjs-loaders" {
  2165. export * from "babylonjs-loaders/legacy/legacy";
  2166. }
  2167. declare module BABYLON {
  2168. /**
  2169. * Mode that determines the coordinate system to use.
  2170. */
  2171. export enum GLTFLoaderCoordinateSystemMode {
  2172. /**
  2173. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2174. */
  2175. AUTO = 0,
  2176. /**
  2177. * Sets the useRightHandedSystem flag on the scene.
  2178. */
  2179. FORCE_RIGHT_HANDED = 1
  2180. }
  2181. /**
  2182. * Mode that determines what animations will start.
  2183. */
  2184. export enum GLTFLoaderAnimationStartMode {
  2185. /**
  2186. * No animation will start.
  2187. */
  2188. NONE = 0,
  2189. /**
  2190. * The first animation will start.
  2191. */
  2192. FIRST = 1,
  2193. /**
  2194. * All animations will start.
  2195. */
  2196. ALL = 2
  2197. }
  2198. /**
  2199. * Interface that contains the data for the glTF asset.
  2200. */
  2201. export interface IGLTFLoaderData {
  2202. /**
  2203. * Object that represents the glTF JSON.
  2204. */
  2205. json: Object;
  2206. /**
  2207. * The BIN chunk of a binary glTF.
  2208. */
  2209. bin: Nullable<ArrayBufferView>;
  2210. }
  2211. /**
  2212. * Interface for extending the loader.
  2213. */
  2214. export interface IGLTFLoaderExtension {
  2215. /**
  2216. * The name of this extension.
  2217. */
  2218. readonly name: string;
  2219. /**
  2220. * Defines whether this extension is enabled.
  2221. */
  2222. enabled: boolean;
  2223. }
  2224. /**
  2225. * Loader state.
  2226. */
  2227. export enum GLTFLoaderState {
  2228. /**
  2229. * The asset is loading.
  2230. */
  2231. LOADING = 0,
  2232. /**
  2233. * The asset is ready for rendering.
  2234. */
  2235. READY = 1,
  2236. /**
  2237. * The asset is completely loaded.
  2238. */
  2239. COMPLETE = 2
  2240. }
  2241. /** @hidden */
  2242. export interface IGLTFLoader extends IDisposable {
  2243. readonly state: Nullable<GLTFLoaderState>;
  2244. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  2245. meshes: AbstractMesh[];
  2246. particleSystems: IParticleSystem[];
  2247. skeletons: Skeleton[];
  2248. animationGroups: AnimationGroup[];
  2249. }>;
  2250. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2251. }
  2252. /**
  2253. * File loader for loading glTF files into a scene.
  2254. */
  2255. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2256. /** @hidden */
  2257. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2258. /** @hidden */
  2259. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2260. /**
  2261. * Raised when the asset has been parsed
  2262. */
  2263. onParsedObservable: Observable<IGLTFLoaderData>;
  2264. private _onParsedObserver;
  2265. /**
  2266. * Raised when the asset has been parsed
  2267. */
  2268. onParsed: (loaderData: IGLTFLoaderData) => void;
  2269. /**
  2270. * 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.
  2271. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2272. * Defaults to true.
  2273. * @hidden
  2274. */
  2275. static IncrementalLoading: boolean;
  2276. /**
  2277. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2278. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2279. * @hidden
  2280. */
  2281. static HomogeneousCoordinates: boolean;
  2282. /**
  2283. * The coordinate system mode. Defaults to AUTO.
  2284. */
  2285. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2286. /**
  2287. * The animation start mode. Defaults to FIRST.
  2288. */
  2289. animationStartMode: GLTFLoaderAnimationStartMode;
  2290. /**
  2291. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2292. */
  2293. compileMaterials: boolean;
  2294. /**
  2295. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2296. */
  2297. useClipPlane: boolean;
  2298. /**
  2299. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2300. */
  2301. compileShadowGenerators: boolean;
  2302. /**
  2303. * Defines if the Alpha blended materials are only applied as coverage.
  2304. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2305. * If true, no extra effects are applied to transparent pixels.
  2306. */
  2307. transparencyAsCoverage: boolean;
  2308. /**
  2309. * Function called before loading a url referenced by the asset.
  2310. */
  2311. preprocessUrlAsync: (url: string) => Promise<string>;
  2312. /**
  2313. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2314. */
  2315. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2316. private _onMeshLoadedObserver;
  2317. /**
  2318. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2319. */
  2320. onMeshLoaded: (mesh: AbstractMesh) => void;
  2321. /**
  2322. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2323. */
  2324. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2325. private _onTextureLoadedObserver;
  2326. /**
  2327. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2328. */
  2329. onTextureLoaded: (texture: BaseTexture) => void;
  2330. /**
  2331. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2332. */
  2333. readonly onMaterialLoadedObservable: Observable<Material>;
  2334. private _onMaterialLoadedObserver;
  2335. /**
  2336. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2337. */
  2338. onMaterialLoaded: (material: Material) => void;
  2339. /**
  2340. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2341. */
  2342. readonly onCameraLoadedObservable: Observable<Camera>;
  2343. private _onCameraLoadedObserver;
  2344. /**
  2345. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2346. */
  2347. onCameraLoaded: (camera: Camera) => void;
  2348. /**
  2349. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2350. * For assets with LODs, raised when all of the LODs are complete.
  2351. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2352. */
  2353. readonly onCompleteObservable: Observable<void>;
  2354. private _onCompleteObserver;
  2355. /**
  2356. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2357. * For assets with LODs, raised when all of the LODs are complete.
  2358. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2359. */
  2360. onComplete: () => void;
  2361. /**
  2362. * Observable raised when an error occurs.
  2363. */
  2364. readonly onErrorObservable: Observable<any>;
  2365. private _onErrorObserver;
  2366. /**
  2367. * Callback raised when an error occurs.
  2368. */
  2369. onError: (reason: any) => void;
  2370. /**
  2371. * Observable raised after the loader is disposed.
  2372. */
  2373. readonly onDisposeObservable: Observable<void>;
  2374. private _onDisposeObserver;
  2375. /**
  2376. * Callback raised after the loader is disposed.
  2377. */
  2378. onDispose: () => void;
  2379. /**
  2380. * Observable raised after a loader extension is created.
  2381. * Set additional options for a loader extension in this event.
  2382. */
  2383. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2384. private _onExtensionLoadedObserver;
  2385. /**
  2386. * Callback raised after a loader extension is created.
  2387. */
  2388. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  2389. /**
  2390. * Defines if the loader logging is enabled.
  2391. */
  2392. loggingEnabled: boolean;
  2393. /**
  2394. * Defines if the loader should capture performance counters.
  2395. */
  2396. capturePerformanceCounters: boolean;
  2397. /**
  2398. * Defines if the loader should validate the asset.
  2399. */
  2400. validate: boolean;
  2401. /**
  2402. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2403. */
  2404. readonly onValidatedObservable: Observable<IGLTFValidationResults>;
  2405. private _onValidatedObserver;
  2406. /**
  2407. * Callback raised after a loader extension is created.
  2408. */
  2409. onValidated: (results: IGLTFValidationResults) => void;
  2410. private _loader;
  2411. /**
  2412. * Name of the loader ("gltf")
  2413. */
  2414. name: string;
  2415. /**
  2416. * Supported file extensions of the loader (.gltf, .glb)
  2417. */
  2418. extensions: ISceneLoaderPluginExtensions;
  2419. /**
  2420. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2421. */
  2422. dispose(): void;
  2423. /** @hidden */
  2424. _clear(): void;
  2425. /**
  2426. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  2427. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2428. * @param scene the scene the meshes should be added to
  2429. * @param data the glTF data to load
  2430. * @param rootUrl root url to load from
  2431. * @param onProgress event that fires when loading progress has occured
  2432. * @param fileName Defines the name of the file to load
  2433. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2434. */
  2435. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2436. meshes: AbstractMesh[];
  2437. particleSystems: IParticleSystem[];
  2438. skeletons: Skeleton[];
  2439. animationGroups: AnimationGroup[];
  2440. }>;
  2441. /**
  2442. * Imports all objects from the loaded glTF data and adds them to the scene
  2443. * @param scene the scene the objects should be added to
  2444. * @param data the glTF data to load
  2445. * @param rootUrl root url to load from
  2446. * @param onProgress event that fires when loading progress has occured
  2447. * @param fileName Defines the name of the file to load
  2448. * @returns a promise which completes when objects have been loaded to the scene
  2449. */
  2450. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2451. /**
  2452. * Load into an asset container.
  2453. * @param scene The scene to load into
  2454. * @param data The data to import
  2455. * @param rootUrl The root url for scene and resources
  2456. * @param onProgress The callback when the load progresses
  2457. * @param fileName Defines the name of the file to load
  2458. * @returns The loaded asset container
  2459. */
  2460. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2461. /**
  2462. * If the data string can be loaded directly.
  2463. * @param data string contianing the file data
  2464. * @returns if the data can be loaded directly
  2465. */
  2466. canDirectLoad(data: string): boolean;
  2467. /**
  2468. * Rewrites a url by combining a root url and response url.
  2469. */
  2470. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  2471. /**
  2472. * Instantiates a glTF file loader plugin.
  2473. * @returns the created plugin
  2474. */
  2475. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2476. /**
  2477. * The loader state or null if the loader is not active.
  2478. */
  2479. readonly loaderState: Nullable<GLTFLoaderState>;
  2480. /**
  2481. * Returns a promise that resolves when the asset is completely loaded.
  2482. * @returns a promise that resolves when the asset is completely loaded.
  2483. */
  2484. whenCompleteAsync(): Promise<void>;
  2485. private _parseAsync;
  2486. private _validateAsync;
  2487. private _getLoader;
  2488. private _unpackBinary;
  2489. private _unpackBinaryV1;
  2490. private _unpackBinaryV2;
  2491. private static _parseVersion;
  2492. private static _compareVersion;
  2493. private static _decodeBufferToText;
  2494. private static readonly _logSpaces;
  2495. private _logIndentLevel;
  2496. private _loggingEnabled;
  2497. /** @hidden */
  2498. _log: (message: string) => void;
  2499. /** @hidden */
  2500. _logOpen(message: string): void;
  2501. /** @hidden */
  2502. _logClose(): void;
  2503. private _logEnabled;
  2504. private _logDisabled;
  2505. private _capturePerformanceCounters;
  2506. /** @hidden */
  2507. _startPerformanceCounter: (counterName: string) => void;
  2508. /** @hidden */
  2509. _endPerformanceCounter: (counterName: string) => void;
  2510. private _startPerformanceCounterEnabled;
  2511. private _startPerformanceCounterDisabled;
  2512. private _endPerformanceCounterEnabled;
  2513. private _endPerformanceCounterDisabled;
  2514. }
  2515. }
  2516. declare module BABYLON.GLTF1 {
  2517. /**
  2518. * Enums
  2519. * @hidden
  2520. */
  2521. export enum EComponentType {
  2522. BYTE = 5120,
  2523. UNSIGNED_BYTE = 5121,
  2524. SHORT = 5122,
  2525. UNSIGNED_SHORT = 5123,
  2526. FLOAT = 5126
  2527. }
  2528. /** @hidden */
  2529. export enum EShaderType {
  2530. FRAGMENT = 35632,
  2531. VERTEX = 35633
  2532. }
  2533. /** @hidden */
  2534. export enum EParameterType {
  2535. BYTE = 5120,
  2536. UNSIGNED_BYTE = 5121,
  2537. SHORT = 5122,
  2538. UNSIGNED_SHORT = 5123,
  2539. INT = 5124,
  2540. UNSIGNED_INT = 5125,
  2541. FLOAT = 5126,
  2542. FLOAT_VEC2 = 35664,
  2543. FLOAT_VEC3 = 35665,
  2544. FLOAT_VEC4 = 35666,
  2545. INT_VEC2 = 35667,
  2546. INT_VEC3 = 35668,
  2547. INT_VEC4 = 35669,
  2548. BOOL = 35670,
  2549. BOOL_VEC2 = 35671,
  2550. BOOL_VEC3 = 35672,
  2551. BOOL_VEC4 = 35673,
  2552. FLOAT_MAT2 = 35674,
  2553. FLOAT_MAT3 = 35675,
  2554. FLOAT_MAT4 = 35676,
  2555. SAMPLER_2D = 35678
  2556. }
  2557. /** @hidden */
  2558. export enum ETextureWrapMode {
  2559. CLAMP_TO_EDGE = 33071,
  2560. MIRRORED_REPEAT = 33648,
  2561. REPEAT = 10497
  2562. }
  2563. /** @hidden */
  2564. export enum ETextureFilterType {
  2565. NEAREST = 9728,
  2566. LINEAR = 9728,
  2567. NEAREST_MIPMAP_NEAREST = 9984,
  2568. LINEAR_MIPMAP_NEAREST = 9985,
  2569. NEAREST_MIPMAP_LINEAR = 9986,
  2570. LINEAR_MIPMAP_LINEAR = 9987
  2571. }
  2572. /** @hidden */
  2573. export enum ETextureFormat {
  2574. ALPHA = 6406,
  2575. RGB = 6407,
  2576. RGBA = 6408,
  2577. LUMINANCE = 6409,
  2578. LUMINANCE_ALPHA = 6410
  2579. }
  2580. /** @hidden */
  2581. export enum ECullingType {
  2582. FRONT = 1028,
  2583. BACK = 1029,
  2584. FRONT_AND_BACK = 1032
  2585. }
  2586. /** @hidden */
  2587. export enum EBlendingFunction {
  2588. ZERO = 0,
  2589. ONE = 1,
  2590. SRC_COLOR = 768,
  2591. ONE_MINUS_SRC_COLOR = 769,
  2592. DST_COLOR = 774,
  2593. ONE_MINUS_DST_COLOR = 775,
  2594. SRC_ALPHA = 770,
  2595. ONE_MINUS_SRC_ALPHA = 771,
  2596. DST_ALPHA = 772,
  2597. ONE_MINUS_DST_ALPHA = 773,
  2598. CONSTANT_COLOR = 32769,
  2599. ONE_MINUS_CONSTANT_COLOR = 32770,
  2600. CONSTANT_ALPHA = 32771,
  2601. ONE_MINUS_CONSTANT_ALPHA = 32772,
  2602. SRC_ALPHA_SATURATE = 776
  2603. }
  2604. /** @hidden */
  2605. export interface IGLTFProperty {
  2606. extensions?: {
  2607. [key: string]: any;
  2608. };
  2609. extras?: Object;
  2610. }
  2611. /** @hidden */
  2612. export interface IGLTFChildRootProperty extends IGLTFProperty {
  2613. name?: string;
  2614. }
  2615. /** @hidden */
  2616. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  2617. bufferView: string;
  2618. byteOffset: number;
  2619. byteStride: number;
  2620. count: number;
  2621. type: string;
  2622. componentType: EComponentType;
  2623. max?: number[];
  2624. min?: number[];
  2625. name?: string;
  2626. }
  2627. /** @hidden */
  2628. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  2629. buffer: string;
  2630. byteOffset: number;
  2631. byteLength: number;
  2632. byteStride: number;
  2633. target?: number;
  2634. }
  2635. /** @hidden */
  2636. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  2637. uri: string;
  2638. byteLength?: number;
  2639. type?: string;
  2640. }
  2641. /** @hidden */
  2642. export interface IGLTFShader extends IGLTFChildRootProperty {
  2643. uri: string;
  2644. type: EShaderType;
  2645. }
  2646. /** @hidden */
  2647. export interface IGLTFProgram extends IGLTFChildRootProperty {
  2648. attributes: string[];
  2649. fragmentShader: string;
  2650. vertexShader: string;
  2651. }
  2652. /** @hidden */
  2653. export interface IGLTFTechniqueParameter {
  2654. type: number;
  2655. count?: number;
  2656. semantic?: string;
  2657. node?: string;
  2658. value?: number | boolean | string | Array<any>;
  2659. source?: string;
  2660. babylonValue?: any;
  2661. }
  2662. /** @hidden */
  2663. export interface IGLTFTechniqueCommonProfile {
  2664. lightingModel: string;
  2665. texcoordBindings: Object;
  2666. parameters?: Array<any>;
  2667. }
  2668. /** @hidden */
  2669. export interface IGLTFTechniqueStatesFunctions {
  2670. blendColor?: number[];
  2671. blendEquationSeparate?: number[];
  2672. blendFuncSeparate?: number[];
  2673. colorMask: boolean[];
  2674. cullFace: number[];
  2675. }
  2676. /** @hidden */
  2677. export interface IGLTFTechniqueStates {
  2678. enable: number[];
  2679. functions: IGLTFTechniqueStatesFunctions;
  2680. }
  2681. /** @hidden */
  2682. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  2683. parameters: {
  2684. [key: string]: IGLTFTechniqueParameter;
  2685. };
  2686. program: string;
  2687. attributes: {
  2688. [key: string]: string;
  2689. };
  2690. uniforms: {
  2691. [key: string]: string;
  2692. };
  2693. states: IGLTFTechniqueStates;
  2694. }
  2695. /** @hidden */
  2696. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  2697. technique?: string;
  2698. values: string[];
  2699. }
  2700. /** @hidden */
  2701. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  2702. attributes: {
  2703. [key: string]: string;
  2704. };
  2705. indices: string;
  2706. material: string;
  2707. mode?: number;
  2708. }
  2709. /** @hidden */
  2710. export interface IGLTFMesh extends IGLTFChildRootProperty {
  2711. primitives: IGLTFMeshPrimitive[];
  2712. }
  2713. /** @hidden */
  2714. export interface IGLTFImage extends IGLTFChildRootProperty {
  2715. uri: string;
  2716. }
  2717. /** @hidden */
  2718. export interface IGLTFSampler extends IGLTFChildRootProperty {
  2719. magFilter?: number;
  2720. minFilter?: number;
  2721. wrapS?: number;
  2722. wrapT?: number;
  2723. }
  2724. /** @hidden */
  2725. export interface IGLTFTexture extends IGLTFChildRootProperty {
  2726. sampler: string;
  2727. source: string;
  2728. format?: ETextureFormat;
  2729. internalFormat?: ETextureFormat;
  2730. target?: number;
  2731. type?: number;
  2732. babylonTexture?: Texture;
  2733. }
  2734. /** @hidden */
  2735. export interface IGLTFAmbienLight {
  2736. color?: number[];
  2737. }
  2738. /** @hidden */
  2739. export interface IGLTFDirectionalLight {
  2740. color?: number[];
  2741. }
  2742. /** @hidden */
  2743. export interface IGLTFPointLight {
  2744. color?: number[];
  2745. constantAttenuation?: number;
  2746. linearAttenuation?: number;
  2747. quadraticAttenuation?: number;
  2748. }
  2749. /** @hidden */
  2750. export interface IGLTFSpotLight {
  2751. color?: number[];
  2752. constantAttenuation?: number;
  2753. fallOfAngle?: number;
  2754. fallOffExponent?: number;
  2755. linearAttenuation?: number;
  2756. quadraticAttenuation?: number;
  2757. }
  2758. /** @hidden */
  2759. export interface IGLTFLight extends IGLTFChildRootProperty {
  2760. type: string;
  2761. }
  2762. /** @hidden */
  2763. export interface IGLTFCameraOrthographic {
  2764. xmag: number;
  2765. ymag: number;
  2766. zfar: number;
  2767. znear: number;
  2768. }
  2769. /** @hidden */
  2770. export interface IGLTFCameraPerspective {
  2771. aspectRatio: number;
  2772. yfov: number;
  2773. zfar: number;
  2774. znear: number;
  2775. }
  2776. /** @hidden */
  2777. export interface IGLTFCamera extends IGLTFChildRootProperty {
  2778. type: string;
  2779. }
  2780. /** @hidden */
  2781. export interface IGLTFAnimationChannelTarget {
  2782. id: string;
  2783. path: string;
  2784. }
  2785. /** @hidden */
  2786. export interface IGLTFAnimationChannel {
  2787. sampler: string;
  2788. target: IGLTFAnimationChannelTarget;
  2789. }
  2790. /** @hidden */
  2791. export interface IGLTFAnimationSampler {
  2792. input: string;
  2793. output: string;
  2794. interpolation?: string;
  2795. }
  2796. /** @hidden */
  2797. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  2798. channels?: IGLTFAnimationChannel[];
  2799. parameters?: {
  2800. [key: string]: string;
  2801. };
  2802. samplers?: {
  2803. [key: string]: IGLTFAnimationSampler;
  2804. };
  2805. }
  2806. /** @hidden */
  2807. export interface IGLTFNodeInstanceSkin {
  2808. skeletons: string[];
  2809. skin: string;
  2810. meshes: string[];
  2811. }
  2812. /** @hidden */
  2813. export interface IGLTFSkins extends IGLTFChildRootProperty {
  2814. bindShapeMatrix: number[];
  2815. inverseBindMatrices: string;
  2816. jointNames: string[];
  2817. babylonSkeleton?: Skeleton;
  2818. }
  2819. /** @hidden */
  2820. export interface IGLTFNode extends IGLTFChildRootProperty {
  2821. camera?: string;
  2822. children: string[];
  2823. skin?: string;
  2824. jointName?: string;
  2825. light?: string;
  2826. matrix: number[];
  2827. mesh?: string;
  2828. meshes?: string[];
  2829. rotation?: number[];
  2830. scale?: number[];
  2831. translation?: number[];
  2832. babylonNode?: Node;
  2833. }
  2834. /** @hidden */
  2835. export interface IGLTFScene extends IGLTFChildRootProperty {
  2836. nodes: string[];
  2837. }
  2838. /** @hidden */
  2839. export interface IGLTFRuntime {
  2840. extensions: {
  2841. [key: string]: any;
  2842. };
  2843. accessors: {
  2844. [key: string]: IGLTFAccessor;
  2845. };
  2846. buffers: {
  2847. [key: string]: IGLTFBuffer;
  2848. };
  2849. bufferViews: {
  2850. [key: string]: IGLTFBufferView;
  2851. };
  2852. meshes: {
  2853. [key: string]: IGLTFMesh;
  2854. };
  2855. lights: {
  2856. [key: string]: IGLTFLight;
  2857. };
  2858. cameras: {
  2859. [key: string]: IGLTFCamera;
  2860. };
  2861. nodes: {
  2862. [key: string]: IGLTFNode;
  2863. };
  2864. images: {
  2865. [key: string]: IGLTFImage;
  2866. };
  2867. textures: {
  2868. [key: string]: IGLTFTexture;
  2869. };
  2870. shaders: {
  2871. [key: string]: IGLTFShader;
  2872. };
  2873. programs: {
  2874. [key: string]: IGLTFProgram;
  2875. };
  2876. samplers: {
  2877. [key: string]: IGLTFSampler;
  2878. };
  2879. techniques: {
  2880. [key: string]: IGLTFTechnique;
  2881. };
  2882. materials: {
  2883. [key: string]: IGLTFMaterial;
  2884. };
  2885. animations: {
  2886. [key: string]: IGLTFAnimation;
  2887. };
  2888. skins: {
  2889. [key: string]: IGLTFSkins;
  2890. };
  2891. currentScene?: Object;
  2892. scenes: {
  2893. [key: string]: IGLTFScene;
  2894. };
  2895. extensionsUsed: string[];
  2896. extensionsRequired?: string[];
  2897. buffersCount: number;
  2898. shaderscount: number;
  2899. scene: Scene;
  2900. rootUrl: string;
  2901. loadedBufferCount: number;
  2902. loadedBufferViews: {
  2903. [name: string]: ArrayBufferView;
  2904. };
  2905. loadedShaderCount: number;
  2906. importOnlyMeshes: boolean;
  2907. importMeshesNames?: string[];
  2908. dummyNodes: Node[];
  2909. }
  2910. /** @hidden */
  2911. export interface INodeToRoot {
  2912. bone: Bone;
  2913. node: IGLTFNode;
  2914. id: string;
  2915. }
  2916. /** @hidden */
  2917. export interface IJointNode {
  2918. node: IGLTFNode;
  2919. id: string;
  2920. }
  2921. }
  2922. declare module BABYLON.GLTF1 {
  2923. /**
  2924. * Utils functions for GLTF
  2925. * @hidden
  2926. */
  2927. export class GLTFUtils {
  2928. /**
  2929. * Sets the given "parameter" matrix
  2930. * @param scene: the Scene object
  2931. * @param source: the source node where to pick the matrix
  2932. * @param parameter: the GLTF technique parameter
  2933. * @param uniformName: the name of the shader's uniform
  2934. * @param shaderMaterial: the shader material
  2935. */
  2936. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  2937. /**
  2938. * Sets the given "parameter" matrix
  2939. * @param shaderMaterial: the shader material
  2940. * @param uniform: the name of the shader's uniform
  2941. * @param value: the value of the uniform
  2942. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  2943. */
  2944. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  2945. /**
  2946. * Returns the wrap mode of the texture
  2947. * @param mode: the mode value
  2948. */
  2949. static GetWrapMode(mode: number): number;
  2950. /**
  2951. * Returns the byte stride giving an accessor
  2952. * @param accessor: the GLTF accessor objet
  2953. */
  2954. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  2955. /**
  2956. * Returns the texture filter mode giving a mode value
  2957. * @param mode: the filter mode value
  2958. */
  2959. static GetTextureFilterMode(mode: number): ETextureFilterType;
  2960. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  2961. /**
  2962. * Returns a buffer from its accessor
  2963. * @param gltfRuntime: the GLTF runtime
  2964. * @param accessor: the GLTF accessor
  2965. */
  2966. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  2967. /**
  2968. * Decodes a buffer view into a string
  2969. * @param view: the buffer view
  2970. */
  2971. static DecodeBufferToText(view: ArrayBufferView): string;
  2972. /**
  2973. * Returns the default material of gltf. Related to
  2974. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  2975. * @param scene: the Babylon.js scene
  2976. */
  2977. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  2978. private static _DefaultMaterial;
  2979. }
  2980. }
  2981. declare module BABYLON.GLTF1 {
  2982. /**
  2983. * Implementation of the base glTF spec
  2984. * @hidden
  2985. */
  2986. export class GLTFLoaderBase {
  2987. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  2988. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  2989. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  2990. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  2991. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  2992. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  2993. }
  2994. /**
  2995. * glTF V1 Loader
  2996. * @hidden
  2997. */
  2998. export class GLTFLoader implements IGLTFLoader {
  2999. static Extensions: {
  3000. [name: string]: GLTFLoaderExtension;
  3001. };
  3002. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3003. state: Nullable<GLTFLoaderState>;
  3004. dispose(): void;
  3005. private _importMeshAsync;
  3006. /**
  3007. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3008. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3009. * @param scene the scene the meshes should be added to
  3010. * @param data gltf data containing information of the meshes in a loaded file
  3011. * @param rootUrl root url to load from
  3012. * @param onProgress event that fires when loading progress has occured
  3013. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3014. */
  3015. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  3016. meshes: AbstractMesh[];
  3017. particleSystems: IParticleSystem[];
  3018. skeletons: Skeleton[];
  3019. animationGroups: AnimationGroup[];
  3020. }>;
  3021. private _loadAsync;
  3022. /**
  3023. * Imports all objects from a loaded gltf file and adds them to the scene
  3024. * @param scene the scene the objects should be added to
  3025. * @param data gltf data containing information of the meshes in a loaded file
  3026. * @param rootUrl root url to load from
  3027. * @param onProgress event that fires when loading progress has occured
  3028. * @returns a promise which completes when objects have been loaded to the scene
  3029. */
  3030. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3031. private _loadShadersAsync;
  3032. private _loadBuffersAsync;
  3033. private _createNodes;
  3034. }
  3035. /** @hidden */
  3036. export abstract class GLTFLoaderExtension {
  3037. private _name;
  3038. constructor(name: string);
  3039. readonly name: string;
  3040. /**
  3041. * Defines an override for loading the runtime
  3042. * Return true to stop further extensions from loading the runtime
  3043. */
  3044. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3045. /**
  3046. * Defines an onverride for creating gltf runtime
  3047. * Return true to stop further extensions from creating the runtime
  3048. */
  3049. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3050. /**
  3051. * Defines an override for loading buffers
  3052. * Return true to stop further extensions from loading this buffer
  3053. */
  3054. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3055. /**
  3056. * Defines an override for loading texture buffers
  3057. * Return true to stop further extensions from loading this texture data
  3058. */
  3059. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3060. /**
  3061. * Defines an override for creating textures
  3062. * Return true to stop further extensions from loading this texture
  3063. */
  3064. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3065. /**
  3066. * Defines an override for loading shader strings
  3067. * Return true to stop further extensions from loading this shader data
  3068. */
  3069. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3070. /**
  3071. * Defines an override for loading materials
  3072. * Return true to stop further extensions from loading this material
  3073. */
  3074. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3075. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3076. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3077. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3078. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3079. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3080. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3081. private static LoadTextureBufferAsync;
  3082. private static CreateTextureAsync;
  3083. private static ApplyExtensions;
  3084. }
  3085. }
  3086. declare module BABYLON.GLTF1 {
  3087. /** @hidden */
  3088. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3089. private _bin;
  3090. constructor();
  3091. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3092. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3093. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3094. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3095. }
  3096. }
  3097. declare module BABYLON.GLTF1 {
  3098. /** @hidden */
  3099. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3100. constructor();
  3101. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3102. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3103. private _loadTexture;
  3104. }
  3105. }
  3106. declare module BABYLON.GLTF2.Loader {
  3107. /**
  3108. * Loader interface with an index field.
  3109. */
  3110. export interface IArrayItem {
  3111. /**
  3112. * The index of this item in the array.
  3113. */
  3114. index: number;
  3115. }
  3116. /**
  3117. * Loader interface with additional members.
  3118. */
  3119. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3120. /** @hidden */
  3121. _data?: Promise<ArrayBufferView>;
  3122. /** @hidden */
  3123. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3124. }
  3125. /**
  3126. * Loader interface with additional members.
  3127. */
  3128. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3129. }
  3130. /** @hidden */
  3131. export interface _IAnimationSamplerData {
  3132. input: Float32Array;
  3133. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3134. output: Float32Array;
  3135. }
  3136. /**
  3137. * Loader interface with additional members.
  3138. */
  3139. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3140. /** @hidden */
  3141. _data?: Promise<_IAnimationSamplerData>;
  3142. }
  3143. /**
  3144. * Loader interface with additional members.
  3145. */
  3146. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3147. channels: IAnimationChannel[];
  3148. samplers: IAnimationSampler[];
  3149. /** @hidden */
  3150. _babylonAnimationGroup?: AnimationGroup;
  3151. }
  3152. /**
  3153. * Loader interface with additional members.
  3154. */
  3155. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3156. /** @hidden */
  3157. _data?: Promise<ArrayBufferView>;
  3158. }
  3159. /**
  3160. * Loader interface with additional members.
  3161. */
  3162. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3163. /** @hidden */
  3164. _data?: Promise<ArrayBufferView>;
  3165. /** @hidden */
  3166. _babylonBuffer?: Promise<Buffer>;
  3167. }
  3168. /**
  3169. * Loader interface with additional members.
  3170. */
  3171. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3172. }
  3173. /**
  3174. * Loader interface with additional members.
  3175. */
  3176. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3177. /** @hidden */
  3178. _data?: Promise<ArrayBufferView>;
  3179. }
  3180. /**
  3181. * Loader interface with additional members.
  3182. */
  3183. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3184. }
  3185. /**
  3186. * Loader interface with additional members.
  3187. */
  3188. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3189. }
  3190. /**
  3191. * Loader interface with additional members.
  3192. */
  3193. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3194. baseColorTexture?: ITextureInfo;
  3195. metallicRoughnessTexture?: ITextureInfo;
  3196. }
  3197. /**
  3198. * Loader interface with additional members.
  3199. */
  3200. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3201. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3202. normalTexture?: IMaterialNormalTextureInfo;
  3203. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3204. emissiveTexture?: ITextureInfo;
  3205. /** @hidden */
  3206. _data?: {
  3207. [babylonDrawMode: number]: {
  3208. babylonMaterial: Material;
  3209. babylonMeshes: AbstractMesh[];
  3210. promise: Promise<void>;
  3211. };
  3212. };
  3213. }
  3214. /**
  3215. * Loader interface with additional members.
  3216. */
  3217. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3218. primitives: IMeshPrimitive[];
  3219. }
  3220. /**
  3221. * Loader interface with additional members.
  3222. */
  3223. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3224. /** @hidden */
  3225. _instanceData?: {
  3226. babylonSourceMesh: Mesh;
  3227. promise: Promise<any>;
  3228. };
  3229. }
  3230. /**
  3231. * Loader interface with additional members.
  3232. */
  3233. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3234. /**
  3235. * The parent glTF node.
  3236. */
  3237. parent?: INode;
  3238. /** @hidden */
  3239. _babylonTransformNode?: TransformNode;
  3240. /** @hidden */
  3241. _primitiveBabylonMeshes?: AbstractMesh[];
  3242. /** @hidden */
  3243. _babylonBones?: Bone[];
  3244. /** @hidden */
  3245. _numMorphTargets?: number;
  3246. }
  3247. /** @hidden */
  3248. export interface _ISamplerData {
  3249. noMipMaps: boolean;
  3250. samplingMode: number;
  3251. wrapU: number;
  3252. wrapV: number;
  3253. }
  3254. /**
  3255. * Loader interface with additional members.
  3256. */
  3257. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3258. /** @hidden */
  3259. _data?: _ISamplerData;
  3260. }
  3261. /**
  3262. * Loader interface with additional members.
  3263. */
  3264. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3265. }
  3266. /**
  3267. * Loader interface with additional members.
  3268. */
  3269. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3270. /** @hidden */
  3271. _data?: {
  3272. babylonSkeleton: Skeleton;
  3273. promise: Promise<void>;
  3274. };
  3275. }
  3276. /**
  3277. * Loader interface with additional members.
  3278. */
  3279. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3280. }
  3281. /**
  3282. * Loader interface with additional members.
  3283. */
  3284. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3285. }
  3286. /**
  3287. * Loader interface with additional members.
  3288. */
  3289. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3290. accessors?: IAccessor[];
  3291. animations?: IAnimation[];
  3292. buffers?: IBuffer[];
  3293. bufferViews?: IBufferView[];
  3294. cameras?: ICamera[];
  3295. images?: IImage[];
  3296. materials?: IMaterial[];
  3297. meshes?: IMesh[];
  3298. nodes?: INode[];
  3299. samplers?: ISampler[];
  3300. scenes?: IScene[];
  3301. skins?: ISkin[];
  3302. textures?: ITexture[];
  3303. }
  3304. }
  3305. declare module BABYLON.GLTF2 {
  3306. /**
  3307. * Interface for a glTF loader extension.
  3308. */
  3309. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3310. /**
  3311. * Called after the loader state changes to LOADING.
  3312. */
  3313. onLoading?(): void;
  3314. /**
  3315. * Called after the loader state changes to READY.
  3316. */
  3317. onReady?(): void;
  3318. /**
  3319. * Define this method to modify the default behavior when loading scenes.
  3320. * @param context The context when loading the asset
  3321. * @param scene The glTF scene property
  3322. * @returns A promise that resolves when the load is complete or null if not handled
  3323. */
  3324. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3325. /**
  3326. * Define this method to modify the default behavior when loading nodes.
  3327. * @param context The context when loading the asset
  3328. * @param node The glTF node property
  3329. * @param assign A function called synchronously after parsing the glTF properties
  3330. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3331. */
  3332. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3333. /**
  3334. * Define this method to modify the default behavior when loading cameras.
  3335. * @param context The context when loading the asset
  3336. * @param camera The glTF camera property
  3337. * @param assign A function called synchronously after parsing the glTF properties
  3338. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3339. */
  3340. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3341. /**
  3342. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3343. * @param context The context when loading the asset
  3344. * @param primitive The glTF mesh primitive property
  3345. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3346. */
  3347. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3348. /**
  3349. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3350. * @param context The context when loading the asset
  3351. * @param material The glTF material property
  3352. * @param assign A function called synchronously after parsing the glTF properties
  3353. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3354. */
  3355. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3356. /**
  3357. * Define this method to modify the default behavior when creating materials.
  3358. * @param context The context when loading the asset
  3359. * @param material The glTF material property
  3360. * @param babylonDrawMode The draw mode for the Babylon material
  3361. * @returns The Babylon material or null if not handled
  3362. */
  3363. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3364. /**
  3365. * Define this method to modify the default behavior when loading material properties.
  3366. * @param context The context when loading the asset
  3367. * @param material The glTF material property
  3368. * @param babylonMaterial The Babylon material
  3369. * @returns A promise that resolves when the load is complete or null if not handled
  3370. */
  3371. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3372. /**
  3373. * Define this method to modify the default behavior when loading texture infos.
  3374. * @param context The context when loading the asset
  3375. * @param textureInfo The glTF texture info property
  3376. * @param assign A function called synchronously after parsing the glTF properties
  3377. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3378. */
  3379. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3380. /**
  3381. * Define this method to modify the default behavior when loading animations.
  3382. * @param context The context when loading the asset
  3383. * @param animation The glTF animation property
  3384. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3385. */
  3386. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3387. /**
  3388. * Define this method to modify the default behavior when loading uris.
  3389. * @param context The context when loading the asset
  3390. * @param uri The uri to load
  3391. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3392. */
  3393. _loadUriAsync?(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  3394. }
  3395. }
  3396. declare module BABYLON.GLTF2 {
  3397. /**
  3398. * Helper class for working with arrays when loading the glTF asset
  3399. */
  3400. export class ArrayItem {
  3401. /**
  3402. * Gets an item from the given array.
  3403. * @param context The context when loading the asset
  3404. * @param array The array to get the item from
  3405. * @param index The index to the array
  3406. * @returns The array item
  3407. */
  3408. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3409. /**
  3410. * Assign an `index` field to each item of the given array.
  3411. * @param array The array of items
  3412. */
  3413. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3414. }
  3415. /**
  3416. * The glTF 2.0 loader
  3417. */
  3418. export class GLTFLoader implements IGLTFLoader {
  3419. /** The glTF object parsed from the JSON. */
  3420. gltf: IGLTF;
  3421. /** The Babylon scene when loading the asset. */
  3422. babylonScene: Scene;
  3423. /** @hidden */
  3424. _completePromises: Promise<any>[];
  3425. private _disposed;
  3426. private _parent;
  3427. private _state;
  3428. private _extensions;
  3429. private _rootUrl;
  3430. private _fileName;
  3431. private _uniqueRootUrl;
  3432. private _rootBabylonMesh;
  3433. private _defaultBabylonMaterialData;
  3434. private _progressCallback?;
  3435. private _requests;
  3436. private static readonly _DefaultSampler;
  3437. private static _ExtensionNames;
  3438. private static _ExtensionFactories;
  3439. /**
  3440. * Registers a loader extension.
  3441. * @param name The name of the loader extension.
  3442. * @param factory The factory function that creates the loader extension.
  3443. */
  3444. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3445. /**
  3446. * Unregisters a loader extension.
  3447. * @param name The name of the loader extenion.
  3448. * @returns A boolean indicating whether the extension has been unregistered
  3449. */
  3450. static UnregisterExtension(name: string): boolean;
  3451. /**
  3452. * Gets the loader state.
  3453. */
  3454. readonly state: Nullable<GLTFLoaderState>;
  3455. /** @hidden */
  3456. constructor(parent: GLTFFileLoader);
  3457. /** @hidden */
  3458. dispose(): void;
  3459. /** @hidden */
  3460. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  3461. meshes: AbstractMesh[];
  3462. particleSystems: IParticleSystem[];
  3463. skeletons: Skeleton[];
  3464. animationGroups: AnimationGroup[];
  3465. }>;
  3466. /** @hidden */
  3467. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3468. private _loadAsync;
  3469. private _loadData;
  3470. private _setupData;
  3471. private _loadExtensions;
  3472. private _checkExtensions;
  3473. private _setState;
  3474. private _createRootNode;
  3475. /**
  3476. * Loads a glTF scene.
  3477. * @param context The context when loading the asset
  3478. * @param scene The glTF scene property
  3479. * @returns A promise that resolves when the load is complete
  3480. */
  3481. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3482. private _forEachPrimitive;
  3483. private _getMeshes;
  3484. private _getSkeletons;
  3485. private _getAnimationGroups;
  3486. private _startAnimations;
  3487. /**
  3488. * Loads a glTF node.
  3489. * @param context The context when loading the asset
  3490. * @param node The glTF node property
  3491. * @param assign A function called synchronously after parsing the glTF properties
  3492. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3493. */
  3494. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3495. private _loadMeshAsync;
  3496. private _loadMeshPrimitiveAsync;
  3497. private _loadVertexDataAsync;
  3498. private _createMorphTargets;
  3499. private _loadMorphTargetsAsync;
  3500. private _loadMorphTargetVertexDataAsync;
  3501. private static _LoadTransform;
  3502. private _loadSkinAsync;
  3503. private _loadBones;
  3504. private _loadBone;
  3505. private _loadSkinInverseBindMatricesDataAsync;
  3506. private _updateBoneMatrices;
  3507. private _getNodeMatrix;
  3508. /**
  3509. * Loads a glTF camera.
  3510. * @param context The context when loading the asset
  3511. * @param camera The glTF camera property
  3512. * @param assign A function called synchronously after parsing the glTF properties
  3513. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3514. */
  3515. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  3516. private _loadAnimationsAsync;
  3517. /**
  3518. * Loads a glTF animation.
  3519. * @param context The context when loading the asset
  3520. * @param animation The glTF animation property
  3521. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3522. */
  3523. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  3524. private _loadAnimationChannelAsync;
  3525. private _loadAnimationSamplerAsync;
  3526. private _loadBufferAsync;
  3527. /**
  3528. * Loads a glTF buffer view.
  3529. * @param context The context when loading the asset
  3530. * @param bufferView The glTF buffer view property
  3531. * @returns A promise that resolves with the loaded data when the load is complete
  3532. */
  3533. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  3534. private _loadIndicesAccessorAsync;
  3535. private _loadFloatAccessorAsync;
  3536. private _loadVertexBufferViewAsync;
  3537. private _loadVertexAccessorAsync;
  3538. private _loadMaterialMetallicRoughnessPropertiesAsync;
  3539. /** @hidden */
  3540. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  3541. private _createDefaultMaterial;
  3542. /**
  3543. * Creates a Babylon material from a glTF material.
  3544. * @param context The context when loading the asset
  3545. * @param material The glTF material property
  3546. * @param babylonDrawMode The draw mode for the Babylon material
  3547. * @returns The Babylon material
  3548. */
  3549. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  3550. /**
  3551. * Loads properties from a glTF material into a Babylon material.
  3552. * @param context The context when loading the asset
  3553. * @param material The glTF material property
  3554. * @param babylonMaterial The Babylon material
  3555. * @returns A promise that resolves when the load is complete
  3556. */
  3557. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3558. /**
  3559. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3560. * @param context The context when loading the asset
  3561. * @param material The glTF material property
  3562. * @param babylonMaterial The Babylon material
  3563. * @returns A promise that resolves when the load is complete
  3564. */
  3565. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3566. /**
  3567. * Loads the alpha properties from a glTF material into a Babylon material.
  3568. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3569. * @param context The context when loading the asset
  3570. * @param material The glTF material property
  3571. * @param babylonMaterial The Babylon material
  3572. */
  3573. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  3574. /**
  3575. * Loads a glTF texture info.
  3576. * @param context The context when loading the asset
  3577. * @param textureInfo The glTF texture info property
  3578. * @param assign A function called synchronously after parsing the glTF properties
  3579. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3580. */
  3581. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  3582. private _loadTextureAsync;
  3583. private _loadSampler;
  3584. /**
  3585. * Loads a glTF image.
  3586. * @param context The context when loading the asset
  3587. * @param image The glTF image property
  3588. * @returns A promise that resolves with the loaded data when the load is complete
  3589. */
  3590. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  3591. /**
  3592. * Loads a glTF uri.
  3593. * @param context The context when loading the asset
  3594. * @param uri The base64 or relative uri
  3595. * @returns A promise that resolves with the loaded data when the load is complete
  3596. */
  3597. loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  3598. private _onProgress;
  3599. /**
  3600. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3601. * @param babylonObject the Babylon object with metadata
  3602. * @param pointer the JSON pointer
  3603. */
  3604. static AddPointerMetadata(babylonObject: {
  3605. metadata: any;
  3606. }, pointer: string): void;
  3607. private static _GetTextureWrapMode;
  3608. private static _GetTextureSamplingMode;
  3609. private static _GetTypedArray;
  3610. private static _GetNumComponents;
  3611. private static _ValidateUri;
  3612. private static _GetDrawMode;
  3613. private _compileMaterialsAsync;
  3614. private _compileShadowGeneratorsAsync;
  3615. private _forEachExtensions;
  3616. private _applyExtensions;
  3617. private _extensionsOnLoading;
  3618. private _extensionsOnReady;
  3619. private _extensionsLoadSceneAsync;
  3620. private _extensionsLoadNodeAsync;
  3621. private _extensionsLoadCameraAsync;
  3622. private _extensionsLoadVertexDataAsync;
  3623. private _extensionsLoadMaterialAsync;
  3624. private _extensionsCreateMaterial;
  3625. private _extensionsLoadMaterialPropertiesAsync;
  3626. private _extensionsLoadTextureInfoAsync;
  3627. private _extensionsLoadAnimationAsync;
  3628. private _extensionsLoadUriAsync;
  3629. /**
  3630. * Helper method called by a loader extension to load an glTF extension.
  3631. * @param context The context when loading the asset
  3632. * @param property The glTF property to load the extension from
  3633. * @param extensionName The name of the extension to load
  3634. * @param actionAsync The action to run
  3635. * @returns The promise returned by actionAsync or null if the extension does not exist
  3636. */
  3637. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3638. /**
  3639. * Helper method called by a loader extension to load a glTF extra.
  3640. * @param context The context when loading the asset
  3641. * @param property The glTF property to load the extra from
  3642. * @param extensionName The name of the extension to load
  3643. * @param actionAsync The action to run
  3644. * @returns The promise returned by actionAsync or null if the extra does not exist
  3645. */
  3646. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3647. /**
  3648. * Increments the indentation level and logs a message.
  3649. * @param message The message to log
  3650. */
  3651. logOpen(message: string): void;
  3652. /**
  3653. * Decrements the indentation level.
  3654. */
  3655. logClose(): void;
  3656. /**
  3657. * Logs a message
  3658. * @param message The message to log
  3659. */
  3660. log(message: string): void;
  3661. /**
  3662. * Starts a performance counter.
  3663. * @param counterName The name of the performance counter
  3664. */
  3665. startPerformanceCounter(counterName: string): void;
  3666. /**
  3667. * Ends a performance counter.
  3668. * @param counterName The name of the performance counter
  3669. */
  3670. endPerformanceCounter(counterName: string): void;
  3671. }
  3672. }
  3673. declare module BABYLON.GLTF2.Loader.Extensions {
  3674. /**
  3675. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  3676. */
  3677. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  3678. /** The name of this extension. */
  3679. readonly name: string;
  3680. /** Defines whether this extension is enabled. */
  3681. enabled: boolean;
  3682. private _loader;
  3683. private _lights?;
  3684. /** @hidden */
  3685. constructor(loader: GLTFLoader);
  3686. /** @hidden */
  3687. dispose(): void;
  3688. /** @hidden */
  3689. onLoading(): void;
  3690. /** @hidden */
  3691. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  3692. private _loadLightAsync;
  3693. }
  3694. }
  3695. declare module BABYLON.GLTF2.Loader.Extensions {
  3696. /**
  3697. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  3698. */
  3699. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  3700. /** The name of this extension. */
  3701. readonly name: string;
  3702. /** Defines whether this extension is enabled. */
  3703. enabled: boolean;
  3704. private _loader;
  3705. private _dracoCompression?;
  3706. /** @hidden */
  3707. constructor(loader: GLTFLoader);
  3708. /** @hidden */
  3709. dispose(): void;
  3710. /** @hidden */
  3711. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3712. }
  3713. }
  3714. declare module BABYLON.GLTF2.Loader.Extensions {
  3715. /**
  3716. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  3717. */
  3718. export class KHR_lights implements IGLTFLoaderExtension {
  3719. /** The name of this extension. */
  3720. readonly name: string;
  3721. /** Defines whether this extension is enabled. */
  3722. enabled: boolean;
  3723. private _loader;
  3724. private _lights?;
  3725. /** @hidden */
  3726. constructor(loader: GLTFLoader);
  3727. /** @hidden */
  3728. dispose(): void;
  3729. /** @hidden */
  3730. onLoading(): void;
  3731. /** @hidden */
  3732. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3733. }
  3734. }
  3735. declare module BABYLON.GLTF2.Loader.Extensions {
  3736. /**
  3737. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  3738. */
  3739. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  3740. /** The name of this extension. */
  3741. readonly name: string;
  3742. /** Defines whether this extension is enabled. */
  3743. enabled: boolean;
  3744. private _loader;
  3745. /** @hidden */
  3746. constructor(loader: GLTFLoader);
  3747. /** @hidden */
  3748. dispose(): void;
  3749. /** @hidden */
  3750. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3751. private _loadSpecularGlossinessPropertiesAsync;
  3752. }
  3753. }
  3754. declare module BABYLON.GLTF2.Loader.Extensions {
  3755. /**
  3756. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  3757. */
  3758. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  3759. /** The name of this extension. */
  3760. readonly name: string;
  3761. /** Defines whether this extension is enabled. */
  3762. enabled: boolean;
  3763. private _loader;
  3764. /** @hidden */
  3765. constructor(loader: GLTFLoader);
  3766. /** @hidden */
  3767. dispose(): void;
  3768. /** @hidden */
  3769. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3770. private _loadUnlitPropertiesAsync;
  3771. }
  3772. }
  3773. declare module BABYLON.GLTF2.Loader.Extensions {
  3774. /**
  3775. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  3776. */
  3777. export class KHR_texture_transform implements IGLTFLoaderExtension {
  3778. /** The name of this extension. */
  3779. readonly name: string;
  3780. /** Defines whether this extension is enabled. */
  3781. enabled: boolean;
  3782. private _loader;
  3783. /** @hidden */
  3784. constructor(loader: GLTFLoader);
  3785. /** @hidden */
  3786. dispose(): void;
  3787. /** @hidden */
  3788. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3789. }
  3790. }
  3791. declare module BABYLON.GLTF2.Loader.Extensions {
  3792. /**
  3793. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  3794. */
  3795. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  3796. /** The name of this extension. */
  3797. readonly name: string;
  3798. /** Defines whether this extension is enabled. */
  3799. enabled: boolean;
  3800. private _loader;
  3801. private _clips;
  3802. private _emitters;
  3803. /** @hidden */
  3804. constructor(loader: GLTFLoader);
  3805. /** @hidden */
  3806. dispose(): void;
  3807. /** @hidden */
  3808. onLoading(): void;
  3809. /** @hidden */
  3810. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  3811. /** @hidden */
  3812. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3813. /** @hidden */
  3814. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3815. private _loadClipAsync;
  3816. private _loadEmitterAsync;
  3817. private _getEventAction;
  3818. private _loadAnimationEventAsync;
  3819. }
  3820. }
  3821. declare module BABYLON.GLTF2.Loader.Extensions {
  3822. /**
  3823. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  3824. */
  3825. export class MSFT_lod implements IGLTFLoaderExtension {
  3826. /** The name of this extension. */
  3827. readonly name: string;
  3828. /** Defines whether this extension is enabled. */
  3829. enabled: boolean;
  3830. /**
  3831. * Maximum number of LODs to load, starting from the lowest LOD.
  3832. */
  3833. maxLODsToLoad: number;
  3834. /**
  3835. * Observable raised when all node LODs of one level are loaded.
  3836. * The event data is the index of the loaded LOD starting from zero.
  3837. * Dispose the loader to cancel the loading of the next level of LODs.
  3838. */
  3839. onNodeLODsLoadedObservable: Observable<number>;
  3840. /**
  3841. * Observable raised when all material LODs of one level are loaded.
  3842. * The event data is the index of the loaded LOD starting from zero.
  3843. * Dispose the loader to cancel the loading of the next level of LODs.
  3844. */
  3845. onMaterialLODsLoadedObservable: Observable<number>;
  3846. private _loader;
  3847. private _nodeIndexLOD;
  3848. private _nodeSignalLODs;
  3849. private _nodePromiseLODs;
  3850. private _materialIndexLOD;
  3851. private _materialSignalLODs;
  3852. private _materialPromiseLODs;
  3853. /** @hidden */
  3854. constructor(loader: GLTFLoader);
  3855. /** @hidden */
  3856. dispose(): void;
  3857. /** @hidden */
  3858. onReady(): void;
  3859. /** @hidden */
  3860. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3861. /** @hidden */
  3862. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3863. /** @hidden */
  3864. _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  3865. /**
  3866. * Gets an array of LOD properties from lowest to highest.
  3867. */
  3868. private _getLODs;
  3869. private _disposeUnusedMaterials;
  3870. }
  3871. }
  3872. declare module BABYLON.GLTF2.Loader.Extensions {
  3873. /** @hidden */
  3874. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  3875. readonly name: string;
  3876. enabled: boolean;
  3877. private _loader;
  3878. constructor(loader: GLTFLoader);
  3879. dispose(): void;
  3880. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3881. }
  3882. }
  3883. declare module BABYLON.GLTF2.Loader.Extensions {
  3884. /** @hidden */
  3885. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  3886. readonly name: string;
  3887. enabled: boolean;
  3888. private _loader;
  3889. constructor(loader: GLTFLoader);
  3890. dispose(): void;
  3891. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3892. }
  3893. }
  3894. declare module BABYLON {
  3895. /**
  3896. * Class reading and parsing the MTL file bundled with the obj file.
  3897. */
  3898. export class MTLFileLoader {
  3899. /**
  3900. * All material loaded from the mtl will be set here
  3901. */
  3902. materials: StandardMaterial[];
  3903. /**
  3904. * This function will read the mtl file and create each material described inside
  3905. * This function could be improve by adding :
  3906. * -some component missing (Ni, Tf...)
  3907. * -including the specific options available
  3908. *
  3909. * @param scene defines the scene the material will be created in
  3910. * @param data defines the mtl data to parse
  3911. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  3912. */
  3913. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  3914. /**
  3915. * Gets the texture for the material.
  3916. *
  3917. * If the material is imported from input file,
  3918. * We sanitize the url to ensure it takes the textre from aside the material.
  3919. *
  3920. * @param rootUrl The root url to load from
  3921. * @param value The value stored in the mtl
  3922. * @return The Texture
  3923. */
  3924. private static _getTexture;
  3925. }
  3926. /**
  3927. * OBJ file type loader.
  3928. * This is a babylon scene loader plugin.
  3929. */
  3930. export class OBJFileLoader implements ISceneLoaderPluginAsync {
  3931. /**
  3932. * Defines if UVs are optimized by default during load.
  3933. */
  3934. static OPTIMIZE_WITH_UV: boolean;
  3935. /**
  3936. * Invert model on y-axis (does a model scaling inversion)
  3937. */
  3938. static INVERT_Y: boolean;
  3939. /**
  3940. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  3941. */
  3942. static IMPORT_VERTEX_COLORS: boolean;
  3943. /**
  3944. * Compute the normals for the model, even if normals are present in the file
  3945. */
  3946. static COMPUTE_NORMALS: boolean;
  3947. /**
  3948. * Defines the name of the plugin.
  3949. */
  3950. name: string;
  3951. /**
  3952. * Defines the extension the plugin is able to load.
  3953. */
  3954. extensions: string;
  3955. /** @hidden */
  3956. obj: RegExp;
  3957. /** @hidden */
  3958. group: RegExp;
  3959. /** @hidden */
  3960. mtllib: RegExp;
  3961. /** @hidden */
  3962. usemtl: RegExp;
  3963. /** @hidden */
  3964. smooth: RegExp;
  3965. /** @hidden */
  3966. vertexPattern: RegExp;
  3967. /** @hidden */
  3968. normalPattern: RegExp;
  3969. /** @hidden */
  3970. uvPattern: RegExp;
  3971. /** @hidden */
  3972. facePattern1: RegExp;
  3973. /** @hidden */
  3974. facePattern2: RegExp;
  3975. /** @hidden */
  3976. facePattern3: RegExp;
  3977. /** @hidden */
  3978. facePattern4: RegExp;
  3979. /** @hidden */
  3980. facePattern5: RegExp;
  3981. /**
  3982. * Calls synchronously the MTL file attached to this obj.
  3983. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  3984. * Without this function materials are not displayed in the first frame (but displayed after).
  3985. * In consequence it is impossible to get material information in your HTML file
  3986. *
  3987. * @param url The URL of the MTL file
  3988. * @param rootUrl
  3989. * @param onSuccess Callback function to be called when the MTL file is loaded
  3990. * @private
  3991. */
  3992. private _loadMTL;
  3993. /**
  3994. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  3995. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3996. * @param scene the scene the meshes should be added to
  3997. * @param data the OBJ data to load
  3998. * @param rootUrl root url to load from
  3999. * @param onProgress event that fires when loading progress has occured
  4000. * @param fileName Defines the name of the file to load
  4001. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4002. */
  4003. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4004. meshes: AbstractMesh[];
  4005. particleSystems: IParticleSystem[];
  4006. skeletons: Skeleton[];
  4007. animationGroups: AnimationGroup[];
  4008. }>;
  4009. /**
  4010. * Imports all objects from the loaded OBJ data and adds them to the scene
  4011. * @param scene the scene the objects should be added to
  4012. * @param data the OBJ data to load
  4013. * @param rootUrl root url to load from
  4014. * @param onProgress event that fires when loading progress has occured
  4015. * @param fileName Defines the name of the file to load
  4016. * @returns a promise which completes when objects have been loaded to the scene
  4017. */
  4018. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4019. /**
  4020. * Load into an asset container.
  4021. * @param scene The scene to load into
  4022. * @param data The data to import
  4023. * @param rootUrl The root url for scene and resources
  4024. * @param onProgress The callback when the load progresses
  4025. * @param fileName Defines the name of the file to load
  4026. * @returns The loaded asset container
  4027. */
  4028. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4029. /**
  4030. * Read the OBJ file and create an Array of meshes.
  4031. * Each mesh contains all information given by the OBJ and the MTL file.
  4032. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4033. *
  4034. * @param meshesNames
  4035. * @param scene Scene The scene where are displayed the data
  4036. * @param data String The content of the obj file
  4037. * @param rootUrl String The path to the folder
  4038. * @returns Array<AbstractMesh>
  4039. * @private
  4040. */
  4041. private _parseSolid;
  4042. }
  4043. }
  4044. declare module BABYLON {
  4045. /**
  4046. * STL file type loader.
  4047. * This is a babylon scene loader plugin.
  4048. */
  4049. export class STLFileLoader implements ISceneLoaderPlugin {
  4050. /** @hidden */
  4051. solidPattern: RegExp;
  4052. /** @hidden */
  4053. facetsPattern: RegExp;
  4054. /** @hidden */
  4055. normalPattern: RegExp;
  4056. /** @hidden */
  4057. vertexPattern: RegExp;
  4058. /**
  4059. * Defines the name of the plugin.
  4060. */
  4061. name: string;
  4062. /**
  4063. * Defines the extensions the stl loader is able to load.
  4064. * force data to come in as an ArrayBuffer
  4065. * we'll convert to string if it looks like it's an ASCII .stl
  4066. */
  4067. extensions: ISceneLoaderPluginExtensions;
  4068. /**
  4069. * Import meshes into a scene.
  4070. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4071. * @param scene The scene to import into
  4072. * @param data The data to import
  4073. * @param rootUrl The root url for scene and resources
  4074. * @param meshes The meshes array to import into
  4075. * @param particleSystems The particle systems array to import into
  4076. * @param skeletons The skeletons array to import into
  4077. * @param onError The callback when import fails
  4078. * @returns True if successful or false otherwise
  4079. */
  4080. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4081. /**
  4082. * Load into a scene.
  4083. * @param scene The scene to load into
  4084. * @param data The data to import
  4085. * @param rootUrl The root url for scene and resources
  4086. * @param onError The callback when import fails
  4087. * @returns true if successful or false otherwise
  4088. */
  4089. load(scene: Scene, data: any, rootUrl: string): boolean;
  4090. /**
  4091. * Load into an asset container.
  4092. * @param scene The scene to load into
  4093. * @param data The data to import
  4094. * @param rootUrl The root url for scene and resources
  4095. * @param onError The callback when import fails
  4096. * @returns The loaded asset container
  4097. */
  4098. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4099. private _isBinary;
  4100. private _parseBinary;
  4101. private _parseASCII;
  4102. }
  4103. }