solidParser.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
  2. import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
  3. import type { Scene } from "@babylonjs/core/scene.js";
  4. import type { Nullable } from "@babylonjs/core/types.js";
  5. import type { OBJLoadingOptions } from "./objLoadingOptions";
  6. /**
  7. * Class used to load mesh data from OBJ content
  8. */
  9. export declare class SolidParser {
  10. /** Object descriptor */
  11. static ObjectDescriptor: RegExp;
  12. /** Group descriptor */
  13. static GroupDescriptor: RegExp;
  14. /** Material lib descriptor */
  15. static MtlLibGroupDescriptor: RegExp;
  16. /** Use a material descriptor */
  17. static UseMtlDescriptor: RegExp;
  18. /** Smooth descriptor */
  19. static SmoothDescriptor: RegExp;
  20. /** Pattern used to detect a vertex */
  21. static VertexPattern: RegExp;
  22. /** Pattern used to detect a normal */
  23. static NormalPattern: RegExp;
  24. /** Pattern used to detect a UV set */
  25. static UVPattern: RegExp;
  26. /** Pattern used to detect a first kind of face (f vertex vertex vertex) */
  27. static FacePattern1: RegExp;
  28. /** Pattern used to detect a second kind of face (f vertex/uvs vertex/uvs vertex/uvs) */
  29. static FacePattern2: RegExp;
  30. /** Pattern used to detect a third kind of face (f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal) */
  31. static FacePattern3: RegExp;
  32. /** Pattern used to detect a fourth kind of face (f vertex//normal vertex//normal vertex//normal)*/
  33. static FacePattern4: RegExp;
  34. /** Pattern used to detect a fifth kind of face (f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal) */
  35. static FacePattern5: RegExp;
  36. /** Pattern used to detect a line(l vertex vertex) */
  37. static LinePattern1: RegExp;
  38. /** Pattern used to detect a second kind of line (l vertex/uvs vertex/uvs) */
  39. static LinePattern2: RegExp;
  40. /** Pattern used to detect a third kind of line (l vertex/uvs/normal vertex/uvs/normal) */
  41. static LinePattern3: RegExp;
  42. private _loadingOptions;
  43. private _positions;
  44. private _normals;
  45. private _uvs;
  46. private _colors;
  47. private _meshesFromObj;
  48. private _handledMesh;
  49. private _indicesForBabylon;
  50. private _wrappedPositionForBabylon;
  51. private _wrappedUvsForBabylon;
  52. private _wrappedColorsForBabylon;
  53. private _wrappedNormalsForBabylon;
  54. private _tuplePosNorm;
  55. private _curPositionInIndices;
  56. private _hasMeshes;
  57. private _unwrappedPositionsForBabylon;
  58. private _unwrappedColorsForBabylon;
  59. private _unwrappedNormalsForBabylon;
  60. private _unwrappedUVForBabylon;
  61. private _triangles;
  62. private _materialNameFromObj;
  63. private _objMeshName;
  64. private _increment;
  65. private _isFirstMaterial;
  66. private _grayColor;
  67. private _materialToUse;
  68. private _babylonMeshesArray;
  69. private _pushTriangle;
  70. private _handednessSign;
  71. /**
  72. * Creates a new SolidParser
  73. * @param materialToUse defines the array to fill with the list of materials to use (it will be filled by the parse function)
  74. * @param babylonMeshesArray defines the array to fill with the list of loaded meshes (it will be filled by the parse function)
  75. * @param loadingOptions defines the loading options to use
  76. */
  77. constructor(materialToUse: string[], babylonMeshesArray: Array<Mesh>, loadingOptions: OBJLoadingOptions);
  78. /**
  79. * Search for obj in the given array.
  80. * This function is called to check if a couple of data already exists in an array.
  81. *
  82. * If found, returns the index of the founded tuple index. Returns -1 if not found
  83. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  84. * @param obj Array<number>
  85. * @returns {boolean}
  86. */
  87. private _isInArray;
  88. private _isInArrayUV;
  89. /**
  90. * This function set the data for each triangle.
  91. * Data are position, normals and uvs
  92. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  93. * If the tuple already exist, add only their indice
  94. *
  95. * @param indicePositionFromObj Integer The index in positions array
  96. * @param indiceUvsFromObj Integer The index in uvs array
  97. * @param indiceNormalFromObj Integer The index in normals array
  98. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  99. * @param textureVectorFromOBJ Vector3 The value of uvs
  100. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  101. * @param positionColorsFromOBJ
  102. */
  103. private _setData;
  104. /**
  105. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  106. */
  107. private _unwrapData;
  108. /**
  109. * Create triangles from polygons
  110. * It is important to notice that a triangle is a polygon
  111. * We get 5 patterns of face defined in OBJ File :
  112. * facePattern1 = ["1","2","3","4","5","6"]
  113. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  114. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  115. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  116. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  117. * Each pattern is divided by the same method
  118. * @param faces Array[String] The indices of elements
  119. * @param v Integer The variable to increment
  120. */
  121. private _getTriangles;
  122. /**
  123. * Create triangles and push the data for each polygon for the pattern 1
  124. * In this pattern we get vertice positions
  125. * @param face
  126. * @param v
  127. */
  128. private _setDataForCurrentFaceWithPattern1;
  129. /**
  130. * Create triangles and push the data for each polygon for the pattern 2
  131. * In this pattern we get vertice positions and uvs
  132. * @param face
  133. * @param v
  134. */
  135. private _setDataForCurrentFaceWithPattern2;
  136. /**
  137. * Create triangles and push the data for each polygon for the pattern 3
  138. * In this pattern we get vertice positions, uvs and normals
  139. * @param face
  140. * @param v
  141. */
  142. private _setDataForCurrentFaceWithPattern3;
  143. /**
  144. * Create triangles and push the data for each polygon for the pattern 4
  145. * In this pattern we get vertice positions and normals
  146. * @param face
  147. * @param v
  148. */
  149. private _setDataForCurrentFaceWithPattern4;
  150. private _setDataForCurrentFaceWithPattern5;
  151. private _addPreviousObjMesh;
  152. private _optimizeNormals;
  153. /**
  154. * Function used to parse an OBJ string
  155. * @param meshesNames defines the list of meshes to load (all if not defined)
  156. * @param data defines the OBJ string
  157. * @param scene defines the hosting scene
  158. * @param assetContainer defines the asset container to load data in
  159. * @param onFileToLoadFound defines a callback that will be called if a MTL file is found
  160. */
  161. parse(meshesNames: any, data: string, scene: Scene, assetContainer: Nullable<AssetContainer>, onFileToLoadFound: (fileToLoad: string) => void): void;
  162. }