babylonjs.loaders.module.d.ts 203 KB

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