glTFLoaderExtension.d.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import type { Nullable } from "@babylonjs/core/types.js";
  2. import type { Animation } from "@babylonjs/core/Animations/animation.js";
  3. import type { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
  4. import type { Material } from "@babylonjs/core/Materials/material.js";
  5. import type { Camera } from "@babylonjs/core/Cameras/camera.js";
  6. import type { Geometry } from "@babylonjs/core/Meshes/geometry.js";
  7. import type { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
  8. import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
  9. import type { Mesh } from "@babylonjs/core/Meshes/mesh.js";
  10. import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
  11. import type { IDisposable } from "@babylonjs/core/scene.js";
  12. import type { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation, ITexture, IBufferView, IBuffer, IAnimationChannel } from "./glTFLoaderInterfaces";
  13. import type { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "../glTFFileLoader";
  14. import type { IProperty } from "babylonjs-gltf2interface";
  15. import type { IAnimatable } from "@babylonjs/core/Animations/animatable.interface.js";
  16. /**
  17. * Interface for a glTF loader extension.
  18. */
  19. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  20. /**
  21. * Called after the loader state changes to LOADING.
  22. */
  23. onLoading?(): void;
  24. /**
  25. * Called after the loader state changes to READY.
  26. */
  27. onReady?(): void;
  28. /**
  29. * Define this method to modify the default behavior when loading scenes.
  30. * @param context The context when loading the asset
  31. * @param scene The glTF scene property
  32. * @returns A promise that resolves when the load is complete or null if not handled
  33. */
  34. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  35. /**
  36. * Define this method to modify the default behavior when loading nodes.
  37. * @param context The context when loading the asset
  38. * @param node The glTF node property
  39. * @param assign A function called synchronously after parsing the glTF properties
  40. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  41. */
  42. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  43. /**
  44. * Define this method to modify the default behavior when loading cameras.
  45. * @param context The context when loading the asset
  46. * @param camera The glTF camera property
  47. * @param assign A function called synchronously after parsing the glTF properties
  48. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  49. */
  50. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  51. /**
  52. * @internal
  53. * Define this method to modify the default behavior when loading vertex data for mesh primitives.
  54. * @param context The context when loading the asset
  55. * @param primitive The glTF mesh primitive property
  56. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  57. */
  58. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  59. /**
  60. * @internal
  61. * Define this method to modify the default behavior when loading data for mesh primitives.
  62. * @param context The context when loading the asset
  63. * @param name The mesh name when loading the asset
  64. * @param node The glTF node when loading the asset
  65. * @param mesh The glTF mesh when loading the asset
  66. * @param primitive The glTF mesh primitive property
  67. * @param assign A function called synchronously after parsing the glTF properties
  68. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  69. */
  70. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  71. /**
  72. * @internal
  73. * Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  74. * @param context The context when loading the asset
  75. * @param material The glTF material property
  76. * @param assign A function called synchronously after parsing the glTF properties
  77. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  78. */
  79. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Nullable<Mesh>, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  80. /**
  81. * Define this method to modify the default behavior when creating materials.
  82. * @param context The context when loading the asset
  83. * @param material The glTF material property
  84. * @param babylonDrawMode The draw mode for the Babylon material
  85. * @returns The Babylon material or null if not handled
  86. */
  87. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  88. /**
  89. * Define this method to modify the default behavior when loading material properties.
  90. * @param context The context when loading the asset
  91. * @param material The glTF material property
  92. * @param babylonMaterial The Babylon material
  93. * @returns A promise that resolves when the load is complete or null if not handled
  94. */
  95. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  96. /**
  97. * Define this method to modify the default behavior when loading texture infos.
  98. * @param context The context when loading the asset
  99. * @param textureInfo The glTF texture info property
  100. * @param assign A function called synchronously after parsing the glTF properties
  101. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  102. */
  103. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  104. /**
  105. * @internal
  106. * Define this method to modify the default behavior when loading textures.
  107. * @param context The context when loading the asset
  108. * @param texture The glTF texture property
  109. * @param assign A function called synchronously after parsing the glTF properties
  110. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  111. */
  112. _loadTextureAsync?(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  113. /**
  114. * Define this method to modify the default behavior when loading animations.
  115. * @param context The context when loading the asset
  116. * @param animation The glTF animation property
  117. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  118. */
  119. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  120. /**
  121. * @internal
  122. * Define this method to modify the default behvaior when loading animation channels.
  123. * @param context The context when loading the asset
  124. * @param animationContext The context of the animation when loading the asset
  125. * @param animation The glTF animation property
  126. * @param channel The glTF animation channel property
  127. * @param onLoad Called for each animation loaded
  128. * @returns A void promise that resolves when the load is complete or null if not handled
  129. */
  130. _loadAnimationChannelAsync?(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Nullable<Promise<void>>;
  131. /**
  132. * @internal
  133. * Define this method to modify the default behavior when loading skins.
  134. * @param context The context when loading the asset
  135. * @param node The glTF node property
  136. * @param skin The glTF skin property
  137. * @returns A promise that resolves when the load is complete or null if not handled
  138. */
  139. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  140. /**
  141. * @internal
  142. * Define this method to modify the default behavior when loading uris.
  143. * @param context The context when loading the asset
  144. * @param property The glTF property associated with the uri
  145. * @param uri The uri to load
  146. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  147. */
  148. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  149. /**
  150. * Define this method to modify the default behavior when loading buffer views.
  151. * @param context The context when loading the asset
  152. * @param bufferView The glTF buffer view property
  153. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  154. */
  155. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  156. /**
  157. * Define this method to modify the default behavior when loading buffers.
  158. * @param context The context when loading the asset
  159. * @param buffer The glTF buffer property
  160. * @param byteOffset The byte offset to load
  161. * @param byteLength The byte length to load
  162. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  163. */
  164. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  165. }