glTFLoaderExtension.ts 8.9 KB

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