babylonjs.loaders.module.d.ts 183 KB

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