import type { AssetContainer } from "@babylonjs/core/assetContainer.js"; import { Mesh } from "@babylonjs/core/Meshes/mesh.js"; import type { Scene } from "@babylonjs/core/scene.js"; import type { Nullable } from "@babylonjs/core/types.js"; import type { OBJLoadingOptions } from "./objLoadingOptions"; /** * Class used to load mesh data from OBJ content */ export declare class SolidParser { /** Object descriptor */ static ObjectDescriptor: RegExp; /** Group descriptor */ static GroupDescriptor: RegExp; /** Material lib descriptor */ static MtlLibGroupDescriptor: RegExp; /** Use a material descriptor */ static UseMtlDescriptor: RegExp; /** Smooth descriptor */ static SmoothDescriptor: RegExp; /** Pattern used to detect a vertex */ static VertexPattern: RegExp; /** Pattern used to detect a normal */ static NormalPattern: RegExp; /** Pattern used to detect a UV set */ static UVPattern: RegExp; /** Pattern used to detect a first kind of face (f vertex vertex vertex) */ static FacePattern1: RegExp; /** Pattern used to detect a second kind of face (f vertex/uvs vertex/uvs vertex/uvs) */ static FacePattern2: RegExp; /** Pattern used to detect a third kind of face (f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal) */ static FacePattern3: RegExp; /** Pattern used to detect a fourth kind of face (f vertex//normal vertex//normal vertex//normal)*/ static FacePattern4: RegExp; /** Pattern used to detect a fifth kind of face (f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal) */ static FacePattern5: RegExp; /** Pattern used to detect a line(l vertex vertex) */ static LinePattern1: RegExp; /** Pattern used to detect a second kind of line (l vertex/uvs vertex/uvs) */ static LinePattern2: RegExp; /** Pattern used to detect a third kind of line (l vertex/uvs/normal vertex/uvs/normal) */ static LinePattern3: RegExp; private _loadingOptions; private _positions; private _normals; private _uvs; private _colors; private _meshesFromObj; private _handledMesh; private _indicesForBabylon; private _wrappedPositionForBabylon; private _wrappedUvsForBabylon; private _wrappedColorsForBabylon; private _wrappedNormalsForBabylon; private _tuplePosNorm; private _curPositionInIndices; private _hasMeshes; private _unwrappedPositionsForBabylon; private _unwrappedColorsForBabylon; private _unwrappedNormalsForBabylon; private _unwrappedUVForBabylon; private _triangles; private _materialNameFromObj; private _objMeshName; private _increment; private _isFirstMaterial; private _grayColor; private _materialToUse; private _babylonMeshesArray; private _pushTriangle; private _handednessSign; /** * Creates a new SolidParser * @param materialToUse defines the array to fill with the list of materials to use (it will be filled by the parse function) * @param babylonMeshesArray defines the array to fill with the list of loaded meshes (it will be filled by the parse function) * @param loadingOptions defines the loading options to use */ constructor(materialToUse: string[], babylonMeshesArray: Array, loadingOptions: OBJLoadingOptions); /** * Search for obj in the given array. * This function is called to check if a couple of data already exists in an array. * * If found, returns the index of the founded tuple index. Returns -1 if not found * @param arr Array<{ normals: Array, idx: Array }> * @param obj Array * @returns {boolean} */ private _isInArray; private _isInArrayUV; /** * This function set the data for each triangle. * Data are position, normals and uvs * If a tuple of (position, normal) is not set, add the data into the corresponding array * If the tuple already exist, add only their indice * * @param indicePositionFromObj Integer The index in positions array * @param indiceUvsFromObj Integer The index in uvs array * @param indiceNormalFromObj Integer The index in normals array * @param positionVectorFromOBJ Vector3 The value of position at index objIndice * @param textureVectorFromOBJ Vector3 The value of uvs * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale * @param positionColorsFromOBJ */ private _setData; /** * Transform Vector() and BABYLON.Color() objects into numbers in an array */ private _unwrapData; /** * Create triangles from polygons * It is important to notice that a triangle is a polygon * We get 5 patterns of face defined in OBJ File : * facePattern1 = ["1","2","3","4","5","6"] * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"] * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"] * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"] * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"] * Each pattern is divided by the same method * @param faces Array[String] The indices of elements * @param v Integer The variable to increment */ private _getTriangles; /** * Create triangles and push the data for each polygon for the pattern 1 * In this pattern we get vertice positions * @param face * @param v */ private _setDataForCurrentFaceWithPattern1; /** * Create triangles and push the data for each polygon for the pattern 2 * In this pattern we get vertice positions and uvs * @param face * @param v */ private _setDataForCurrentFaceWithPattern2; /** * Create triangles and push the data for each polygon for the pattern 3 * In this pattern we get vertice positions, uvs and normals * @param face * @param v */ private _setDataForCurrentFaceWithPattern3; /** * Create triangles and push the data for each polygon for the pattern 4 * In this pattern we get vertice positions and normals * @param face * @param v */ private _setDataForCurrentFaceWithPattern4; private _setDataForCurrentFaceWithPattern5; private _addPreviousObjMesh; private _optimizeNormals; /** * Function used to parse an OBJ string * @param meshesNames defines the list of meshes to load (all if not defined) * @param data defines the OBJ string * @param scene defines the hosting scene * @param assetContainer defines the asset container to load data in * @param onFileToLoadFound defines a callback that will be called if a MTL file is found */ parse(meshesNames: any, data: string, scene: Scene, assetContainer: Nullable, onFileToLoadFound: (fileToLoad: string) => void): void; }