babylonjs.loaders.module.d.ts 182 KB

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