objFileLoader.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
  2. import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from "@babylonjs/core/Loading/sceneLoader.js";
  3. import { AssetContainer } from "@babylonjs/core/assetContainer.js";
  4. import type { Scene } from "@babylonjs/core/scene.js";
  5. import type { OBJLoadingOptions } from "./objLoadingOptions";
  6. /**
  7. * OBJ file type loader.
  8. * This is a babylon scene loader plugin.
  9. */
  10. export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  11. /**
  12. * Defines if UVs are optimized by default during load.
  13. */
  14. static OPTIMIZE_WITH_UV: boolean;
  15. /**
  16. * Invert model on y-axis (does a model scaling inversion)
  17. */
  18. static INVERT_Y: boolean;
  19. /**
  20. * Invert Y-Axis of referenced textures on load
  21. */
  22. static get INVERT_TEXTURE_Y(): boolean;
  23. static set INVERT_TEXTURE_Y(value: boolean);
  24. /**
  25. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  26. */
  27. static IMPORT_VERTEX_COLORS: boolean;
  28. /**
  29. * Compute the normals for the model, even if normals are present in the file.
  30. */
  31. static COMPUTE_NORMALS: boolean;
  32. /**
  33. * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.
  34. * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
  35. */
  36. static OPTIMIZE_NORMALS: boolean;
  37. /**
  38. * Defines custom scaling of UV coordinates of loaded meshes.
  39. */
  40. static UV_SCALING: Vector2;
  41. /**
  42. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  43. */
  44. static SKIP_MATERIALS: boolean;
  45. /**
  46. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  47. *
  48. * Defaults to true for backwards compatibility.
  49. */
  50. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  51. /**
  52. * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.
  53. */
  54. static USE_LEGACY_BEHAVIOR: boolean;
  55. /**
  56. * Defines the name of the plugin.
  57. */
  58. name: string;
  59. /**
  60. * Defines the extension the plugin is able to load.
  61. */
  62. extensions: string;
  63. private _assetContainer;
  64. private _loadingOptions;
  65. /**
  66. * Creates loader for .OBJ files
  67. *
  68. * @param loadingOptions options for loading and parsing OBJ/MTL files.
  69. */
  70. constructor(loadingOptions?: OBJLoadingOptions);
  71. private static get _DefaultLoadingOptions();
  72. /**
  73. * Calls synchronously the MTL file attached to this obj.
  74. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  75. * Without this function materials are not displayed in the first frame (but displayed after).
  76. * In consequence it is impossible to get material information in your HTML file
  77. *
  78. * @param url The URL of the MTL file
  79. * @param rootUrl defines where to load data from
  80. * @param onSuccess Callback function to be called when the MTL file is loaded
  81. * @param onFailure
  82. */
  83. private _loadMTL;
  84. /**
  85. * Instantiates a OBJ file loader plugin.
  86. * @returns the created plugin
  87. */
  88. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  89. /**
  90. * If the data string can be loaded directly.
  91. * @returns if the data can be loaded directly
  92. */
  93. canDirectLoad(): boolean;
  94. /**
  95. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  96. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  97. * @param scene the scene the meshes should be added to
  98. * @param data the OBJ data to load
  99. * @param rootUrl root url to load from
  100. * @returns a promise containing the loaded meshes, particles, skeletons and animations
  101. */
  102. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult>;
  103. /**
  104. * Imports all objects from the loaded OBJ data and adds them to the scene
  105. * @param scene the scene the objects should be added to
  106. * @param data the OBJ data to load
  107. * @param rootUrl root url to load from
  108. * @returns a promise which completes when objects have been loaded to the scene
  109. */
  110. loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void>;
  111. /**
  112. * Load into an asset container.
  113. * @param scene The scene to load into
  114. * @param data The data to import
  115. * @param rootUrl The root url for scene and resources
  116. * @returns The loaded asset container
  117. */
  118. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer>;
  119. /**
  120. * Read the OBJ file and create an Array of meshes.
  121. * Each mesh contains all information given by the OBJ and the MTL file.
  122. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  123. * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file
  124. * @param scene defines the scene where are displayed the data
  125. * @param data defines the content of the obj file
  126. * @param rootUrl defines the path to the folder
  127. * @returns the list of loaded meshes
  128. */
  129. private _parseSolid;
  130. }