glTFLoaderExtension.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { IDisposable } from "babylonjs/scene";
  10. import { IScene, INode, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation } from "./glTFLoaderInterfaces";
  11. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "../glTFFileLoader";
  12. import { IProperty } from 'babylonjs-gltf2interface';
  13. /**
  14. * Interface for a glTF loader extension.
  15. */
  16. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  17. /**
  18. * Called after the loader state changes to LOADING.
  19. */
  20. onLoading?(): void;
  21. /**
  22. * Called after the loader state changes to READY.
  23. */
  24. onReady?(): void;
  25. /**
  26. * Define this method to modify the default behavior when loading scenes.
  27. * @param context The context when loading the asset
  28. * @param scene The glTF scene property
  29. * @returns A promise that resolves when the load is complete or null if not handled
  30. */
  31. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  32. /**
  33. * Define this method to modify the default behavior when loading nodes.
  34. * @param context The context when loading the asset
  35. * @param node The glTF node property
  36. * @param assign A function called synchronously after parsing the glTF properties
  37. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  38. */
  39. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  40. /**
  41. * Define this method to modify the default behavior when loading cameras.
  42. * @param context The context when loading the asset
  43. * @param camera The glTF camera property
  44. * @param assign A function called synchronously after parsing the glTF properties
  45. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  46. */
  47. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  48. /**
  49. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  50. * @param context The context when loading the asset
  51. * @param primitive The glTF mesh primitive property
  52. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  53. */
  54. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  55. /**
  56. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  57. * @param context The context when loading the asset
  58. * @param material The glTF material property
  59. * @param assign A function called synchronously after parsing the glTF properties
  60. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  61. */
  62. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  63. /**
  64. * Define this method to modify the default behavior when creating materials.
  65. * @param context The context when loading the asset
  66. * @param material The glTF material property
  67. * @param babylonDrawMode The draw mode for the Babylon material
  68. * @returns The Babylon material or null if not handled
  69. */
  70. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  71. /**
  72. * Define this method to modify the default behavior when loading material properties.
  73. * @param context The context when loading the asset
  74. * @param material The glTF material property
  75. * @param babylonMaterial The Babylon material
  76. * @returns A promise that resolves when the load is complete or null if not handled
  77. */
  78. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  79. /**
  80. * Define this method to modify the default behavior when loading texture infos.
  81. * @param context The context when loading the asset
  82. * @param textureInfo The glTF texture info property
  83. * @param assign A function called synchronously after parsing the glTF properties
  84. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  85. */
  86. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  87. /**
  88. * Define this method to modify the default behavior when loading animations.
  89. * @param context The context when loading the asset
  90. * @param animation The glTF animation property
  91. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  92. */
  93. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  94. /**
  95. * Define this method to modify the default behavior when loading uris.
  96. * @param context The context when loading the asset
  97. * @param property The glTF property associated with the uri
  98. * @param uri The uri to load
  99. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  100. */
  101. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  102. }