Vegetation processing method and device in virtual scene, electronic equipment and storage medium
By generating scene height maps and vegetation density maps, combining vegetation height information, adding pixel values to the density map, and compressing and storing only vegetation that meets the conditions, the problems of distortion and logical errors in vegetation restoration are solved, and efficient vegetation data processing is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XINGZHEN TECH (SHANGHAI) CO LTD
- Filing Date
- 2025-12-09
- Publication Date
- 2026-05-01
AI Technical Summary
In existing technologies, the compression and storage of vegetation information through density maps can lead to distortion or logical errors during vegetation restoration, affecting the accuracy of vegetation restoration.
Generate a scene height map of the target virtual scene. Combine the preset horizontal position and height information of vegetation with the corresponding pixel values added to the preset density map to generate a vegetation density map. Only vegetation that meets the conditions is compressed and stored to avoid compressing and storing vegetation that does not meet the conditions.
It improves the accuracy of vegetation restoration, achieves a balance between vegetation data storage efficiency and restoration accuracy, and avoids distortion and logical errors during vegetation restoration.
Smart Images

Figure CN121944512A_ABST
Abstract
Description
Methods, devices, electronic equipment and storage media for vegetation processing in virtual scenes Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for processing vegetation in a virtual scene. Background Technology
[0002] In the development of interactive platforms, constructing realistic and immersive outdoor environments is a key aspect of enhancing the player experience. For example, in game scenes, vegetation, as an indispensable visual element in natural landscapes, is widely used in the construction of environments such as forests, grasslands, and mountains, playing a decisive role in the ecological feel and visual richness of the scene. However, with the continuous improvement of game graphics, the requirements for the quantity, variety, and visual detail of vegetation are also increasing, often resulting in the deployment of tens of thousands or even millions of vegetation instances in outdoor scenes. Related technologies use density maps to describe the distribution of vegetation. Density maps divide the entire scene into several grid cells or regions, each cell corresponding to a specific geographical location and assigned a value to that location to represent the expected amount of vegetation to be generated within that region. This method abandons the reliance on the precise coordinates of individual vegetation instances, instead focusing on the overall distribution pattern and density changes of vegetation, significantly reducing the amount of data that needs to be stored. However, because density maps compress and store a large amount of vegetation location information, it can lead to distortion or logical errors during vegetation reconstruction, thus affecting the accuracy of vegetation reconstruction. Summary of the Invention
[0003] This disclosure provides a method, apparatus, electronic device, and storage medium for processing vegetation in a virtual scene, in order to at least solve the problem in the related art where the compression and storage of vegetation information through density maps leads to distortion or logical errors during vegetation restoration, thereby affecting the accuracy of vegetation restoration. The technical solution of this disclosure is as follows: According to a first aspect of the embodiments of this disclosure, a method for processing vegetation in a virtual scene is provided, comprising: generating a scene height map corresponding to a target virtual scene; associating the pixel value of any pixel in the scene height map with the height of a corresponding scene area in the target virtual scene; determining a first pixel in a preset density map corresponding to a preset horizontal position based on a preset horizontal position of vegetation to be created in the target virtual scene; any pixel in the preset density map corresponding to a corresponding scene area in the target virtual scene; when the pixel value of a second pixel in the scene height map matches the preset height position of the vegetation to be created, increasing the pixel value of the first pixel in the preset density map; the position of the second pixel in the scene height map matching the position of the first pixel in the preset density map; generating a vegetation density map corresponding to the target virtual scene based on the preset density map with the increased pixel value; and associating the pixel value of any pixel in the vegetation density map with the amount of vegetation in a corresponding scene area in the target virtual scene.
[0004] In an exemplary embodiment, the method further includes: when the pixel value of the second pixel in the scene height map does not match the vegetation height of the vegetation to be created, storing the preset horizontal position of the vegetation to be created in the target virtual scene and the vegetation height of the vegetation to be created.
[0005] In an exemplary embodiment, the method further includes: determining at least one set of pixel pairs based on the pixel values of each pixel in the scene height map; each set of pixel pairs includes two adjacent pixels, and the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference; determining an edge scene region in the target virtual scene; the edge scene region is the corresponding scene region of the at least one set of pixel pairs in the target virtual scene; and storing a preset horizontal position of vegetation in the edge scene region and the vegetation height of vegetation in the edge scene region.
[0006] In an exemplary embodiment, the pixel value of each pixel in the preset density map that has undergone pixel value increment processing is the number of vegetation in the corresponding scene area of the target virtual scene; the step of generating a vegetation density map corresponding to the target virtual scene based on the preset density map that has undergone pixel value increment processing includes: normalizing the number of vegetation corresponding to each pixel in the preset density map that has undergone pixel value increment processing to generate a vegetation density map corresponding to the target virtual scene.
[0007] In an exemplary embodiment, generating a scene height map corresponding to a target virtual scene includes: determining camera parameters and an orthogonal matrix for an orthogonal camera based on the scene horizontal range and the target height of the target virtual scene; the target height is the height of the highest static element in the target virtual scene excluding vegetation; the orthogonal matrix is used to map the target virtual scene to device space; mapping the three-dimensional coordinates of each static element in the target virtual scene to device space coordinates of each static element based on the orthogonal matrix; the device space coordinates include depth information of each static element; determining depth information of pixel coordinates based on the device space coordinates of each static element, the depth information of each static element, and the correspondence between device space coordinates and pixel coordinates; the pixel coordinates are coordinates within a target pixel range; determining the height corresponding to each pixel within the target pixel range based on the depth information of the pixel coordinates; and generating the scene height map based on the height corresponding to each pixel within the target pixel range.
[0008] In an exemplary embodiment, the method further includes: in response to a vegetation creation instruction for the target virtual scene, acquiring the scene height map and the vegetation density map; traversing the pixels in the vegetation density map; when a third pixel in the vegetation density map is reached and the pixel value of the third pixel is not zero, selecting at least one candidate location in the target scene region; the target scene region is the region in the target virtual scene corresponding to the third pixel, and the number of the at least one candidate location is determined based on the pixel value of the third pixel; determining the target region height corresponding to the target scene region based on the scene height map; and creating the target vegetation at the target region height of the at least one candidate location.
[0009] In an exemplary embodiment, determining the target region height corresponding to the target scene region based on the scene height map includes: determining a plurality of neighboring pixels of a fourth pixel from the scene height map; matching the position of the fourth pixel in the scene height map with the position of the third pixel in the vegetation density map; performing data fusion on the pixel values of the plurality of neighboring pixels to obtain fused pixel values; and determining the target region height based on the fused pixel values.
[0010] According to a second aspect of the present disclosure, a vegetation processing apparatus in a virtual scene is provided, comprising: a scene height map generation unit configured to generate a scene height map corresponding to a target virtual scene; wherein the pixel value of any pixel in the scene height map is associated with the height of a corresponding scene area in the target virtual scene; a pixel determination unit configured to determine a first pixel in a preset density map corresponding to a preset horizontal position based on a preset horizontal position of vegetation to be created in the target virtual scene; wherein any pixel in the preset density map corresponds to a corresponding scene area in the target virtual scene; a density increasing unit configured to increase the pixel value of the first pixel in the preset density map when the pixel value of a second pixel in the scene height map matches the preset height position of the vegetation to be created; wherein the position of the second pixel in the scene height map matches the position of the first pixel in the preset density map; and a density map generation unit configured to generate a vegetation density map corresponding to the target virtual scene based on the preset density map that has undergone pixel value increasing processing; wherein the pixel value of any pixel in the vegetation density map is associated with the vegetation quantity in a corresponding scene area in the target virtual scene.
[0011] In one exemplary embodiment, the apparatus further includes a first storage unit configured to perform: storing a preset horizontal position of the vegetation to be created in the target virtual scene and the vegetation height of the vegetation to be created when the pixel value of the second pixel in the scene height map does not match the vegetation height of the vegetation to be created.
[0012] In one exemplary embodiment, the apparatus further includes a second storage unit configured to perform: determining at least one set of pixel pairs based on the pixel values of each pixel in the scene height map; each set of pixel pairs includes two adjacent pixels, and the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference; determining an edge scene region in the target virtual scene; the edge scene region is the corresponding scene region of the at least one set of pixel pairs in the target virtual scene; and storing a preset horizontal position of vegetation in the edge scene region and the vegetation height of vegetation in the edge scene region.
[0013] In an exemplary embodiment, the pixel value of each pixel in the preset density map that has undergone pixel value increment processing is the number of vegetation in the corresponding scene area of the target virtual scene; the density map generation unit is configured to perform: normalize the number of vegetation corresponding to each pixel in the preset density map that has undergone pixel value increment processing, and generate a vegetation density map corresponding to the target virtual scene.
[0014] In an exemplary embodiment, the scene height map generation unit is configured to perform the following: determining camera parameters and an orthogonal matrix for an orthogonal camera based on the scene horizontal range and the target height of the target virtual scene; the target height being the height of the highest static element in the target virtual scene excluding vegetation; the orthogonal matrix being used to map the target virtual scene to device space; mapping the three-dimensional coordinates of each static element in the target virtual scene to device space coordinates of each static element based on the orthogonal matrix; the device space coordinates including depth information of each static element; determining depth information of pixel coordinates based on the device space coordinates of each static element, the depth information of each static element, and the correspondence between device space coordinates and pixel coordinates; the pixel coordinates being coordinates within a target pixel range; determining the height corresponding to each pixel within the target pixel range based on the depth information of the pixel coordinates; and generating the scene height map based on the height corresponding to each pixel within the target pixel range.
[0015] In one exemplary embodiment, the apparatus further includes a vegetation creation unit configured to perform: in response to a vegetation creation instruction for the target virtual scene, acquiring the scene height map and the vegetation density map; traversing the pixels in the vegetation density map; when a third pixel in the vegetation density map is reached and the pixel value of the third pixel is not zero, selecting at least one candidate location in the target scene region; the target scene region being the region in the target virtual scene corresponding to the third pixel, the number of the at least one candidate location being determined based on the pixel value of the third pixel; determining the target region height corresponding to the target scene region based on the scene height map; and creating the target vegetation at the target region height of the at least one candidate location.
[0016] In an exemplary embodiment, the vegetation creation unit is configured to perform: determining a plurality of neighboring pixels of a fourth pixel from the scene height map; matching the position of the fourth pixel in the scene height map with the position of the third pixel in the vegetation density map; performing data fusion on the pixel values of the plurality of neighboring pixels to obtain fused pixel values; and determining the height of the target area based on the fused pixel values.
[0017] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the vegetation processing method in a virtual scene as described above.
[0018] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the vegetation processing method in a virtual scene as described above.
[0019] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product including a computer program stored in a readable storage medium, wherein at least one processor of a computer device reads from the readable storage medium and executes the computer program, causing the device to perform the above-described vegetation processing method in a virtual scene.
[0020] The technical solutions provided by the embodiments of this disclosure bring at least the following beneficial effects: This disclosure generates a scene height map corresponding to the target virtual scene, and the pixel value of any pixel in the scene height map can represent the height of the corresponding scene area in the target virtual scene; further, when it is determined that the preset horizontal position of the vegetation to be created corresponds to the pixel value of the first pixel in the preset density map, it can be determined whether the pixel value of the first pixel needs to be increased by combining the pixel value of the corresponding second pixel in the scene height map. Thus, when the vegetation height of the vegetation to be created matches the pixel value of the second pixel in the scene height map, the pixel value of the first pixel is increased in the preset density map, that is, the vegetation to be created that meets the preset conditions is compressed and stored by the density map; if the height information is not combined for judgment, the vegetation information corresponding to different heights in the same vertical direction will be accumulated in the density map. Accordingly, in the process of instantiating the vegetation, the vegetation will be directly instantiated to the ground part of the corresponding scene area based on the density map, which is inconsistent with the expectation that the vegetation is at different heights in the same vertical direction. Therefore, compressing and storing vegetation that meets the preset conditions using density maps, while not compressing and storing vegetation that does not meet the preset conditions using density maps, can avoid distortion and logical errors when restoring vegetation based on density maps. This improves the accuracy of vegetation restoration based on density maps and achieves a balance between the storage efficiency and restoration accuracy of vegetation data.
[0021] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0023] Figure 1 is a schematic diagram of an implementation environment according to an exemplary embodiment.
[0024] Figure 2 is a flowchart illustrating a vegetation processing method in a virtual scene according to an exemplary embodiment.
[0025] Figure 3 is a flowchart illustrating a scene height map generation method according to an exemplary embodiment.
[0026] Figure 4 is a schematic diagram illustrating the process of generating a vegetation density map corresponding to a target virtual scene according to an exemplary embodiment.
[0027] Figure 5 is a flowchart illustrating a method for creating target vegetation according to an exemplary embodiment.
[0028] Figure 6 is a schematic diagram illustrating the process of restoring vegetation in a target virtual scene according to an exemplary embodiment.
[0029] Figure 7 is a block diagram of a vegetation treatment device in a virtual scene according to an exemplary embodiment.
[0030] Figure 8 is a schematic diagram of an electronic device structure according to an exemplary embodiment.
[0031] Figure 9 is a schematic diagram of another electronic device structure according to an exemplary embodiment. Detailed Implementation
[0032] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0033] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0034] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0035] Please refer to Figure 1, which shows a schematic diagram of the implementation environment provided by the embodiments of this disclosure. The implementation environment may include at least one terminal 110 and a server 120, and the terminal 110 and the server 120 can communicate with each other via a network.
[0036] Optionally, terminal 110 may include: smartphones, tablets, laptops, digital assistants, smart wearable devices, in-vehicle terminals, servers, etc. Terminal 110 has an interactive application installed and running. In this embodiment, the interactive application may be an application that provides virtual scene display functions, such as a social application, instant messaging application, live streaming application, game application, e-commerce application, virtual reality (VR) application, augmented reality (AR) application, etc. This application embodiment does not limit the specific type of application.
[0037] Optionally, server 120 provides background services for the interactive application installed on terminal 110. Terminal 110 can communicate with server 120 based on browser / server (B / S) mode or client / server (C / S) mode. The operating system running on terminal 110 in this embodiment may include, but is not limited to, Android, iOS, Linux, Windows, etc.
[0038] Server 120 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0039] To address the issue in related technologies where vegetation information is compressed and stored using density maps, leading to distortion or logical errors during vegetation restoration and thus affecting restoration accuracy, this disclosure provides a method for processing vegetation in a virtual scene. The method can be executed by the aforementioned terminal or server. Referring to Figure 2, the method may include: S210. Generating a scene height map corresponding to the target virtual scene; the pixel value of any pixel in the scene height map is correlated with the height of the corresponding scene region in the target virtual scene.
[0040] In this embodiment, the target virtual scene can be a virtual space carrier constructed by an interactive platform. The target virtual scene can be a scene displayed during the interactive platform's display process. The target virtual scene can include static elements, dynamic elements, environmental atmosphere elements, etc. Static elements can include terrain, buildings, vegetation, public facilities, etc. Dynamic elements can include virtual tasks, virtual props, rivers, drifting clouds, flashing lights, etc. Environmental atmosphere elements can include lighting, climate, music, visual effects.
[0041] In an optional embodiment, the target virtual scene can be a virtual scene in a game. It can refer to a virtual carrier with digital spatial attributes and interactive logic, which is constructed based on the core gameplay requirements and user experience goals of a video game through rendering engines, modeling tools, logic operation modules, etc., and is used to carry core elements such as game characters, props, and rules, so as to provide users with an immersive interactive experience.
[0042] In another alternative embodiment, the target virtual scene can be a simulation test virtual scene, which can refer to a digital virtual carrier built with high-precision modeling, physics engine, data-driven rendering, rule simulation module, etc., based on the performance verification requirements of a specific test object (such as a vehicle, equipment, or system), used to reproduce the real test environment or simulate extreme working conditions, so as to verify the function, performance, safety and other indicators of the test object.
[0043] The scene height map corresponding to the target virtual scene can represent the height information of static elements in the target virtual scene except for vegetation. Every pixel in the scene height map has a corresponding scene area in the target virtual space. Therefore, the pixel value of any pixel in the scene height map is associated with the height of the corresponding scene area in the target virtual scene. The pixel value of any pixel in the scene height map can be the actual height of the corresponding scene area in the target virtual scene; or it can be that there is a correlation between the pixel value of any pixel in the scene height map and the actual height of the corresponding scene area in the target virtual scene. That is, by processing the pixel value of any pixel in the scene height map, the actual height of the corresponding scene area in the target virtual scene can be obtained.
[0044] S220. Based on the preset horizontal position of the vegetation to be created in the target virtual scene, determine the first pixel in the preset density map corresponding to the preset horizontal position; any pixel in the preset density map corresponds to the corresponding scene area in the target virtual scene.
[0045] As can be seen from the above, the target virtual scene can include vegetation as a static element, and the vegetation can be configured in advance. For example, the number of vegetation to be created, the location of vegetation to be created, and the type of vegetation to be created can be configured in the target virtual scene. The vegetation types of vegetation at different locations in the target virtual scene can be the same or different.
[0046] The preset density map can be an image of a preset size, and the initial pixel value of each pixel in the preset density map is a preset pixel value, which can be 0. Each pixel in the preset density map corresponds to a corresponding scene area in the target virtual scene. For example, each pixel in the preset density map corresponds to an area of N*N meters in the target virtual scene. When there are multiple vegetation plants to be created, multiple vegetation plants can be traversed. For each vegetation plant to be created, the first pixel corresponding to the preset horizontal position in the preset density map can be determined according to its preset horizontal position in the target virtual scene.
[0047] S230. If the pixel value of the second pixel in the scene height map matches the preset height position of the vegetation to be created, the pixel value of the first pixel is increased in the preset density map; the position of the second pixel in the scene height map matches the position of the first pixel in the preset density map.
[0048] Vegetation to be created can be placed on the ground surface of the corresponding scene area. The preset height position of the vegetation corresponds to the area height of the corresponding scene area. The area height of the corresponding scene area can represent the height of static elements in the scene area relative to a horizontal reference plane, such as the height of the ground surface relative to a horizontal reference plane. The preset height position of the vegetation can be the position where the height difference between the root of the vegetation and the horizontal reference plane is the preset height. When the pixel value of each pixel in the scene height map is the actual height, matching the pixel value of the second pixel in the scene height map with the preset height position of the vegetation means that the difference between the pixel value of the second pixel and the height corresponding to the preset height position of the vegetation is less than or equal to a preset first difference. That is, the area height of the corresponding scene area is close to or equal to the preset height. In this case, the pixel value of the first pixel can be added to the preset density map.
[0049] Each pixel in the density map represents the vegetation density within an N*N meter range of the scene. Therefore, the density map baking process involves projecting each vegetation instance to be created in the scene onto the density map space and accumulating the density value at its corresponding pixel. For a vegetation instance with spatial coordinates (x, y, z) in the target virtual scene, (x, y) represents the coordinate position of the vegetation to be created within the horizontal range of the target virtual scene, and z represents the vegetation height. Based on the ratio of the scene size to the density map size, the corresponding pixel (a, b) in the preset density map is determined. At this point, the density value is not directly accumulated on the density map pixel (a, b). Instead, the pixel value c of pixel (a, b) is further obtained from the scene height map, which is the scene projection height. If the vegetation height z of the vegetation to be created is close to or equal to the scene projection height c, the vegetation is considered to be located at the scene projection, and the density value at its corresponding pixel is accumulated. Otherwise, the vegetation data is considered to be uncompressible by the density map.
[0050] For example, consider a scene with a three-dimensional layered structure, containing both surface and underground portions, such as underground caves. The surface portion may also contain non-convex terrain features like caves, and vegetation may exist within both caves and underground caves. In this embodiment, the scene height map is a projected height taken from above. For points that overlap vertically, the height map only records the height of the uppermost point, such as the ground height above a cave or the ground height above an underground cave. If the height is not determined and vegetation is directly accumulated in the density map, subsequent runtime instantiation will directly instantiate the vegetation inside the cave and the underground cave onto the ground above them, which does not match the desired performance.
[0051] S240. Generate a vegetation density map corresponding to the target virtual scene based on a preset density map that has undergone pixel value enhancement processing; the pixel value of any pixel in the vegetation density map is associated with the amount of vegetation in the corresponding scene area of the target virtual scene.
[0052] The following steps are performed on each vegetation to be created: Based on the preset horizontal position of the vegetation to be created in the target virtual scene, determine the first pixel corresponding to the preset horizontal position in the preset density map; each pixel in the preset density map corresponds to a corresponding scene area in the target virtual scene; if the pixel value of the second pixel in the scene height map matches the preset height position of the vegetation to be created, and the pixel value of the first pixel is added to the preset density map, the pixel value addition processing of the preset density map is completed, and thus the vegetation density map corresponding to the target virtual scene can be obtained. The pixel value of any pixel in the vegetation density map can be the number of vegetation in the corresponding scene area in the target virtual scene, and the pixel value of any pixel in the vegetation density map can also be related to the number of vegetation in the corresponding scene area in the target virtual scene. For example, the number of vegetation in the corresponding scene area in the target virtual scene can be obtained by processing the pixel value of any pixel in the vegetation density map.
[0053] In this embodiment, the dimensions of the scene height map, preset density map, and vegetation density map corresponding to the target virtual scene are matched. The dimensions of the scene height map, preset density map, and vegetation density map corresponding to the target virtual scene can be consistent. The dimensions of the scene height map, preset density map, and vegetation density map corresponding to the target virtual scene can have a linear mapping relationship, which can be determined according to the specific implementation.
[0054] This disclosure generates a scene height map corresponding to the target virtual scene. The pixel value of any pixel in the scene height map can represent the height of the corresponding scene area in the target virtual scene. Furthermore, when the pixel value of the first pixel in the preset density map corresponds to the preset horizontal position of the vegetation to be created, it can be determined whether the pixel value of the first pixel needs to be increased by combining the pixel value of the corresponding second pixel in the scene height map. Thus, when the vegetation height of the vegetation to be created matches the pixel value of the second pixel in the scene height map, the pixel value of the first pixel is increased in the preset density map. That is, the vegetation to be created that meets the preset conditions is compressed and stored through the density map. If the height information is not used for judgment, the vegetation information corresponding to different heights in the same vertical direction will be accumulated in the density map. Consequently, during the instantiation of vegetation, all vegetation will be instantiated directly to the ground part of the corresponding scene area based on the density map, which does not meet the expectation of vegetation at different heights in the same vertical direction. Therefore, compressing and storing vegetation that meets the preset conditions using density maps, while not compressing and storing vegetation that does not meet the preset conditions using density maps, can avoid distortion and logical errors when restoring vegetation based on density maps. This improves the accuracy of vegetation restoration based on density maps and achieves a balance between the storage efficiency and restoration accuracy of vegetation data.
[0055] In this embodiment, vegetation to be created that meets the preset conditions is compressed and stored using a vegetation density map. Correspondingly, in an optional embodiment, the vegetation processing method in the virtual scene of this embodiment may further include: when the pixel value of the second pixel in the scene height map does not match the vegetation height of the vegetation to be created, storing the preset horizontal position of the vegetation to be created in the target virtual scene and the vegetation height of the vegetation to be created.
[0056] For vegetation to be created that does not meet the preset conditions, the original vegetation data can be stored directly without compressing it through the vegetation density map. This allows the vegetation to be restored directly based on the original vegetation data during restoration, avoiding distortion and logical errors that may occur during the restoration process due to compression through the vegetation density map. This improves the restoration accuracy of vegetation that has not been compressed through the density map.
[0057] In another optional embodiment, for the edge region of the target virtual scene, this embodiment provides a vegetation processing method for the edge region that may further include: determining at least one set of pixel pairs based on the pixel values of each pixel in the scene height map; each set of pixel pairs includes two adjacent pixels, and the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference; determining an edge scene region in the target virtual scene; the edge scene region is the corresponding scene region of the at least one set of pixel pairs in the target virtual scene; and storing the preset horizontal position of the vegetation in the edge scene region and the vegetation height of the vegetation in the edge scene region.
[0058] Optionally, any two adjacent pixels in the scene height map can be traversed. For any two adjacent pixels, it can be determined whether the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference. If the difference in pixel values between any two adjacent pixels is greater than or equal to the preset difference, the two adjacent pixels can be determined as a pair of pixels.
[0059] Furthermore, based on the correspondence between scene regions in the target virtual scene and pixels in the scene height map, at least one set of pixel pairs can be identified as edge scene regions in the target virtual scene. For vegetation located in edge scene regions, there is no need to compress and store it using a vegetation density map; instead, the preset horizontal position and height of the vegetation to be created in that edge scene region are directly stored.
[0060] For example, in a virtual scene, a cliff might be located within a single pixel of the scene heightmap. A single pixel in the heightmap can only record the height above or below the cliff. If vegetation instances above or below the cliff are baked into that pixel area, instantiating the vegetation might result in it being instantiated on the other side of the cliff, or even floating in mid-air. Therefore, for areas with significant height differences between adjacent pixels in the heightmap, density mapping of the vegetation is not performed; instead, its precise spatial point data is retained. This allows for restoration based on the original vegetation data during the restoration process, thereby improving the accuracy of vegetation restoration that was not compressed and stored using a density map.
[0061] The method provided in this embodiment compresses the precise spatial point data of vegetation into a density map with a smaller storage size while maintaining the original distribution of vegetation. At a scale of one pixel per square meter, if there are 100 vegetation instances within one square meter, the original data required to store the floating-point representation of the three-dimensional coordinates, totaling 12,000 bytes. After compression, only 4 bytes of density data need to be stored. Furthermore, this embodiment can further compress the density map. The pixel value of each pixel in the preset density map, which has undergone pixel value enhancement processing, represents the number of vegetation units in the corresponding scene area of the target virtual scene. Generating the vegetation density map corresponding to the target virtual scene based on the preset density map with enhanced pixel values includes: normalizing the number of vegetation units corresponding to each pixel in the preset density map with enhanced pixel values to generate the vegetation density map corresponding to the target virtual scene.
[0062] After the baking stage, the density map pixels store the number of vegetation instances within the scene area represented by that pixel. This number can be stored using an integer type (int), which requires 4 bytes of storage space. However, for landscape vegetation, a precise count is not necessary; whether there are 100 or 101 vegetation instances per square meter will not make a difference in performance. Therefore, this embodiment can also search for the maximum and minimum values of pixels in the density map and normalize each pixel in the density map. The normalized values range from [0-1), which can be stored using a single byte of uint8 type, thereby reducing the storage space of the vegetation density map by four times.
[0063] In this embodiment, by normalizing the vegetation data corresponding to each pixel in the density map, the storage space required for each pixel value is reduced from 4 bytes to only 1 byte, thereby further reducing the storage space occupied by the vegetation density map.
[0064] In an optional embodiment, please refer to Figure 3, which illustrates a scene height map generation method, which may include: S310. Determining camera parameters and an orthogonal matrix of an orthogonal camera based on the scene horizontal range of the target virtual scene and the target height of the target virtual scene; the target height is the height of the highest static element in the target virtual scene excluding vegetation; the orthogonal matrix is used to map the target virtual scene to device space.
[0065] The horizontal range of the target virtual scene can be X∈[X_min, X_max], Y∈[Y_min, Y_max], and the target height can be the height range Z∈[Z_min, Z_max], where Z_min = the lowest point on the ground, and Z_max = the highest static element, such as the tallest building. Correspondingly, the camera parameters of the orthographic camera can be determined: position (0,0,Z_max), viewpoint downwards along the -Z axis, looking down at the entire scene; clipping planes: near=0 (the clipping plane closest to the camera, corresponding to Z_max), far=Z_max (the clipping plane furthest from the camera, corresponding to Z=0).
[0066] The mapping rule of orthogonal matrices is to map a cuboid of world space X∈[X_min, X_max], Y∈[Y_min, Y_max], Z∈[Z_min, Z_max] to a 2*2*1 device space, that is, to a device space of X∈[-1,1], Y∈[-1,1], Z∈[0,1]. The associated parameters of orthogonal matrices include: left=X_min, right=X_max, bottom=Y_min, top=Y_max, near=0, far=Z_max.
[0067] S320. Based on the orthogonal matrix, map the three-dimensional coordinates of each static element in the target virtual scene to the device space coordinates of each static element; the device space coordinates include the depth information of each static element.
[0068] By mapping the three-dimensional coordinates (x, y, z) of the static element using the aforementioned orthogonal matrix, the device space coordinates (X, y, z) of the static element are obtained. dev ,Y dev ,D), where D is the depth information of the static element.
[0069] S330. Based on the device space coordinates of each static element, the depth information of each static element, and the correspondence between device space coordinates and pixel coordinates, determine the depth information of the pixel coordinates; the pixel coordinates are coordinates within the target pixel range.
[0070] Given the device space coordinates of a static element, these coordinates can be mapped to screen space coordinates. This allows normalized device space coordinates [-1, 1] to be mapped to the target pixel range [0, Width-1] and [0, Height-1] in screen space. The corresponding mapping formula is as follows: (1) Where, (X) dev + 1) / 2 can convert X dev Normalizing ∈[-1,1] to the range [0,1] eliminates negative coordinates; multiplying by (Width-1) scales the range [0,1] to the screen's horizontal pixel index, such as scaling to [0,511] at 512 resolution; the Y-axis mapping logic is consistent with the X-axis, because when viewed from above by an orthographic camera, the Y-axis... dev There is no flipping in the vertical direction of the screen.
[0071] The corresponding pixel coordinates can be obtained by further rounding and rasterizing the screen space coordinates.
[0072] Taking the central building vertex (0,0,30) as an example, the process of converting 3D space to coordinates to pixels is explained as follows: 1. World space coordinates: (X=0, Y=0, Z=30); 2. Orthogonal matrix mapping: Substituting into the matrix yields the device space coordinates (X... dev =0, Y dev =0, D=0) (because Z=30, D=(30-30) / 30=0); 3. Device space coordinates → screen space coordinates (target pixel range: Width=512, Height=512): X_screen=(0+1) / 2×511≈256, Y_screen=(0+1) / 2×511≈256; 4. Screen space coordinates → pixel coordinates: after rounding, we get (u=256, v=256); 5. Depth association: D=0 After depth testing (less than the initial value 1.0), it is written to the depth buffer (256,256) position, and the final depth value of the pixel is 0.
[0073] S340. Determine the height of each pixel within the target pixel range based on the depth information of the pixel coordinates.
[0074] The relationship between the world's altitude and depth can be expressed by the following formula: (2) Where H is the target height of the target virtual scene, i.e., the height of the tallest static element other than vegetation; D is the depth of the pixel, and Z is the height corresponding to the pixel. That is, given the depth of the pixel, the height corresponding to the pixel can be calculated.
[0075] S350. Generate the scene height map based on the height of each pixel within the target pixel range.
[0076] Once the height of each pixel within the target pixel range is determined, a corresponding scene height map can be generated.
[0077] In this embodiment, an orthogonal camera is used to render static elements in the target virtual scene from top to bottom, excluding vegetation, and the scene height map is obtained by inverse calculation of the orthogonal matrix. This scene height map generation method can obtain the height of various static objects in the scene more generally, and is not limited to terrain height, which provides the possibility for compressing vegetation data on non-terrain components in subsequent steps.
[0078] Please refer to Figure 4, which illustrates the process of generating a vegetation density map corresponding to a target virtual scene. This process may include: 1. Generating a scene height map of the target virtual scene; 2. Obtaining the 3D spatial position (x, y, z) of the vegetation to be created in the target virtual scene; 3. Determining whether the pixel value of the pixel corresponding to position (x, y) in the scene height map matches the height z of the vegetation to be created; 4. If they match, incrementing the pixel value of the pixel corresponding to position (x, y) by 1 in the preset density map; 5. If they do not match, directly recording the 3D spatial position of the vegetation to be created in a global array; 6. If there are unprocessed vegetation to be created, repeating steps 2-5 until the processing of the vegetation to be created is complete; 7. Normalizing the preset density map after pixel value accumulation; 8. Storing the density map and the global array.
[0079] By executing the method described above in this embodiment, a scene height map and a vegetation density map corresponding to the target virtual scene can be obtained. Based on the scene height map and vegetation density map corresponding to the target virtual scene, the vegetation to be created in the target virtual scene can be restored. Optionally, please refer to Figure 5, which shows a target vegetation creation method. The method may include: S510. In response to a vegetation creation instruction for the target virtual scene, the scene height map and the vegetation density map are obtained.
[0080] In this embodiment, the vegetation creation command for the target virtual scene can be a vegetation creation command triggered during scene testing to test whether the vegetation in the target virtual scene can be accurately created. Alternatively, the vegetation creation command for the target virtual scene can be an automatically triggered command in the actual game scene when the target virtual scene needs to be displayed. In response to the vegetation creation command for the target virtual scene, a scene height map and a vegetation density map of the target virtual scene can be obtained. These maps can be generated using the method described in this embodiment, and will not be elaborated further here.
[0081] If there are vegetation plants to be created that have not been compressed and stored in the vegetation density map, a global array recording the three-dimensional spatial location of the vegetation plants to be created can also be obtained, so that the corresponding vegetation can be created directly based on the three-dimensional spatial location recorded in the global array.
[0082] S520. Traverse the pixels in the vegetation density map.
[0083] S530. When the third pixel in the vegetation density map is reached and the pixel value of the third pixel is not zero, at least one candidate position is selected in the target scene area; the target scene area is the area in the target virtual scene corresponding to the third pixel, and the number of the at least one candidate position is determined based on the pixel value of the third pixel.
[0084] In an optional embodiment, at least one candidate location can be randomly selected in the target scene area. For example, a series of coordinate points (x, y) can be randomly selected as the base location of the new vegetation instance. The randomization process not only ensures the naturalness and diversity of vegetation distribution, but also increases the realism of the scene.
[0085] In another alternative embodiment, at least one candidate location can be selected in the target scene area based on preset vegetation distribution information. For example, a series of coordinate points (x, y) can be randomly selected as the base location of the new vegetation instance. Selecting vegetation location based on preset vegetation distribution information can create vegetation that conforms to the preset vegetation distribution information, thereby improving the flexibility and controllability of vegetation creation.
[0086] Furthermore, the number of candidate locations selected in the target scene area can be determined based on the pixel value of the third pixel in the vegetation density map. If the pixel value of each pixel in the vegetation density map corresponds to the actual amount of vegetation, the pixel value corresponding to the third pixel can be directly determined as the number of candidate locations. If the vegetation density map has been normalized, it can be denormalized first to make the pixel value of each pixel in the vegetation density map denormalized to an integer type, and then the number of candidate locations can be determined based on the pixel value corresponding to the third pixel.
[0087] S540. Determine the target area height corresponding to the target scene area based on the scene height map.
[0088] Optionally, the target region height can be determined based on the pixel values of the pixels corresponding to the target scene region in the scene height map; alternatively, it can be determined based on the pixel values of multiple associated pixels corresponding to the target scene region in the scene height map. The target region height can represent the height information of each static element in the target scene region relative to the horizontal reference plane of the target virtual scene, such as the height information of static elements like terrain, buildings, vegetation, and public facilities. Thus, the target region height z can be determined, and consequently, the three-dimensional spatial position of the vegetation to be created can be determined as (x, y, z).
[0089] S550. Create the target vegetation at the target area height of the at least one candidate location.
[0090] Once the height z of the target area is determined, the three-dimensional spatial location of the vegetation to be created is determined as (x, y, z), and the target vegetation can be created at the target area height (x, y, z) of the corresponding candidate location.
[0091] Optionally, the vegetation types of multiple target vegetation areas created in the target scene area can be the same or different. In one optional embodiment, the target vegetation type corresponding to the target scene area can be determined based on the preset correspondence between area height and vegetation type, and then target vegetation of the target vegetation type can be created at the target area height of the target scene area.
[0092] In this embodiment, after obtaining the three-dimensional coordinates (x, y, z), corresponding vegetation instances can be created and placed in the virtual scene. This process is repeated until all pixels on the density map are traversed, thus completing the dynamic generation of vegetation instances in the entire scene. This ensures the rationality of the vegetation layout and greatly enriches the scene details, providing users with a more immersive experience. The scene height map can represent the undulation of the terrain in the target virtual scene. Therefore, the change of pixel value of each pixel in the scene height map can reflect the change of terrain height in the target virtual scene. Thus, the target area height of the target scene area can be determined by combining the pixel value of the pixel corresponding to the target scene area in the scene height map, and the target vegetation can be created at the corresponding target area height. This ensures that the creation of the target vegetation can be adapted to the target area height of the target scene area, ensuring that the vegetation can be accurately placed on its corresponding terrain surface, enhancing the realism and visual consistency of the entire virtual environment.
[0093] In an optional embodiment, determining the target region height corresponding to the target scene region based on the scene height map includes: determining a plurality of neighboring pixels of the fourth pixel from the scene height map; matching the position of the fourth pixel in the scene height map with the position of the third pixel in the vegetation density map; performing data fusion on the pixel values of the plurality of neighboring pixels to obtain fused pixel values; and determining the target region height based on the fused pixel values.
[0094] The multiple neighboring pixels of the fourth pixel can be the multiple pixels closest to the fourth pixel in the scene height map. The number of neighboring pixels can be determined based on the actual implementation. The multiple neighboring pixels can include pixels directly adjacent to the fourth pixel, or pixels indirectly adjacent to the fourth pixel. For example, in a row, pixels 1, 2, 3, 4, and 5 are included in sequence. For pixel 3, the pixels directly adjacent to pixel 3 include pixels 2 and 4, and the pixels indirectly adjacent to pixel 3 include pixels 1 and 5.
[0095] Optionally, data fusion of pixel values from multiple neighboring pixels can refer to averaging the pixel values of multiple neighboring pixels and determining the average value as the fused pixel value. Alternatively, data fusion can be performed by determining the weight of each neighboring pixel based on its distance to the fourth pixel, then performing a weighted sum based on the weights and pixel values of each neighboring pixel, and finally determining the fused pixel value as the weighted sum. The weight of each neighboring pixel is inversely proportional to its distance to the fourth pixel. Furthermore, during data fusion based on the pixel values of multiple neighboring pixels, the pixel values of multiple neighboring pixels can also be combined with the pixel value of the fourth pixel to obtain the fused pixel value.
[0096] When data fusion is performed on the pixel values of multiple neighboring pixels to obtain a fused pixel value, the fused pixel value can be used as the target area height of the target scene region.
[0097] For example, based on the selected coordinate point (x, y) in the target scene region, and its corresponding fourth pixel in the scene height map, the height of the target region is obtained by fusing the pixel values of the fourth pixel with the pixel values of its nearest surrounding pixels in the scene height map. This method can accurately reflect the undulations of the terrain, ensuring that vegetation instances can be accurately placed on their corresponding terrain surfaces, making the vegetation look as if it is growing there naturally, thus enhancing the realism and visual consistency of the entire virtual environment.
[0098] Please refer to Figure 6, which illustrates the process of restoring vegetation in a target virtual scene. This process may include: 1. Obtaining the scene height map and vegetation density map corresponding to the target virtual scene; 2. Obtaining the pixel value 'a' corresponding to pixel (x, y) in the vegetation density map; 3. Selecting 'a' points (xi, yi) in the target scene area corresponding to pixel (x, y); 4. Performing bilinear interpolation on the scene height map based on (xi, yi) to obtain zi; 5. Creating target vegetation at (xi, yi, zi) in the target scene area; 6. Determining whether all pixels in the vegetation density map have been processed; 7. If all pixels in the vegetation density map have been processed, reading the global array recording vegetation data not compressed by the density map, and creating vegetation based on the vegetation data in the global array; 8. If not all pixels in the vegetation density map have been processed, repeating steps 2-6 until all pixels in the vegetation density map have been processed.
[0099] The vegetation density map baking method based on heightmap provided in this embodiment introduces an automated judgment and processing mechanism that can effectively distinguish which vegetation instances in the scene are suitable for baking into the density map, and which should retain their original precise spatial coordinates. This method uses the reconstructed scene heightmap as a spatial reference, combined with the actual location information of the vegetation instances, and evaluates whether each vegetation instance meets the "baking" criteria through geometric consistency analysis.
[0100] Specifically, during the baking process, the system first samples the vegetation instance's horizontal coordinates (x, y) on the height map to obtain the corresponding terrain height z0. This value is then compared to the actual height z of the vegetation instance. If the two are close within a preset tolerance range, the vegetation is considered to be located on a predictable surface structure (such as ground, gentle slopes, or platforms), exhibiting good spatial regularity and repeatability. Therefore, it is suitable as part of the density map, and its position is restored during runtime through random resampling, significantly reducing data storage overhead. Conversely, for vegetation instances where the actual height z deviates significantly from the height map sample value z0, the system classifies them as "unbaked" instances. Forcing such vegetation into the density map and relying on runtime random generation may lead to positional errors, clipping, or visual logic errors. Therefore, the system retains the original three-dimensional coordinates of these vegetation instances, storing them as static instance data to ensure accurate restoration to the designed location during runtime, avoiding restoration distortion or logical errors.
[0101] The advantage of this method lies in achieving an intelligent balance between storage efficiency and performance accuracy: on the one hand, a large amount of common surface vegetation can be compressed and stored using density maps, greatly reducing the package size and loading burden; on the other hand, key or special vegetation still maintains high-fidelity restoration capabilities, ensuring the integrity of the virtual scene presentation. The entire process can be completed automatically without manually marking "baked" areas or configuring the bakeable type of each vegetation, exhibiting a high degree of automation and robustness. In addition, the density map scheme significantly reduces the overall package size of the game or application. A smaller package size means users can download and install faster, while also reducing the requirements for device storage space. During runtime, the scene loading speed is greatly improved because the system only needs to load a density map and the corresponding height map, without having to process massive amounts of vegetation instance coordinate data, thus significantly shortening the loading time.
[0102] It should be noted that any of the methods described above in this embodiment can be combined based on the actual implementation situation and have corresponding beneficial effects, which will not be elaborated here.
[0103] Figure 7 is a block diagram of a vegetation processing device in a virtual scene according to an exemplary embodiment. Referring to Figure 7, the device includes: a scene height map generation unit 710, configured to generate a scene height map corresponding to a target virtual scene; the pixel value of any pixel in the scene height map is associated with the height of a corresponding scene area in the target virtual scene; a pixel determination unit 720, configured to determine a first pixel in a preset density map corresponding to a preset horizontal position based on a preset horizontal position of the vegetation to be created in the target virtual scene; any pixel in the preset density map corresponds to a corresponding scene area in the target virtual scene; a density increasing unit 730, configured to increase the pixel value of the first pixel in the preset density map when the pixel value of a second pixel in the scene height map matches the preset height position of the vegetation to be created; the position of the second pixel in the scene height map matches the position of the first pixel in the preset density map; and a density map generation unit 740, configured to generate a vegetation density map corresponding to the target virtual scene based on the preset density map that has undergone pixel value increasing processing; the pixel value of any pixel in the vegetation density map is associated with the amount of vegetation in a corresponding scene area in the target virtual scene.
[0104] In one exemplary embodiment, the apparatus further includes a first storage unit configured to perform: storing a preset horizontal position of the vegetation to be created in the target virtual scene and the vegetation height of the vegetation to be created when the pixel value of the second pixel in the scene height map does not match the vegetation height of the vegetation to be created.
[0105] In one exemplary embodiment, the apparatus further includes a second storage unit configured to perform: determining at least one set of pixel pairs based on the pixel values of each pixel in the scene height map; each set of pixel pairs includes two adjacent pixels, and the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference; determining an edge scene region in the target virtual scene; the edge scene region is the corresponding scene region of the at least one set of pixel pairs in the target virtual scene; and storing a preset horizontal position of vegetation in the edge scene region and the vegetation height of vegetation in the edge scene region.
[0106] In an exemplary embodiment, the pixel value of each pixel in the preset density map that has undergone pixel value increment processing is the number of vegetation in the corresponding scene area of the target virtual scene; the density map generation unit is configured to perform: normalize the number of vegetation corresponding to each pixel in the preset density map that has undergone pixel value increment processing, and generate a vegetation density map corresponding to the target virtual scene.
[0107] In an exemplary embodiment, the scene height map generation unit is configured to perform the following: determining camera parameters and an orthogonal matrix for an orthogonal camera based on the scene horizontal range and the target height of the target virtual scene; the target height being the height of the highest static element in the target virtual scene excluding vegetation; the orthogonal matrix being used to map the target virtual scene to device space; mapping the three-dimensional coordinates of each static element in the target virtual scene to device space coordinates of each static element based on the orthogonal matrix; the device space coordinates including depth information of each static element; determining depth information of pixel coordinates based on the device space coordinates of each static element, the depth information of each static element, and the correspondence between device space coordinates and pixel coordinates; the pixel coordinates being coordinates within a target pixel range; determining the height corresponding to each pixel within the target pixel range based on the depth information of the pixel coordinates; and generating the scene height map based on the height corresponding to each pixel within the target pixel range.
[0108] In one exemplary embodiment, the apparatus further includes a vegetation creation unit configured to perform: in response to a vegetation creation instruction for the target virtual scene, acquiring the scene height map and the vegetation density map; traversing the pixels in the vegetation density map; when a third pixel in the vegetation density map is reached and the pixel value of the third pixel is not zero, selecting at least one candidate location in the target scene region; the target scene region being the region in the target virtual scene corresponding to the third pixel, the number of the at least one candidate location being determined based on the pixel value of the third pixel; determining the target region height corresponding to the target scene region based on the scene height map; and creating the target vegetation at the target region height of the at least one candidate location.
[0109] In an exemplary embodiment, the vegetation creation unit is configured to perform: determining a plurality of neighboring pixels of a fourth pixel from the scene height map; matching the position of the fourth pixel in the scene height map with the position of the third pixel in the vegetation density map; performing data fusion on the pixel values of the plurality of neighboring pixels to obtain fused pixel values; and determining the height of the target area based on the fused pixel values.
[0110] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0111] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided. Optionally, the computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform any of the methods described above.
[0112] In an exemplary embodiment, a computer program product is also provided, the computer program product including a computer program stored in a readable storage medium, wherein at least one processor of a computer device reads from the readable storage medium and executes the computer program, causing the device to perform any of the methods described above.
[0113] Figure 8 is a block diagram of an electronic device for vegetation processing in a virtual scene according to an exemplary embodiment. The electronic device can be a server, and its internal structure is shown in Figure 8. The electronic device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the electronic device is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a vegetation processing method in a virtual scene. Those skilled in the art will understand that the structure shown in Figure 8 is merely a block diagram of a portion of the structure related to the present disclosure and does not constitute a limitation on the electronic device to which the present disclosure is applied. A specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0114] Figure 9 is a block diagram of an electronic device for vegetation processing in a virtual scene according to an exemplary embodiment. This electronic device can be a terminal, and its internal structure, as shown in Figure 9, may include an RF (Radio Frequency) circuit 910, a memory 920 including one or more computer-readable storage media, an input unit 930, a display unit 940, a sensor 950, an audio circuit 960, a WiFi (Wireless Fidelity) module 970, a processor 980 including one or more processing cores, and a power supply 990, among other components. Those skilled in the art will understand that the terminal structure shown in Figure 9 does not constitute a limitation on the terminal; it may include more or fewer components than shown, or combine certain components, or have different component arrangements. Specifically, the RF circuit 910 can be used for receiving and transmitting signals during information transmission or calls. In particular, it receives downlink information from the base station and hands it over to one or more processors 980 for processing; additionally, it transmits uplink data to the base station. Typically, the RF circuit 910 includes, but is not limited to, an antenna, at least one amplifier, a tuner, one or more oscillators, a Subscriber Identity Module (SIM) card, a transceiver, a coupler, an LNA (Low Noise Amplifier), a duplexer, etc. Furthermore, the RF circuit 910 can communicate wirelessly with networks and other terminals. Wireless communication can use any communication standard or protocol, including but not limited to GSM (Global System for Mobile communication), GPRS (General Packet Radio Service), CDMA (Code Division Multiple Access), WCDMA (Wideband Code Division Multiple Access), LTE (Long Term Evolution), email, SMS (Short Messaging Service), etc.
[0115] The memory 920 can be used to store software programs and modules. The processor 980 executes various functional applications and data processing by running the software programs and modules stored in the memory 920. The memory 920 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for the functions, etc.; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 920 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 920 may also include a memory controller to provide access to the memory 920 for the processor 980 and the input unit 930.
[0116] The input unit 930 can be used to receive input digital or character information, and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control. Specifically, the input unit 930 may include a touch-sensitive surface 931 and other input devices 932. The touch-sensitive surface 931, also known as a touch display screen or touchpad, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch-sensitive surface 931), and drive the corresponding connection device according to a pre-set program. Optionally, the touch-sensitive surface 931 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, sends it to the processor 980, and can receive and execute commands from the processor 980. In addition, the touch-sensitive surface 931 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface 931, the input unit 930 may also include other input devices 932. Specifically, other input devices 932 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc. The display unit 940 can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the terminal. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. The display unit 940 may include a display panel 941, which may optionally be configured as an LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), etc. Further, the touch-sensitive surface 931 may cover the display panel 941. When the touch-sensitive surface 931 detects a touch operation on or near it, it transmits the information to the processor 980 to determine the type of touch event. Subsequently, the processor 980 provides corresponding visual output on the display panel 941 according to the type of touch event. The touch-sensitive surface 931 and the display panel 941 can be two independent components to realize input and output functions. However, in some embodiments, the touch-sensitive surface 931 and the display panel 941 can be integrated to realize input and output functions.
[0117] The terminal may also include at least one sensor 950, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 941 according to the ambient light level, and the proximity sensor can turn off the display panel 941 and / or backlight when the terminal is moved to the ear. As a type of motion sensor, a gravity acceleration sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that identify the terminal's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition-related functions (such as pedometer, tapping), etc. Other sensors that may be configured on the terminal, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.
[0118] Audio circuitry 960, speaker 961, and microphone 962 provide an audio interface between the user and the terminal. Audio circuitry 960 converts received audio data into electrical signals, which are then transmitted to speaker 961, where they are converted into sound signals for output. Conversely, microphone 962 converts collected sound signals into electrical signals, which are received by audio circuitry 960, converted back into audio data, and then processed by processor 980 before being transmitted via RF circuitry 910 to, for example, another terminal, or output to memory 920 for further processing. Audio circuitry 960 may also include an earphone jack to facilitate communication between a peripheral headset and the terminal.
[0119] WiFi is a short-range wireless transmission technology. This terminal, through the WiFi module 970, can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 9 shows the WiFi module 970, it is understood that it is not an essential component of this terminal and can be omitted as needed without changing the essence of the invention.
[0120] The processor 980 is the control center of the terminal, connecting various parts of the terminal via various interfaces and lines. It executes software programs and / or modules stored in the memory 920, and calls data stored in the memory 920, to perform various functions and process data, thereby enabling overall monitoring of the terminal. Optionally, the processor 980 may include one or more processing cores; preferably, the processor 980 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 980.
[0121] The terminal also includes a power supply 990 (such as a battery) to power various components. Preferably, the power supply can be logically connected to the processor 980 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 990 may also include one or more DC or AC power supplies, a recharging system, a power fault detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.
[0122] Although not shown, the terminal may also include a camera, Bluetooth module, etc., which will not be described in detail here. Specifically, in this embodiment, the display unit of the terminal is a touch screen display, and the terminal also includes a memory and one or more programs, wherein one or more programs are stored in the memory and configured to be executed by one or more processors of the instructions in the method embodiment of the present invention.
[0123] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0124] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A method for processing vegetation in a virtual scene, characterized in that, The method includes: generating a scene height map corresponding to a target virtual scene; associating the pixel value of any pixel in the scene height map with the height of a corresponding scene area in the target virtual scene; determining a first pixel in a preset density map corresponding to a preset horizontal position based on a preset horizontal position of the vegetation to be created in the target virtual scene; any pixel in the preset density map corresponding to a corresponding scene area in the target virtual scene; if the pixel value of a second pixel in the scene height map matches the preset height position of the vegetation to be created, increasing the pixel value of the first pixel in the preset density map; the position of the second pixel in the scene height map matching the position of the first pixel in the preset density map; generating a vegetation density map corresponding to the target virtual scene based on the preset density map with the increased pixel value; and associating the pixel value of any pixel in the vegetation density map with the amount of vegetation in a corresponding scene area in the target virtual scene.
2. The method according to claim 1, characterized in that, The method further includes: when the pixel value of the second pixel in the scene height map does not match the vegetation height of the vegetation to be created, storing the preset horizontal position of the vegetation to be created in the target virtual scene and the vegetation height of the vegetation to be created.
3. The method according to claim 1, characterized in that, The method further includes: determining at least one set of pixel pairs based on the pixel values of each pixel in the scene height map; each set of pixel pairs includes two adjacent pixels, and the difference in pixel values between the two adjacent pixels is greater than or equal to a preset difference; determining an edge scene region in the target virtual scene; the edge scene region is the corresponding scene region of the at least one set of pixel pairs in the target virtual scene; and storing the preset horizontal position of the vegetation in the edge scene region and the vegetation height of the vegetation in the edge scene region.
4. The method according to claim 1, characterized in that, The pixel value of each pixel in the preset density map that has undergone pixel value enhancement processing is the number of vegetation in the corresponding scene area of the target virtual scene; the step of generating the vegetation density map corresponding to the target virtual scene based on the preset density map that has undergone pixel value enhancement processing includes: normalizing the number of vegetation corresponding to each pixel in the preset density map that has undergone pixel value enhancement processing to generate the vegetation density map corresponding to the target virtual scene.
5. The method according to claim 1, characterized in that, The process of generating a scene height map corresponding to the target virtual scene includes: determining the camera parameters and orthogonal matrix of an orthogonal camera based on the scene horizontal range and the target height of the target virtual scene; the target height is the height of the highest static element in the target virtual scene excluding vegetation; the orthogonal matrix is used to map the target virtual scene to device space; the orthogonal matrix is used to map the three-dimensional coordinates of each static element in the target virtual scene to device space coordinates of each static element based on the orthogonal matrix; the device space coordinates include the depth information of each static element; the depth information of pixel coordinates is determined based on the device space coordinates of each static element, the depth information of each static element, and the correspondence between device space coordinates and pixel coordinates; the pixel coordinates are coordinates within a target pixel range; the height corresponding to each pixel within the target pixel range is determined based on the depth information of the pixel coordinates; and the scene height map is generated based on the height corresponding to each pixel within the target pixel range.
6. The method according to claim 1, characterized in that, The method further includes: in response to a vegetation creation instruction for the target virtual scene, obtaining the scene height map and the vegetation density map; traversing the pixels in the vegetation density map; when a third pixel in the vegetation density map is reached and the pixel value of the third pixel is not zero, selecting at least one candidate location in the target scene region; the target scene region is the region in the target virtual scene corresponding to the third pixel, and the number of the at least one candidate location is determined based on the pixel value of the third pixel; determining the target region height corresponding to the target scene region based on the scene height map; and creating the target vegetation at the target region height of the at least one candidate location.
7. The method according to claim 6, characterized in that, The step of determining the target area height corresponding to the target scene area based on the scene height map includes: determining multiple neighboring pixels of the fourth pixel from the scene height map; matching the position of the fourth pixel in the scene height map with the position of the third pixel in the vegetation density map; performing data fusion on the pixel values of the multiple neighboring pixels to obtain fused pixel values; and determining the target area height based on the fused pixel values.
8. A vegetation processing device in a virtual scene, characterized in that, The apparatus includes: a scene height map generation unit configured to generate a scene height map corresponding to a target virtual scene; wherein the pixel value of any pixel in the scene height map is associated with the height of a corresponding scene area in the target virtual scene; a pixel determination unit configured to determine a first pixel in a preset density map corresponding to a preset horizontal position based on a preset horizontal position of vegetation to be created in the target virtual scene; wherein any pixel in the preset density map corresponds to a corresponding scene area in the target virtual scene; a density increasing unit configured to increase the pixel value of the first pixel in the preset density map when the pixel value of a second pixel in the scene height map matches the preset height position of the vegetation to be created; wherein the position of the second pixel in the scene height map matches the position of the first pixel in the preset density map; and a density map generation unit configured to generate a vegetation density map corresponding to the target virtual scene based on the preset density map that has undergone pixel value increasing processing; wherein the pixel value of any pixel in the vegetation density map is associated with the amount of vegetation in a corresponding scene area in the target virtual scene.
9. An electronic device, characterized in that, include: processor; A memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the vegetation processing method in a virtual scene as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the vegetation processing method in the virtual scene as described in any one of claims 1 to 7.
11. A computer program product, characterized in that, The computer program product includes a computer program stored in a readable storage medium, wherein at least one processor of a computer device reads from the readable storage medium and executes the computer program, causing the device to perform a vegetation processing method in a virtual scene as described in any one of claims 1 to 7.