Three-dimensional model loading method and device based on shared memory and medium
By using shared memory in computer devices to store three-dimensional model data and allowing multiple processes to access it, the problem of repeated loading and low efficiency when large-scale three-dimensional models is solved, and more efficient three-dimensional model loading performance is achieved.
Patent Information
- Application Number
- CN202510009150.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-05-06
AI Technical Summary
The prior art is less efficient when loading repetitive and large volumes of three-dimensional models.
The three-dimensional model loading method based on shared memory is adopted to store three-dimensional model data through shared memory and allow multiple processes to access it, so that data is directly read from shared memory when loading the three-dimensional model.
Improves the performance and efficiency of 3D model loading, especially when multiple identical processes read the same 3D model data, which is faster.
Smart Images

Figure CN119938359A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of model loading, and in particular to a three-dimensional model loading method, device and medium based on shared memory. Background Art
[0002] At present, most of the technologies related to data storage exist in two ways. The first is to store data in the form of a database, and the second is to store data in the form of a file. When a process needs to operate on the stored data, it is necessary to read the data in the database or file into the memory first, and the process can read the data in the memory and start to operate on the corresponding data. Therefore, when the process needs to operate on the data, it takes too much time to write the data in the database or file into the memory, thereby reducing the efficiency of subsequent model loading. For example, when a three-dimensional model needs to be loaded, the model data of the three-dimensional model in the file or database needs to be converted into computer memory. When the model data is read into the computer memory, the program can start to operate on the corresponding data, resulting in low efficiency in loading the three-dimensional model. Especially when loading repeated and large-volume three-dimensional models, the loading efficiency and performance are lower. Summary of the invention
[0003] The main technical problem solved by the present invention is that the efficiency of loading repeated and large-volume three-dimensional models is currently low.
[0004] According to a first aspect, an embodiment provides a three-dimensional model loading method based on a shared memory, which is applied to a computer device, wherein the computer device includes a memory, the memory includes a shared memory, the shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used for access by multiple processes, and the three-dimensional model loading method includes:
[0005] When any process needs to load a three-dimensional model, it is determined whether there is model data required to load the three-dimensional model in the shared memory;
[0006] If it exists, the model data required for loading the three-dimensional model to be loaded is read from the shared memory, and the corresponding three-dimensional model is loaded according to the model data.
[0007] In some embodiments, it also includes:
[0008] If the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory, the three-dimensional model data of the three-dimensional model to be loaded is read from a preset storage medium;
[0009] The three-dimensional model data is loaded according to the loading strategy, and the loaded three-dimensional model data is stored in the shared memory.
[0010] In some embodiments, the shared memory includes multiple bytes, the first byte in the shared memory is set to a first identifier, and the bytes adjacent to the first byte in the shared memory are set to a second identifier, wherein the first identifier is used to indicate whether the shared memory stores model data required for loading a three-dimensional model, and the second identifier is used to indicate the storage status of the process of storing the loaded three-dimensional model data in the shared memory, and the storage status includes completed data storage and ongoing data storage.
[0011] In some embodiments, storing the loaded three-dimensional model data in the shared memory includes:
[0012] Creating a new shared memory block in the shared memory;
[0013] The loaded three-dimensional model data is stored in the new shared memory block.
[0014] In some embodiments, the shared memory includes multiple shared memory blocks, wherein a corresponding identifier is configured for each shared memory block when the shared memory block is created, and the identifier of the shared memory block is notified to the process so that the process accesses the corresponding shared memory block according to the identifier of the shared memory block and reads the model data therein.
[0015] In some embodiments, the model data of each three-dimensional model has a file name, and the identifier of each shared memory block corresponds to the file name of the model data stored therein;
[0016] The determining whether the shared memory contains model data required for loading the three-dimensional model to be loaded includes:
[0017] Determine the identifier of the corresponding shared memory block according to the file name of the model data required when loading the three-dimensional model to be loaded;
[0018] Accessing the corresponding shared memory block according to the identifier of the shared memory block;
[0019] When the accessed shared memory block stores model data required for loading the three-dimensional model to be loaded, it is determined that the shared memory contains the model data required for loading the three-dimensional model to be loaded;
[0020] Otherwise, it is determined that the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory.
[0021] In some embodiments, when the shared memory block is accessed by any process, the shared memory block cannot be accessed by other processes except the process until the access is completed.
[0022] According to the second aspect, an embodiment provides a computer device, including:
[0023] A memory, wherein the memory includes an internal memory and an external memory, wherein the external memory is used to store programs, and the internal memory includes a shared memory, wherein the shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used to be accessed by multiple processes;
[0024] A processor is used to implement the three-dimensional model loading method by executing the program stored in the memory.
[0025] According to the third aspect, an embodiment provides a computer-readable storage medium, on which a program is stored, and the program can be executed by a processor to implement the three-dimensional model loading method.
[0026] According to the fourth aspect, an embodiment provides a computer program product, including a computer program and / or instructions, which implement the three-dimensional model loading method when executed by a processor.
[0027] According to the three-dimensional model loading method based on shared memory, computer equipment, computer-readable storage medium and computer program product of the above-mentioned embodiment, since the model data required for loading the three-dimensional model is stored in the shared memory, and the shared memory is accessed by multiple processes, when any process needs to load the three-dimensional model, it is determined whether the model data required for loading the three-dimensional model to be loaded exists in the shared memory. If it exists, the corresponding model data is directly read from the shared memory, and the corresponding three-dimensional model is loaded according to the model data, thereby saving the time of extracting data from a database or file and storing it in the memory, and then reading the data from the memory to load the model. At the same time, the speed of directly reading data from the shared memory is faster, which improves the performance and efficiency of loading the three-dimensional model. In particular, when multiple identical processes read the model data of the same three-dimensional model, the efficiency is faster. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of an embodiment for determining whether there is model data required for loading a three-dimensional model to be loaded in a shared memory;
[0029] Figure 2 A flowchart of a shared memory-based three-dimensional model loading method according to an embodiment;
[0030] Figure 3A flowchart of an embodiment of reading three-dimensional model data of a to-be-loaded three-dimensional model and storing it in a shared memory;
[0031] Figure 4 A flowchart of storing loaded three-dimensional model data into a shared memory according to an embodiment;
[0032] Figure 5 A schematic diagram of the structure of a computer device according to an embodiment. DETAILED DESCRIPTION
[0033] The present invention is further described in detail below by specific embodiments in conjunction with the accompanying drawings. Wherein similar elements in different embodiments adopt associated similar element numbers. In the following embodiments, many detailed descriptions are for making the present application better understood. However, those skilled in the art can easily recognize that some features can be omitted in different situations, or can be replaced by other elements, materials, methods. In some cases, some operations related to the present application are not shown or described in the specification, this is to avoid the core part of the present application being overwhelmed by too much description, and for those skilled in the art, it is not necessary to describe these related operations in detail, and they can fully understand the related operations according to the description in the specification and the general technical knowledge in the art.
[0034] In addition, the features, operations or characteristics described in the specification can be combined in any appropriate manner to form various implementations. At the same time, the steps or actions in the method description can also be interchanged or adjusted in a manner that is obvious to those skilled in the art. Therefore, the various sequences in the specification and the drawings are only for the purpose of clearly describing a certain embodiment and are not meant to be a required sequence, unless otherwise specified that a certain sequence must be followed.
[0035] The serial numbers of the components in this document, such as "first", "second", etc., are only used to distinguish the objects described and do not have any order or technical meaning. The "connection" and "coupling" mentioned in this application, unless otherwise specified, include direct and indirect connections (couplings).
[0036] In an embodiment of the present invention, a three-dimensional model loading method based on shared memory is provided, which is applied to a computer device. The computer device includes a memory, and the memory includes a shared memory. The shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used for access by multiple processes. The three-dimensional model loading method includes steps S10 to S20, which are described in detail below.
[0037] Step S10: When any process needs to load a three-dimensional model, it is determined whether there is model data required to load the three-dimensional model in the shared memory.
[0038] In some embodiments, the shared memory includes multiple shared memory blocks, wherein a corresponding identifier is configured for each shared memory block when the shared memory block is created, and the identifier of the shared memory block is notified to the process so that the process accesses the corresponding shared memory block according to the identifier of the shared memory block and reads the model data therein.
[0039] In this embodiment, when creating a shared memory block, a corresponding identifier is configured for each shared memory block, and the identifier is a string, and the identifier is unique. For example, three shared memory blocks are created and the corresponding identifiers of the three shared memory blocks are configured as "new001", "new002" and "new003". Among them, the identifier of the shared memory block is notified to the process, and the process can access the corresponding shared memory block according to the identifier of the shared memory block and read the model data therein. For example, in process A, the corresponding shared memory block can be accessed through the identifier "new001" of the shared memory block, and in process B, the corresponding shared memory block can also be accessed through the identifier "new001" of the shared memory block. At this time, process A and process B access the same shared memory block, and can read the model data of the three-dimensional model in the shared memory block identified as "new001".
[0040] In some embodiments, the model data of each three-dimensional model has a file name, and the identifier of each shared memory block corresponds to the file name of the model data stored therein. For example, the model data of three-dimensional model A is stored in a file and its file name is model, and the model data with the file name model is stored in a shared memory block with the identifier configured as model01, wherein the identifier model01 of the shared memory block corresponds to the file name model of the model data stored therein.
[0041] Please refer to Figure 1 In some embodiments, step S10 determines whether there is model data required for loading the three-dimensional model to be loaded in the shared memory, including steps S11 to S15, which are described in detail below.
[0042] Step S11: determining the identifier of the corresponding shared memory block according to the file name of the model data required when loading the three-dimensional model to be loaded.
[0043] In some embodiments, assuming that the file name of the model data required when loading the three-dimensional model to be loaded is model, the identifier of the corresponding shared memory block is determined to be model01.
[0044] Step S12: Access the corresponding shared memory block according to the identifier of the shared memory block.
[0045] In some embodiments, the corresponding shared memory block is accessed according to the identifier model01 of the shared memory block.
[0046] Step S13: determining whether the accessed shared memory block stores model data required for loading the three-dimensional model to be loaded.
[0047] In some embodiments, it is determined whether the shared memory block identified as model01 stores model data required for loading the three-dimensional model to be loaded.
[0048] Step S14: when the accessed shared memory block stores the model data required for loading the three-dimensional model to be loaded, it is determined that the shared memory contains the model data required for loading the three-dimensional model to be loaded.
[0049] Step S15: Otherwise, it is determined that the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory.
[0050] Step S20: If it exists, the model data required for loading the three-dimensional model to be loaded is read from the shared memory, and the corresponding three-dimensional model is loaded according to the model data.
[0051] In some embodiments, if the model data required for loading the 3D model to be loaded exists in the shared memory, the model data required for loading the 3D model to be loaded is directly read from the shared memory, and the corresponding 3D model is loaded according to the model data, thereby improving the efficiency and performance of 3D model loading. In particular, when multiple different processes are loading repeated and large-volume 3D models at the same time, the corresponding model data can be directly read from the shared memory and loaded, thereby effectively improving the 3D model loading performance.
[0052] Please refer to Figure 2 In some embodiments, the three-dimensional model loading method further includes step S30: if the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory, the three-dimensional model data of the three-dimensional model to be loaded is read and stored in the shared memory.
[0053] In this embodiment, if the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory, the three-dimensional model data of the three-dimensional model to be loaded needs to be read and stored in the shared memory, so that when the three-dimensional model to be loaded is subsequently loaded, the data can be directly read from the shared memory and the model can be loaded, thereby improving the comprehensiveness of the three-dimensional model data stored in the shared memory and improving the efficiency of three-dimensional model loading.
[0054] Please refer to Figure 3 In some embodiments, step S30 reads the three-dimensional model data of the three-dimensional model to be loaded and stores it in the shared memory, including steps S31 to S32, which are described in detail below.
[0055] Step S31: reading the 3D model data of the 3D model to be loaded from a preset storage medium.
[0056] In some embodiments, the preset storage medium is a database or a file, and the three-dimensional model data of the three-dimensional model to be loaded is stored in the database or the file. When the model data required to load the three-dimensional model to be loaded does not exist in the shared memory, the corresponding three-dimensional model data needs to be read from the database or the file in order to subsequently load the three-dimensional model.
[0057] Step S32: Load the 3D model data according to the loading strategy, and store the loaded 3D model data in the shared memory.
[0058] In some embodiments, the three-dimensional model data includes geometric data and attribute data, and the corresponding three-dimensional model can be completely restored and loaded through the three-dimensional model data. Among them, the geometric data includes the model structure tree data, that is, the data of the child-parent relationship structure, which is the data describing the hierarchical relationship between the various parts of the model, and each part can be a sub-part of another part, so as to form a tree structure. The geometric data also includes rendering data used for rendering, which is data describing the surface shape and details of the model, usually including information such as vertices, edges, and faces, wherein the vertex data defines the position of the vertex in the three-dimensional space. The attribute data includes the corresponding node description data, which can be a name, ID, pointer address, data length, etc. Before storing the three-dimensional model data in the shared memory, the three-dimensional model needs to be loaded and processed through the loading strategy. For the geometric data, it is necessary to perform instantiation loading processing and data batch loading processing to solve the problem that the repeated and large-volume data affects the efficiency of loading. Among them, the instantiation loading processing refers to storing only one copy of the geometric data for the recurring objects, and creating multiple instances by referencing the geometric data when necessary, thereby significantly reducing the demand for storage space and improving the efficiency of subsequent loading. The batch loading process of data refers to merging the rendering operations of the loaded model into one or a few rendering calls to reduce the number of calls. For attribute data, the attribute data and geometric attributes are mapped through the loading strategy, so that it can be better called when the model is loaded later.
[0059] In some embodiments, the shared memory includes multiple bytes, the first byte in the shared memory is set as a first identifier, and the bytes adjacent to the first byte in the shared memory are set as a second identifier, wherein the first identifier is used to indicate whether the shared memory stores model data required for loading a three-dimensional model, and the second identifier is used to indicate the storage status of the process of storing the loaded three-dimensional model data in the shared memory, and the storage status includes completed data storage and ongoing data storage.
[0060] In some embodiments, when the first identifier is 1, it indicates that the shared memory stores the model data required for loading the three-dimensional model, and when the first identifier is 0, it indicates that the shared memory does not store the model data required for loading the three-dimensional model. When the second identifier is 1, it indicates that the model data of the loaded three-dimensional model has been stored in the shared memory, and when the second identifier is 0, it indicates that the loaded three-dimensional model data is being stored in the shared memory.
[0061] Please refer to Figure 4 In some embodiments, step S32 stores the loaded three-dimensional model data in the shared memory, including steps S321 to S322, which are described in detail below.
[0062] Step S321: Create a new shared memory block in the shared memory.
[0063] In some embodiments, a new shared memory block is created in the shared memory, and a new identifier is configured for the new shared memory block.
[0064] Step S322: storing the loaded three-dimensional model data in a new shared memory block.
[0065] In some embodiments, the loaded three-dimensional model data is stored in a new shared memory block, so as to independently store the model data of each three-dimensional model in the corresponding shared memory block, thereby improving the efficiency of the process in reading data when loading the model.
[0066] In some embodiments, when a shared memory block is accessed by any process, the shared memory block can be accessed by other processes except the process until the access is completed. For example, when a shared memory block is accessed by process A, process B cannot access the shared memory block at this time. Only when process A has completed accessing the shared memory block can process B access the shared memory block. Assuming that when process A writes model data to the shared memory model01, it will judge the current storage status in the shared memory model01 through the second identifier in the shared memory model01. When the second identifier is 1, it means that the model data of the loaded three-dimensional model has been stored in the shared memory model01. At this time, process B can start to access the shared memory model01. When the second identifier is 0, it means that the loaded three-dimensional model data is being stored in the shared memory model01. At this time, process B cannot access the shared memory model01 and needs to wait until the data is written. After that, that is, when the second identifier is 1, process B can access the shared memory model01.
[0067] This embodiment proposes a shared memory technology based on computer equipment to achieve different processes sharing the same model data, solve the needs of efficient reading and avoiding repeated occupation of data memory. In this embodiment, the model data is first read into the shared memory to reduce the time of data reading. If there are multiple identical processes reading the same model data at the same time, the effect of the three-dimensional model loading method of this embodiment becomes more obvious. The existing processing process is to use a process to process a file data or read the data in the database, and convert the file data or the data in the database into the computer memory. When the reading is completed, that is, when the data is read into the computer memory, the process can start to operate the corresponding data. In this embodiment, the model data is first read into the shared memory and the loading strategy is stored. When the process needs to operate the model data, it does not need to spend too much time reading the data from the file or database. The corresponding data can be copied from the shared memory by memory copying, wherein the speed of memory copying is faster than the speed of reading the data from the hard disk to the shared memory. Reading the model data directly from the shared memory can effectively improve the loading performance of the three-dimensional model, especially the repeated and large-volume three-dimensional model.
[0068] Please refer to Figure 5 In one embodiment, a computer device is provided, including: a memory 1000, the memory 1000 includes an internal memory and an external memory, the external memory is used to store programs, the internal memory includes a shared memory, the shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used for access by multiple processes; a processor 1100, used to implement a three-dimensional model loading method by executing a program stored in the memory 1000.
[0069] In one embodiment, a computer-readable storage medium is provided, on which a program is stored. The program can be executed by a processor to implement a three-dimensional model loading method.
[0070] In one embodiment, a computer program product is provided, including a computer program and / or instructions, and when the computer program and / or instructions are executed by a processor, a three-dimensional model loading method is implemented.
[0071] Those skilled in the art will appreciate that all or part of the functions of the various methods in the above-mentioned embodiments can be implemented by hardware or by computer programs. When all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can be stored in a computer-readable storage medium, and the storage medium can include: read-only memory, random access memory, disk, optical disk, hard disk, etc., and the program is executed by a computer to implement the above-mentioned functions. For example, the program is stored in the memory of the device, and when the program in the memory is executed by the processor, all or part of the above-mentioned functions can be implemented. In addition, when all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can also be stored in a storage medium such as a server, another computer, disk, optical disk, flash disk or mobile hard disk, and can be downloaded or copied and saved in the memory of the local device, or the system of the local device is updated, and when the program in the memory is executed by the processor, all or part of the functions in the above-mentioned embodiments can be implemented.
[0072] The above specific examples are used to illustrate the present invention, which are only used to help understand the present invention and are not used to limit the present invention. For those skilled in the art to which the present invention belongs, some simple deductions, modifications or substitutions can be made according to the idea of the present invention.
Claims
1. A three-dimensional model loading method based on shared memory, applied to a computer device, wherein the computer device includes a memory, characterized in that: The memory includes a shared memory, the shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used for access by multiple processes. The three-dimensional model loading method includes: When any process needs to load a three-dimensional model, it is determined whether there is model data required to load the three-dimensional model in the shared memory; If it exists, the model data required for loading the three-dimensional model to be loaded is read from the shared memory, and the corresponding three-dimensional model is loaded according to the model data.
2. The three-dimensional model loading method according to claim 1, characterized in that: Also includes: If the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory, the three-dimensional model data of the three-dimensional model to be loaded is read from a preset storage medium; The three-dimensional model data is loaded according to the loading strategy, and the loaded three-dimensional model data is stored in the shared memory.
3. The three-dimensional model loading method according to claim 2, characterized in that: The shared memory includes multiple bytes, the first byte in the shared memory is set as a first identifier, and the bytes adjacent to the first byte in the shared memory are set as a second identifier, wherein the first identifier is used to indicate whether the shared memory stores model data required for loading a three-dimensional model, and the second identifier is used to indicate the storage status of the process of storing the loaded three-dimensional model data in the shared memory, and the storage status includes completed data storage and ongoing data storage.
4. The three-dimensional model loading method according to claim 2, characterized in that: The storing the loaded three-dimensional model data into the shared memory comprises: Creating a new shared memory block in the shared memory; The loaded three-dimensional model data is stored in the new shared memory block.
5. The three-dimensional model loading method according to any one of claims 1 to 4, characterized in that: The shared memory includes multiple shared memory blocks, wherein a corresponding identifier is configured for each shared memory block when the shared memory block is created, and the identifier of the shared memory block is notified to the process, so that the process accesses the corresponding shared memory block according to the identifier of the shared memory block and reads the model data therein.
6. The three-dimensional model loading method according to claim 5, characterized in that: The model data of each three-dimensional model has a file name, and the identifier of each shared memory block corresponds to the file name of the model data stored therein; The determining whether the shared memory contains model data required for loading the three-dimensional model to be loaded includes: Determine the identifier of the corresponding shared memory block according to the file name of the model data required when loading the three-dimensional model to be loaded; Accessing the corresponding shared memory block according to the identifier of the shared memory block; When the accessed shared memory block stores model data required for loading the three-dimensional model to be loaded, it is determined that the shared memory contains the model data required for loading the three-dimensional model to be loaded; Otherwise, it is determined that the model data required for loading the three-dimensional model to be loaded does not exist in the shared memory.
7. The three-dimensional model loading method according to claim 5, characterized in that: When the shared memory block is accessed by any process, the shared memory block can be accessed by other processes except the process until the access is completed.
8. A computer device, characterized in that: include: A memory, wherein the memory includes an internal memory and an external memory, wherein the external memory is used to store programs, and the internal memory includes a shared memory, wherein the shared memory is used to store model data required when loading a three-dimensional model, and the shared memory is used to be accessed by multiple processes; A processor, configured to implement the three-dimensional model loading method according to any one of claims 1 to 7 by executing the program stored in the memory.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program, and the program can be executed by a processor to implement the three-dimensional model loading method according to any one of claims 1 to 7.
10. A computer program product comprising a computer program and / or instructions, characterized in that: When the computer program and / or the instructions are executed by the processor, the three-dimensional model loading method according to any one of claims 1 to 7 is implemented.