babylonjs.loaders.module.d.ts 186 KB

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