babylonjs.loaders.module.d.ts 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369
  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 { Vector2 } from "babylonjs/Maths/math";
  1952. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1953. import { Skeleton } from "babylonjs/Bones/skeleton";
  1954. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1955. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  1956. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1957. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin } from "babylonjs/Loading/sceneLoader";
  1958. import { AssetContainer } from "babylonjs/assetContainer";
  1959. import { Scene } from "babylonjs/scene";
  1960. /**
  1961. * Class reading and parsing the MTL file bundled with the obj file.
  1962. */
  1963. export class MTLFileLoader {
  1964. /**
  1965. * All material loaded from the mtl will be set here
  1966. */
  1967. materials: StandardMaterial[];
  1968. /**
  1969. * This function will read the mtl file and create each material described inside
  1970. * This function could be improve by adding :
  1971. * -some component missing (Ni, Tf...)
  1972. * -including the specific options available
  1973. *
  1974. * @param scene defines the scene the material will be created in
  1975. * @param data defines the mtl data to parse
  1976. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1977. */
  1978. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1979. /**
  1980. * Gets the texture for the material.
  1981. *
  1982. * If the material is imported from input file,
  1983. * We sanitize the url to ensure it takes the textre from aside the material.
  1984. *
  1985. * @param rootUrl The root url to load from
  1986. * @param value The value stored in the mtl
  1987. * @return The Texture
  1988. */
  1989. private static _getTexture;
  1990. }
  1991. /**
  1992. * Options for loading OBJ/MTL files
  1993. */
  1994. type MeshLoadOptions = {
  1995. /**
  1996. * Defines if UVs are optimized by default during load.
  1997. */
  1998. OptimizeWithUV: boolean;
  1999. /**
  2000. * Defines custom scaling of UV coordinates of loaded meshes.
  2001. */
  2002. UVScaling: Vector2;
  2003. /**
  2004. * Invert model on y-axis (does a model scaling inversion)
  2005. */
  2006. InvertY: boolean;
  2007. /**
  2008. * Invert Y-Axis of referenced textures on load
  2009. */
  2010. InvertTextureY: boolean;
  2011. /**
  2012. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2013. */
  2014. ImportVertexColors: boolean;
  2015. /**
  2016. * Compute the normals for the model, even if normals are present in the file.
  2017. */
  2018. ComputeNormals: boolean;
  2019. /**
  2020. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2021. */
  2022. SkipMaterials: boolean;
  2023. /**
  2024. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2025. */
  2026. MaterialLoadingFailsSilently: boolean;
  2027. };
  2028. /**
  2029. * OBJ file type loader.
  2030. * This is a babylon scene loader plugin.
  2031. */
  2032. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2033. /**
  2034. * Defines if UVs are optimized by default during load.
  2035. */
  2036. static OPTIMIZE_WITH_UV: boolean;
  2037. /**
  2038. * Invert model on y-axis (does a model scaling inversion)
  2039. */
  2040. static INVERT_Y: boolean;
  2041. /**
  2042. * Invert Y-Axis of referenced textures on load
  2043. */
  2044. static INVERT_TEXTURE_Y: boolean;
  2045. /**
  2046. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2047. */
  2048. static IMPORT_VERTEX_COLORS: boolean;
  2049. /**
  2050. * Compute the normals for the model, even if normals are present in the file.
  2051. */
  2052. static COMPUTE_NORMALS: boolean;
  2053. /**
  2054. * Defines custom scaling of UV coordinates of loaded meshes.
  2055. */
  2056. static UV_SCALING: Vector2;
  2057. /**
  2058. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2059. */
  2060. static SKIP_MATERIALS: boolean;
  2061. /**
  2062. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2063. *
  2064. * Defaults to true for backwards compatibility.
  2065. */
  2066. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2067. /**
  2068. * Defines the name of the plugin.
  2069. */
  2070. name: string;
  2071. /**
  2072. * Defines the extension the plugin is able to load.
  2073. */
  2074. extensions: string;
  2075. /** @hidden */
  2076. obj: RegExp;
  2077. /** @hidden */
  2078. group: RegExp;
  2079. /** @hidden */
  2080. mtllib: RegExp;
  2081. /** @hidden */
  2082. usemtl: RegExp;
  2083. /** @hidden */
  2084. smooth: RegExp;
  2085. /** @hidden */
  2086. vertexPattern: RegExp;
  2087. /** @hidden */
  2088. normalPattern: RegExp;
  2089. /** @hidden */
  2090. uvPattern: RegExp;
  2091. /** @hidden */
  2092. facePattern1: RegExp;
  2093. /** @hidden */
  2094. facePattern2: RegExp;
  2095. /** @hidden */
  2096. facePattern3: RegExp;
  2097. /** @hidden */
  2098. facePattern4: RegExp;
  2099. /** @hidden */
  2100. facePattern5: RegExp;
  2101. private _meshLoadOptions;
  2102. /**
  2103. * Creates loader for .OBJ files
  2104. *
  2105. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2106. */
  2107. constructor(meshLoadOptions?: MeshLoadOptions);
  2108. private static readonly currentMeshLoadOptions;
  2109. /**
  2110. * Calls synchronously the MTL file attached to this obj.
  2111. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2112. * Without this function materials are not displayed in the first frame (but displayed after).
  2113. * In consequence it is impossible to get material information in your HTML file
  2114. *
  2115. * @param url The URL of the MTL file
  2116. * @param rootUrl
  2117. * @param onSuccess Callback function to be called when the MTL file is loaded
  2118. * @private
  2119. */
  2120. private _loadMTL;
  2121. /**
  2122. * Instantiates a OBJ file loader plugin.
  2123. * @returns the created plugin
  2124. */
  2125. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2126. /**
  2127. * If the data string can be loaded directly.
  2128. *
  2129. * @param data string containing the file data
  2130. * @returns if the data can be loaded directly
  2131. */
  2132. canDirectLoad(data: string): boolean;
  2133. /**
  2134. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2135. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2136. * @param scene the scene the meshes should be added to
  2137. * @param data the OBJ data to load
  2138. * @param rootUrl root url to load from
  2139. * @param onProgress event that fires when loading progress has occured
  2140. * @param fileName Defines the name of the file to load
  2141. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2142. */
  2143. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2144. meshes: AbstractMesh[];
  2145. particleSystems: IParticleSystem[];
  2146. skeletons: Skeleton[];
  2147. animationGroups: AnimationGroup[];
  2148. }>;
  2149. /**
  2150. * Imports all objects from the loaded OBJ data and adds them to the scene
  2151. * @param scene the scene the objects should be added to
  2152. * @param data the OBJ data to load
  2153. * @param rootUrl root url to load from
  2154. * @param onProgress event that fires when loading progress has occured
  2155. * @param fileName Defines the name of the file to load
  2156. * @returns a promise which completes when objects have been loaded to the scene
  2157. */
  2158. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2159. /**
  2160. * Load into an asset container.
  2161. * @param scene The scene to load into
  2162. * @param data The data to import
  2163. * @param rootUrl The root url for scene and resources
  2164. * @param onProgress The callback when the load progresses
  2165. * @param fileName Defines the name of the file to load
  2166. * @returns The loaded asset container
  2167. */
  2168. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2169. /**
  2170. * Read the OBJ file and create an Array of meshes.
  2171. * Each mesh contains all information given by the OBJ and the MTL file.
  2172. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2173. *
  2174. * @param meshesNames
  2175. * @param scene Scene The scene where are displayed the data
  2176. * @param data String The content of the obj file
  2177. * @param rootUrl String The path to the folder
  2178. * @returns Array<AbstractMesh>
  2179. * @private
  2180. */
  2181. private _parseSolid;
  2182. }
  2183. }
  2184. declare module "babylonjs-loaders/OBJ/index" {
  2185. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2186. }
  2187. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2188. import { Nullable } from "babylonjs/types";
  2189. import { Skeleton } from "babylonjs/Bones/skeleton";
  2190. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2191. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2192. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2193. import { AssetContainer } from "babylonjs/assetContainer";
  2194. import { Scene } from "babylonjs/scene";
  2195. /**
  2196. * STL file type loader.
  2197. * This is a babylon scene loader plugin.
  2198. */
  2199. export class STLFileLoader implements ISceneLoaderPlugin {
  2200. /** @hidden */
  2201. solidPattern: RegExp;
  2202. /** @hidden */
  2203. facetsPattern: RegExp;
  2204. /** @hidden */
  2205. normalPattern: RegExp;
  2206. /** @hidden */
  2207. vertexPattern: RegExp;
  2208. /**
  2209. * Defines the name of the plugin.
  2210. */
  2211. name: string;
  2212. /**
  2213. * Defines the extensions the stl loader is able to load.
  2214. * force data to come in as an ArrayBuffer
  2215. * we'll convert to string if it looks like it's an ASCII .stl
  2216. */
  2217. extensions: ISceneLoaderPluginExtensions;
  2218. /**
  2219. * Import meshes into a scene.
  2220. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2221. * @param scene The scene to import into
  2222. * @param data The data to import
  2223. * @param rootUrl The root url for scene and resources
  2224. * @param meshes The meshes array to import into
  2225. * @param particleSystems The particle systems array to import into
  2226. * @param skeletons The skeletons array to import into
  2227. * @param onError The callback when import fails
  2228. * @returns True if successful or false otherwise
  2229. */
  2230. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2231. /**
  2232. * Load into a scene.
  2233. * @param scene The scene to load into
  2234. * @param data The data to import
  2235. * @param rootUrl The root url for scene and resources
  2236. * @param onError The callback when import fails
  2237. * @returns true if successful or false otherwise
  2238. */
  2239. load(scene: Scene, data: any, rootUrl: string): boolean;
  2240. /**
  2241. * Load into an asset container.
  2242. * @param scene The scene to load into
  2243. * @param data The data to import
  2244. * @param rootUrl The root url for scene and resources
  2245. * @param onError The callback when import fails
  2246. * @returns The loaded asset container
  2247. */
  2248. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2249. private _isBinary;
  2250. private _parseBinary;
  2251. private _parseASCII;
  2252. }
  2253. }
  2254. declare module "babylonjs-loaders/STL/index" {
  2255. export * from "babylonjs-loaders/STL/stlFileLoader";
  2256. }
  2257. declare module "babylonjs-loaders/index" {
  2258. export * from "babylonjs-loaders/glTF/index";
  2259. export * from "babylonjs-loaders/OBJ/index";
  2260. export * from "babylonjs-loaders/STL/index";
  2261. }
  2262. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2263. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2264. }
  2265. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2266. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2267. export { GLTF1 };
  2268. }
  2269. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2270. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2271. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2272. }
  2273. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2274. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2275. export { GLTF2 };
  2276. }
  2277. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2278. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2279. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2280. }
  2281. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2282. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2283. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2284. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2285. }
  2286. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2287. export * from "babylonjs-loaders/OBJ/index";
  2288. }
  2289. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2290. export * from "babylonjs-loaders/STL/index";
  2291. }
  2292. declare module "babylonjs-loaders/legacy/legacy" {
  2293. import "babylonjs-loaders/index";
  2294. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2295. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2296. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2297. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2298. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2299. }
  2300. declare module "babylonjs-loaders" {
  2301. export * from "babylonjs-loaders/legacy/legacy";
  2302. }
  2303. declare module BABYLON {
  2304. /**
  2305. * Mode that determines the coordinate system to use.
  2306. */
  2307. export enum GLTFLoaderCoordinateSystemMode {
  2308. /**
  2309. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2310. */
  2311. AUTO = 0,
  2312. /**
  2313. * Sets the useRightHandedSystem flag on the scene.
  2314. */
  2315. FORCE_RIGHT_HANDED = 1
  2316. }
  2317. /**
  2318. * Mode that determines what animations will start.
  2319. */
  2320. export enum GLTFLoaderAnimationStartMode {
  2321. /**
  2322. * No animation will start.
  2323. */
  2324. NONE = 0,
  2325. /**
  2326. * The first animation will start.
  2327. */
  2328. FIRST = 1,
  2329. /**
  2330. * All animations will start.
  2331. */
  2332. ALL = 2
  2333. }
  2334. /**
  2335. * Interface that contains the data for the glTF asset.
  2336. */
  2337. export interface IGLTFLoaderData {
  2338. /**
  2339. * Object that represents the glTF JSON.
  2340. */
  2341. json: Object;
  2342. /**
  2343. * The BIN chunk of a binary glTF.
  2344. */
  2345. bin: Nullable<ArrayBufferView>;
  2346. }
  2347. /**
  2348. * Interface for extending the loader.
  2349. */
  2350. export interface IGLTFLoaderExtension {
  2351. /**
  2352. * The name of this extension.
  2353. */
  2354. readonly name: string;
  2355. /**
  2356. * Defines whether this extension is enabled.
  2357. */
  2358. enabled: boolean;
  2359. }
  2360. /**
  2361. * Loader state.
  2362. */
  2363. export enum GLTFLoaderState {
  2364. /**
  2365. * The asset is loading.
  2366. */
  2367. LOADING = 0,
  2368. /**
  2369. * The asset is ready for rendering.
  2370. */
  2371. READY = 1,
  2372. /**
  2373. * The asset is completely loaded.
  2374. */
  2375. COMPLETE = 2
  2376. }
  2377. /** @hidden */
  2378. export interface IGLTFLoader extends IDisposable {
  2379. readonly state: Nullable<GLTFLoaderState>;
  2380. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  2381. meshes: AbstractMesh[];
  2382. particleSystems: IParticleSystem[];
  2383. skeletons: Skeleton[];
  2384. animationGroups: AnimationGroup[];
  2385. }>;
  2386. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2387. }
  2388. /**
  2389. * File loader for loading glTF files into a scene.
  2390. */
  2391. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2392. /** @hidden */
  2393. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2394. /** @hidden */
  2395. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2396. /**
  2397. * Raised when the asset has been parsed
  2398. */
  2399. onParsedObservable: Observable<IGLTFLoaderData>;
  2400. private _onParsedObserver;
  2401. /**
  2402. * Raised when the asset has been parsed
  2403. */
  2404. onParsed: (loaderData: IGLTFLoaderData) => void;
  2405. /**
  2406. * 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.
  2407. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2408. * Defaults to true.
  2409. * @hidden
  2410. */
  2411. static IncrementalLoading: boolean;
  2412. /**
  2413. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2414. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2415. * @hidden
  2416. */
  2417. static HomogeneousCoordinates: boolean;
  2418. /**
  2419. * The coordinate system mode. Defaults to AUTO.
  2420. */
  2421. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2422. /**
  2423. * The animation start mode. Defaults to FIRST.
  2424. */
  2425. animationStartMode: GLTFLoaderAnimationStartMode;
  2426. /**
  2427. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2428. */
  2429. compileMaterials: boolean;
  2430. /**
  2431. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2432. */
  2433. useClipPlane: boolean;
  2434. /**
  2435. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2436. */
  2437. compileShadowGenerators: boolean;
  2438. /**
  2439. * Defines if the Alpha blended materials are only applied as coverage.
  2440. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2441. * If true, no extra effects are applied to transparent pixels.
  2442. */
  2443. transparencyAsCoverage: boolean;
  2444. /**
  2445. * Function called before loading a url referenced by the asset.
  2446. */
  2447. preprocessUrlAsync: (url: string) => Promise<string>;
  2448. /**
  2449. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2450. */
  2451. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2452. private _onMeshLoadedObserver;
  2453. /**
  2454. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2455. */
  2456. onMeshLoaded: (mesh: AbstractMesh) => void;
  2457. /**
  2458. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2459. */
  2460. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2461. private _onTextureLoadedObserver;
  2462. /**
  2463. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2464. */
  2465. onTextureLoaded: (texture: BaseTexture) => void;
  2466. /**
  2467. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2468. */
  2469. readonly onMaterialLoadedObservable: Observable<Material>;
  2470. private _onMaterialLoadedObserver;
  2471. /**
  2472. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2473. */
  2474. onMaterialLoaded: (material: Material) => void;
  2475. /**
  2476. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2477. */
  2478. readonly onCameraLoadedObservable: Observable<Camera>;
  2479. private _onCameraLoadedObserver;
  2480. /**
  2481. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2482. */
  2483. onCameraLoaded: (camera: Camera) => void;
  2484. /**
  2485. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2486. * For assets with LODs, raised when all of the LODs are complete.
  2487. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2488. */
  2489. readonly onCompleteObservable: Observable<void>;
  2490. private _onCompleteObserver;
  2491. /**
  2492. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2493. * For assets with LODs, raised when all of the LODs are complete.
  2494. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2495. */
  2496. onComplete: () => void;
  2497. /**
  2498. * Observable raised when an error occurs.
  2499. */
  2500. readonly onErrorObservable: Observable<any>;
  2501. private _onErrorObserver;
  2502. /**
  2503. * Callback raised when an error occurs.
  2504. */
  2505. onError: (reason: any) => void;
  2506. /**
  2507. * Observable raised after the loader is disposed.
  2508. */
  2509. readonly onDisposeObservable: Observable<void>;
  2510. private _onDisposeObserver;
  2511. /**
  2512. * Callback raised after the loader is disposed.
  2513. */
  2514. onDispose: () => void;
  2515. /**
  2516. * Observable raised after a loader extension is created.
  2517. * Set additional options for a loader extension in this event.
  2518. */
  2519. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2520. private _onExtensionLoadedObserver;
  2521. /**
  2522. * Callback raised after a loader extension is created.
  2523. */
  2524. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  2525. /**
  2526. * Defines if the loader logging is enabled.
  2527. */
  2528. loggingEnabled: boolean;
  2529. /**
  2530. * Defines if the loader should capture performance counters.
  2531. */
  2532. capturePerformanceCounters: boolean;
  2533. /**
  2534. * Defines if the loader should validate the asset.
  2535. */
  2536. validate: boolean;
  2537. /**
  2538. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2539. */
  2540. readonly onValidatedObservable: Observable<IGLTFValidationResults>;
  2541. private _onValidatedObserver;
  2542. /**
  2543. * Callback raised after a loader extension is created.
  2544. */
  2545. onValidated: (results: IGLTFValidationResults) => void;
  2546. private _loader;
  2547. /**
  2548. * Name of the loader ("gltf")
  2549. */
  2550. name: string;
  2551. /**
  2552. * Supported file extensions of the loader (.gltf, .glb)
  2553. */
  2554. extensions: ISceneLoaderPluginExtensions;
  2555. /**
  2556. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2557. */
  2558. dispose(): void;
  2559. /** @hidden */
  2560. _clear(): void;
  2561. /**
  2562. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  2563. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2564. * @param scene the scene the meshes should be added to
  2565. * @param data the glTF data to load
  2566. * @param rootUrl root url to load from
  2567. * @param onProgress event that fires when loading progress has occured
  2568. * @param fileName Defines the name of the file to load
  2569. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2570. */
  2571. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2572. meshes: AbstractMesh[];
  2573. particleSystems: IParticleSystem[];
  2574. skeletons: Skeleton[];
  2575. animationGroups: AnimationGroup[];
  2576. }>;
  2577. /**
  2578. * Imports all objects from the loaded glTF data and adds them to the scene
  2579. * @param scene the scene the objects should be added to
  2580. * @param data the glTF data to load
  2581. * @param rootUrl root url to load from
  2582. * @param onProgress event that fires when loading progress has occured
  2583. * @param fileName Defines the name of the file to load
  2584. * @returns a promise which completes when objects have been loaded to the scene
  2585. */
  2586. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2587. /**
  2588. * Load into an asset container.
  2589. * @param scene The scene to load into
  2590. * @param data The data to import
  2591. * @param rootUrl The root url for scene and resources
  2592. * @param onProgress The callback when the load progresses
  2593. * @param fileName Defines the name of the file to load
  2594. * @returns The loaded asset container
  2595. */
  2596. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2597. /**
  2598. * If the data string can be loaded directly.
  2599. * @param data string contianing the file data
  2600. * @returns if the data can be loaded directly
  2601. */
  2602. canDirectLoad(data: string): boolean;
  2603. /**
  2604. * Rewrites a url by combining a root url and response url.
  2605. */
  2606. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  2607. /**
  2608. * Instantiates a glTF file loader plugin.
  2609. * @returns the created plugin
  2610. */
  2611. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2612. /**
  2613. * The loader state or null if the loader is not active.
  2614. */
  2615. readonly loaderState: Nullable<GLTFLoaderState>;
  2616. /**
  2617. * Returns a promise that resolves when the asset is completely loaded.
  2618. * @returns a promise that resolves when the asset is completely loaded.
  2619. */
  2620. whenCompleteAsync(): Promise<void>;
  2621. private _parseAsync;
  2622. private _validateAsync;
  2623. private _getLoader;
  2624. private _unpackBinary;
  2625. private _unpackBinaryV1;
  2626. private _unpackBinaryV2;
  2627. private static _parseVersion;
  2628. private static _compareVersion;
  2629. private static _decodeBufferToText;
  2630. private static readonly _logSpaces;
  2631. private _logIndentLevel;
  2632. private _loggingEnabled;
  2633. /** @hidden */
  2634. _log: (message: string) => void;
  2635. /** @hidden */
  2636. _logOpen(message: string): void;
  2637. /** @hidden */
  2638. _logClose(): void;
  2639. private _logEnabled;
  2640. private _logDisabled;
  2641. private _capturePerformanceCounters;
  2642. /** @hidden */
  2643. _startPerformanceCounter: (counterName: string) => void;
  2644. /** @hidden */
  2645. _endPerformanceCounter: (counterName: string) => void;
  2646. private _startPerformanceCounterEnabled;
  2647. private _startPerformanceCounterDisabled;
  2648. private _endPerformanceCounterEnabled;
  2649. private _endPerformanceCounterDisabled;
  2650. }
  2651. }
  2652. declare module BABYLON.GLTF1 {
  2653. /**
  2654. * Enums
  2655. * @hidden
  2656. */
  2657. export enum EComponentType {
  2658. BYTE = 5120,
  2659. UNSIGNED_BYTE = 5121,
  2660. SHORT = 5122,
  2661. UNSIGNED_SHORT = 5123,
  2662. FLOAT = 5126
  2663. }
  2664. /** @hidden */
  2665. export enum EShaderType {
  2666. FRAGMENT = 35632,
  2667. VERTEX = 35633
  2668. }
  2669. /** @hidden */
  2670. export enum EParameterType {
  2671. BYTE = 5120,
  2672. UNSIGNED_BYTE = 5121,
  2673. SHORT = 5122,
  2674. UNSIGNED_SHORT = 5123,
  2675. INT = 5124,
  2676. UNSIGNED_INT = 5125,
  2677. FLOAT = 5126,
  2678. FLOAT_VEC2 = 35664,
  2679. FLOAT_VEC3 = 35665,
  2680. FLOAT_VEC4 = 35666,
  2681. INT_VEC2 = 35667,
  2682. INT_VEC3 = 35668,
  2683. INT_VEC4 = 35669,
  2684. BOOL = 35670,
  2685. BOOL_VEC2 = 35671,
  2686. BOOL_VEC3 = 35672,
  2687. BOOL_VEC4 = 35673,
  2688. FLOAT_MAT2 = 35674,
  2689. FLOAT_MAT3 = 35675,
  2690. FLOAT_MAT4 = 35676,
  2691. SAMPLER_2D = 35678
  2692. }
  2693. /** @hidden */
  2694. export enum ETextureWrapMode {
  2695. CLAMP_TO_EDGE = 33071,
  2696. MIRRORED_REPEAT = 33648,
  2697. REPEAT = 10497
  2698. }
  2699. /** @hidden */
  2700. export enum ETextureFilterType {
  2701. NEAREST = 9728,
  2702. LINEAR = 9728,
  2703. NEAREST_MIPMAP_NEAREST = 9984,
  2704. LINEAR_MIPMAP_NEAREST = 9985,
  2705. NEAREST_MIPMAP_LINEAR = 9986,
  2706. LINEAR_MIPMAP_LINEAR = 9987
  2707. }
  2708. /** @hidden */
  2709. export enum ETextureFormat {
  2710. ALPHA = 6406,
  2711. RGB = 6407,
  2712. RGBA = 6408,
  2713. LUMINANCE = 6409,
  2714. LUMINANCE_ALPHA = 6410
  2715. }
  2716. /** @hidden */
  2717. export enum ECullingType {
  2718. FRONT = 1028,
  2719. BACK = 1029,
  2720. FRONT_AND_BACK = 1032
  2721. }
  2722. /** @hidden */
  2723. export enum EBlendingFunction {
  2724. ZERO = 0,
  2725. ONE = 1,
  2726. SRC_COLOR = 768,
  2727. ONE_MINUS_SRC_COLOR = 769,
  2728. DST_COLOR = 774,
  2729. ONE_MINUS_DST_COLOR = 775,
  2730. SRC_ALPHA = 770,
  2731. ONE_MINUS_SRC_ALPHA = 771,
  2732. DST_ALPHA = 772,
  2733. ONE_MINUS_DST_ALPHA = 773,
  2734. CONSTANT_COLOR = 32769,
  2735. ONE_MINUS_CONSTANT_COLOR = 32770,
  2736. CONSTANT_ALPHA = 32771,
  2737. ONE_MINUS_CONSTANT_ALPHA = 32772,
  2738. SRC_ALPHA_SATURATE = 776
  2739. }
  2740. /** @hidden */
  2741. export interface IGLTFProperty {
  2742. extensions?: {
  2743. [key: string]: any;
  2744. };
  2745. extras?: Object;
  2746. }
  2747. /** @hidden */
  2748. export interface IGLTFChildRootProperty extends IGLTFProperty {
  2749. name?: string;
  2750. }
  2751. /** @hidden */
  2752. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  2753. bufferView: string;
  2754. byteOffset: number;
  2755. byteStride: number;
  2756. count: number;
  2757. type: string;
  2758. componentType: EComponentType;
  2759. max?: number[];
  2760. min?: number[];
  2761. name?: string;
  2762. }
  2763. /** @hidden */
  2764. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  2765. buffer: string;
  2766. byteOffset: number;
  2767. byteLength: number;
  2768. byteStride: number;
  2769. target?: number;
  2770. }
  2771. /** @hidden */
  2772. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  2773. uri: string;
  2774. byteLength?: number;
  2775. type?: string;
  2776. }
  2777. /** @hidden */
  2778. export interface IGLTFShader extends IGLTFChildRootProperty {
  2779. uri: string;
  2780. type: EShaderType;
  2781. }
  2782. /** @hidden */
  2783. export interface IGLTFProgram extends IGLTFChildRootProperty {
  2784. attributes: string[];
  2785. fragmentShader: string;
  2786. vertexShader: string;
  2787. }
  2788. /** @hidden */
  2789. export interface IGLTFTechniqueParameter {
  2790. type: number;
  2791. count?: number;
  2792. semantic?: string;
  2793. node?: string;
  2794. value?: number | boolean | string | Array<any>;
  2795. source?: string;
  2796. babylonValue?: any;
  2797. }
  2798. /** @hidden */
  2799. export interface IGLTFTechniqueCommonProfile {
  2800. lightingModel: string;
  2801. texcoordBindings: Object;
  2802. parameters?: Array<any>;
  2803. }
  2804. /** @hidden */
  2805. export interface IGLTFTechniqueStatesFunctions {
  2806. blendColor?: number[];
  2807. blendEquationSeparate?: number[];
  2808. blendFuncSeparate?: number[];
  2809. colorMask: boolean[];
  2810. cullFace: number[];
  2811. }
  2812. /** @hidden */
  2813. export interface IGLTFTechniqueStates {
  2814. enable: number[];
  2815. functions: IGLTFTechniqueStatesFunctions;
  2816. }
  2817. /** @hidden */
  2818. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  2819. parameters: {
  2820. [key: string]: IGLTFTechniqueParameter;
  2821. };
  2822. program: string;
  2823. attributes: {
  2824. [key: string]: string;
  2825. };
  2826. uniforms: {
  2827. [key: string]: string;
  2828. };
  2829. states: IGLTFTechniqueStates;
  2830. }
  2831. /** @hidden */
  2832. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  2833. technique?: string;
  2834. values: string[];
  2835. }
  2836. /** @hidden */
  2837. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  2838. attributes: {
  2839. [key: string]: string;
  2840. };
  2841. indices: string;
  2842. material: string;
  2843. mode?: number;
  2844. }
  2845. /** @hidden */
  2846. export interface IGLTFMesh extends IGLTFChildRootProperty {
  2847. primitives: IGLTFMeshPrimitive[];
  2848. }
  2849. /** @hidden */
  2850. export interface IGLTFImage extends IGLTFChildRootProperty {
  2851. uri: string;
  2852. }
  2853. /** @hidden */
  2854. export interface IGLTFSampler extends IGLTFChildRootProperty {
  2855. magFilter?: number;
  2856. minFilter?: number;
  2857. wrapS?: number;
  2858. wrapT?: number;
  2859. }
  2860. /** @hidden */
  2861. export interface IGLTFTexture extends IGLTFChildRootProperty {
  2862. sampler: string;
  2863. source: string;
  2864. format?: ETextureFormat;
  2865. internalFormat?: ETextureFormat;
  2866. target?: number;
  2867. type?: number;
  2868. babylonTexture?: Texture;
  2869. }
  2870. /** @hidden */
  2871. export interface IGLTFAmbienLight {
  2872. color?: number[];
  2873. }
  2874. /** @hidden */
  2875. export interface IGLTFDirectionalLight {
  2876. color?: number[];
  2877. }
  2878. /** @hidden */
  2879. export interface IGLTFPointLight {
  2880. color?: number[];
  2881. constantAttenuation?: number;
  2882. linearAttenuation?: number;
  2883. quadraticAttenuation?: number;
  2884. }
  2885. /** @hidden */
  2886. export interface IGLTFSpotLight {
  2887. color?: number[];
  2888. constantAttenuation?: number;
  2889. fallOfAngle?: number;
  2890. fallOffExponent?: number;
  2891. linearAttenuation?: number;
  2892. quadraticAttenuation?: number;
  2893. }
  2894. /** @hidden */
  2895. export interface IGLTFLight extends IGLTFChildRootProperty {
  2896. type: string;
  2897. }
  2898. /** @hidden */
  2899. export interface IGLTFCameraOrthographic {
  2900. xmag: number;
  2901. ymag: number;
  2902. zfar: number;
  2903. znear: number;
  2904. }
  2905. /** @hidden */
  2906. export interface IGLTFCameraPerspective {
  2907. aspectRatio: number;
  2908. yfov: number;
  2909. zfar: number;
  2910. znear: number;
  2911. }
  2912. /** @hidden */
  2913. export interface IGLTFCamera extends IGLTFChildRootProperty {
  2914. type: string;
  2915. }
  2916. /** @hidden */
  2917. export interface IGLTFAnimationChannelTarget {
  2918. id: string;
  2919. path: string;
  2920. }
  2921. /** @hidden */
  2922. export interface IGLTFAnimationChannel {
  2923. sampler: string;
  2924. target: IGLTFAnimationChannelTarget;
  2925. }
  2926. /** @hidden */
  2927. export interface IGLTFAnimationSampler {
  2928. input: string;
  2929. output: string;
  2930. interpolation?: string;
  2931. }
  2932. /** @hidden */
  2933. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  2934. channels?: IGLTFAnimationChannel[];
  2935. parameters?: {
  2936. [key: string]: string;
  2937. };
  2938. samplers?: {
  2939. [key: string]: IGLTFAnimationSampler;
  2940. };
  2941. }
  2942. /** @hidden */
  2943. export interface IGLTFNodeInstanceSkin {
  2944. skeletons: string[];
  2945. skin: string;
  2946. meshes: string[];
  2947. }
  2948. /** @hidden */
  2949. export interface IGLTFSkins extends IGLTFChildRootProperty {
  2950. bindShapeMatrix: number[];
  2951. inverseBindMatrices: string;
  2952. jointNames: string[];
  2953. babylonSkeleton?: Skeleton;
  2954. }
  2955. /** @hidden */
  2956. export interface IGLTFNode extends IGLTFChildRootProperty {
  2957. camera?: string;
  2958. children: string[];
  2959. skin?: string;
  2960. jointName?: string;
  2961. light?: string;
  2962. matrix: number[];
  2963. mesh?: string;
  2964. meshes?: string[];
  2965. rotation?: number[];
  2966. scale?: number[];
  2967. translation?: number[];
  2968. babylonNode?: Node;
  2969. }
  2970. /** @hidden */
  2971. export interface IGLTFScene extends IGLTFChildRootProperty {
  2972. nodes: string[];
  2973. }
  2974. /** @hidden */
  2975. export interface IGLTFRuntime {
  2976. extensions: {
  2977. [key: string]: any;
  2978. };
  2979. accessors: {
  2980. [key: string]: IGLTFAccessor;
  2981. };
  2982. buffers: {
  2983. [key: string]: IGLTFBuffer;
  2984. };
  2985. bufferViews: {
  2986. [key: string]: IGLTFBufferView;
  2987. };
  2988. meshes: {
  2989. [key: string]: IGLTFMesh;
  2990. };
  2991. lights: {
  2992. [key: string]: IGLTFLight;
  2993. };
  2994. cameras: {
  2995. [key: string]: IGLTFCamera;
  2996. };
  2997. nodes: {
  2998. [key: string]: IGLTFNode;
  2999. };
  3000. images: {
  3001. [key: string]: IGLTFImage;
  3002. };
  3003. textures: {
  3004. [key: string]: IGLTFTexture;
  3005. };
  3006. shaders: {
  3007. [key: string]: IGLTFShader;
  3008. };
  3009. programs: {
  3010. [key: string]: IGLTFProgram;
  3011. };
  3012. samplers: {
  3013. [key: string]: IGLTFSampler;
  3014. };
  3015. techniques: {
  3016. [key: string]: IGLTFTechnique;
  3017. };
  3018. materials: {
  3019. [key: string]: IGLTFMaterial;
  3020. };
  3021. animations: {
  3022. [key: string]: IGLTFAnimation;
  3023. };
  3024. skins: {
  3025. [key: string]: IGLTFSkins;
  3026. };
  3027. currentScene?: Object;
  3028. scenes: {
  3029. [key: string]: IGLTFScene;
  3030. };
  3031. extensionsUsed: string[];
  3032. extensionsRequired?: string[];
  3033. buffersCount: number;
  3034. shaderscount: number;
  3035. scene: Scene;
  3036. rootUrl: string;
  3037. loadedBufferCount: number;
  3038. loadedBufferViews: {
  3039. [name: string]: ArrayBufferView;
  3040. };
  3041. loadedShaderCount: number;
  3042. importOnlyMeshes: boolean;
  3043. importMeshesNames?: string[];
  3044. dummyNodes: Node[];
  3045. }
  3046. /** @hidden */
  3047. export interface INodeToRoot {
  3048. bone: Bone;
  3049. node: IGLTFNode;
  3050. id: string;
  3051. }
  3052. /** @hidden */
  3053. export interface IJointNode {
  3054. node: IGLTFNode;
  3055. id: string;
  3056. }
  3057. }
  3058. declare module BABYLON.GLTF1 {
  3059. /**
  3060. * Utils functions for GLTF
  3061. * @hidden
  3062. */
  3063. export class GLTFUtils {
  3064. /**
  3065. * Sets the given "parameter" matrix
  3066. * @param scene: the Scene object
  3067. * @param source: the source node where to pick the matrix
  3068. * @param parameter: the GLTF technique parameter
  3069. * @param uniformName: the name of the shader's uniform
  3070. * @param shaderMaterial: the shader material
  3071. */
  3072. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  3073. /**
  3074. * Sets the given "parameter" matrix
  3075. * @param shaderMaterial: the shader material
  3076. * @param uniform: the name of the shader's uniform
  3077. * @param value: the value of the uniform
  3078. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3079. */
  3080. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  3081. /**
  3082. * Returns the wrap mode of the texture
  3083. * @param mode: the mode value
  3084. */
  3085. static GetWrapMode(mode: number): number;
  3086. /**
  3087. * Returns the byte stride giving an accessor
  3088. * @param accessor: the GLTF accessor objet
  3089. */
  3090. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  3091. /**
  3092. * Returns the texture filter mode giving a mode value
  3093. * @param mode: the filter mode value
  3094. */
  3095. static GetTextureFilterMode(mode: number): ETextureFilterType;
  3096. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  3097. /**
  3098. * Returns a buffer from its accessor
  3099. * @param gltfRuntime: the GLTF runtime
  3100. * @param accessor: the GLTF accessor
  3101. */
  3102. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  3103. /**
  3104. * Decodes a buffer view into a string
  3105. * @param view: the buffer view
  3106. */
  3107. static DecodeBufferToText(view: ArrayBufferView): string;
  3108. /**
  3109. * Returns the default material of gltf. Related to
  3110. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3111. * @param scene: the Babylon.js scene
  3112. */
  3113. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  3114. private static _DefaultMaterial;
  3115. }
  3116. }
  3117. declare module BABYLON.GLTF1 {
  3118. /**
  3119. * Implementation of the base glTF spec
  3120. * @hidden
  3121. */
  3122. export class GLTFLoaderBase {
  3123. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  3124. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3125. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  3126. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3127. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  3128. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3129. }
  3130. /**
  3131. * glTF V1 Loader
  3132. * @hidden
  3133. */
  3134. export class GLTFLoader implements IGLTFLoader {
  3135. static Extensions: {
  3136. [name: string]: GLTFLoaderExtension;
  3137. };
  3138. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3139. state: Nullable<GLTFLoaderState>;
  3140. dispose(): void;
  3141. private _importMeshAsync;
  3142. /**
  3143. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3144. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3145. * @param scene the scene the meshes should be added to
  3146. * @param data gltf data containing information of the meshes in a loaded file
  3147. * @param rootUrl root url to load from
  3148. * @param onProgress event that fires when loading progress has occured
  3149. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3150. */
  3151. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  3152. meshes: AbstractMesh[];
  3153. particleSystems: IParticleSystem[];
  3154. skeletons: Skeleton[];
  3155. animationGroups: AnimationGroup[];
  3156. }>;
  3157. private _loadAsync;
  3158. /**
  3159. * Imports all objects from a loaded gltf file and adds them to the scene
  3160. * @param scene the scene the objects should be added to
  3161. * @param data gltf data containing information of the meshes in a loaded file
  3162. * @param rootUrl root url to load from
  3163. * @param onProgress event that fires when loading progress has occured
  3164. * @returns a promise which completes when objects have been loaded to the scene
  3165. */
  3166. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3167. private _loadShadersAsync;
  3168. private _loadBuffersAsync;
  3169. private _createNodes;
  3170. }
  3171. /** @hidden */
  3172. export abstract class GLTFLoaderExtension {
  3173. private _name;
  3174. constructor(name: string);
  3175. readonly name: string;
  3176. /**
  3177. * Defines an override for loading the runtime
  3178. * Return true to stop further extensions from loading the runtime
  3179. */
  3180. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3181. /**
  3182. * Defines an onverride for creating gltf runtime
  3183. * Return true to stop further extensions from creating the runtime
  3184. */
  3185. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3186. /**
  3187. * Defines an override for loading buffers
  3188. * Return true to stop further extensions from loading this buffer
  3189. */
  3190. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3191. /**
  3192. * Defines an override for loading texture buffers
  3193. * Return true to stop further extensions from loading this texture data
  3194. */
  3195. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3196. /**
  3197. * Defines an override for creating textures
  3198. * Return true to stop further extensions from loading this texture
  3199. */
  3200. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3201. /**
  3202. * Defines an override for loading shader strings
  3203. * Return true to stop further extensions from loading this shader data
  3204. */
  3205. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3206. /**
  3207. * Defines an override for loading materials
  3208. * Return true to stop further extensions from loading this material
  3209. */
  3210. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3211. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3212. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3213. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3214. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3215. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3216. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3217. private static LoadTextureBufferAsync;
  3218. private static CreateTextureAsync;
  3219. private static ApplyExtensions;
  3220. }
  3221. }
  3222. declare module BABYLON.GLTF1 {
  3223. /** @hidden */
  3224. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3225. private _bin;
  3226. constructor();
  3227. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3228. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3229. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3230. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3231. }
  3232. }
  3233. declare module BABYLON.GLTF1 {
  3234. /** @hidden */
  3235. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3236. constructor();
  3237. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3238. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3239. private _loadTexture;
  3240. }
  3241. }
  3242. declare module BABYLON.GLTF2.Loader {
  3243. /**
  3244. * Loader interface with an index field.
  3245. */
  3246. export interface IArrayItem {
  3247. /**
  3248. * The index of this item in the array.
  3249. */
  3250. index: number;
  3251. }
  3252. /**
  3253. * Loader interface with additional members.
  3254. */
  3255. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3256. /** @hidden */
  3257. _data?: Promise<ArrayBufferView>;
  3258. /** @hidden */
  3259. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3260. }
  3261. /**
  3262. * Loader interface with additional members.
  3263. */
  3264. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3265. }
  3266. /** @hidden */
  3267. export interface _IAnimationSamplerData {
  3268. input: Float32Array;
  3269. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3270. output: Float32Array;
  3271. }
  3272. /**
  3273. * Loader interface with additional members.
  3274. */
  3275. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3276. /** @hidden */
  3277. _data?: Promise<_IAnimationSamplerData>;
  3278. }
  3279. /**
  3280. * Loader interface with additional members.
  3281. */
  3282. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3283. channels: IAnimationChannel[];
  3284. samplers: IAnimationSampler[];
  3285. /** @hidden */
  3286. _babylonAnimationGroup?: AnimationGroup;
  3287. }
  3288. /**
  3289. * Loader interface with additional members.
  3290. */
  3291. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3292. /** @hidden */
  3293. _data?: Promise<ArrayBufferView>;
  3294. }
  3295. /**
  3296. * Loader interface with additional members.
  3297. */
  3298. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3299. /** @hidden */
  3300. _data?: Promise<ArrayBufferView>;
  3301. /** @hidden */
  3302. _babylonBuffer?: Promise<Buffer>;
  3303. }
  3304. /**
  3305. * Loader interface with additional members.
  3306. */
  3307. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3308. }
  3309. /**
  3310. * Loader interface with additional members.
  3311. */
  3312. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3313. /** @hidden */
  3314. _data?: Promise<ArrayBufferView>;
  3315. }
  3316. /**
  3317. * Loader interface with additional members.
  3318. */
  3319. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3320. }
  3321. /**
  3322. * Loader interface with additional members.
  3323. */
  3324. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3325. }
  3326. /**
  3327. * Loader interface with additional members.
  3328. */
  3329. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3330. baseColorTexture?: ITextureInfo;
  3331. metallicRoughnessTexture?: ITextureInfo;
  3332. }
  3333. /**
  3334. * Loader interface with additional members.
  3335. */
  3336. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3337. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3338. normalTexture?: IMaterialNormalTextureInfo;
  3339. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3340. emissiveTexture?: ITextureInfo;
  3341. /** @hidden */
  3342. _data?: {
  3343. [babylonDrawMode: number]: {
  3344. babylonMaterial: Material;
  3345. babylonMeshes: AbstractMesh[];
  3346. promise: Promise<void>;
  3347. };
  3348. };
  3349. }
  3350. /**
  3351. * Loader interface with additional members.
  3352. */
  3353. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3354. primitives: IMeshPrimitive[];
  3355. }
  3356. /**
  3357. * Loader interface with additional members.
  3358. */
  3359. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3360. /** @hidden */
  3361. _instanceData?: {
  3362. babylonSourceMesh: Mesh;
  3363. promise: Promise<any>;
  3364. };
  3365. }
  3366. /**
  3367. * Loader interface with additional members.
  3368. */
  3369. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3370. /**
  3371. * The parent glTF node.
  3372. */
  3373. parent?: INode;
  3374. /** @hidden */
  3375. _babylonTransformNode?: TransformNode;
  3376. /** @hidden */
  3377. _primitiveBabylonMeshes?: AbstractMesh[];
  3378. /** @hidden */
  3379. _babylonBones?: Bone[];
  3380. /** @hidden */
  3381. _numMorphTargets?: number;
  3382. }
  3383. /** @hidden */
  3384. export interface _ISamplerData {
  3385. noMipMaps: boolean;
  3386. samplingMode: number;
  3387. wrapU: number;
  3388. wrapV: number;
  3389. }
  3390. /**
  3391. * Loader interface with additional members.
  3392. */
  3393. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3394. /** @hidden */
  3395. _data?: _ISamplerData;
  3396. }
  3397. /**
  3398. * Loader interface with additional members.
  3399. */
  3400. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3401. }
  3402. /**
  3403. * Loader interface with additional members.
  3404. */
  3405. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3406. /** @hidden */
  3407. _data?: {
  3408. babylonSkeleton: Skeleton;
  3409. promise: Promise<void>;
  3410. };
  3411. }
  3412. /**
  3413. * Loader interface with additional members.
  3414. */
  3415. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3416. }
  3417. /**
  3418. * Loader interface with additional members.
  3419. */
  3420. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3421. }
  3422. /**
  3423. * Loader interface with additional members.
  3424. */
  3425. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3426. accessors?: IAccessor[];
  3427. animations?: IAnimation[];
  3428. buffers?: IBuffer[];
  3429. bufferViews?: IBufferView[];
  3430. cameras?: ICamera[];
  3431. images?: IImage[];
  3432. materials?: IMaterial[];
  3433. meshes?: IMesh[];
  3434. nodes?: INode[];
  3435. samplers?: ISampler[];
  3436. scenes?: IScene[];
  3437. skins?: ISkin[];
  3438. textures?: ITexture[];
  3439. }
  3440. }
  3441. declare module BABYLON.GLTF2 {
  3442. /**
  3443. * Interface for a glTF loader extension.
  3444. */
  3445. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3446. /**
  3447. * Called after the loader state changes to LOADING.
  3448. */
  3449. onLoading?(): void;
  3450. /**
  3451. * Called after the loader state changes to READY.
  3452. */
  3453. onReady?(): void;
  3454. /**
  3455. * Define this method to modify the default behavior when loading scenes.
  3456. * @param context The context when loading the asset
  3457. * @param scene The glTF scene property
  3458. * @returns A promise that resolves when the load is complete or null if not handled
  3459. */
  3460. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3461. /**
  3462. * Define this method to modify the default behavior when loading nodes.
  3463. * @param context The context when loading the asset
  3464. * @param node The glTF node property
  3465. * @param assign A function called synchronously after parsing the glTF properties
  3466. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3467. */
  3468. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3469. /**
  3470. * Define this method to modify the default behavior when loading cameras.
  3471. * @param context The context when loading the asset
  3472. * @param camera The glTF camera property
  3473. * @param assign A function called synchronously after parsing the glTF properties
  3474. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3475. */
  3476. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3477. /**
  3478. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3479. * @param context The context when loading the asset
  3480. * @param primitive The glTF mesh primitive property
  3481. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3482. */
  3483. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3484. /**
  3485. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3486. * @param context The context when loading the asset
  3487. * @param name The mesh name when loading the asset
  3488. * @param node The glTF node when loading the asset
  3489. * @param mesh The glTF mesh when loading the asset
  3490. * @param primitive The glTF mesh primitive property
  3491. * @param assign A function called synchronously after parsing the glTF properties
  3492. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3493. */
  3494. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3495. /**
  3496. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3497. * @param context The context when loading the asset
  3498. * @param material The glTF material property
  3499. * @param assign A function called synchronously after parsing the glTF properties
  3500. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3501. */
  3502. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3503. /**
  3504. * Define this method to modify the default behavior when creating materials.
  3505. * @param context The context when loading the asset
  3506. * @param material The glTF material property
  3507. * @param babylonDrawMode The draw mode for the Babylon material
  3508. * @returns The Babylon material or null if not handled
  3509. */
  3510. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3511. /**
  3512. * Define this method to modify the default behavior when loading material properties.
  3513. * @param context The context when loading the asset
  3514. * @param material The glTF material property
  3515. * @param babylonMaterial The Babylon material
  3516. * @returns A promise that resolves when the load is complete or null if not handled
  3517. */
  3518. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3519. /**
  3520. * Define this method to modify the default behavior when loading texture infos.
  3521. * @param context The context when loading the asset
  3522. * @param textureInfo The glTF texture info property
  3523. * @param assign A function called synchronously after parsing the glTF properties
  3524. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3525. */
  3526. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3527. /**
  3528. * Define this method to modify the default behavior when loading animations.
  3529. * @param context The context when loading the asset
  3530. * @param animation The glTF animation property
  3531. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3532. */
  3533. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3534. /**
  3535. * @hidden Define this method to modify the default behavior when loading skins.
  3536. * @param context The context when loading the asset
  3537. * @param node The glTF node property
  3538. * @param skin The glTF skin property
  3539. * @returns A promise that resolves when the load is complete or null if not handled
  3540. */
  3541. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  3542. /**
  3543. * @hidden Define this method to modify the default behavior when loading uris.
  3544. * @param context The context when loading the asset
  3545. * @param property The glTF property associated with the uri
  3546. * @param uri The uri to load
  3547. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3548. */
  3549. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  3550. }
  3551. }
  3552. declare module BABYLON.GLTF2 {
  3553. /**
  3554. * Helper class for working with arrays when loading the glTF asset
  3555. */
  3556. export class ArrayItem {
  3557. /**
  3558. * Gets an item from the given array.
  3559. * @param context The context when loading the asset
  3560. * @param array The array to get the item from
  3561. * @param index The index to the array
  3562. * @returns The array item
  3563. */
  3564. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3565. /**
  3566. * Assign an `index` field to each item of the given array.
  3567. * @param array The array of items
  3568. */
  3569. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3570. }
  3571. /**
  3572. * The glTF 2.0 loader
  3573. */
  3574. export class GLTFLoader implements IGLTFLoader {
  3575. /** @hidden */
  3576. _completePromises: Promise<any>[];
  3577. private _disposed;
  3578. private _parent;
  3579. private _state;
  3580. private _extensions;
  3581. private _rootUrl;
  3582. private _fileName;
  3583. private _uniqueRootUrl;
  3584. private _gltf;
  3585. private _babylonScene;
  3586. private _rootBabylonMesh;
  3587. private _defaultBabylonMaterialData;
  3588. private _progressCallback?;
  3589. private _requests;
  3590. private static readonly _DefaultSampler;
  3591. private static _ExtensionNames;
  3592. private static _ExtensionFactories;
  3593. /**
  3594. * Registers a loader extension.
  3595. * @param name The name of the loader extension.
  3596. * @param factory The factory function that creates the loader extension.
  3597. */
  3598. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3599. /**
  3600. * Unregisters a loader extension.
  3601. * @param name The name of the loader extenion.
  3602. * @returns A boolean indicating whether the extension has been unregistered
  3603. */
  3604. static UnregisterExtension(name: string): boolean;
  3605. /**
  3606. * Gets the loader state.
  3607. */
  3608. readonly state: Nullable<GLTFLoaderState>;
  3609. /**
  3610. * The glTF object parsed from the JSON.
  3611. */
  3612. readonly gltf: IGLTF;
  3613. /**
  3614. * The Babylon scene when loading the asset.
  3615. */
  3616. readonly babylonScene: Scene;
  3617. /**
  3618. * The root Babylon mesh when loading the asset.
  3619. */
  3620. readonly rootBabylonMesh: Mesh;
  3621. /** @hidden */
  3622. constructor(parent: GLTFFileLoader);
  3623. /** @hidden */
  3624. dispose(): void;
  3625. /** @hidden */
  3626. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  3627. meshes: AbstractMesh[];
  3628. particleSystems: IParticleSystem[];
  3629. skeletons: Skeleton[];
  3630. animationGroups: AnimationGroup[];
  3631. }>;
  3632. /** @hidden */
  3633. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3634. private _loadAsync;
  3635. private _loadData;
  3636. private _setupData;
  3637. private _loadExtensions;
  3638. private _checkExtensions;
  3639. private _setState;
  3640. private _createRootNode;
  3641. /**
  3642. * Loads a glTF scene.
  3643. * @param context The context when loading the asset
  3644. * @param scene The glTF scene property
  3645. * @returns A promise that resolves when the load is complete
  3646. */
  3647. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3648. private _forEachPrimitive;
  3649. private _getMeshes;
  3650. private _getSkeletons;
  3651. private _getAnimationGroups;
  3652. private _startAnimations;
  3653. /**
  3654. * Loads a glTF node.
  3655. * @param context The context when loading the asset
  3656. * @param node The glTF node property
  3657. * @param assign A function called synchronously after parsing the glTF properties
  3658. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3659. */
  3660. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3661. private _loadMeshAsync;
  3662. /**
  3663. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3664. * @param context The context when loading the asset
  3665. * @param name The mesh name when loading the asset
  3666. * @param node The glTF node when loading the asset
  3667. * @param mesh The glTF mesh when loading the asset
  3668. * @param primitive The glTF mesh primitive property
  3669. * @param assign A function called synchronously after parsing the glTF properties
  3670. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3671. */
  3672. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3673. private _loadVertexDataAsync;
  3674. private _createMorphTargets;
  3675. private _loadMorphTargetsAsync;
  3676. private _loadMorphTargetVertexDataAsync;
  3677. private static _LoadTransform;
  3678. private _loadSkinAsync;
  3679. private _loadBones;
  3680. private _loadBone;
  3681. private _loadSkinInverseBindMatricesDataAsync;
  3682. private _updateBoneMatrices;
  3683. private _getNodeMatrix;
  3684. /**
  3685. * Loads a glTF camera.
  3686. * @param context The context when loading the asset
  3687. * @param camera The glTF camera property
  3688. * @param assign A function called synchronously after parsing the glTF properties
  3689. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3690. */
  3691. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  3692. private _loadAnimationsAsync;
  3693. /**
  3694. * Loads a glTF animation.
  3695. * @param context The context when loading the asset
  3696. * @param animation The glTF animation property
  3697. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3698. */
  3699. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  3700. /**
  3701. * @hidden Loads a glTF animation channel.
  3702. * @param context The context when loading the asset
  3703. * @param animationContext The context of the animation when loading the asset
  3704. * @param animation The glTF animation property
  3705. * @param channel The glTF animation channel property
  3706. * @param babylonAnimationGroup The babylon animation group property
  3707. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3708. * @returns A void promise when the channel load is complete
  3709. */
  3710. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  3711. private _loadAnimationSamplerAsync;
  3712. private _loadBufferAsync;
  3713. /**
  3714. * Loads a glTF buffer view.
  3715. * @param context The context when loading the asset
  3716. * @param bufferView The glTF buffer view property
  3717. * @returns A promise that resolves with the loaded data when the load is complete
  3718. */
  3719. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  3720. private _loadIndicesAccessorAsync;
  3721. private _loadFloatAccessorAsync;
  3722. private _loadVertexBufferViewAsync;
  3723. private _loadVertexAccessorAsync;
  3724. private _loadMaterialMetallicRoughnessPropertiesAsync;
  3725. /** @hidden */
  3726. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  3727. private _createDefaultMaterial;
  3728. /**
  3729. * Creates a Babylon material from a glTF material.
  3730. * @param context The context when loading the asset
  3731. * @param material The glTF material property
  3732. * @param babylonDrawMode The draw mode for the Babylon material
  3733. * @returns The Babylon material
  3734. */
  3735. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  3736. /**
  3737. * Loads properties from a glTF material into a Babylon material.
  3738. * @param context The context when loading the asset
  3739. * @param material The glTF material property
  3740. * @param babylonMaterial The Babylon material
  3741. * @returns A promise that resolves when the load is complete
  3742. */
  3743. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3744. /**
  3745. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3746. * @param context The context when loading the asset
  3747. * @param material The glTF material property
  3748. * @param babylonMaterial The Babylon material
  3749. * @returns A promise that resolves when the load is complete
  3750. */
  3751. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  3752. /**
  3753. * Loads the alpha properties from a glTF material into a Babylon material.
  3754. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3755. * @param context The context when loading the asset
  3756. * @param material The glTF material property
  3757. * @param babylonMaterial The Babylon material
  3758. */
  3759. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  3760. /**
  3761. * Loads a glTF texture info.
  3762. * @param context The context when loading the asset
  3763. * @param textureInfo The glTF texture info property
  3764. * @param assign A function called synchronously after parsing the glTF properties
  3765. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3766. */
  3767. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  3768. private _loadTextureAsync;
  3769. private _loadSampler;
  3770. /**
  3771. * Loads a glTF image.
  3772. * @param context The context when loading the asset
  3773. * @param image The glTF image property
  3774. * @returns A promise that resolves with the loaded data when the load is complete
  3775. */
  3776. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  3777. /**
  3778. * Loads a glTF uri.
  3779. * @param context The context when loading the asset
  3780. * @param property The glTF property associated with the uri
  3781. * @param uri The base64 or relative uri
  3782. * @returns A promise that resolves with the loaded data when the load is complete
  3783. */
  3784. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  3785. private _onProgress;
  3786. /**
  3787. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3788. * @param babylonObject the Babylon object with metadata
  3789. * @param pointer the JSON pointer
  3790. */
  3791. static AddPointerMetadata(babylonObject: {
  3792. metadata: any;
  3793. }, pointer: string): void;
  3794. private static _GetTextureWrapMode;
  3795. private static _GetTextureSamplingMode;
  3796. private static _GetTypedArray;
  3797. private static _GetNumComponents;
  3798. private static _ValidateUri;
  3799. private static _GetDrawMode;
  3800. private _compileMaterialsAsync;
  3801. private _compileShadowGeneratorsAsync;
  3802. private _forEachExtensions;
  3803. private _applyExtensions;
  3804. private _extensionsOnLoading;
  3805. private _extensionsOnReady;
  3806. private _extensionsLoadSceneAsync;
  3807. private _extensionsLoadNodeAsync;
  3808. private _extensionsLoadCameraAsync;
  3809. private _extensionsLoadVertexDataAsync;
  3810. private _extensionsLoadMeshPrimitiveAsync;
  3811. private _extensionsLoadMaterialAsync;
  3812. private _extensionsCreateMaterial;
  3813. private _extensionsLoadMaterialPropertiesAsync;
  3814. private _extensionsLoadTextureInfoAsync;
  3815. private _extensionsLoadAnimationAsync;
  3816. private _extensionsLoadSkinAsync;
  3817. private _extensionsLoadUriAsync;
  3818. /**
  3819. * Helper method called by a loader extension to load an glTF extension.
  3820. * @param context The context when loading the asset
  3821. * @param property The glTF property to load the extension from
  3822. * @param extensionName The name of the extension to load
  3823. * @param actionAsync The action to run
  3824. * @returns The promise returned by actionAsync or null if the extension does not exist
  3825. */
  3826. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3827. /**
  3828. * Helper method called by a loader extension to load a glTF extra.
  3829. * @param context The context when loading the asset
  3830. * @param property The glTF property to load the extra from
  3831. * @param extensionName The name of the extension to load
  3832. * @param actionAsync The action to run
  3833. * @returns The promise returned by actionAsync or null if the extra does not exist
  3834. */
  3835. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  3836. /**
  3837. * Increments the indentation level and logs a message.
  3838. * @param message The message to log
  3839. */
  3840. logOpen(message: string): void;
  3841. /**
  3842. * Decrements the indentation level.
  3843. */
  3844. logClose(): void;
  3845. /**
  3846. * Logs a message
  3847. * @param message The message to log
  3848. */
  3849. log(message: string): void;
  3850. /**
  3851. * Starts a performance counter.
  3852. * @param counterName The name of the performance counter
  3853. */
  3854. startPerformanceCounter(counterName: string): void;
  3855. /**
  3856. * Ends a performance counter.
  3857. * @param counterName The name of the performance counter
  3858. */
  3859. endPerformanceCounter(counterName: string): void;
  3860. }
  3861. }
  3862. declare module BABYLON.GLTF2.Loader.Extensions {
  3863. /**
  3864. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  3865. */
  3866. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  3867. /** The name of this extension. */
  3868. readonly name: string;
  3869. /** Defines whether this extension is enabled. */
  3870. enabled: boolean;
  3871. private _loader;
  3872. private _lights?;
  3873. /** @hidden */
  3874. constructor(loader: GLTFLoader);
  3875. /** @hidden */
  3876. dispose(): void;
  3877. /** @hidden */
  3878. onLoading(): void;
  3879. /** @hidden */
  3880. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  3881. private _loadLightAsync;
  3882. }
  3883. }
  3884. declare module BABYLON.GLTF2.Loader.Extensions {
  3885. /**
  3886. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  3887. */
  3888. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  3889. /** The name of this extension. */
  3890. readonly name: string;
  3891. /** The draco compression used to decode vertex data. */
  3892. dracoCompression?: DracoCompression;
  3893. /** Defines whether this extension is enabled. */
  3894. enabled: boolean;
  3895. private _loader;
  3896. private _dracoCompressionOwned;
  3897. /** @hidden */
  3898. constructor(loader: GLTFLoader);
  3899. /** @hidden */
  3900. dispose(): void;
  3901. /** @hidden */
  3902. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3903. }
  3904. }
  3905. declare module BABYLON.GLTF2.Loader.Extensions {
  3906. /**
  3907. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  3908. */
  3909. export class KHR_lights implements IGLTFLoaderExtension {
  3910. /** The name of this extension. */
  3911. readonly name: string;
  3912. /** Defines whether this extension is enabled. */
  3913. enabled: boolean;
  3914. private _loader;
  3915. private _lights?;
  3916. /** @hidden */
  3917. constructor(loader: GLTFLoader);
  3918. /** @hidden */
  3919. dispose(): void;
  3920. /** @hidden */
  3921. onLoading(): void;
  3922. /** @hidden */
  3923. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3924. }
  3925. }
  3926. declare module BABYLON.GLTF2.Loader.Extensions {
  3927. /**
  3928. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  3929. */
  3930. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  3931. /** The name of this extension. */
  3932. readonly name: string;
  3933. /** Defines whether this extension is enabled. */
  3934. enabled: boolean;
  3935. private _loader;
  3936. /** @hidden */
  3937. constructor(loader: GLTFLoader);
  3938. /** @hidden */
  3939. dispose(): void;
  3940. /** @hidden */
  3941. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3942. private _loadSpecularGlossinessPropertiesAsync;
  3943. }
  3944. }
  3945. declare module BABYLON.GLTF2.Loader.Extensions {
  3946. /**
  3947. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  3948. */
  3949. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  3950. /** The name of this extension. */
  3951. readonly name: string;
  3952. /** Defines whether this extension is enabled. */
  3953. enabled: boolean;
  3954. private _loader;
  3955. /** @hidden */
  3956. constructor(loader: GLTFLoader);
  3957. /** @hidden */
  3958. dispose(): void;
  3959. /** @hidden */
  3960. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3961. private _loadUnlitPropertiesAsync;
  3962. }
  3963. }
  3964. declare module BABYLON.GLTF2.Loader.Extensions {
  3965. /**
  3966. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  3967. */
  3968. export class KHR_texture_transform implements IGLTFLoaderExtension {
  3969. /** The name of this extension. */
  3970. readonly name: string;
  3971. /** Defines whether this extension is enabled. */
  3972. enabled: boolean;
  3973. private _loader;
  3974. /** @hidden */
  3975. constructor(loader: GLTFLoader);
  3976. /** @hidden */
  3977. dispose(): void;
  3978. /** @hidden */
  3979. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3980. }
  3981. }
  3982. declare module BABYLON.GLTF2.Loader.Extensions {
  3983. /**
  3984. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  3985. */
  3986. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  3987. /** The name of this extension. */
  3988. readonly name: string;
  3989. /** Defines whether this extension is enabled. */
  3990. enabled: boolean;
  3991. private _loader;
  3992. private _clips;
  3993. private _emitters;
  3994. /** @hidden */
  3995. constructor(loader: GLTFLoader);
  3996. /** @hidden */
  3997. dispose(): void;
  3998. /** @hidden */
  3999. onLoading(): void;
  4000. /** @hidden */
  4001. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4002. /** @hidden */
  4003. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4004. /** @hidden */
  4005. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  4006. private _loadClipAsync;
  4007. private _loadEmitterAsync;
  4008. private _getEventAction;
  4009. private _loadAnimationEventAsync;
  4010. }
  4011. }
  4012. declare module BABYLON.GLTF2.Loader.Extensions {
  4013. /**
  4014. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4015. */
  4016. export class MSFT_lod implements IGLTFLoaderExtension {
  4017. /** The name of this extension. */
  4018. readonly name: string;
  4019. /** Defines whether this extension is enabled. */
  4020. enabled: boolean;
  4021. /**
  4022. * Maximum number of LODs to load, starting from the lowest LOD.
  4023. */
  4024. maxLODsToLoad: number;
  4025. /**
  4026. * Observable raised when all node LODs of one level are loaded.
  4027. * The event data is the index of the loaded LOD starting from zero.
  4028. * Dispose the loader to cancel the loading of the next level of LODs.
  4029. */
  4030. onNodeLODsLoadedObservable: Observable<number>;
  4031. /**
  4032. * Observable raised when all material LODs of one level are loaded.
  4033. * The event data is the index of the loaded LOD starting from zero.
  4034. * Dispose the loader to cancel the loading of the next level of LODs.
  4035. */
  4036. onMaterialLODsLoadedObservable: Observable<number>;
  4037. private _loader;
  4038. private _nodeIndexLOD;
  4039. private _nodeSignalLODs;
  4040. private _nodePromiseLODs;
  4041. private _materialIndexLOD;
  4042. private _materialSignalLODs;
  4043. private _materialPromiseLODs;
  4044. /** @hidden */
  4045. constructor(loader: GLTFLoader);
  4046. /** @hidden */
  4047. dispose(): void;
  4048. /** @hidden */
  4049. onReady(): void;
  4050. /** @hidden */
  4051. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4052. /** @hidden */
  4053. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  4054. /** @hidden */
  4055. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  4056. /**
  4057. * Gets an array of LOD properties from lowest to highest.
  4058. */
  4059. private _getLODs;
  4060. private _disposeUnusedMaterials;
  4061. }
  4062. }
  4063. declare module BABYLON.GLTF2.Loader.Extensions {
  4064. /** @hidden */
  4065. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  4066. readonly name: string;
  4067. enabled: boolean;
  4068. private _loader;
  4069. constructor(loader: GLTFLoader);
  4070. dispose(): void;
  4071. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4072. }
  4073. }
  4074. declare module BABYLON.GLTF2.Loader.Extensions {
  4075. /** @hidden */
  4076. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  4077. readonly name: string;
  4078. enabled: boolean;
  4079. private _loader;
  4080. constructor(loader: GLTFLoader);
  4081. dispose(): void;
  4082. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4083. }
  4084. }
  4085. declare module BABYLON {
  4086. /**
  4087. * Class reading and parsing the MTL file bundled with the obj file.
  4088. */
  4089. export class MTLFileLoader {
  4090. /**
  4091. * All material loaded from the mtl will be set here
  4092. */
  4093. materials: StandardMaterial[];
  4094. /**
  4095. * This function will read the mtl file and create each material described inside
  4096. * This function could be improve by adding :
  4097. * -some component missing (Ni, Tf...)
  4098. * -including the specific options available
  4099. *
  4100. * @param scene defines the scene the material will be created in
  4101. * @param data defines the mtl data to parse
  4102. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  4103. */
  4104. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  4105. /**
  4106. * Gets the texture for the material.
  4107. *
  4108. * If the material is imported from input file,
  4109. * We sanitize the url to ensure it takes the textre from aside the material.
  4110. *
  4111. * @param rootUrl The root url to load from
  4112. * @param value The value stored in the mtl
  4113. * @return The Texture
  4114. */
  4115. private static _getTexture;
  4116. }
  4117. /**
  4118. * Options for loading OBJ/MTL files
  4119. */
  4120. type MeshLoadOptions = {
  4121. /**
  4122. * Defines if UVs are optimized by default during load.
  4123. */
  4124. OptimizeWithUV: boolean;
  4125. /**
  4126. * Defines custom scaling of UV coordinates of loaded meshes.
  4127. */
  4128. UVScaling: Vector2;
  4129. /**
  4130. * Invert model on y-axis (does a model scaling inversion)
  4131. */
  4132. InvertY: boolean;
  4133. /**
  4134. * Invert Y-Axis of referenced textures on load
  4135. */
  4136. InvertTextureY: boolean;
  4137. /**
  4138. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4139. */
  4140. ImportVertexColors: boolean;
  4141. /**
  4142. * Compute the normals for the model, even if normals are present in the file.
  4143. */
  4144. ComputeNormals: boolean;
  4145. /**
  4146. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4147. */
  4148. SkipMaterials: boolean;
  4149. /**
  4150. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4151. */
  4152. MaterialLoadingFailsSilently: boolean;
  4153. };
  4154. /**
  4155. * OBJ file type loader.
  4156. * This is a babylon scene loader plugin.
  4157. */
  4158. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  4159. /**
  4160. * Defines if UVs are optimized by default during load.
  4161. */
  4162. static OPTIMIZE_WITH_UV: boolean;
  4163. /**
  4164. * Invert model on y-axis (does a model scaling inversion)
  4165. */
  4166. static INVERT_Y: boolean;
  4167. /**
  4168. * Invert Y-Axis of referenced textures on load
  4169. */
  4170. static INVERT_TEXTURE_Y: boolean;
  4171. /**
  4172. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4173. */
  4174. static IMPORT_VERTEX_COLORS: boolean;
  4175. /**
  4176. * Compute the normals for the model, even if normals are present in the file.
  4177. */
  4178. static COMPUTE_NORMALS: boolean;
  4179. /**
  4180. * Defines custom scaling of UV coordinates of loaded meshes.
  4181. */
  4182. static UV_SCALING: Vector2;
  4183. /**
  4184. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4185. */
  4186. static SKIP_MATERIALS: boolean;
  4187. /**
  4188. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4189. *
  4190. * Defaults to true for backwards compatibility.
  4191. */
  4192. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  4193. /**
  4194. * Defines the name of the plugin.
  4195. */
  4196. name: string;
  4197. /**
  4198. * Defines the extension the plugin is able to load.
  4199. */
  4200. extensions: string;
  4201. /** @hidden */
  4202. obj: RegExp;
  4203. /** @hidden */
  4204. group: RegExp;
  4205. /** @hidden */
  4206. mtllib: RegExp;
  4207. /** @hidden */
  4208. usemtl: RegExp;
  4209. /** @hidden */
  4210. smooth: RegExp;
  4211. /** @hidden */
  4212. vertexPattern: RegExp;
  4213. /** @hidden */
  4214. normalPattern: RegExp;
  4215. /** @hidden */
  4216. uvPattern: RegExp;
  4217. /** @hidden */
  4218. facePattern1: RegExp;
  4219. /** @hidden */
  4220. facePattern2: RegExp;
  4221. /** @hidden */
  4222. facePattern3: RegExp;
  4223. /** @hidden */
  4224. facePattern4: RegExp;
  4225. /** @hidden */
  4226. facePattern5: RegExp;
  4227. private _meshLoadOptions;
  4228. /**
  4229. * Creates loader for .OBJ files
  4230. *
  4231. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  4232. */
  4233. constructor(meshLoadOptions?: MeshLoadOptions);
  4234. private static readonly currentMeshLoadOptions;
  4235. /**
  4236. * Calls synchronously the MTL file attached to this obj.
  4237. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  4238. * Without this function materials are not displayed in the first frame (but displayed after).
  4239. * In consequence it is impossible to get material information in your HTML file
  4240. *
  4241. * @param url The URL of the MTL file
  4242. * @param rootUrl
  4243. * @param onSuccess Callback function to be called when the MTL file is loaded
  4244. * @private
  4245. */
  4246. private _loadMTL;
  4247. /**
  4248. * Instantiates a OBJ file loader plugin.
  4249. * @returns the created plugin
  4250. */
  4251. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  4252. /**
  4253. * If the data string can be loaded directly.
  4254. *
  4255. * @param data string containing the file data
  4256. * @returns if the data can be loaded directly
  4257. */
  4258. canDirectLoad(data: string): boolean;
  4259. /**
  4260. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  4261. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  4262. * @param scene the scene the meshes should be added to
  4263. * @param data the OBJ data to load
  4264. * @param rootUrl root url to load from
  4265. * @param onProgress event that fires when loading progress has occured
  4266. * @param fileName Defines the name of the file to load
  4267. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4268. */
  4269. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4270. meshes: AbstractMesh[];
  4271. particleSystems: IParticleSystem[];
  4272. skeletons: Skeleton[];
  4273. animationGroups: AnimationGroup[];
  4274. }>;
  4275. /**
  4276. * Imports all objects from the loaded OBJ data and adds them to the scene
  4277. * @param scene the scene the objects should be added to
  4278. * @param data the OBJ data to load
  4279. * @param rootUrl root url to load from
  4280. * @param onProgress event that fires when loading progress has occured
  4281. * @param fileName Defines the name of the file to load
  4282. * @returns a promise which completes when objects have been loaded to the scene
  4283. */
  4284. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4285. /**
  4286. * Load into an asset container.
  4287. * @param scene The scene to load into
  4288. * @param data The data to import
  4289. * @param rootUrl The root url for scene and resources
  4290. * @param onProgress The callback when the load progresses
  4291. * @param fileName Defines the name of the file to load
  4292. * @returns The loaded asset container
  4293. */
  4294. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4295. /**
  4296. * Read the OBJ file and create an Array of meshes.
  4297. * Each mesh contains all information given by the OBJ and the MTL file.
  4298. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4299. *
  4300. * @param meshesNames
  4301. * @param scene Scene The scene where are displayed the data
  4302. * @param data String The content of the obj file
  4303. * @param rootUrl String The path to the folder
  4304. * @returns Array<AbstractMesh>
  4305. * @private
  4306. */
  4307. private _parseSolid;
  4308. }
  4309. }
  4310. declare module BABYLON {
  4311. /**
  4312. * STL file type loader.
  4313. * This is a babylon scene loader plugin.
  4314. */
  4315. export class STLFileLoader implements ISceneLoaderPlugin {
  4316. /** @hidden */
  4317. solidPattern: RegExp;
  4318. /** @hidden */
  4319. facetsPattern: RegExp;
  4320. /** @hidden */
  4321. normalPattern: RegExp;
  4322. /** @hidden */
  4323. vertexPattern: RegExp;
  4324. /**
  4325. * Defines the name of the plugin.
  4326. */
  4327. name: string;
  4328. /**
  4329. * Defines the extensions the stl loader is able to load.
  4330. * force data to come in as an ArrayBuffer
  4331. * we'll convert to string if it looks like it's an ASCII .stl
  4332. */
  4333. extensions: ISceneLoaderPluginExtensions;
  4334. /**
  4335. * Import meshes into a scene.
  4336. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4337. * @param scene The scene to import into
  4338. * @param data The data to import
  4339. * @param rootUrl The root url for scene and resources
  4340. * @param meshes The meshes array to import into
  4341. * @param particleSystems The particle systems array to import into
  4342. * @param skeletons The skeletons array to import into
  4343. * @param onError The callback when import fails
  4344. * @returns True if successful or false otherwise
  4345. */
  4346. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4347. /**
  4348. * Load into a scene.
  4349. * @param scene The scene to load into
  4350. * @param data The data to import
  4351. * @param rootUrl The root url for scene and resources
  4352. * @param onError The callback when import fails
  4353. * @returns true if successful or false otherwise
  4354. */
  4355. load(scene: Scene, data: any, rootUrl: string): boolean;
  4356. /**
  4357. * Load into an asset container.
  4358. * @param scene The scene to load into
  4359. * @param data The data to import
  4360. * @param rootUrl The root url for scene and resources
  4361. * @param onError The callback when import fails
  4362. * @returns The loaded asset container
  4363. */
  4364. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4365. private _isBinary;
  4366. private _parseBinary;
  4367. private _parseASCII;
  4368. }
  4369. }