3D Model Loading Method and System Based on WebGPU
Through the WebGPU-based three-dimensional model loading method, the WebGPU loader is built and data analysis and format conversion is performed, which solves the problem that traditional technology cannot load three-dimensional models in the Web environment, and realizes high-performance and flexible three-dimensional model loading and rendering.
Patent Information
- Application Number
- CN202411936126.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2044-12-26
AI Technical Summary
The traditional three-dimensional model loading method cannot directly load three-dimensional models in the web environment, and cannot meet the needs of modern applications for high performance and flexibility.
Using a three-dimensional model loading method based on WebGPU, by building a WebGPU loader, reading three-dimensional model files, parsing and extracting vertex data and index data, performing format conversion, and storing the data in the buffer bound by the rendering pipeline of the GPU.
It realizes efficient loading of three-dimensional models in the web environment, improves data compatibility and rendering performance, and enables three-dimensional models to be loaded and rendered correctly in mainstream browsers.
Smart Images

Figure CN119359884B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of 3D model processing, especially a 3D model loading method and system based on WebGPU. Background Art
[0002] 3D model loading is an important part in the fields of computer graphics and virtual reality. With the rapid development of modern technologies, 3D models are increasingly widely used in various fields, including game development, architectural design, urban planning, geographic information system (GIS), etc.
[0003] Traditional 3D model loading methods often rely on old graphics APIs such as OpenGL or DirectX. Although these APIs are powerful, they can no longer meet the requirements of modern applications for high performance and flexibility in some aspects. Especially with the continuous progress of web technologies, more and more applications need to run 3D graphics in browsers. However, traditional 3D model loading methods cannot directly load 3D models into the web environment. Summary of the Invention
[0004] To be able to load 3D models in the web environment, this application provides a 3D model loading method and system based on WebGPU.
[0005] In a first aspect, this application provides a 3D model loading method based on WebGPU, adopting the following technical solution:
[0006] The 3D model loading method based on WebGPU includes the following steps:
[0007] Model acquisition: Obtain the 3D model file to be loaded, denoted as the target file;
[0008] Model loading: Includes obtaining the path, first construction, file parsing, format conversion, and second construction;
[0009] Obtaining the path: Obtain the path of the target file;
[0010] First construction: Use WebGPU technology to construct a loader, and the loader reads the target file through the path;
[0011] File parsing: Use the loader to parse the read target file to obtain a parsing result, and extract vertex data and index data from the parsing result;
[0012] Format conversion: Convert the formats of the vertex data and index data into the target data format, denote the vertex data after format conversion as the first data, and denote the index data after format conversion as the second data;
[0013] Second construction: Create a first buffer storing the first data and the second data, and bind the first buffer to the rendering pipeline of the GPU.
[0014] By adopting the above technical solution, the present application uses the WebGPU technology to construct a loader. The loader reads the target file through the specified path, parses the target file after reading it, extracts vertex data and index data from the parsing result, and then converts the vertex data and index data into the target data format (obtaining the first data and the second data). After that, a first buffer storing the first data and the second data is created and bound to the GPU rendering pipeline. In this process, the present application adopts the WebGPU technology. WebGPU can be developed and debugged on mainstream browsers such as Chromium, Chrome, and Firefox. These browsers provide APIs based on the WebGPU standard, as well as corresponding debugging tools and performance analyzers, realizing the function of loading 3D model files in the Web environment. In addition, the format conversion improves the compatibility of the data, enabling the relevant data to be correctly processed by the GPU. Creating the first buffer and binding the first buffer to the GPU rendering pipeline can realize the function of correctly rendering the 3D model.
[0015] Optionally, after the step of performing file parsing and before the step of performing format conversion, it further includes:
[0016] Third construction: Use any one of the vertex data in the target file as the origin to construct a spatial coordinate system;
[0017] First judgment: Judge whether there are multiple vertex data in the current octant. If so, use the 3D model file of the current octant as the new target file and execute the steps of the third construction; if not, execute the steps of the first calculation;
[0018] First calculation: Use the Jaccard similarity to calculate the similarity of the vertex data in adjacent octants;
[0019] Second judgment: Judge whether the similarity is greater than the preset threshold. If so, execute the merging step; if not, execute the first retention step;
[0020] Merging: Merge the two octants corresponding to the similarity into a new octant, delete any one of the vertex data corresponding to the similarity, and execute the steps of the first calculation;
[0021] First retention: Retain the vertex data in the two octants corresponding to the similarity;
[0022] Data update: Use the remaining vertex data in the merging step, the vertex data retained in the first retention step, the vertex data on the coordinate axes corresponding to the new octants in the merging step, and the vertex data on the coordinate axes corresponding to the two octants in the first retention step as the new vertex data, and establish new index data based on the new vertex data.
[0023] By adopting the above technical solution, in this application, any vertex data is used as the origin, and a space coordinate system is constructed in any direction, so as to determine the spatial position relationship between the vertex data and the remaining vertex data. If there are multiple vertex data in the current octant (a spatial division region), the 3D model file of the current octant is used as the new target file, and the space coordinate system is reconstructed until there is only one vertex data or no vertex data in an octant. Then, calculate the similarity of the vertex data in adjacent octants, merge the two octants with similarity greater than the preset threshold to obtain a new octant, delete any vertex data in the new octant, and re-execute the steps of the first calculation. If the similarity of adjacent octants is lower than the preset threshold, retain the two octants and the internal vertex data. Finally, use the remaining vertex data in the merging step, the vertex data retained in the first retention step, the vertex data on the coordinate axes corresponding to the new octants in the merging step, and the vertex data on the coordinate axes corresponding to the two octants in the first retention step as the new vertex data, and establish new index data for these new vertex data, thereby reducing redundant data and optimizing the data structure.
[0024] Optionally, after performing the third construction step and before performing the first judgment step, it further includes:
[0025] Determine the direction: Take the direction from the origin to the camera as the positive direction of the x-axis, perform a cross product of the normal vector of the vertex data and the unit vector of the x-axis to determine the positive direction of the y-axis, and use the right-hand rule to determine the positive direction of the z-axis, and construct a space coordinate system based on the x-axis, y-axis, and z-axis;
[0026] Determine the coordinate: Determine the abscissa of the far plane of the frustum, denoted as the first coordinate;
[0027] Delete the file: Obtain the coordinate points with abscissa less than the first coordinate, denoted as the second coordinate, and delete the target file corresponding to the second coordinate.
[0028] By adopting the above technical solution, this application defines the directions of each coordinate axis, deletes the 3D model files behind the far plane of the frustum, reduces the number of vertex data, improves the loading efficiency, and reduces resource consumption.
[0029] Optionally, after performing the first retention step and before performing the data update step, it further includes:
[0030] Second calculation: Count the number of vertex data with the same ordinate and abscissa, denoted as the third data;
[0031] Third judgment: Judge whether the third data is 1. If so, execute the data update step; if not, execute the second retention step;
[0032] Second retention: Retain the vertex data with the largest abscissa among the vertex data with the same ordinate and abscissa, and execute the data update step.
[0033] By adopting the above technical solution, the present application streamlines the vertex data with the same ordinate and abscissa. When multiple vertex data have the same ordinate and abscissa, there must be an occlusion and occluded relationship among these vertex data. The present application retains the one with the largest abscissa among the vertex data with the same ordinate and abscissa, that is, deletes the occluded vertex data, further reducing the number of vertex data to be loaded and improving the loading speed.
[0034] Optionally, after performing the first construction step and before performing the file parsing step, it further includes:
[0035] Fourth judgment: Judge whether the loader successfully reads the target file. If so, execute the file parsing step; if not, execute the process clearing step;
[0036] Process clearing: Clear the loading process in the loader and send an alarm signal.
[0037] When the path of the target file is correct, the present application first checks whether the loader successfully reads the target file, so that the target file will be parsed by the loader only when it is successfully read, reducing the probability of errors in subsequent steps. When the target file fails to be read successfully, the present application will clear the loading process in the loader and send an alarm signal to prompt the operation and maintenance personnel that there is a problem with the current loading queue. By adopting the above technical solution, the present application will perform file parsing only when the loader successfully reads the file, improving the stability and correctness of the loading process.
[0038] Optionally, in the first construction step, the loader includes multiple loading queues, and a HOOK function is provided at the end of each code line of each loading queue. After performing the fourth judgment step and before performing the process clearing step, it further includes:
[0039] Log collection: Collect the running logs of the loader and obtain error information based on the running logs;
[0040] Collection location: Locate the error code based on the error information;
[0041] Jump: Use the HOOK function at the end of the previous line of code with the error code to jump to the new loading queue and continue loading the target file.
[0042] In this application, by collecting the operation logs, detailed error information is obtained. Based on the collected error information, the code that causes the error is further located. When constructing the loader, a HOOK function is set at the end of each line of code in each loading queue. The HOOK function of each line of code points to the end of the same line of code in another loading queue, and the HOOK function at the end of this line of code is only triggered when an error occurs in the code. So that when an error occurs in the code running in the current loading queue, the HOOK function is used to jump to the new loading queue, thereby bypassing the current error code. This application uses the new loading queue to reload the target file, so that when a problem occurs in a certain loading queue of the loader, it will not affect the loading of the entire target file. By collecting logs, locating the error location, and setting jumps, this application can more accurately diagnose and solve the problems encountered by the loader when reading the target file.
[0043] Optionally, after the step of performing the merge and before the step of performing the data update, it further includes:
[0044] First acquisition: Integrate the vertex data deleted in the merge step into a data set;
[0045] Third calculation: Use the Jaccard similarity to calculate the similarity between any two vertex data in the data set, denoted as the fourth data;
[0046] Fifth judgment: Judge whether the fourth data is greater than the preset threshold. If so, perform the elimination step; if not, perform the format conversion step;
[0047] Elimination: Eliminate any one of the vertex data corresponding to the fourth data in the data set, and perform the third calculation step until the stop calculation condition is met;
[0048] Third retention: Retain the vertex data corresponding to the fourth data.
[0049] This application collects the deleted vertex data, integrates it into a data set, calculates the similarity between any two vertex data in the data set, and makes a judgment on the similarity. If the similarity is greater than the preset threshold, it means that there is redundancy in the vertex data in the data set. Then, one of the vertex data is deleted in the data set, and the third calculation step is performed again. On the contrary, it means that the two vertex data have different characteristics or information, and the two vertex data need to be retained. By adopting the above technical solution, this application further filters the deleted vertex data and screens out the vertex data with different characteristics or information.
[0050] Optionally, after the step of performing data update and before the step of performing format conversion, the method further includes:
[0051] First setting: Regarding the vertices corresponding to the vertex data in the step of data update as the main control points;
[0052] Second setting: Regarding the vertices corresponding to the vertex data reserved in the third reservation step as the secondary control points, and establishing index data for the secondary control points;
[0053] In the step of format conversion, the method further includes: Converting the format of the vertex data corresponding to the secondary control points into the target data format, denoted as the fourth data; converting the format of the index data corresponding to the secondary control points into the target data format, denoted as the fifth data;
[0054] In the step of second construction, the method further includes: Creating a second buffer storing the fourth data and the fifth data, and binding the second buffer to the rendering pipeline of the GPU.
[0055] By adopting the above technical solution, the present application sets the main control points and the secondary control points, and in the step of format conversion, converts the formats of the vertex data and the index data corresponding to the secondary control points into the target data format, creates a second buffer storing the converted vertex data and index data, and binds it to the rendering pipeline of the GPU, so that the secondary control points can also be loaded, improving the loading accuracy of the 3D model.
[0056] Optionally, after the step of performing second construction, the method further includes:
[0057] First rendering: The rendering pipeline renders the data in the first buffer to the user interface to obtain the first rendering effect;
[0058] Second rendering: The rendering pipeline renders the data in the second buffer to the user interface to obtain the second rendering effect;
[0059] Rendering merging: Using the GPU to merge the first rendering effect and the second rendering effect.
[0060] The present application first renders the data corresponding to the main control points (stored in the first buffer), providing the user with basic or preliminary visual feedback, and then renders the secondary control points (stored in the second buffer), providing a higher quality or more refined visual effect. This hierarchical rendering strategy helps to gradually construct and present complex scenes. Through two renderings, the user interface can present a richer and more delicate visual effect, thus enhancing the user's visual experience.
[0061] In a second aspect, the present application provides a 3D model loading system based on WebGPU, adopting the following technical solution:
[0062] A 3D model loading system based on WebGPU, comprising:
[0063] A model acquisition module for obtaining a 3D model file to be loaded, denoted as the target file;
[0064] A model loading module, including a path acquisition unit, a first construction unit, a file parsing unit, a format conversion unit, and a second construction unit;
[0065] The path acquisition unit, communicatively connected to the model acquisition module, for obtaining the path of the target file;
[0066] The first construction unit, communicatively connected to the path acquisition unit, for constructing a loader using WebGPU technology, and the loader reads the target file through the path;
[0067] The file parsing unit, communicatively connected to the first construction unit, for parsing the read target file using the loader to obtain a parsing result, and extracting vertex data and index data from the parsing result;
[0068] The format conversion unit, communicatively connected to the file parsing unit, for converting the formats of the vertex data and the index data into a target data format, denoting the vertex data after format conversion as the first data, and denoting the index data after format conversion as the second data;
[0069] The second construction unit, communicatively connected to the format conversion unit, for creating a first buffer storing the first data and the second data, and binding the first buffer to the rendering pipeline of the GPU.
[0070] By adopting the above technical solution, the present application obtains a 3D model file to be loaded through the model acquisition module, and uses units such as path acquisition, first construction, file parsing, format conversion, and second construction in the model loading module to convert the vertex data and index data of the target file into a format recognizable by the GPU, and stores them in the first buffer bound to the rendering pipeline. The present application uses WebGPU technology to construct a loader, which can directly load 3D models into the Web environment.
[0071] In summary, the present application includes at least one of the following beneficial technical effects:
[0072] 1. This application utilizes WebGPU technology to construct a loader. The loader reads the target file through a specified path, parses the target file after reading it, extracts vertex data and index data from the parsing results, and then converts the vertex data and index data into the target data format (obtaining the first data and the second data). After that, a first buffer storing the first data and the second data is created and bound to the GPU rendering pipeline. In this process, this application adopts WebGPU technology, and WebGPU can be developed and debugged on mainstream browsers such as Chromium, Chrome, and Firefox. These browsers provide APIs based on the WebGPU standard, as well as corresponding debugging tools and performance profilers, realizing the function of loading 3D model files in the Web environment.
[0073] 2. This application simplifies the vertex data with the same ordinate and abscissa. When multiple vertex data have the same ordinate and abscissa, there must be an occlusion relationship among these vertex data. This application retains the one with the largest abscissa among the vertex data with the same ordinate and abscissa, that is, deletes the occluded vertex data, reduces the number of vertex data to be loaded, and improves the loading speed.
[0074] 3. This application collects the running logs to obtain detailed error information. Based on the collected error information, the code that causes the error is further located. When constructing the loader, this application sets a HOOK function at the end of each line of code in the loading queue. The HOOK function of each line of code points to the end of the same line of code in another loading queue, and the HOOK function at the end of this line of code is only triggered when an error occurs in the code. So that when an error occurs in the code running in the current loading queue, the HOOK function is used to jump to a new loading queue, thereby bypassing the current error code. This application uses the new loading queue to reload the target file, so that when there is a problem in a certain loading queue of the loader, it will not affect the loading of the entire target file. By collecting logs, locating the error position, and setting jumps, this application can more accurately diagnose and solve the problems encountered by the loader when reading the target file. Description of the Drawings
[0075] Figure 1 is the flowchart of Embodiment 1 of this application;
[0076] Figure 2 is the flowchart of the third construction to data update of S31 in Embodiment 2 of this application;
[0077] Figure 3 is the flowchart of determining the direction of S41 to data update of S37 in Embodiment 2 of this application;
[0078] Figure 4 It is the flowchart of Embodiment 3 of this application;
[0079] Figure 5 It is the flowchart of Embodiment 4 of this application. Detailed implementation manners
[0080] The following is a further detailed description of this application in conjunction with Figures 1 to 5 to further elaborate on this application.
[0081] Embodiment 1: This embodiment discloses a three-dimensional model loading method based on WebGPU. Referring to Figure 1 , the method includes: S1 model acquisition and S2 model loading. First, obtain the three-dimensional model file to be loaded, then obtain the path of the file, then use the loader constructed by WebGPU technology to read the target file through the path, then use the loader to parse the read target file to obtain the parsing result, then extract vertex data and index data from the parsing result, then convert the formats of the vertex data and index data into the target data format, then create a first buffer, and store the vertex data and index data after format conversion in the first buffer, and then bind the first buffer to the rendering pipeline of the GPU. This embodiment includes the following steps:
[0082] S1 model acquisition, obtain the three-dimensional model file to be loaded, denoted as the target file.
[0083] The target file is stored in the computer and is the export result of 3D modeling software (such as Blender, Maya, 3ds Max, etc.). The format of the target file can be OBJ, FBX, GLTF, etc.
[0084] S2 model loading, including S21 path acquisition, S22 first construction, S23 file parsing, S24 format conversion, and S25 second construction.
[0085] S21 path acquisition, obtain the path of the target file. The path is a string and can be obtained through user input, configuration file reading, or program automatic detection, etc.
[0086] The user input means that the user provides the file path through command-line input or the input box of the graphical user interface (GUI).
[0087] The configuration file stores various configuration information required during the program operation, and the file path is included in these configuration information.
[0088] S22 first construction, this embodiment uses WebGPU technology to construct a loader, and this loader can read the target file through the previously obtained file path. The role of the loader is to load the file from the disk into the memory to prepare for subsequent parsing and rendering.
[0089] WebGPU is an API for high-performance graphics rendering on the web, which provides direct access to modern GPU hardware.
[0090] For S23 file parsing, after the loader reads the target file, it will parse the target file. The purpose of parsing the target file is to extract the key information required to build a 3D model from the target file. The key information mainly includes vertex data (describing the position, color, texture coordinates, etc. of the points on the model surface) and index data (describing how vertices are connected to form polygons). These key information are stored in the target file in binary or text form.
[0091] For S24 format conversion, convert the parsed vertex data and index data into a unified data format suitable for GPU processing. This conversion process includes data type conversion (such as converting from floating-point numbers to fixed-point numbers), data rearrangement (such as storing vertex coordinates, colors, texture coordinates, etc. separately), etc.
[0092] Record the vertex data after converting the format as the first data, and record the index data after converting the format as the second data.
[0093] For S25 second construction, create a first buffer storing the first data and the second data, and bind the first buffer to the rendering pipeline of the GPU.
[0094] In this embodiment, the target file to be loaded is obtained through S1 model acquisition, and then the path of the target file is obtained through S2 model loading. The WebGPU technology is used to build a loader to load the target file. The loader is also used to parse the target file to obtain vertex data and index data, and bind the vertex data and index data to the rendering pipeline of the GPU, so that the 3D model can be correctly and efficiently loaded in the web environment.
[0095] Embodiment 2: Refer to Figure 2 , the difference between this embodiment and Embodiment 1 is that after performing S23 file parsing and before performing S24 format conversion, it further includes:
[0096] For S31 third construction, take any vertex data in the target file as the origin, and then, based on the origin, build three mutually perpendicular coordinate axes (x, y, z axes) to build a space coordinate system. In this step, the specific directions of the three coordinate axes are not limited.
[0097] S32 First judgment: Traverse from the first octant to the eighth octant, and successively judge whether the number of vertex data in each octant is greater than or equal to two. If so, use the 3D model file corresponding to the current octant (the 3D model file includes: the unit model file within the current octant, and the 3D model files on the three coordinate axes corresponding to the current octant) as the new target file, and execute S31 Third construction; if not, execute S33 First calculation.
[0098] S33 First calculation: Use the Jaccard similarity to calculate the similarity of vertex data in adjacent octants.
[0099] For example, in a 3D coordinate system, vertex A and vertex B are vertices corresponding to vertex data in adjacent octants, and their sets of adjacent vertices are as follows.
[0100] Vertex A (located in the first octant): The set of adjacent vertices is {V1, V2, V3, V4};
[0101] Vertex B (located in the octant adjacent to the first octant): The set of adjacent vertices is {V3, V4, V5, V6};
[0102] Find the common adjacent vertices of vertex A and vertex B: {V3, V4};
[0103] According to the definition of Jaccard similarity, calculate the similarity r between vertex A and vertex B:
[0104] ;
[0105] .
[0106] Therefore, the Jaccard similarity between vertex A and vertex B is 1 / 3, indicating that they have a certain degree of similarity, but are not completely similar.
[0107] S34 Second judgment: Judge whether the similarity in S33 First calculation is greater than the preset threshold. If so, execute S35 Merge; if not, execute S36 First retention.
[0108] S35 Merge: Merge the two octants corresponding to the similarity in S33 First calculation into a new octant. At this time, the new octant contains at least two vertex data (that is, the two vertex data corresponding to the similarity in S33 First calculation, and may also include the vertex data on the coordinate axes corresponding to the original two octants). To reduce data redundancy, any one of the vertex data corresponding to the similarity needs to be deleted, and S33 First calculation is executed again.
[0109] S36 First retention: Retain the vertex data within the two octants corresponding to the similarity.
[0110] S37 data update, combining the vertex data in S35 and the first reserved vertex data in S36, as well as the vertex data on the coordinate axes corresponding to the octants in the combination of S35 and the first reserved S36, as the new vertex data, and establishing new index data based on the new vertex data.
[0111] In this embodiment, first, any vertex corresponding to the vertex data in the target file is selected as the origin to construct a three-dimensional space coordinate system. Then, the number of vertex data in each octant of the space coordinate system is judged. If there are multiple vertex data, the space coordinate system is reconstructed until the number of vertices in each octant is zero or one. Then, the similarity between adjacent octant vertices is calculated, and whether to merge the octants or retain the vertex data is determined according to whether the similarity exceeds a preset threshold. Finally, the vertex data and index data are updated. This embodiment can effectively organize and manage the vertex data and delete adjacent and similar vertex data.
[0112] Refer to Figure 3 , in other embodiments, after performing S31 third construction and before performing S32 first judgment, it further includes:
[0113] S41 Determine the direction. Take the direction from the origin to the camera as the positive direction of the x-axis, perform a cross product of the normal vector of the vertex data and the unit vector on the positive direction of the x-axis to determine the positive direction of the y-axis, and use the right-hand rule to determine the positive direction of the z-axis. Construct a space coordinate system based on the x-axis, y-axis, and z-axis.
[0114] In this step, both the origin and the center line of the camera are on the x-axis. The camera can be regarded as a particle, and a ray, that is, the x-axis, can be determined by two points.
[0115] S42 Determine the coordinates. Determine the abscissa of the far plane of the frustum of a cone and record it as the first coordinate. Since in S41 determining the direction, the positive direction of the x-axis is the direction from the origin to the camera, the near plane and the far plane of the camera frustum are planes perpendicular to the x-axis.
[0116] S43 Delete the file. Obtain the coordinate points with abscissa less than the first coordinate, record them as the second coordinate, delete the target file corresponding to the second coordinate, and use the remaining target file as the new target file.
[0117] After that, S32 first judgment to S36 first reservation are executed in sequence.
[0118] S44 Second calculation. Count the number of vertex data with the same ordinate and vertical coordinate among the vertex data reserved in the two steps of S35 combination and S36 first reservation, and record it as the third data.
[0119] S45 Third judgment: Determine whether the third data is 1. If it is, execute S37 data update; if not, execute S46 Second retention.
[0120] S46 Second retention: Retain the vertex data with the largest abscissa among the vertex data with the same ordinate and vertical coordinate, and execute S37 data update.
[0121] In this embodiment, the directions of the three coordinate axes are defined, and the target file is deleted in combination with the field of view range of the camera, that is, the target file after the far plane of the viewing frustum is deleted, and only the remaining three-dimensional model file is processed. Then, the abscissas of the vertex data are compared, and the occluded vertex data is further deleted according to the comparison result. Since the positive direction of the abscissa of the space coordinate system points to the camera, when the camera faces the origin of the space coordinate system, only one vertex data with the largest abscissa can be seen within the field of view of the camera (specifically here: one vertex data with the largest abscissa among the vertex data with the same ordinate and vertical coordinate). The remaining vertex data is deleted, reducing the number of vertex data to be loaded and improving the loading speed of the three-dimensional model file.
[0122] Example 3: Refer to Figure 4 , the difference between this embodiment and Embodiment 1 is that when the path of the target file is correct, but the loader cannot correctly load the target file, it means that there is an error in the current loading queue of the loader, and the loading queue needs to be replaced. And in the step of S22 First construction, the loader includes multiple loading queues, the code corresponding to each loading queue is basically the same (that is, it will execute the task of loading the target file), and there is a HOOK function after each code line, and each HOOK function points to the end of the code line corresponding to this code in other loading queues. After executing S22 First construction and before executing S23 File parsing, it further includes:
[0123] S51 Fourth judgment: Determine whether the loader successfully reads the target file. If it is, it means that the target file has been correctly loaded into the memory and can be further processed, and continue to execute S23 File parsing; if not, it means that there is a problem with the current loading queue and S52 Log collection needs to be executed.
[0124] S52 Log collection: Obtain the detailed running log from the log system of the loader, and obtain the error information based on the running log.
[0125] The running log contains various information during the loading process, including the files successfully loaded, the failed loading attempts, and the error information that occurred during the loading process, etc.
[0126] S53 Acquisition Location: Based on the clues provided in the error message (such as error code, error description, file location where the error occurred, etc.), search for the corresponding error code in the code library.
[0127] S54 Jump: Use the HOOK function at the end of the code in the line before the error code to jump to the corresponding position in the new loading queue in the loader. Use the code after the new loading queue to continue loading the target function, and then continue to execute the fourth judgment in S51 until the preset stop condition is met, and then continue to execute S55 to clear the process.
[0128] The stop condition mentioned in this step is that the number of executions of the S54 jump reaches the preset number of executions.
[0129] The loader does not adopt a parallel processing method, so there is only one loading queue in the loader that is in a working state, and the remaining loading queues are all in an idle state. Therefore, when a problem occurs in a certain loader, you can randomly select a loading queue to jump to, and indicate in the log that there is a fault in the current loading queue to prompt the operation and maintenance personnel to check the program of this loading queue.
[0130] S55 Clear Process: Clear the original loading process in the loader and send an alarm signal.
[0131] This embodiment provides a complete error handling process. When the loader fails to load the target file normally, it means that an error has occurred in the loader. This embodiment automatically jumps to the same position in the new loading queue through the HOOK function, can automatically jump the loading queue when a problem occurs in the loading queue, realize the continuous loading of the target file, and re-execute the steps of the fourth judgment. If the problem remains unresolved, it will still return to the jump step again. When the number of executions of the jump step reaches the preset threshold, it means that this problem cannot be solved by changing the loading queue. At this time, it is necessary to clear the content of the loading queue and send an alarm signal.
[0132] Example 4: Refer to Figure 5 , the difference between this embodiment and Embodiment 2 is that after executing S35 Merge and before executing S37 Data Update, it further includes:
[0133] S61 First Acquisition: Integrate the vertex data deleted in S35 Merge into a data set.
[0134] S62 Third Calculation: Traverse the data set and use the Jaccard similarity to calculate the similarity between each pair of vertex data, and record the similarity as the fourth data.
[0135] S63 Fifth Judgment: Judge whether the fourth data is greater than the preset threshold. If so, execute S64 Exclusion; if not, execute S24 Format Conversion.
[0136] S64 Exclusion: Exclude any vertex data corresponding to the fourth data from the dataset, and perform S62 Third Calculation until the stop calculation condition is met.
[0137] The stop calculation conditions include: the number of executions of S64 Exclusion reaches the maximum number of iterations, the size of the dataset reaches the expected size, etc.
[0138] S65 Third Retention: Retain the vertex data corresponding to the fourth data.
[0139] After that, perform S37 Data Update, and before performing S24 Format Conversion after S37 Data Update, it further includes:
[0140] S71 First Setting: Set the vertices corresponding to the vertex data in S37 Data Update as the main control points. The main control points refer to the vertex data in S37 Data Update, which represent the key positions, shape features, or motion trajectories of the object, etc.
[0141] S72 Second Setting: Set the vertices corresponding to the vertex data retained in S65 Third Retention as the secondary control points, and establish index data for the secondary control points.
[0142] In S24 Format Conversion, convert the format of the vertex data corresponding to the secondary control points to the target data format, denoted as the fourth data; convert the format of the index data corresponding to the secondary control points to the target data format, denoted as the fifth data.
[0143] Format conversion is to make the data compatible with subsequent processing steps or target systems.
[0144] In S25 Second Construction, create a second buffer storing the fourth data and the fifth data, and bind the second buffer to the rendering pipeline of the GPU.
[0145] After performing S25 Second Construction, the method further includes:
[0146] S81 First Rendering: The rendering pipeline renders the data in the first buffer to the user interface to obtain the first rendering effect.
[0147] S82 Second Rendering: The rendering pipeline renders the data in the second buffer to the user interface to obtain the second rendering effect.
[0148] S83 Rendering Combination: In the fragment shader of the GPU, two rendering results can be read and the rendering effects of S81 First Rendering and S82 Second Rendering can be combined (such as adding, blending, etc.).
[0149] In this embodiment, first, the deleted vertex data is further screened to obtain secondary control points. Then, the format of the secondary control points is converted and index data is set. Finally, the primary control points are rendered first to provide basic or preliminary visual feedback, and then the secondary control points are rendered to provide higher-quality or more refined visual effects.
[0150] Embodiment 5: This embodiment discloses a three-dimensional model loading system based on WebGPU. The system includes:
[0151] A model acquisition module, which is responsible for obtaining the three-dimensional model file to be loaded, denoted as the target file. For example, selecting a file from the local file system, downloading a file from a network server, or retrieving a file from a specific database system. Once the target file is obtained, the model acquisition module will prepare it for subsequent processing by the model loading module.
[0152] A model loading module, including a path acquisition unit, a first construction unit, a file parsing unit, a format conversion unit, and a second construction unit.
[0153] The path acquisition unit, which is communicatively connected to the model acquisition module and is used to obtain the path of the target file. This path can be the absolute path or the relative path of the file, depending on the storage location of the target file and the file structure of the system.
[0154] The first construction unit, which is communicatively connected to the path acquisition unit and is used to construct a loader using WebGPU technology. The loader reads the target file through the path.
[0155] The file parsing unit, which is communicatively connected to the first construction unit and is used to parse the read target file using the loader. From the parsing results, vertex data and index data are extracted. The vertex data describes information such as the positions, colors, and texture coordinates of each vertex in the three-dimensional model, while the index data defines how the vertices are connected to form geometric primitives such as triangles or other polygons.
[0156] The format conversion unit, which is communicatively connected to the file parsing unit. Since different Web environments may use different data formats, the format conversion unit needs to appropriately convert the vertex data and index data according to the requirements of the target data format. The vertex data after format conversion is denoted as the first data, and the index data after format conversion is denoted as the second data.
[0157] The second construction unit is communicatively connected to the format conversion unit and is used to create a first buffer storing the first data and the second data, and bind the first buffer to the rendering pipeline of the GPU. The rendering pipeline is a set of steps and operations in the GPU for processing graphics rendering tasks. By binding the first buffer to the rendering pipeline, the GPU can access the vertex data and index data for subsequent rendering processing.
[0158] Through the close cooperation of the model acquisition module and the model loading module in this embodiment, the efficient loading and rendering of 3D model files are achieved. Among them, the model acquisition module is responsible for obtaining the 3D model file to be loaded (the target file), while the model loading module includes a series of sub-units for obtaining the path, constructing a WebGPU loader, parsing the file to extract vertex and index data, converting the data format to the target format, and finally constructing and binding the buffer storing these data to the GPU rendering pipeline, enabling the 3D model to be successfully loaded and ready for rendering.
[0159] The above are all the preferred embodiments of this application. Without limiting the protection scope of this application accordingly, therefore: Any equivalent changes made according to the structure, shape, and principle of this application shall be covered within the protection scope of this application.
Claims
1. A three-dimensional model loading method based on WebGPU, characterized in that: include: Model acquisition: Get the 3D model file to be loaded and record it as the target file; Model loading: including path acquisition, first construction, file parsing, third construction, first judgment, first calculation, second judgment, merging, first retention, data update, format conversion and second construction; Get path: Get the path of the target file; First build: use WebGPU technology to build a loader in the Web environment, and the loader reads the target file through the path; File parsing: Use the loader to parse the read target file, obtain the parsing result, and extract the vertex data and index data from the parsing result; The third construction: take any vertex data in the target file as the origin to construct the spatial coordinate system; First judgment: judging whether the current hexagram contains multiple vertex data, if so, taking the three-dimensional model file of the current hexagram as a new target file, and executing the third construction step; If not, then execute the first calculation step; First calculation: use Jaccard similarity to calculate the similarity of vertex data in adjacent hexagrams; Second judgment: judging whether the similarity is greater than a preset threshold, if so, executing the merging step; if not, executing the first retaining step; Merge: merge the two hexagrams corresponding to the similarity into a new hexagram, delete any vertex data corresponding to the similarity, and execute the first calculation step; First retention: retaining the vertex data in the two hexagrams corresponding to the similarity; Data update: using the remaining vertex data in the merging step, the vertex data retained in the first retaining step, the vertex data on the coordinate axis corresponding to the new hexagram in the merging step, and the vertex data on the coordinate axis corresponding to the two hexagrams in the first retaining step as new vertex data, and establishing new index data based on the new vertex data; Format conversion: converting the format of the new vertex data and the format of the new index data into a target data format, recording the vertex data after the conversion as first data, and recording the index data after the conversion as second data; Second construction: creating a first buffer storing the first data and the second data, and binding the first buffer to the rendering pipeline of the GPU; After the step of performing the merge and before the step of performing the data update, the step further includes: First acquisition: integrate the vertex data deleted in the merging step into a data set; The third calculation: use Jaccard similarity to calculate the similarity of any two vertex data in the data set, recorded as the fourth data; Fifth judgment: judging whether the fourth data is greater than a preset threshold, if so, executing a step of eliminating; if not, executing a step of format conversion; Eliminate: Eliminate any vertex data corresponding to the fourth data in the data set, and execute the third calculation step until the calculation stop condition is met; Third reservation: retain the vertex data corresponding to the fourth data; After executing the step of updating the data and before executing the step of converting the format, the method further includes: First setting: the vertex corresponding to the vertex data in the data update step is used as the main control point; Second setting: taking the vertex corresponding to the vertex data retained in the third retaining step as a secondary control point, and establishing index data of the secondary control point; The format conversion step further includes: converting the format of the vertex data corresponding to the secondary control point into the target data format, recorded as fourth data; converting the format of the index data corresponding to the secondary control point into the target data format, recorded as fifth data; The second construction step also includes: creating a second buffer storing the fourth data and the fifth data, and binding the second buffer to the rendering pipeline of the GPU.
2. The WebGPU-based 3D model loading method according to claim 1, characterized in that: After executing the third construction step and before executing the first judgment step, the method further includes: Determine the direction: Take the direction from the origin to the camera as the positive direction of the x-axis, perform cross multiplication on the normal vector of the vertex data and the unit vector in the positive direction of the x-axis to determine the positive direction of the y-axis, use the right-hand rule to determine the positive direction of the z-axis, and construct a spatial coordinate system based on the x-axis, y-axis, and z-axis; Determine the coordinates: determine the horizontal coordinate of the far plane of the viewing frustum, recorded as the first coordinate; Delete file: Get the coordinate point whose horizontal coordinate is less than the first coordinate, record it as the second coordinate, and delete the target file corresponding to the second coordinate.
3. The WebGPU-based 3D model loading method according to claim 2, characterized in that: After executing the first retention step and before executing the data update step, the method further includes: Second calculation: count the number of vertex data with the same ordinate and vertical coordinate, and record it as the third data; Third judgment: judging whether the third data is one, if so, executing the step of data updating; if not, executing the second reserved step; Second retention: retain the vertex data with the largest horizontal coordinate among the vertex data with the same vertical coordinate and vertical coordinate, and execute the data update step.
4. The WebGPU-based 3D model loading method according to any one of claims 1 to 3, characterized in that: After executing the first building step and before executing the file parsing step, the method further includes: Fourth judgment: judging whether the loader successfully reads the target file, if so, executing the file parsing step; if not, executing the clearing process step; Clear process: Clear the loading process in the loader and issue an alarm signal.
5. The WebGPU-based 3D model loading method according to claim 4, characterized in that: In the first construction step, the loader includes a plurality of loading queues, and a HOOK function is provided at the end of each code line of each loading queue, and after executing the fourth judgment step and before executing the clearing process step, it also includes: Collect logs: collect the running logs of the loader, and obtain error information based on the running logs; Collection location: locate the error code based on the error information; Jump: Use the HOOK function at the end of the previous line of code of the error code to jump to the new loading queue and continue loading the target file.
6. The WebGPU-based 3D model loading method according to claim 1, characterized in that: After performing the second building step, the method further comprises: First rendering: the rendering pipeline renders the data in the first buffer to the user interface to obtain a first rendering effect; Second rendering: the rendering pipeline renders the data in the second buffer to the user interface to obtain a second rendering effect; Rendering Merge: Use the GPU to merge the first rendering effect with the second rendering effect.
7. A three-dimensional model loading system based on WebGPU, the system being used to implement the method according to any one of claims 1 to 6, characterized in that: include: The model acquisition module is used to obtain the 3D model file to be loaded, which is recorded as the target file; A model loading module, comprising a path acquisition unit, a first construction unit, a file parsing unit, a format conversion unit, and a second construction unit; A path acquisition unit is connected to the model acquisition module for acquiring the path of the target file; A first construction unit is communicatively connected with the path acquisition unit and is used to construct a loader using WebGPU technology, and the loader reads the target file through the path; A file parsing unit, which is in communication connection with the first building unit, and is used to parse the read target file using a loader, obtain a parsing result, and extract vertex data and index data from the parsing result; A format conversion unit, connected to the file parsing unit for communication, for converting the format of the vertex data and the format of the index data into a target data format, recording the vertex data after the format conversion as first data, and recording the index data after the format conversion as second data; The second construction unit is communicatively connected to the format conversion unit, and is used to create a first buffer storing the first data and the second data, and bind the first buffer to the rendering pipeline of the GPU.
Citation Information
Patent Citations
Large-scale point cloud visualization method based on improved octree and adaptive reading
CN112308974A