A method, device, equipment, medium and product for terrain interaction of a virtual environment
Patent Information
- Application Number
- CN202610727747.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-25
- Publication Date
- 2026-10-23
AI Technical Summary
[0005]本申请提供一种虚拟环境的地形交互方法、装置、设备、介质及产品,旨在解决采用直接高度图修改技术实现地形交互带来的数据管理开销巨大、数据维护和场景管理难度大、存储和实时同步困难的问题
[0005]本申请提供一种虚拟环境的地形交互方法、装置、设备、介质及产品,旨在解决采用直接高度图修改技术实现地形交互带来的数据管理开销巨大、数据维护和场景管理难度大、存储和实时同步困难的问题。
Smart Images

Figure CN122963337A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of human-computer interaction technology, and in particular to a method, apparatus, device, medium and product for terrain interaction in a virtual environment. Background Technology
[0002] In the fields of large-scale virtual simulation, military exercise simulation, and digital twin engineering construction, terrain interaction is one of the core functions. Terrain interaction refers to the process by which entities in the simulation scene (such as tanks, excavators, bulldozers, etc.) physically alter the terrain environment, typically including digging, compaction, and crater generation. With the development of simulation technology, how to efficiently and accurately handle these physical deformations of the terrain in complex simulation operations has become an important technical requirement in this field.
[0003] In existing technologies, direct heightmap modification is primarily used to implement terrain interaction. Specifically, at the data processing level, when interaction occurs, the system directly reads the current terrain's global heightmap or terrain grid and directly overwrites the original terrain file or writes it into a memory block with the modified data. Furthermore, existing technologies use three-dimensional voxel grids to represent the terrain, supporting the creation of holes and cliff effects through excavation.
[0004] However, the aforementioned existing technologies suffer from serious technical bottlenecks in actual large-scale simulation projects. Because they employ a destructive editing mode that directly modifies the original terrain data, the amount of terrain data change increases dramatically as the simulation progresses and interactions occur. For 3D spatial data, the data volume explodes exponentially, leading to enormous data management overhead. Furthermore, since the original terrain data is completely overwritten after each interaction, scene management faces significant challenges. Additionally, each terrain destruction requires recalculating a massive physical collision mesh, incurring substantial computational costs. Especially in multiplayer online simulations, real-time synchronization of the entire deformed terrain mesh requires high network bandwidth, making it difficult to guarantee a smooth frame rate, and the archived files are enormous and lack flexibility. Summary of the Invention
[0005] This application provides a method, apparatus, device, medium, and product for terrain interaction in a virtual environment, aiming to solve the problems of huge data management overhead, high difficulty in data maintenance and scene management, and difficulties in storage and real-time synchronization caused by using direct height map modification technology to achieve terrain interaction.
[0006] In a first aspect, this application provides a method for terrain interaction in a virtual environment, comprising: Obtain the interaction parameters of virtual entities in the virtual environment; The terrain difference data of the interaction location is determined based on the interaction parameters; Write the terrain difference data into the dynamic interaction layer at the coordinates corresponding to the interaction position; Obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interactive texture at the coordinate position in the dynamic interactive layer; wherein, the basic terrain layer maintains the original landform data in read-only mode; The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position; Based on the final coordinates, the virtual terrain in the virtual environment is driven to deform, so as to obtain the rendered screen after the terrain interaction is completed.
[0007] As one embodiment, obtaining the interaction parameters of virtual entities in a virtual environment includes: Terrain interaction components are dynamically mounted via mounting slot interfaces deployed on the virtual entity; The terrain interaction component identifies the movement speed and posture of the virtual entity on the virtual terrain, which are then used as the interaction parameters.
[0008] As one embodiment, determining the terrain differential data of the interaction location based on the interaction parameters includes: Obtain the contact point and contact normal when the virtual entity collides with the virtual terrain; The penetration depth of the virtual entity into the virtual terrain is determined based on the motion posture, the motion speed, the contact point, and the contact normal. The height change of the local area where the interaction location is located is determined based on the penetration depth. The height change is used as the first part of the terrain difference data.
[0009] As one embodiment, determining the terrain difference data of the interaction location based on the interaction parameters further includes: Determine whether the change in height reaches the material damage threshold; When the height change reaches the material damage threshold, the material weight change of the local area where the interaction position is located is determined based on the distance decay function, with the contact point as the center. The change in material weight is used as the second part of the terrain difference data.
[0010] As an example, the initial data state of the dynamic interaction layer is all zero values; Furthermore, after obtaining the rendered screen after the terrain interaction is complete, it also includes: When saving the scene corresponding to the rendered screen, the dynamic interaction layer is traversed, and non-zero data blocks in the dynamic interaction layer are extracted using sparse coding. The extracted non-zero data blocks are serialized and stored.
[0011] As one embodiment, after writing the terrain differential data into the dynamic interaction layer at the coordinates corresponding to the interaction location, the method further includes: In response to receiving a rollback command from an interactive operation, the most recently written terrain differential data in the dynamic interactive layer is removed.
[0012] As one example, the terrain interaction method in a virtual environment further includes: In response to receiving a full reset command, all terrain difference data of the dynamic interaction layer is cleared so that the virtual environment is restored to the initial state corresponding to the original terrain data.
[0013] Secondly, this application also provides a terrain interaction device for a virtual environment, comprising: An interaction layer is used to acquire interaction parameters of virtual entities in a virtual environment and determine terrain difference data of the interaction location based on the interaction parameters. The core layer includes a basic terrain layer and a dynamic interaction layer. The basic terrain layer maintains the original landform data in a read-only manner, and the dynamic interaction layer is used to record the terrain difference data at the coordinate positions corresponding to the interaction positions. The output layer is used to obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interaction texture at the coordinate position in the dynamic interaction layer, and to perform superposition operation on the basic terrain texture and the dynamic interaction texture to determine the final coordinates of the vertex at the coordinate position, and to drive the virtual terrain in the virtual environment to generate deformation based on the final coordinates, so as to obtain the rendered screen after the terrain interaction is completed.
[0014] As one embodiment, the interaction layer includes an application layer and a component layer; The application layer is deployed with at least one of the virtual entities, and each of the virtual entities is deployed with a mount slot interface; The component layer is equipped with a terrain interaction component. During the operation of the virtual environment, the virtual entity dynamically mounts the terrain interaction component through the mounting slot interface. The terrain interaction component is used to obtain the interaction parameters of the virtual entity in the virtual environment and determine the terrain difference data of the interaction position based on the interaction parameters.
[0015] As one embodiment, the terrain interaction component includes a physical detection module, a deformation calculation module, and a data writing interface; The physical detection module is used to identify physical parameters, including the movement speed and posture of the virtual entity on the virtual terrain, and to obtain the contact point and contact normal when the virtual entity collides with the virtual terrain. The deformation calculation module is used to determine the terrain difference data of the interaction position based on the motion posture, the motion speed, the contact point and the contact normal; The data writing interface is used to transmit the terrain differential data to the dynamic interaction layer.
[0016] Thirdly, this application also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the terrain interaction method of any of the above-mentioned virtual environments.
[0017] Fourthly, this application also provides a non-transitory computer-readable storage medium storing a computer program that, when executed by a processor, implements the terrain interaction method of any of the above-mentioned virtual environments.
[0018] Fifthly, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the terrain interaction method of any of the above-mentioned virtual environments. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating the terrain interaction method for the virtual environment provided in this application; Figure 2 This is a schematic diagram of the terrain interaction device for the virtual environment provided in this application; Figure 3 This is a schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0022] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0023] The terms "first," "second," etc., used in this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class, without limiting the number of objects; for example, a first object can be one or more. Furthermore, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects have an "or" relationship.
[0024] The following description, in conjunction with the accompanying drawings, describes the terrain interaction method, apparatus, equipment, medium, and product of the virtual environment provided in this application.
[0025] It should be noted that the terrain interaction method of the virtual environment provided in this application embodiment is implemented based on the terrain interaction device of the virtual environment. The terrain interaction method of the virtual environment adopts a dual decoupled system architecture of component-based logic mounting and differential data layered rendering, providing a non-destructive terrain editing method. It achieves dynamic deformation without modifying the original terrain data, reduces data management overhead and scene management difficulty, and supports millisecond-level scene reset, low-bandwidth network synchronization and lightweight storage.
[0026] This application describes the terrain interaction method in a virtual environment using a terrain interaction device in a virtual environment as an example.
[0027] Figure 1 This is one of the flowcharts illustrating the terrain interaction method for the virtual environment provided in this application. For example... Figure 1As shown, the terrain interaction method for a virtual environment provided in this application includes: S110: Obtain the interaction parameters of virtual entities in the virtual environment.
[0028] A virtual environment is a three-dimensional simulation scene constructed in fields such as large-scale virtual simulation, military exercise simulation, and digital twin engineering. Virtual entities are various vehicles, equipment, or objects existing within a virtual environment, including but not limited to tanks, excavators, bulldozers, or off-road vehicles. Interaction parameters are the current state or actions performed by a virtual entity.
[0029] In practice, interaction parameters can be obtained by reading the real-time running data of virtual entities in the physics engine. These parameters may include the virtual entity's position coordinates, force conditions, motion vectors, or geometric bounding box information.
[0030] S120: Determine the terrain difference data of the interaction location based on the interaction parameters.
[0031] An interaction location refers to the area where a virtual entity comes into contact with or physically interacts with virtual terrain in the virtual environment. After obtaining the interaction parameters, collision detection algorithms or spatial geometry algorithms can be used to determine the specific coordinates of the interaction area.
[0032] Topographic differential data characterizes the amount of data change in terrain due to physical interactions. In practical applications, topographic differential data can include the degree of shift in surface height, the degree of change in surface texture appearance, etc.
[0033] In practice, deformation algorithms are used to determine the forces or volumetric displacement effects exerted by virtual entities on virtual terrain based on interaction parameters, and the corresponding terrain difference data is calculated. For example, when a bulldozer scoops across the ground, the depression depth corresponding to the area traversed by the blade is calculated as the terrain difference data for the height dimension.
[0034] S130: Write the terrain difference data into the dynamic interaction layer at the coordinate position corresponding to the interaction position.
[0035] To avoid damaging the original terrain data, this application embodiment constructs and maintains a two-layer terrain data structure in memory: a basic terrain layer and a dynamic interaction layer. The dynamic interaction layer is used to carry changes; it is essentially a two-dimensional data buffer or texture table, and its resolution matches that of the basic terrain layer.
[0036] After calculating the terrain difference data, the spatial coordinates of the interaction location are mapped onto the corresponding two-dimensional coordinate grid of the dynamic interaction layer, and the terrain difference data is stored in the local grid node. This writing strategy is an incremental recording method, which ensures that the system only updates data in the local area where the interaction occurs.
[0037] The base terrain layer is used to persistently store the global elevation data or geomorphic features (i.e., the original terrain data) at the initial loading of the simulation scene. Throughout the entire simulation cycle, the base terrain layer is strictly locked in a read-only state, and no terrain interaction logic has the right to overwrite its internal values, thus fundamentally ensuring that the original terrain data is not destroyed.
[0038] S140: Obtain the basic terrain texture at the coordinates in the basic terrain layer and the dynamic interaction texture at the coordinates in the dynamic interaction layer. The basic terrain layer maintains the original landform data in read-only mode.
[0039] Upon entering the rendering process, for the current interactive position, the basic terrain texture representing the original state is read from the basic terrain layer, and simultaneously, the dynamic interactive texture formed after the differential data was written is read from the dynamic interactive layer. Here, "texture" refers to the set of data structures that can be sampled in the graphics rendering pipeline.
[0040] S150: The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position.
[0041] After acquiring the two types of texture data, the basic terrain texture and the dynamic interactive texture are arithmetically added or combined using a specific function. This allows for the real-time calculation of the final absolute 3D spatial coordinates of each vertex in the 3D terrain mesh after physical interaction, thus determining the final coordinates of the vertices whose positions are determined. This process combines the separation of physical data storage with real-time visual merging.
[0042] S160: Based on the final coordinates, drive the virtual terrain in the virtual environment to deform, so as to obtain the rendered screen after the terrain interaction is completed.
[0043] After calculating the final coordinates of the mesh vertices, the graphics rendering pipeline updates the geometric topology of the terrain mesh based on the new spatial coordinates. As the vertex positions move, the virtual terrain surface visually exhibits corresponding physical deformation effects such as depressions, bulges, or flattening. Subsequently, the system performs subsequent rendering steps such as rasterization and shading, and finally outputs the terrain containing the deformation effects to the display terminal, allowing users to view the rendered screen after terrain interaction.
[0044] In one possible implementation, differential data is rendered in a layered manner within the vertex shader of the graphics processing unit (GPU), executing steps S140-S160 as described above, specifically as follows: Sampling: Based on the current world coordinates, sample the base terrain texture at the coordinates corresponding to the interaction positions in the base terrain layer. The dynamic interactive texture corresponding to the coordinate position of the interaction position in the dynamic interaction layer. .
[0045] Overlay: Execute the overlay operation formula to obtain the final coordinates of the vertex corresponding to the interaction position. : ; Output: Using The vertex is offset and the output color of the vertex shader is blended based on the material information of the dynamic interaction layer (including material change amount and material weight change amount).
[0046] By utilizing GPU shaders for real-time mathematical overlay and local rendering, the overhead caused by frequent reconstruction of physical meshes due to dynamic deformation is avoided, maintaining a smooth frame rate even in large-scale multi-vehicle collaborative operation scenarios. Furthermore, this embodiment abandons the traditional modification-overwrite mode and introduces a two-layer terrain data structure consisting of a basic terrain layer and a dynamic interaction layer. While keeping the basic terrain layer unchanged, the dynamic interaction layer records relative changes. Combining the two-layer terrain data enables visual rendering, resulting in a visual alteration of the virtual terrain while the original terrain data remains unchanged.
[0047] This application embodiment maintains a two-layer data structure, allowing the basic terrain layer to permanently retain the original landform data in read-only mode. All interactive deformations are written to the dynamic interaction layer only in the form of terrain difference data. This mechanism abandons the destructive editing mode of directly overwriting the original file, thus perfectly protecting the original terrain. When scene state adjustments or resets are required, there is no need to reload the entire massive map resource. Non-destructive terrain editing solves the technical bottlenecks of data maintenance and scene management difficulties. Secondly, this application embodiment calculates the terrain difference data of the local interaction location only based on the interaction parameters, avoiding the problem of exponential explosion of 3D spatial data as the simulation progresses, and controlling data management overhead. Since there is no need to synchronize the entire deformed terrain mesh in real time, this scheme greatly reduces the network bandwidth requirements in multi-player online simulations, while making the archive file size extremely lightweight and highly flexible. In addition, in the final presentation, the embodiments of this application directly obtain the basic terrain texture and dynamic interactive texture, determine the final coordinates of the vertices through real-time superposition calculation, and drive the virtual terrain to deform accordingly. This coordinate system offset calculation method based on the bottom layer of the graphics pipeline cleverly transfers the deformation calculation, perfectly avoiding the huge computational overhead caused by the CPU to recalculate and rebuild the huge physical collision mesh every time the terrain is destroyed in the prior art, and ensuring the smooth operation of large and complex simulation operations.
[0048] In existing technologies, when developing specific types of virtual entities, developers directly write the terrain interaction logic into the virtual entity's class or blueprint script. This approach achieves strong coupling between the interaction logic and the virtual entity through hard coding, resulting in poor scalability. Specifically, the interaction logic is locked within a specific virtual entity. If the simulation scene needs to introduce multiple different types of virtual entities, developers need to repeatedly write similar interaction logic multiple times. Furthermore, if a general physics algorithm needs to be modified, the code of all virtual entities needs to be modified, resulting in high maintenance costs and difficulty in reusing the code across platforms or different projects.
[0049] In one possible implementation, step S110, obtaining the interaction parameters of the virtual entity in the virtual environment, includes: S1110: Dynamically mount the terrain interaction component through the mounting slot interface deployed on the virtual entity.
[0050] Please refer to Figure 2 The mounting slot interface is a standardized access channel reserved on various virtual entities in the virtual environment. It does not contain any specific code for terrain interaction; it only provides a channel for parameter passing and component attachment. The terrain interaction component is a software instance with interaction recognition capabilities. During the simulation system's operation, according to the scene requirements, the instantiated terrain interaction component is attached to a specified location on the virtual entity by calling the mounting slot interface. This mounting method is plug-and-play (i.e., dynamic mounting).
[0051] Specifically, terrain interaction components are instantiated and attached to designated skeletons of virtual entities via a mounting slot interface. For example, for a bulldozer, the terrain interaction component is mounted to the blade skeleton; for a missile, it is mounted to the warhead. The terrain interaction component automatically recognizes the host's speed and attitude as input for deformation parameters.
[0052] S1120: The terrain interaction component identifies the movement speed and posture of the virtual entity on the virtual terrain, and uses them as the interaction parameters.
[0053] Once the terrain interaction component is mounted, it will automatically detect and extract the current movement speed and posture of the host it is mounted on, and use them directly as interaction parameters.
[0054] This application embodiment achieves complete decoupling between terrain interaction logic and specific equipment entities by designing standardized mounting slot interfaces and independent terrain interaction components. This allows a set of terrain interaction components to be plugged and played onto any virtual entity, greatly improving the system's versatility and development efficiency. When new equipment is introduced into the simulation system, the time to integrate terrain interaction functions is reduced from several days to several minutes, achieving "develop once, run everywhere".
[0055] In one possible implementation, S120, determining the terrain differential data of the interaction location based on the interaction parameters includes: S1210: Perform physical detection on the virtual entity to obtain the contact point and contact normal when the virtual entity collides with the virtual terrain.
[0056] S1220: Determine the penetration depth of the virtual entity into the virtual terrain based on the motion posture, the motion speed, the contact point, and the contact normal.
[0057] Specifically, using the contact normal as the reference plane, and combining the cutting angle determined by the motion velocity vector and motion posture of the virtual entity, spatial Boolean operations or geometric intersection tests are performed to accurately calculate the penetration depth of the virtual entity's virtual excavation volume into the virtual terrain.
[0058] S1230: Determine the height change of the local area where the interaction position is located based on the penetration depth.
[0059] Specifically, the penetration depth is mapped onto the coordinate system of the terrain grid, and the subsidence or uplift values corresponding to each coordinate node in the local area where the interaction location is located are calculated, thereby obtaining the height change of the local area.
[0060] S1240: The height change is used as the first part of the terrain difference data.
[0061] This application's embodiments combine collision contact points, contact normals, and the motion state of entities to accurately calculate penetration depth and height changes, highly replicating the underlying mining and calculation logic of the physics engine. This enables the generated terrain difference data to accurately reflect complex physical processes and enhances the realism of simulation deformation.
[0062] In one possible implementation, terrain differential data It is expressed as follows: ; in, Indicates the change in altitude. Indicates the amount of material change at the interaction location; This indicates the amount of material weight change at the interaction location.
[0063] In S120, determining the terrain difference data of the interaction location based on the interaction parameters further includes: S1250: Determine whether the change in height reaches the material damage threshold.
[0064] The material damage threshold is a pre-set critical depth or deformation value used to determine whether the surface material of the terrain will change its type or weight due to deformation. After obtaining the height change, the height change is compared with the material damage threshold to determine whether to trigger the visual change logic of the material.
[0065] S1260: When the height change reaches the material damage threshold, the material weight change of the local area where the interaction position is located is determined based on the distance decay function, with the contact point as the center.
[0066] Distance decay functions are mathematical models that describe how a value gradually decreases or smoothly transitions with increasing distance, such as Gaussian decay or linear interpolation decay. Material weight change is the difference in increase or decrease of individual materials (such as layer transparency or blending ratio) when multiple terrain textures are blended.
[0067] When the deformation is determined to be severe enough to reach the material damage threshold, the deepest contact point is used as the core. The distance decay function is applied to calculate the change in material weight in the surrounding local area, so that the material weight change in the center is the most severe, while the material change in the edge area gradually weakens.
[0068] S1270: The change in material weight is used as the second part of the terrain difference data.
[0069] This application's embodiments introduce a material damage threshold and a distance decay function to naturally bind the physical height sinking with the damage effect of the surface material (such as changing from grass to soil), forming a visual effect of a digging pit that smoothly transitions from the center to the edge, greatly enhancing the multi-dimensional visual realism of the virtual terrain interaction process.
[0070] In one possible implementation, the initial data state of the dynamic interaction layer is all zero values; Furthermore, after obtaining the rendered screen (S160) after the terrain interaction is completed, it also includes: When saving the scene corresponding to the rendered screen, the dynamic interaction layer is traversed, and non-zero data blocks in the dynamic interaction layer are extracted using sparse coding. The extracted non-zero data blocks are serialized and stored.
[0071] Specifically, a state of all zero values indicates that no interactive offsets occurred at the start of the simulation. Non-zero data blocks are local grid regions in the dynamic interaction layer that actually record terrain difference data. Since most areas of the virtual terrain are not interacted with, when the user or system triggers scene saving, the entire dynamic interaction layer is scanned, ignoring all non-interactive regions that remain at all zero values. Sparse coding techniques are then used to accurately extract the non-zero data blocks that have undergone interaction. Subsequently, the data structure of the extracted non-zero data blocks is converted into binary or related format files suitable for persistent storage or network transmission, lightweightly packaged, and stored (e.g., stored on disk or sent to the cloud), achieving serialized storage and significantly reducing the size of the archive file.
[0072] This application embodiment utilizes the initial all-zero characteristic of the dynamic interaction layer and combines sparse coding to extract non-zero data blocks, so that the system only needs to store and synchronize a very small volume of difference data; compared with the traditional method of directly saving the modified terrain grid, the archive volume of this application embodiment is reduced by more than 90%, which is suitable for network transmission and cloud synchronization.
[0073] In existing direct height map modification techniques, the original terrain data is completely overwritten after each interaction. When scene state reset is required in the future, the system cannot perform efficient terrain state backtracking and usually needs to reload the entire map resource, which makes data maintenance very difficult.
[0074] In one possible implementation, after writing the terrain differential data into the dynamic interaction layer at the coordinates corresponding to the interaction location (S130), the method further includes: In response to receiving a rollback command from an interactive operation, the most recently written terrain differential data in the dynamic interactive layer is removed.
[0075] The rollback command in interactive operations is a control signal issued by the user or system to undo the previous terrain change action. Since the dynamic interaction layer records the overlay, when a rollback command is received, there is no need to reload the terrain model. The terrain difference data operation record at the top of the stack in the dynamic interaction layer (corresponding to the last interaction) is removed from the buffer memory, and the rendering pipeline can automatically render the terrain from the previous step based on the remaining data.
[0076] This application embodiment achieves step-level operation rollback by removing the latest differential data record in the dynamic layer, breaking the technical bottleneck of traditional destructive editing that cannot be undone at low cost, and providing powerful behavior playback and error correction capabilities for instructor evaluation or driver training.
[0077] In one possible implementation, the terrain interaction method for the virtual environment also includes: In response to receiving a full reset command, all terrain difference data of the dynamic interaction layer is cleared so that the virtual environment is restored to the initial state corresponding to the original terrain data.
[0078] Specifically, upon receiving a full reset command, the memory of the dynamic interaction layer can be cleared directly. Since the original terrain data of the base terrain layer remains read-only and untouched, after clearing the dynamic interaction layer, the GPU overlay rendering result will be completely equivalent to the base terrain layer data, thus instantly restoring the virtual scene to its initial state, while the data of the base terrain layer remains unchanged.
[0079] This application's embodiments, by clearing the dynamic interaction layer data with a single click, avoid the lengthy process of rereading and parsing massive original map files, supporting millisecond-level scene resets, and significantly improving the efficiency of reusing simulation training sites and the user experience. In military training or driver training, instructors can reset the site or replay specific digging actions at any time with a single click, which is difficult to achieve at low cost with existing technologies.
[0080] Based on the above, this application also provides a terrain interaction device for a virtual environment. The terrain interaction device for a virtual environment and the terrain interaction method for a virtual environment described above can be referred to in correspondence with each other.
[0081] As an example, such as Figure 2 As shown, the virtual environment terrain interaction device also provided in this application includes an interaction layer, a core layer, and an output layer.
[0082] The interaction layer serves as the medium for interaction between the virtual environment and the user. This layer is used to acquire interaction parameters of virtual entities within the virtual environment and to determine terrain difference data of the interaction location based on these parameters. The core layer includes a basic terrain layer and a dynamic interaction layer. The basic terrain layer maintains the original landform data in a read-only manner, and the dynamic interaction layer is used to record the terrain difference data at the coordinate positions corresponding to the interaction positions.
[0083] In one possible implementation, the core layer maintains a two-layer terrain data structure in memory. The basic terrain layer stores the raw elevation data (i.e., the raw landform data), remaining read-only throughout the simulation cycle to ensure that the raw landform data is not corrupted. The dynamic interaction layer is a texture or buffer with an initial state of all zero values, specifically used to record the changes in height and material weights of the local area where the interaction location is located, passed from the component layer.
[0084] In one possible implementation, such as Figure 2 As shown, the core layer also includes a terrain system manager, which manages the basic terrain layer and the dynamic interaction layer, such as rolling back and clearing dynamic interaction layer data.
[0085] The output layer is used to obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interaction texture at the coordinate position in the dynamic interaction layer, and to perform superposition operation on the basic terrain texture and the dynamic interaction texture to determine the final coordinates of the vertex at the coordinate position, and to drive the virtual terrain in the virtual environment to generate deformation based on the final coordinates, so as to obtain the rendered screen after the terrain interaction is completed.
[0086] In one possible implementation, such as Figure 2 As shown, the output layer includes a real-time overlay rendering pipeline, which is used to perform the above-mentioned image rendering functions.
[0087] In one possible implementation, the real-time overlay rendering pipeline is based on shader technology, such as the GPU's vertex shader.
[0088] In one possible implementation, such as Figure 2 As shown, the output layer also includes a lightweight serialization module for data storage and network transmission. Specifically, when saving the scene corresponding to the rendered screen, the lightweight serialization module traverses the dynamic interaction layer and uses sparse coding to extract non-zero data blocks from the dynamic interaction layer; then, it serializes and stores the extracted non-zero data blocks to obtain a lightweight archive file or network packet in JSON or binary format.
[0089] This application embodiment maintains a two-layer data structure, allowing the basic terrain layer to permanently retain the original landform data in read-only mode. All interactive deformations are written to the dynamic interaction layer only in the form of terrain difference data. This mechanism abandons the destructive editing mode of directly overwriting the original file, thus perfectly protecting the original terrain. When scene state adjustments or resets are required, there is no need to reload the entire massive map resource. Non-destructive terrain editing solves the technical bottlenecks of data maintenance and scene management difficulties. Secondly, this application embodiment calculates the terrain difference data of the local interaction location only based on the interaction parameters, avoiding the problem of exponential explosion of 3D spatial data as the simulation progresses, and controlling data management overhead. Since there is no need to synchronize the entire deformed terrain mesh in real time, this scheme greatly reduces the network bandwidth requirements in multi-player online simulations, while making the archive file size extremely lightweight and highly flexible. Furthermore, in the final rendering of this application, the basic terrain texture and dynamic interactive texture are directly acquired, and the final coordinates of the vertices are determined through real-time overlay calculations. Based on this, the virtual terrain is driven to deform. This coordinate system offset calculation method, based on the graphics pipeline's underlying layer, cleverly transfers the deformation calculation, perfectly avoiding the huge computational overhead caused by the need for CPU recalculation and reconstruction of the massive physical collision mesh for each terrain destruction in existing technologies. This ensures the smooth operation of large and complex simulation tasks. Finally, the terrain interaction device provided in this application has strong reusability and can be directly used as a plug-in package in other virtual environments, solving the problem of difficult function reuse in existing technologies.
[0090] In one possible implementation, such as Figure 2 As shown, the interaction layer includes an application layer and a component layer; The application layer deploys at least one of the aforementioned virtual entities, and each virtual entity has a mounting slot interface. The application layer deploys various virtual entities from the virtual simulation scene, such as various vehicles (e.g., tanks, excavators, bulldozers, etc.). These virtual entities do not contain any specific code for terrain interaction; they only reserve standard mounting slot interfaces for mounting terrain interaction components from the component layer.
[0091] The component layer is equipped with a terrain interaction component. During the operation of the virtual environment, the virtual entity dynamically mounts the terrain interaction component through the mounting slot interface. The terrain interaction component is used to obtain the interaction parameters of the virtual entity in the virtual environment and determine the terrain difference data of the interaction position based on the interaction parameters.
[0092] Specifically, during system runtime, terrain interaction components are instantiated and attached to designated skeletons of virtual entities via a mounting slot interface. For example, for a bulldozer, the terrain interaction component is mounted to the blade skeleton; for a missile, it is mounted to the warhead. The terrain interaction component automatically recognizes the host's speed and attitude as input for deformation parameters.
[0093] This application embodiment separates the interaction logic that is traditionally hard-coded inside the virtual entity into an independent component. Through standardized interface design, the same set of code can be applied to different virtual entities without modification, which greatly improves the versatility and development efficiency of the system. When new equipment is introduced into the simulation system, the time to integrate terrain interaction function is reduced from several days to several minutes.
[0094] In one possible implementation, such as Figure 2 As shown, the terrain interaction component includes a physical detection module, a deformation calculation module, and a data writing interface; The physical detection module is used to perform physical detection on virtual entities and identify physical parameters, including the movement speed and movement posture of the virtual entities on the virtual terrain, as the interaction parameters. The deformation calculation module is used to determine the terrain difference data of the interaction position based on the motion posture, the motion speed, the contact point and the contact normal; The data writing interface is used to transmit the terrain differential data to the dynamic interaction layer.
[0095] This application's embodiments split the terrain interaction component into three independent modules: physical detection, differential calculation, and data writing. This completely decouples the physical state extraction, calculation logic, and data transmission processes. When the simulation system needs to upgrade the collision detection algorithm or optimize the deformation calculation logic, developers only need to update the corresponding independent modules without refactoring the entire interaction component. This greatly reduces code maintenance costs and improves system scalability.
[0096] Figure 3 This is a schematic diagram of the structure of the electronic device provided in this application, such as... Figure 3 As shown, the electronic device may include: a processor 310, a communications interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communications interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute a terrain interaction method for the virtual environment, the method including: Obtain the interaction parameters of virtual entities in the virtual environment; The terrain difference data of the interaction location is determined based on the interaction parameters; Write the terrain difference data into the dynamic interaction layer at the coordinates corresponding to the interaction position; Obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interactive texture at the coordinate position in the dynamic interactive layer; wherein, the basic terrain layer maintains the original landform data in read-only mode; The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position; Based on the final coordinates, the virtual terrain in the virtual environment is driven to deform, so as to obtain the rendered screen after the terrain interaction is completed.
[0097] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0098] On the other hand, this application also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer is able to execute the virtual environment terrain interaction method provided in the above embodiments, the method including: Obtain the interaction parameters of virtual entities in the virtual environment; The terrain difference data of the interaction location is determined based on the interaction parameters; Write the terrain difference data into the dynamic interaction layer at the coordinates corresponding to the interaction position; Obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interactive texture at the coordinate position in the dynamic interactive layer; wherein, the basic terrain layer maintains the original landform data in read-only mode; The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position; Based on the final coordinates, the virtual terrain in the virtual environment is driven to deform, so as to obtain the rendered screen after the terrain interaction is completed.
[0099] In another aspect, this application also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a terrain interaction method for a virtual environment provided in the above embodiments, the method comprising: Obtain the interaction parameters of virtual entities in the virtual environment; The terrain difference data of the interaction location is determined based on the interaction parameters; Write the terrain difference data into the dynamic interaction layer at the coordinates corresponding to the interaction position; Obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interactive texture at the coordinate position in the dynamic interactive layer; wherein, the basic terrain layer maintains the original landform data in read-only mode; The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position; Based on the final coordinates, the virtual terrain in the virtual environment is driven to deform, so as to obtain the rendered screen after the terrain interaction is completed.
[0100] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0101] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0102] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for terrain interaction in a virtual environment, characterized in that, include: Obtain the interaction parameters of virtual entities in the virtual environment; The terrain difference data of the interaction location is determined based on the interaction parameters; Write the terrain difference data into the dynamic interaction layer at the coordinates corresponding to the interaction position; Obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interactive texture at the coordinate position in the dynamic interactive layer; wherein, the basic terrain layer maintains the original landform data in read-only mode; The basic terrain texture and the dynamic interactive texture are superimposed to determine the final coordinates of the vertex at the coordinate position; Based on the final coordinates, the virtual terrain in the virtual environment is driven to deform, so as to obtain the rendered screen after the terrain interaction is completed.
2. The terrain interaction method for a virtual environment according to claim 1, characterized in that, The acquisition of interaction parameters of virtual entities in the virtual environment includes: Terrain interaction components are dynamically mounted via mounting slot interfaces deployed on the virtual entity; The terrain interaction component identifies the movement speed and posture of the virtual entity on the virtual terrain, which are then used as the interaction parameters.
3. The terrain interaction method for a virtual environment according to claim 2, characterized in that, Determining terrain differential data for the interaction location based on the interaction parameters includes: Obtain the contact point and contact normal when the virtual entity collides with the virtual terrain; The penetration depth of the virtual entity into the virtual terrain is determined based on the motion posture, the motion speed, the contact point, and the contact normal. The height change of the local area where the interaction location is located is determined based on the penetration depth. The height change is used as the first part of the terrain difference data.
4. The terrain interaction method for a virtual environment according to claim 3, characterized in that, Determining the terrain difference data of the interaction location based on the interaction parameters also includes: Determine whether the change in height reaches the material damage threshold; When the height change reaches the material damage threshold, the material weight change of the local area where the interaction position is located is determined based on the distance decay function, with the contact point as the center. The change in material weight is used as the second part of the terrain difference data.
5. The terrain interaction method for a virtual environment according to claim 1, characterized in that, The initial data state of the dynamic interaction layer is all zero values; Furthermore, after obtaining the rendered screen after the terrain interaction is complete, it also includes: When saving the scene corresponding to the rendered screen, the dynamic interaction layer is traversed, and non-zero data blocks in the dynamic interaction layer are extracted using sparse coding. The extracted non-zero data blocks are serialized and stored.
6. The terrain interaction method for a virtual environment according to claim 1, characterized in that, After writing the terrain differential data into the dynamic interaction layer at the coordinates corresponding to the interaction location, the process further includes: In response to receiving a rollback command from an interactive operation, the most recently written terrain differential data in the dynamic interactive layer is removed.
7. The terrain interaction method for a virtual environment according to claim 1, characterized in that, Also includes: In response to receiving a full reset command, all terrain difference data of the dynamic interaction layer is cleared so that the virtual environment is restored to the initial state corresponding to the original terrain data.
8. A terrain interaction device for a virtual environment, characterized in that, include: An interaction layer is used to acquire interaction parameters of virtual entities in a virtual environment and determine terrain difference data of the interaction location based on the interaction parameters. The core layer includes a basic terrain layer and a dynamic interaction layer. The basic terrain layer maintains the original landform data in a read-only manner, and the dynamic interaction layer is used to record the terrain difference data at the coordinate positions corresponding to the interaction positions. The output layer is used to obtain the basic terrain texture at the coordinate position in the basic terrain layer and the dynamic interaction texture at the coordinate position in the dynamic interaction layer, and to perform superposition operation on the basic terrain texture and the dynamic interaction texture to determine the final coordinates of the vertex at the coordinate position, and to drive the virtual terrain in the virtual environment to generate deformation based on the final coordinates, so as to obtain the rendered screen after the terrain interaction is completed.
9. The terrain interaction device for a virtual environment according to claim 8, characterized in that, The interaction layer includes an application layer and a component layer; The application layer is deployed with at least one of the virtual entities, and each of the virtual entities is deployed with a mount slot interface; The component layer is equipped with a terrain interaction component. During the operation of the virtual environment, the virtual entity dynamically mounts the terrain interaction component through the mounting slot interface. The terrain interaction component is used to obtain the interaction parameters of the virtual entity in the virtual environment and determine the terrain difference data of the interaction position based on the interaction parameters.
10. The terrain interaction device for a virtual environment according to claim 9, characterized in that, The terrain interaction component includes a physical detection module, a deformation calculation module, and a data writing interface. The physical detection module is used to identify physical parameters, including the movement speed and posture of the virtual entity on the virtual terrain, and to obtain the contact point and contact normal when the virtual entity collides with the virtual terrain. The deformation calculation module is used to determine the terrain difference data of the interaction position based on the motion posture, the motion speed, the contact point and the contact normal; The data writing interface is used to transmit the terrain differential data to the dynamic interaction layer.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the terrain interaction method of the virtual environment as described in any one of claims 1 to 7.
12. A non-transitory computer-readable storage medium, wherein a computer program is stored on the non-transitory computer-readable storage medium, characterized in that, When the computer program is executed by the processor, it implements the terrain interaction method of the virtual environment as described in any one of claims 1 to 7.
13. A computer program product, the computer program product comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the terrain interaction method of the virtual environment as described in any one of claims 1 to 7.