glTFLoaderExtension.ts 9.2 KB

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