babylonjs.loaders.module.d.ts 197 KB

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