babylonjs.loaders.module.d.ts 186 KB

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