babylonjs.loaders.module.d.ts 203 KB

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