Method for realizing three-dimensional scene construction and rendering optimization based on three-dimensional engine
By editing and importing the 3D engine in the 3D scene software for parsing and building high-resolution grids, the problems of low rendering efficiency and poor flexibility of traditional 3D software are solved, and more efficient 3D scene rendering and design are achieved, satisfying the editing Designer needs reduce production cycle and cost.
Patent Information
- Application Number
- CN202411173692.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-11-15
AI Technical Summary
Traditional three-dimensional software has low rendering efficiency, insufficient production accuracy, inability to preview and edit in real time and poor flexibility, resulting in large production workload and long cycles of ground editing designers, which cannot meet design needs.
By editing the three-dimensional scene model in the three-dimensional scene software, the height data, grid vertex normal coordinate data and texture coordinate data are exported, stored as height map files, and imported into the three-dimensional engine to analyze and build high-resolution three-dimensional mesh. , combined with the ray tracing technology of the three-dimensional engine for rendering, achieving quick construction and rendering.
It improves the rendering speed and effect of three-dimensional scenes, enhances the flexibility of the software, meets the design needs of ground-producing designers, reduces modification costs and production cycles, and improves users' immersion in the virtual environment.
Smart Images

Figure CN118967942A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtual reality technology, and in particular to a method and system for implementing three-dimensional scene construction and rendering optimization based on a three-dimensional engine. Background Art
[0002] In traditional 3D scene design, the designers designed and produced the scenes completely based on 2D hand-drawing. With the further development of virtual reality technology, the popularization and continuous improvement of 3D software, the designers added some 3D software and began to use it for rendering while using hand-drawing in the early stage.
[0003] Virtual reality technology is a computer simulation system that can create and experience a virtual world. It uses computers to generate a simulated environment and immerse users in it. The 3D engine can directly view the running effect in the editor, make adjustments and optimizations in real time, and the real-time preview function allows developers to quickly iterate and test game content, saving unnecessary waiting time.
[0004] At present, landscape designers usually use some 3D software to design and produce 3D scenes, and use Arnold and V Ray software for further detailed rendering. However, these software have the following problems in the process of use: 1. Renderer problem: rendering efficiency is low; re-rendering is required after switching the environment, light and camera, and WYSIWYG cannot be achieved. All parameters need to be adjusted manually, and re-rendering is required after the adjustment is completed, which increases the production workload and production cycle.
[0005] 2. Defects of common 3D scene software: insufficient production accuracy; low texture resolution; inability to preview and edit in real time; inability to meet the production needs of editors; poor flexibility and inability to bridge with the engine. Summary of the invention
[0006] To solve the above problems, the present invention provides a method and system for realizing three-dimensional scene construction and rendering optimization based on a three-dimensional engine. The method and system can improve the rendering speed and effect of the three-dimensional scene as a whole, while improving the flexibility of software application and interoperability, satisfying the design effects and design requirements of designers, and reducing modification costs and production cycles.
[0007] In order to achieve the above-mentioned object of the invention, the present invention adopts the following technical scheme: In a first aspect, the present invention discloses a method for implementing 3D scene construction and rendering optimization based on a 3D engine, comprising the following steps: Step 1: Edit the 3D scene in the 3D scene software to obtain a 3D scene model; Step 2: Export the height data, mesh vertex normal coordinate data and texture coordinate data of the 3D scene and store them as a height map file; Step 3: Import the height map file into the 3D engine, parse the data and construct a 3D mesh of triangles composed of vertices; Step 4: Calculate the normal texture coordinates and cover the entire 3D grid with the entire normal texture to obtain a high-resolution map; Step 5: Combine the 3D mesh and high-resolution texture to quickly build and render the 3D scene.
[0008] Furthermore, in step 2, the height data includes the minimum and maximum values of the three-dimensional scene surface height obtained by pixel color, that is, the height threshold; and the size and position information of the map associated with the three-dimensional scene surface height; the texture coordinate data includes material ball attribute information, and the vertex height calculated based on the pixel color of each pixel of the height map image.
[0009] Furthermore, in step 3, the specific method of parsing the data is as follows: Step 3-1: Read the height map data in the file into memory; Step 3-2: Create an array in of unsigned character type to store the read height map data; the size of the array in is equal to the product of the width and height of the height map; Step 3-3: Create an input file stream object inFile, and use the member function open to open the height map file in binary mode; Step 3-4: Use the read function to read data from the height map file into the in array, convert the starting address of the in array into a character pointer, and specify the number of bytes to be read as the size of the in array; Step 3-5: After reading is completed, close the file; Step 3-6: Copy the data in the in array to the mHeightmap array through a loop and scale it; convert the unsigned character data into a floating point number and multiply it by the scaling ratio to get the height and width values of the texture.
[0010] Furthermore, in step 3, the specific method of constructing a three-dimensional mesh of triangles composed of vertices is as follows: Step 31: Create a texture object: Create a texture object associated with the map; Step 32: Calculate the increment value: By dividing the texture width value by the actual width minus 1, we get the horizontal increment of each mesh vertex coordinate to ensure that the texture is correctly mapped to the model in the horizontal direction; adjust the range of the starting Z coordinate and divide it by the actual height value minus 1 to achieve uniform distribution of the texture in the vertical direction.
[0011] Step 33: Create lists: Create a positions list to store the position information of each vertex of the model and confirm the position and shape of the model in space; create a textCoords list to store the coordinate information related to the texture and map the texture to the model; create an indices list to store the index information of the triangles connected by the vertices.
[0012] Step 34: list-to-array conversion: convert the position information posArr of each vertex, the texture coordinate information textCoordsArr, and the index information indicesArr of connecting the vertices to form a triangle from list form to array form.
[0013] Step 35: Create a grid: Use the converted posArr, extCoordsArr, and indicesArr arrays to create a higher precision three-dimensional grid.
[0014] Furthermore, step 4 includes the following specific steps: Step 41: Create a normal list to store the position data information of adjacent vertex variables; Step 42: Obtain the position data of adjacent vertices in the normals list by indexing, obtain the displacement vector between the vertices by calculating the difference between the adjacent vertices, set the displacement vector to the default normal value, and add the normal value of the displacement vector to the normals list; Step 43: Convert the normals list into an array, obtain the normal coordinate value corresponding to each adjacent vertex position through array conversion, arrange the normal coordinates of the vertex position and form a graphic matrix, and finally obtain a high-resolution normal map; Step 44: Create a material object and apply it to the 3D mesh.
[0015] Furthermore, the specific steps of step 5 are as follows: Combine the 3D scenes in steps 3 and 4 with the high-resolution texture in the 3D engine, set the reflection parameters, adjust the direction of light, use the ray tracing technology of the 3D engine to view the real effect, and modify the scene according to the debugging effect.
[0016] In a second aspect, the present invention discloses a system for implementing 3D scene construction and rendering optimization based on a 3D engine, including the following functional modules: A model editing module is used to edit the three-dimensional scene in the three-dimensional scene software to obtain a three-dimensional scene model; A data export and storage module is used to export the height data, mesh vertex normal coordinate data and texture coordinate data of the three-dimensional scene and store them as a height map file; Data parsing and mesh building module, used to import height map files into the 3D engine, parse the data and build a 3D mesh of triangles composed of vertices; The texture acquisition module is used to calculate the normal texture coordinates and cover the entire 3D grid with the normal texture to obtain a high-resolution texture. The scene construction and rendering module is used to combine 3D meshes and high-resolution textures to quickly build and render 3D scenes.
[0017] Compared with the prior art, the present invention has the following beneficial effects: The present invention greatly improves the flexibility of the software through the combined use of three-dimensional software and a three-dimensional engine, satisfies the imagination of the geographer, and can carry out bolder and higher-data-volume creations, truly satisfying the design effects and design concepts required by the geographer. The produced three-dimensional scene, through virtual reality technology, can restore the real effect of the scene to a greater extent, increasing the user's immersion in the virtual environment. The powerful real-time rendering and light and shadow tracking functions of the three-dimensional engine can enable the virtual three-dimensional scene to quickly obtain the effect with materials. The use of a three-dimensional engine can make the three-dimensional scene do not need to be re-rendered after switching the environment and light, reducing time and labor costs and improving efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flowchart of a method for realizing three-dimensional scene construction and rendering optimization based on a three-dimensional engine provided in Example 1; Figure 2 This is a schematic diagram of the system structure for implementing 3D scene construction and rendering optimization based on a 3D engine provided in Example 2; Figure 3 In the first embodiment, triangles are formed based on pixels to form a three-dimensional scene grid map; Figure 4 The schematic diagram of the undulating scene of the three-dimensional scene is realized by changing the Y-axis coordinate of the grid of the three-dimensional scene according to the pixel color based on the pixel points in the first embodiment; Figure 5 It is a schematic diagram of converting information into an array form in step 34 of the first embodiment; Figure 6It is a schematic diagram of the effect of integrating the vertex positions, texture coordinates, normals, connected vertices and other information of the model in the mesh in step 35 of the first embodiment; Figure 7 It is a schematic diagram of the effect of applying the created material to the three-dimensional grid in step 44 of the first embodiment. DETAILED DESCRIPTION
[0019] In order to clearly illustrate the technical features of the present invention, the present invention will be described in detail below through specific implementation methods and in conjunction with the accompanying drawings. The disclosure below provides many different embodiments for realizing different structures of the present invention. In order to simplify the disclosure of the present invention, the components and settings of specific examples are described below. In addition, the present invention may repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplicity and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed. It should be noted that the components illustrated in the accompanying drawings are not necessarily drawn to scale. The present invention omits the description of known components and processing techniques and processes to avoid unnecessary limitations on the present invention.
[0020] Embodiment 1 This embodiment provides a method for implementing 3D scene construction and rendering optimization based on a 3D engine, and the process is as follows: Figure 1 As shown, the following steps are included: Step 1: Use 3D scene software to create a basic visualized 3D scene in Biomes, a random pixel generation website, and add a filter deformer. Create 3D scene materials in Materials, and use masks such as arealayer, curvalure, and slopelight in textures to distinguish materials. Use Sculpt in shapelayers to personalize the 3D scene, and adjust the interval value of 0-1 for personalized fusion adjustment to obtain a 3D scene model.
[0021] Step 2: Store the height data, mesh vertex normal coordinate data and texture coordinate data of the three-dimensional scene in step 1 as a height map file and export it; wherein the height data includes the minimum and maximum values of the three-dimensional scene surface height obtained by pixel color, that is, the height threshold; and the size and position information of the map associated with the three-dimensional scene surface height; the texture coordinate data includes material ball attribute information, and the vertex height calculated based on the pixel color of each pixel of the height map image.
[0022] Step 3: Import the height map file exported in step 2 into the 3D engine. First, parse the data in the height map file. The following is a detailed description of this part combined with the code: Step 3-1: Use the method of std::ifstream::read to read the height map data into memory; Step 3-2: Create an array in of unsigned char type with a size equal to the product of the width and height dimensions of the height map to store the read height map data, Std::vector<unsigned char> in(mInfo.HeightmapWidth * mInfo.HeightmapHeight); Step 3-3: Create an input file stream object inFile and use the member function open to open the specified height map file in binary mode. The file name is obtained through mInfo.HeightMapFilename, std::ifstream inFile; inFile.open(mInfo.HeightMapFilename.c_str(), std::ios_base::binary); Step 3-4: Check if the file is successfully opened through if(inFile). If the file is opened successfully, use the read function to read the data from the height map file into the in array, inFile.read((char*)&in[0], (std::streamsize)in.size()), where (char*)&in[0] represents converting the starting address of the in array to a character pointer, and (std::streamsize)in.size() is the specified number of bytes to be read, which is the size of the in array; Step 3-5: After reading, close the file, inFile.close(); Step 3-6: Copy the data in the in array to the mHeightmap array through a loop and perform scaling processing. For(UINT i = 0; i < mInfo.HeightmapHeight * mInfo.HeightmapWidth; ++i), where mInfo.HeightScale is used to control the scaling ratio, convert the unsigned char data to a floating point number and multiply by the scaling ratio to obtain the height and width values of the final texture.
[0023] After the above data parsing process is completed in Step 3, construct a three-dimensional mesh of triangles composed of vertices through the following method: Step 31: Create a texture object associated with the texture, Texture texture = new Texture(textureFile); Step 32: Calculate the increment value: float incx = getWidth() / (width - 1); float incz = Math.abs(STARTZ * 2) / (height - 1); Among them, the calculation of incx is to evenly distribute the position information in the horizontal direction. By dividing the width value of the texture by the actual width minus 1, the increment of each unit in the horizontal direction is obtained. Ensure that the texture is correctly mapped to the model in the horizontal direction. The calculation of incz is to determine the increment of the position in the vertical direction. Math.abs(STARTZ * 2) adjusts the range of the starting Z coordinate and then divides it by the actual height value minus 1 to achieve even distribution of the texture in the vertical direction, such as Figure 4 As shown; Step 33: Create List: List <float>positions = new ArrayList(); List <float>textCoords = new ArrayList(); List <integer>indices = new ArrayList(); The positions list stores the position information of each vertex of the model and confirms the position and shape of the model in space. The textCoords list stores the coordinate information related to the texture and maps the texture to the model. The indices list stores the index information of the triangles formed by connecting the vertices.
[0024] Step 34: Convert the position information posArr of each vertex, the texture coordinate information textCoordsArr, and the index information indicesArr of the triangle connected by the vertices into an array form, such as Figure 5 As shown: float[] posArr=Utils.listToArray(positions); int[] indicesArr=indices.stream().mapToInt(i ->i).toArray(); float[] textCoordsArr=Utils.listToArray(textCoords).
[0025] Step 35: Use the converted posArr array, extCoordsArr array and indicesArr array to create a higher precision 3D mesh, this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); The mesh integrates the model's vertex position, texture coordinates, normals, connected vertices and other information, such as Figure 6 shown.
[0026] Step 4: Calculate the normal texture coordinates, cover the entire 3D grid with the entire normal texture, and obtain a high-resolution map. The specific method is as follows: Step 41: Create a normal list to store the position data information of adjacent vertex variables; Step 42: Obtain the position data of adjacent vertices in the normals list by indexing, obtain the displacement vector between the vertices by calculating the difference between the adjacent vertices, set the displacement vector to the default normal value, and add the normal value of the displacement vector to the normals list; Step 43: Finally, the normals list is converted into an array. Through the array conversion, the normal coordinate value corresponding to each adjacent vertex position is obtained. The normal coordinates of the vertex positions are arranged and formed into a graphic matrix, and finally a high-resolution normal map is obtained; Step 44: Create a material object, Material material = new Material(texture, 0.0f); apply the created material to the 3D mesh through mesh.setMaterial(material), such as Figure 7 shown.
[0027] Step 5: Combine the 3D scenes in steps 3 and 4 with the high-resolution texture in the 3D engine, set the reflection parameters, move, rotate and change the direction of the light, use the ray tracing technology of the 3D engine to view the real effect, and modify the scene according to the debugging effect.
[0028] Embodiment 2 This embodiment discloses a system for implementing 3D scene construction and rendering optimization based on a 3D engine, including the following functional modules: A model editing module is used to edit the three-dimensional scene in the three-dimensional scene software to obtain a three-dimensional scene model; A data export and storage module is used to export the height data, mesh vertex normal coordinate data and texture coordinate data of the three-dimensional scene and store them as a height map file; Data parsing and mesh construction module, used to import height map files into the 3D engine, parse the data and construct a 3D mesh of triangles composed of vertices; The texture acquisition module is used to calculate the normal texture coordinates and cover the entire 3D grid with the normal texture to obtain a high-resolution texture. The scene construction and rendering module is used to combine 3D meshes and high-resolution textures to quickly build and render 3D scenes.
[0029] The above embodiments are only technical solutions of the present invention rather than limitations thereof. It should be pointed out that, for those skilled in the art, the specific implementation modes of the present invention may be modified or replaced by equivalents without departing from the technical principles of the present invention. Any modification or equivalent replacement without departing from the spirit and scope of the present invention shall be included in the scope of the claims of the present invention.< / integer> < / float> < / float>
Claims
1. A method for realizing three-dimensional scene construction and rendering optimization based on a three-dimensional engine, characterized in that: The following steps are involved: Step 1: Edit the 3D scene in the 3D scene software to obtain a 3D scene model; Step 2: Export the height data, mesh vertex normal coordinate data and texture coordinate data of the 3D scene and store them as a height map file; Step 3: Import the height map file into the 3D engine, parse the data and construct a 3D mesh of triangles composed of vertices; Step 4: Calculate the normal texture coordinates and cover the entire 3D grid with the entire normal texture to obtain a high-resolution map; Step 5: Combine the 3D mesh and high-resolution texture to quickly build and render the 3D scene.
2. A method for realizing three-dimensional scene construction and rendering optimization based on a three-dimensional engine as claimed in claim 1, characterized in that: In step 2: The height data includes the minimum and maximum values of the height of the three-dimensional scene surface obtained by pixel color, that is, the height threshold; and the size and position information of the map associated with the height of the three-dimensional scene surface; The texture coordinate data includes material ball attribute information; and the height of each vertex calculated based on the color of each pixel of the height map image.
3. The method for realizing 3D scene construction and rendering optimization based on a 3D engine according to claim 1, characterized in that: In step 3, the method for parsing data is as follows: 3-1: Read the height map data in the file into memory; 3-2: Create an array in of unsigned character type to store the read height map data; the size of the array in is equal to the product of the width and height of the height map; 3-3: Create an input file stream object inFile, and use the member function open to open the height map file in binary mode; 3-4: Use the read function to read data from the height map file into the in array, convert the starting address of the in array into a character pointer, and specify the number of bytes to be read as the size of the in array; 3-5: After reading, close the file; 3-6: Copy the data in the in array to the mHeightmap array through a loop and scale it; Convert the unsigned character data to a floating point number and multiply it by the scaling factor to get the final texture height and width values.
4. The method for realizing 3D scene construction and rendering optimization based on a 3D engine according to claim 1, characterized in that: In step 3, the specific method of constructing a three-dimensional mesh of triangles composed of vertices is as follows: 31: Create texture object: Create a texture object associated with a map; 32: Calculate the increment value: By dividing the width value of the texture by the actual width minus 1, the increment of each mesh vertex coordinate in the horizontal direction is obtained to ensure that the texture is correctly mapped to the model in the horizontal direction; adjust the range of the starting Z coordinate and divide it by the actual height value minus 1 to achieve uniform distribution of the texture in the vertical direction; 33: Create lists: Create a positions list to store the position information of each vertex of the model and confirm the position and shape of the model in space; create a textCoords list to store the coordinate information related to the texture and map the texture to the model; create an indices list to store the index information of the triangles connected to the vertices; 34: List to array conversion: convert the position information posArr of each vertex, the texture coordinate information textCoordsArr, and the index information indicesArr of connecting vertices to form a triangle from list form to array form; 35: Create a grid: Use the converted posArr, extCoordsArr, and indicesArr arrays to create a higher precision three-dimensional grid.
5. The method for realizing 3D scene construction and rendering optimization based on a 3D engine according to claim 1, characterized in that: The step 4 comprises the following specific steps: Step 41: Create a normal list to store the position data information of adjacent vertex variables; Step 42: Obtain the position data of adjacent vertices in the normals list by indexing, obtain the displacement vector between the vertices by calculating the difference between the adjacent vertices, set the displacement vector to the default normal value, and add the normal value of the displacement vector to the normals list; Step 43: Convert the normals list into an array, obtain the normal coordinate value corresponding to each adjacent vertex position through array conversion, arrange the normal coordinates of the vertex position and form a graphic matrix, and finally obtain a high-resolution normal map; Step 44: Create a material object and apply it to the 3D mesh.
6. The method for realizing 3D scene construction and rendering optimization based on a 3D engine according to claim 1, characterized in that: The specific steps of step 5 are as follows: Combine the 3D scenes in steps 3 and 4 with the high-resolution texture in the 3D engine, set the reflection parameters, adjust the direction of light, use the ray tracing technology of the 3D engine to view the real effect, and modify the scene according to the debugging effect.
7. A system for implementing 3D scene construction and rendering optimization based on a 3D engine, used to implement the method according to any one of claims 1 to 6, characterized in that: include: A model editing module is used to edit the three-dimensional scene in the three-dimensional scene software to obtain a three-dimensional scene model; A data export and storage module is used to export the height data, mesh vertex normal coordinate data and texture coordinate data of the three-dimensional scene and store them as a height map file; Data parsing and mesh construction module, used to import height map files into the 3D engine, parse the data and construct a 3D mesh of triangles composed of vertices; The texture acquisition module is used to calculate the normal texture coordinates and cover the entire 3D grid with the normal texture to obtain a high-resolution texture. The scene construction and rendering module is used to combine 3D meshes and high-resolution textures to quickly build and render 3D scenes.
Citation Information
Cited By
Image rendering method and device and electronic equipment
CN119625146A
An image rendering method, apparatus and electronic device
CN119625146B
