Liquid pouring simulation method, device, equipment and medium based on virtual reality
By simulating the liquid pouring process in virtual reality according to the position and tilt state of the operating handle, the problem of unrealistic simulation of liquid behavior in virtual reality is solved, achieving higher interactivity and realism, which has important educational significance.
Patent Information
- Application Number
- CN202410788226.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-06-19
AI Technical Summary
The existing technology lacks in-depth simulation of liquid behavior and interaction in virtual reality, resulting in unrealistic simulation of the pouring process and affecting user experience.
By obtaining the distance and geometric properties between virtual containers in real time based on the position and tilt state of the operating handle in three-dimensional space, trigonometric functions are used to calculate the angle between the liquid's tilted surface and the horizontal surface and the contact between the liquid and the container wall. Angle, determine and simulate the liquid pouring process, and stop pouring when the liquid overflows.
It realizes a real simulation of the liquid pouring process in a virtual environment, enhances the interactivity and realism of virtual reality technology, and promotes the understanding of fluid dynamics and physical simulation, which has important educational and training significance.
Smart Images

Figure CN118363464B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a liquid pouring simulation method, device, equipment and medium based on virtual reality. Background Art
[0002] Currently, VR technology is mainly used in games, training, and simulation. However, simulating the pouring process in a virtual environment is not common, and the application of existing technologies in this regard is relatively limited. Some VR applications may provide simple pouring animations, but lack in-depth simulation of liquid behavior and interaction.
[0003] With the development of virtual reality technology, people's demand for simulating real-life experiences in virtual environments is increasing. There is an urgent need for a novel water pouring simulation method to simulate real situations and enhance user experience. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a liquid pouring simulation method based on virtual reality to solve the technical problem of the lack of in-depth simulation of liquid behavior and interaction in the prior art. The method includes:
[0005] According to the position of the operating handle in the three-dimensional space, displaying a virtual handle to simulate grabbing a first virtual container containing the liquid to be poured;
[0006] In the process of moving the virtual handle, obtaining in real time the distance between the first virtual container and a second virtual container, where the second virtual container is used to receive the liquid;
[0007] When it is determined by the distance that the first virtual container can pour liquid into the second virtual container, the tilting of the first virtual container is simulated according to the tilting state of the virtual handle, and the process of the first virtual container pouring liquid into the second virtual container is simulated; the simulating the tilting of the first virtual container according to the tilting state of the virtual handle and the process of the first virtual container pouring liquid into the second virtual container includes: simulating the tilting of the first virtual container according to the tilting angle of the virtual handle; acquiring the cylinder bottom radius, cylinder height, liquid height and cylinder tilting angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface by using trigonometric functions based on the cylinder tilting angle, the cylinder bottom radius and the liquid height; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is determined that the liquid can be poured out, and then the process of the first virtual container pouring liquid into the second virtual container is simulated;
[0008] The volume of the liquid poured into the second virtual container is acquired in real time, and when it is determined according to the liquid volume that the liquid in the second virtual container overflows, a prompt is given to stop the liquid pouring process.
[0009] The embodiment of the present invention also provides a liquid pouring simulation device based on virtual reality to solve the technical problem of the lack of in-depth simulation of liquid behavior and interaction in the prior art. The device includes:
[0010] A grabbing module, used for displaying a virtual handle to simulate grabbing a first virtual container containing liquid to be poured according to the position of the operating handle in the three-dimensional space;
[0011] A moving module, used for acquiring the distance between the first virtual container and a second virtual container in real time during the process of moving the virtual handle, wherein the second virtual container is used to receive the liquid;
[0012] a pouring module, for simulating the inclination of the first virtual container according to the inclination state of the virtual handle, and simulating the process of the first virtual container pouring liquid into the second virtual container, when it is judged by the distance that the first virtual container can pour liquid into the second virtual container; the simulating the inclination of the first virtual container according to the inclination state of the virtual handle, and simulating the process of the first virtual container pouring liquid into the second virtual container, comprising: simulating the inclination of the first virtual container by the inclination angle of the virtual handle; acquiring the cylinder bottom radius, cylinder height, liquid height and cylinder inclination angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface by using trigonometric functions based on the cylinder inclination angle, the cylinder bottom radius and the liquid height; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is judged that the liquid can be poured out, and then the process of the first virtual container pouring liquid into the second virtual container is simulated;
[0013] The liquid overflow judgment module is used to obtain the volume of the liquid poured into the second virtual container in real time, and when it is judged that the liquid in the second virtual container overflows according to the liquid volume, prompt to stop the liquid pouring process.
[0014] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned virtual reality-based liquid pouring simulation methods when executing the computer program, so as to solve the technical problem of the lack of in-depth simulation of liquid behavior and interaction in the prior art.
[0015] An embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program for executing any of the above-mentioned virtual reality-based liquid pouring simulation methods to solve the technical problem of the lack of in-depth simulation of liquid behavior and interaction in the prior art.
[0016] Compared with the prior art, the beneficial effects achieved by at least one of the above technical solutions adopted in the embodiments of this specification include at least: according to the position of the operating handle in the three-dimensional space, displaying a virtual handle to simulate grabbing the first virtual container containing the liquid to be poured; in the process of moving the virtual handle, obtaining the distance between the first virtual container and the second virtual container in real time, and the second virtual container is used to receive the liquid; when it is judged by the distance that the first virtual container can pour the liquid into the second virtual container, simulating the inclination of the first virtual container according to the inclination state of the virtual handle, simulating the process of pouring the liquid from the first virtual container to the second virtual container; obtaining the volume of the liquid poured into the second virtual container in real time, and when it is judged that the liquid in the second virtual container overflows according to the liquid volume, prompting to stop the liquid pouring process. Through the method of the present application, users can truly simulate the process of pouring liquid in a virtual environment to enhance the interactivity and realism of virtual reality technology, and can promote users' understanding of fields such as fluid dynamics and physical simulation, which has important educational and training significance. Therefore, the present application can provide users with a highly interactive virtual reality experience, enrich the application field of VR virtual reality technology, and bring users a more in-depth and vivid virtual experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 is a flow chart of a liquid pouring simulation method based on virtual reality provided by an embodiment of the present invention;
[0019] Figure 2 is a structural block diagram of a computer device provided by an embodiment of the present invention;
[0020] Figure 3 It is a structural block diagram of a liquid pouring simulation device based on virtual reality provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0021] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0022] The following describes the implementation methods of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the absence of conflict, the following embodiments and the features in the embodiments can be combined with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work belong to the scope of protection of the present application.
[0023] In an embodiment of the present invention, a liquid pouring simulation method based on virtual reality is provided, such as Figure 1 As shown, the method includes:
[0024] Step S101, displaying a virtual handle to simulate grabbing a first virtual container containing liquid to be poured according to the position of the operating handle in the three-dimensional space;
[0025] Step S102: in the process of moving the virtual handle, obtaining in real time the distance between the first virtual container and a second virtual container, where the second virtual container is used to receive the liquid;
[0026] Step S103: when it is determined by the distance that the first virtual container can pour liquid into the second virtual container, the tilting of the first virtual container is simulated according to the tilting state of the virtual handle, and the process of the first virtual container pouring liquid into the second virtual container is simulated; the simulating the tilting of the first virtual container according to the tilting state of the virtual handle and the process of the first virtual container pouring liquid into the second virtual container includes: simulating the tilting of the first virtual container according to the tilting angle of the virtual handle; acquiring the cylinder bottom radius, cylinder height, liquid height and cylinder tilting angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface based on the cylinder tilting angle, the cylinder bottom radius and the liquid height by using trigonometric functions; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is determined that the liquid can be poured out, and then the process of the first virtual container pouring liquid into the second virtual container is simulated;
[0027] Step S104: acquiring the volume of the liquid poured into the second virtual container in real time, and when it is determined according to the liquid volume that the liquid in the second virtual container overflows, prompting to stop the liquid pouring process.
[0028] The basic implementation platform for implementing the method of this embodiment is based on the Unity editor, and has imported two plug-ins for developing VR virtual reality software, SteamVR and VRTK. SteamVR is a software platform developed by Valve, which aims to provide users with virtual reality (VR) experience. It is closely integrated with the Steam platform, allowing users to enjoy VR games and applications with compatible VR hardware; VRTK is an open source virtual reality (VR) development framework designed for the Unity engine, which aims to accelerate and simplify the development process of VR applications. This toolkit contains a series of modules and presets, allowing developers to quickly integrate standard VR functions, such as object interaction, environment navigation, user interface management, etc. The purpose of these two plug-ins is:
[0029] 1. You can easily obtain the coordinates of the handle in the virtual environment (the position of the virtual handle in the three-dimensional space) and the angle state of the handle (the Euler angle of the virtual handle in the three-dimensional space);
[0030] Second, the event status of the virtual handle grabbing or releasing an object can be easily obtained, which is used to control the grabbing, pouring, and releasing of liquid containers in a virtual environment.
[0031] For effect performance: Import the LiquidVolume plug-in to display the effect of the liquid surface.
[0032] Through the method of the above embodiment, the user can realistically simulate the process of pouring liquid in a virtual environment to enhance the interactivity and realism of virtual reality technology, and promote the user's understanding of fields such as fluid dynamics and physical simulation, which has important educational and training significance. Therefore, the present application can provide users with a highly interactive virtual reality experience, enrich the application field of VR virtual reality technology, and bring users a more in-depth and vivid virtual experience.
[0033] In the specific implementation, before performing step S101, a scene arrangement is performed: in a VR virtual environment, there is a VR operator (including two operating handles), and two virtual containers are placed on a virtual table, namely, a first virtual container A (with a height of Ha) and a second virtual container B (with a height of Hb), both of which are placed with their container mouths vertically upward, and there is liquid with a height of h1 in A and liquid with a height of h2 in B, both of which are not full. For the convenience of description, in the following embodiments, the first virtual container A is used as a container for pouring liquid, and the second virtual container B is used as a container for receiving liquid.
[0034] In one embodiment, the real-time acquisition of the distance between the first virtual container and the second virtual container includes:
[0035] Acquire the first position coordinates of the first virtual container in the virtual handle in the three-dimensional space through the API in VRTK;
[0036] Acquire second position coordinates of the second virtual container in the three-dimensional space;
[0037] The distance between the first virtual container and the second virtual container is calculated according to the first position coordinates and the second position coordinates.
[0038] In specific implementation, when the virtual handle grabs container A, in the program code, each frame is opened, and the position of container A in the virtual handle in three-dimensional space is obtained as HandTargetPosition (first position coordinate) through the VRTK API, and then the distance between HandTargetPosition and the position of container B (second position coordinate) is calculated, that is, the distance between the two objects is detected. The specific calculation is as follows:
[0039] public static double Distance(Point3D point1, Point3D point2){
[0040] double deltaX = point2.X - point1.X;
[0041] double deltaY = point2.Y - point1.Y;
[0042] double deltaZ = point2.Z - point1.Z;
[0043] return Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ *deltaZ);
[0044] }
[0045] API is the abbreviation of Application Programming Interface, which refers to the application program interface. API defines the interaction between components in a software system, allowing different software to interact and communicate with each other. It is a set of prescribed conventions and protocols that define the communication between different modules and components in the software.
[0046] In one embodiment, judging by the distance that the first virtual container can pour liquid into the second virtual container includes:
[0047] Presetting the shortest approach distance between the first virtual container and the second virtual container;
[0048] When the distance between the first virtual container and the second virtual container is less than the shortest approach distance, performing contact detection of the model grid;
[0049] When the hollow ring mesh model at the top of the container opening of the first virtual container overlaps with the hollow ring mesh model at the top of the container opening of the second virtual container, it is determined that the first virtual container can pour liquid into the second virtual container.
[0050] In the contact detection of this embodiment, the distance between two objects is calculated first, and then the mesh contact is calculated, which can effectively reduce performance consumption and avoid the increase of hardware consumption caused by real-time mesh contact detection.
[0051] In specific implementation, for example, a minimum approach distance minDistance is set. When the calculated distance between the first virtual container and the second virtual container is less than minDistance, a new contact detection algorithm between model grids and model grids is started. When a circle of hollow ring grid models on the container mouth of container A overlaps with a circle of hollow grid models on the container mouth of container B, the detection of the liquid pouring algorithm is triggered. The contact function of the grid used in the contact detection algorithm is:
[0052] public MeshRenderer meshRendererA;
[0053] public MeshRenderer meshRendererB;
[0054] void Update()
[0055] {
[0056] / / Check if the bounding boxes of the two models intersect
[0057] if(meshRendererA.bounds.Intersects(meshRendererB.bounds))
[0058] {
[0059] Debug.Log("The two models are in contact!");
[0060] }
[0061] }
[0062] When the two models come into contact, the liquid pouring algorithm is triggered to detect and calculate the liquid capacity of container A poured into container B in each frame. The remaining liquid capacity of container A and container B is calculated in each frame, and then the liquid level height and the liquid level height of container B are calculated based on the tilt angle of container A.
[0063] In specific implementation, when container A is tilted toward container B, the following algorithm is used to calculate whether the liquid can be poured out:
[0064] public float r; / / radius of the cylinder bottom
[0065] public float h; / / cylinder height
[0066] public float H; / / Liquid height
[0067] public float tiltAngle; / / The tilt angle of the cylinder, that is, container A obtains the tilt angle through the handle's positioning angle Rotation
[0068] / / Check if it is possible to pour liquid
[0069] void CheckOverflow()
[0070] {
[0071] / / Calculate the angle between the inclined surface of the liquid and the horizontal surface (assuming the liquid surface is flat)
[0072] float tiltAngleRad = Mathf.Deg2Rad * tiltAngle;
[0073] float inclinedAngleRad = Mathf.Atan(H / r);
[0074] / / Calculate the contact angle
[0075] float contactAngle = 90f - Mathf.Rad2Deg * (tiltAngleRad -inclinedAngleRad);
[0076] / / Calculate the conditions under which the liquid can be poured out (the liquid level is greater than the height of the cylinder, or the contact angle between the liquid and the wall of the first virtual container is less than 0)
[0077] bool overflow = H>h&&contactAngle<0;
[0078] if (overflow)
[0079] {
[0080] Debug.Log("The liquid will be poured out!");
[0081] / / Here you can perform the operation of pouring liquid
[0082] }
[0083] else
[0084] {
[0085] Debug.Log("Liquid will not be poured out");
[0086] }
[0087] }
[0088] In the above algorithm, what is implemented is the description of a cylindrical container with specific geometric dimensions (bottom radius, height) and liquid filling state (liquid height), and whether the liquid will overflow when the container is tilted is taken into account. The specific explanation is as follows:
[0089] public float r;: defines the radius of the bottom of the cylinder;
[0090] public float h;: defines the overall height of the cylinder;
[0091] public float H;: indicates the height of the liquid in the container;
[0092] public float tiltAngle;: indicates the current tilt angle of the cylinder. This angle is obtained through external means (such as the positioning of the VR handle) and is used to determine whether the liquid can be poured out later;
[0093] The CheckOverflow method checks whether the liquid in the container will overflow at the current tilt angle, including:
[0094] Calculate the angle between the inclined surface and the horizontal surface: first convert tiltAngle from degrees to radians (tiltAngleRad), and then use the inverse tangent function Mathf.Atan to calculate the angle inclinedAngleRad formed by the natural inclination of the liquid surface due to gravity (assuming that the liquid surface is an ideal plane);
[0095] Calculate the contact angle: Next, calculate the contact angle, which is the angle between the liquid surface and the cylinder wall. The contact angle is expressed here as 90 degrees minus the difference between the natural inclination angle of the liquid surface and the inclination angle of the cylinder.
[0096] Whether the liquid overflows is determined based on two conditions:
[0097] Condition 1: If the liquid height H is greater than the cylinder height h, it means that the liquid has exceeded the physical limits of the container;
[0098] Condition 2: If the calculated contact angle contactAngle is less than 0, it means that the contact between the liquid and the container wall in the inclined state indicates that the liquid may overflow;
[0099] If any of the conditions are met, the overflow variable is set to true, indicating that the liquid should be poured out; otherwise, the liquid will not overflow.
[0100] Output result: According to the overflow value, the corresponding information is output to the Unity console through Debug.Log to prompt the user or developer whether the liquid will be poured out. The actual pouring operation is not implemented here, but in theory, the corresponding logic can be added in the if (overflow) block to handle the liquid pouring behavior.
[0101] Therefore, through the above method, it can be determined whether the liquid can be poured out, and when it is determined that the liquid can be poured out, the operation of pouring the liquid can be performed.
[0102] In one embodiment, the cylindrical inclination angle of the first virtual container is calculated based on the positioning angle of the virtual handle.
[0103] In one embodiment, obtaining the volume of liquid poured into the second virtual container includes:
[0104] The volume of the liquid poured into the second virtual container is obtained by detecting the inclination angle of the cylinder of the first virtual container.
[0105] When it is implemented, the specific algorithm is as follows:
[0106] / / Define container parameters (unit: cm)
[0107] public float R = 1f; / / bottom radius
[0108] public float H = 5f; / / container height
[0109] / / Define liquid parameters (unit: cm)
[0110] public float h = 3f; / / Liquid height
[0111] / / Define calculation precision
[0112] public int accuracy = 100;
[0113] / / Initial tilt angle
[0114] public float initialAngle = 90f;
[0115] / / Tilt speed (unit: degrees / second)
[0116] public float tiltSpeed = 1f;
[0117] / / Current tilt angle
[0118] private float currentAngle;
[0119] / / Volume of liquid poured out per frame
[0120] private float currentVolume = 0f;
[0121] void Start()
[0122] {
[0123] / / Initialize the tilt angle
[0124] currentAngle = initialAngle;
[0125] }
[0126] void Update()
[0127] {
[0128] / / Get the rotation information of the handle
[0129] float controllerRotation = GetControllerRotation();
[0130] / / Calculate the tilt angle based on the handle rotation information
[0131] currentAngle = Mathf.Clamp(initialAngle - controllerRotation, 0f,90f);
[0132] / / Calculate the volume of liquid poured at the current tilt angle
[0133] currentVolume = CalculateLiquidVolume(currentAngle);
[0134] / / Output the current tilt angle and the volume of the poured liquid
[0135] Debug.Log($"Tilt angle: {currentAngle} degrees, poured liquid volume: {currentVolume} cubic meters.");
[0136] }
[0137] / / Calculate the volume of the poured liquid at a given tilt angle ([Algorithm for calculating the poured volume])
[0138] float CalculateLiquidVolume(float angle)
[0139] {
[0140] float liquidVolume = 0f;
[0141] / / Convert the angle to radians
[0142] float radians = angle * Mathf.Deg2Rad;
[0143] / / Calculate the height of the liquid when the inclination angle is theta
[0144] float liquidHeight = h + (R - Mathf.Cos(radians) * R);
[0145] / / Calculate the liquid volume according to the calculation accuracy
[0146] for (int i = 0; i <accuracy; i++)
[0147] {
[0148] float x = i * R / accuracy;
[0149] float liquidSliceHeight = Mathf.Min(liquidHeight, Mathf.Sqrt(Mathf.Pow(R, 2) - Mathf.Pow(x, 2)));
[0150] liquidVolume += liquidSliceHeight * (2 * R / accuracy) * (2 * H / accuracy);
[0151] }
[0152] return liquidVolume;
[0153] }
[0154] / / Get the rotation information of the handle and the tilt angle of the tilted hand controller
[0155] float GetControllerRotation()
[0156] {
[0157] / / Here we assume that VRTK's SDKManager is used and the controller is the left controller
[0158] VRTK_ControllerEvents controllerEvents = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<>();
[0159] return controllerEvents.GetTouchpadAxisAngle();
[0160] }
[0161] In the above algorithm, R, H, h, accuracy, initialAngle, tiltSpeed, currentAngle and currentVolume represent the bottom radius of the container, the height of the container, the initial height of the liquid, the calculation accuracy, the initial tilt angle, the tilt speed, the current tilt angle and the volume of liquid poured out per frame respectively. These variables are used to define the physical properties of the container and the liquid and the parameters of the simulation process. For the Start() method, the currentAngle is initialized to the initialAngle at the beginning of the game, that is, the set initial tilt angle. For the Update() method, it is called every frame, and the currentAngle is updated in real time according to the rotation information of the VR handle (obtained by the GetControllerRotation() method), ensuring that the tilt angle is between 0° and 90° (using Mathf.Clamp limit); the CalculateLiquidVolume method is called to calculate the volume of liquid poured out at the current tilt angle, and the result is stored in currentVolume; Debug.Log is used to output the current tilt angle and the volume of liquid poured out, which is usually used for debugging information display in the development stage. For the CalculateLiquidVolume(float angle) method, a tilt angle is received as a parameter to calculate the volume of the remaining liquid in the container at this angle; first, the angle is converted into radians, and then the actual height of the liquid in the container is calculated based on trigonometric functions; then, the idea of numerical integration is used to calculate the tiny volume of the container cross section (considering that the liquid height changes with position) and accumulate it to obtain the total liquid volume. For the GetControllerRotation() method, this method is used to obtain the rotation angle of the touchpad from the VR handle (here it is assumed to be the left handle) so as to dynamically adjust the tilt of the container according to the user's operation. The VRTK_ControllerEvents component of the VRTK framework is used here to read the handle input.
[0162] Therefore, the method of this embodiment constructs a basic physical simulation scene, which can dynamically calculate and display the process of tilting the container and pouring liquid according to the interaction of the VR handle, including the real-time calculation of the liquid volume.
[0163] In one embodiment, determining, according to the liquid volume, whether the liquid in the second virtual container overflows, includes:
[0164] Acquire the cylinder height of the second virtual container;
[0165] Calculating the height of the liquid in the second virtual container according to the volume of the liquid poured into the second virtual container;
[0166] When the height of the liquid in the second virtual container is greater than the height of the cylinder of the second virtual container, it is determined that the liquid in the second virtual container overflows.
[0167] In specific implementation, the liquid level of the liquid poured into container B is calculated by the volume of the poured liquid, and the liquid level of container A is also calculated at the same time, which is specifically implemented by the following algorithm:
[0168] / / Define container A parameters (unit: meter)
[0169] public float RA = 1f; / / Bottom radius of container A
[0170] public float HA = 5f; / / container A height
[0171] / / Define container B parameters (unit: meter)
[0172] public float RB = 1.5f; / / Bottom radius of container B
[0173] public float HB = 8f; / / container B height
[0174] / / Define liquid parameters (unit: meter)
[0175] public float h = 3f; / / Liquid height
[0176] / / Define calculation precision
[0177] public int accuracy = 100;
[0178] / / Initial tilt angle
[0179] public float initialAngle = 90f;
[0180] / / Tilt speed (unit: degrees / second)
[0181] public float tiltSpeed = 1f;
[0182] / / Current tilt angle
[0183] private float currentAngle;
[0184] / / Current liquid level
[0185] private float currentLiquidHeightA; / / Liquid level in container A
[0186] private float currentLiquidHeightB; / / Liquid level in container B
[0187] / / Volume of liquid poured out per frame
[0188] private float currentVolume = 0f;
[0189] void Start()
[0190] {
[0191] / / Initialize the tilt angle
[0192] currentAngle = initialAngle;
[0193] / / The initial liquid level is the initial height of the liquid
[0194] currentLiquidHeightA = h; / / Liquid level in container A
[0195] currentLiquidHeightB = 0f; / / The liquid level in container B is 0
[0196] }
[0197] void Update()
[0198] {
[0199] / / Get the rotation information of the handle
[0200] float controllerRotation = GetControllerRotation();
[0201] / / Calculate the tilt angle based on the handle rotation information
[0202] currentAngle = Mathf.Clamp(initialAngle - controllerRotation, 0f,90f);
[0203] / / Calculate the volume of liquid poured at the current tilt angle
[0204] currentVolume = CalculateLiquidVolume(currentAngle);
[0205] / / Update the liquid level
[0206] float deltaHeightA = CalculateDeltaHeightA(currentAngle); / / Calculate the change in height of the liquid level in container A
[0207] currentLiquidHeightA -= deltaHeightA; / / The liquid level in container A decreases
[0208] currentLiquidHeightB += deltaHeightA; / / The liquid level in container B rises
[0209] / / Output the current tilt angle, the volume of liquid poured out, and the liquid level
[0210] Debug.Log($"Tilt angle: {currentAngle} degrees, poured liquid volume: {currentVolume} cubic meters, container A liquid level: {currentLiquidHeightA} meters, container B liquid level: {currentLiquidHeightB} meters.");
[0211] }
[0212] / / Get the rotation information of the handle
[0213] float GetControllerRotation()
[0214] {
[0215] / / Here we assume that VRTK's SDKManager is used and the controller is the left controller
[0216] VRTK_ControllerEvents controllerEvents = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<>();
[0217] return controllerEvents.GetTouchpadAxisAngle();
[0218] }
[0219] / / Calculate the volume of the poured liquid at a given tilt angle
[0220] float CalculateLiquidVolume(float angle)
[0221] {
[0222] float liquidVolume = 0f;
[0223] / / Convert the angle to radians
[0224] float radians = angle * Mathf.Deg2Rad;
[0225] / / Calculate the height of the liquid when the inclination angle is theta
[0226] float liquidHeight = h + (RA - Mathf.Cos(radians) * RA);
[0227] / / Calculate the liquid volume according to the calculation accuracy
[0228] for (int i = 0; i <accuracy; i++)
[0229] {
[0230] float x = i * RA / accuracy;
[0231] float liquidSliceHeight = Mathf.Min(liquidHeight, Mathf.Sqrt(Mathf.Pow(RA, 2) - Mathf.Pow(x, 2)));
[0232] liquidVolume += liquidSliceHeight * (2 * RA / accuracy) * (2 * HA / accuracy);
[0233] }
[0234] return liquidVolume;
[0235] }
[0236] / / Calculate the change in height of the liquid level in container A
[0237] float CalculateDeltaHeightA(float angle)
[0238] {
[0239] / / Calculate the vertical distance from the liquid surface to the lowest point of the container
[0240] float liquidToBottomDistance = (HA - currentLiquidHeightA) *Mathf.Sin(angle * Mathf.Deg2Rad);
[0241] return liquidToBottomDistance;
[0242] }
[0243] In the above method, variables are defined first, including:
[0244] Container A and Container B parameters: define the bottom radius (RA, RB) and height (HA, HB) of the two containers;
[0245] Liquid parameters: initial liquid level h;
[0246] Calculation accuracy: accuracy, the degree of subdivision during numerical integration, used to calculate the liquid volume more accurately;
[0247] Tilt angle related parameters: initial tilt angle initialAngle, tilt speed tiltSpeed and current tilt angle currentAngle;
[0248] Liquid level tracking: Track the current liquid level currentLiquidHeightA in container A and the current liquid level currentLiquidHeightB in container A respectively;
[0249] For the Start() method, initialize the tilt angle to the initial angle and set the initial liquid level of the two containers, where container A is filled to a height of h and container B is empty. For the Update() method, it is executed every frame, and the current tilt angle is adjusted according to the VR handle rotation information, and the angle is ensured to be between 0° and 90°; call CalculateLiquidVolume to calculate the volume of liquid that flows out due to tilt; update the liquid level in the two containers: remove the amount of liquid level drop caused by the calculated volume from container A, and add the same volume to the liquid level of container B; output the current tilt angle, the volume of liquid poured out, and the liquid level of the two containers to the console. For the GetControllerRotation() method, get the rotation angle of the VR handle (assuming it is the left handle) to control the tilt of the container. For the CalculateLiquidVolume (float angle) method, calculate the volume of liquid that can flow out of container A at a given tilt angle; calculate the liquid height by converting the angle into radians, and then use the numerical integration method to gradually accumulate small volume slices to obtain the total volume. For the CalculateDeltaHeightA(float angle) method, the vertical distance from the liquid surface in container A to the bottom of the container is calculated according to the inclination angle. This distance is used to update the liquid surface height in subsequent processing.
[0250] The above process dynamically simulates the physical process of liquid flowing between two containers of different sizes by responding to the input of the VR handle, involving multiple aspects such as angle transformation, volume calculation, and liquid level update.
[0251] Furthermore, the method of the present application also includes:
[0252] Assign the liquid level value fields of container A and container B to the liquid level plug-in component in each frame to display the changes of liquid level in VR in real time;
[0253] At the same time, in each frame, it is detected whether the hollow ring mesh models of the container mouths of the two models are in contact. If there is no contact, it is determined that the pouring process is terminated.
[0254] In specific implementation, the operation process mainly includes: the user grabs container A through the handle operation, and the virtual handle in the virtual scene will also grab container A at the same time. The program monitors the virtual handle's grabbing status of container A through VRTK (after A is grabbed, its position Position and angle EularAngle will change with the position and angle of the grabbing handle). After grabbing, the distance between the grabbed container A and the container B into which the liquid is poured is synchronously detected. Through a certain distance and the model grid edge contact algorithm, it is detected whether container A is close to container B and at the edge of B, and the user is prompted to perform the operation of pouring liquid.
[0255] The pouring process mainly includes: the user controls the tilt angle of the handle, and the container A will also change the angle and position accordingly in the virtual handle, and the geometric properties of the container are combined to calculate the pouring volume corresponding to the tilt angle. Then, the height of the liquid surface is adjusted according to the tilt angle to simulate the pouring process. During the pouring process, the system detects the volume of the container water poured into the liquid in real time, and the program detects whether it exceeds the height range of the container. When the volume of the liquid in the container exceeds the height range of the container, the system will issue a warning to prompt the user that the water has overflowed. If the user moves container A to a certain range outside B, the pouring process is completed and the operation is over.
[0256] Through the method of the present application, users can realistically simulate the process of pouring liquid in a virtual environment to enhance the interactivity and realism of virtual reality technology, and can also promote users' understanding of fields such as fluid dynamics and physical simulation, which has important educational and training significance. Therefore, the present application aims to provide users with a highly interactive virtual reality experience, enrich the application fields of VR virtual reality technology, and bring users a more in-depth and vivid virtual experience. The method of the present application can be applied to fields such as VR games, VR virtual training, and VR educational courseware simulation, providing users with an immersive virtual experience and having certain educational and entertainment functions.
[0257] In this embodiment, a computer device is provided, such as Figure 2 As shown, it includes a memory 201, a processor 202, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, any of the above-mentioned virtual reality-based liquid pouring simulation methods is implemented.
[0258] Specifically, the computer device may be a computer terminal, a server or a similar computing device.
[0259] In this embodiment, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program for executing any of the above-mentioned virtual reality-based liquid pouring simulation methods.
[0260] Specifically, computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0261] Based on the same inventive concept, a liquid pouring simulation device based on virtual reality is also provided in the embodiments of the present invention, as described in the following embodiments. Since the principle of solving the problem by the liquid pouring simulation device based on virtual reality is similar to that of the liquid pouring simulation method based on virtual reality, the implementation of the liquid pouring simulation device based on virtual reality can refer to the implementation of the liquid pouring simulation method based on virtual reality, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.
[0262] Figure 3 is a structural block diagram of a liquid pouring simulation device based on virtual reality according to an embodiment of the present invention, such as Figure 3 As shown, it includes: a grabbing module 301, a moving module 302, a pouring module 303 and a liquid overflow judging module 304, and the structure is described below.
[0263] A grabbing module 301, configured to display a virtual handle to simulate grabbing a first virtual container containing liquid to be poured according to the position of the operating handle in the three-dimensional space;
[0264] A moving module 302, used for acquiring the distance between the first virtual container and a second virtual container in real time during the process of moving the virtual handle, wherein the second virtual container is used to receive the liquid;
[0265] The pouring module 303 is used to simulate the inclination of the first virtual container according to the inclination state of the virtual handle, and simulate the process of the first virtual container pouring liquid into the second virtual container when it is judged that the first virtual container can pour liquid into the second virtual container through the distance; the simulation of the inclination of the first virtual container according to the inclination state of the virtual handle and the process of the first virtual container pouring liquid into the second virtual container includes: simulating the inclination of the first virtual container through the inclination angle of the virtual handle; obtaining the cylinder bottom radius, cylinder height, liquid height and cylinder inclination angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface based on the cylinder inclination angle, the cylinder bottom radius and the liquid height by trigonometric function; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is judged that the liquid can be poured out, and then the process of the first virtual container pouring liquid into the second virtual container is simulated;
[0266] The liquid overflow judgment module 304 is used to obtain the volume of the liquid poured into the second virtual container in real time, and when it is judged that the liquid in the second virtual container overflows according to the liquid volume, prompt to stop the liquid pouring process.
[0267] In one embodiment, the mobile module 302 is further used for:
[0268] Acquire the first position coordinates of the first virtual container in the virtual handle in the three-dimensional space through the API in VRTK;
[0269] Acquire second position coordinates of the second virtual container in the three-dimensional space;
[0270] The distance between the first virtual container and the second virtual container is calculated according to the first position coordinates and the second position coordinates.
[0271] In one embodiment, the dumping module 303 is further used to:
[0272] Presetting the shortest approach distance between the first virtual container and the second virtual container;
[0273] When the distance between the first virtual container and the second virtual container is less than the shortest approach distance, performing contact detection of the model grid;
[0274] When the hollow ring mesh model at the top of the container opening of the first virtual container overlaps with the hollow ring mesh model at the top of the container opening of the second virtual container, it is determined that the first virtual container can pour liquid into the second virtual container.
[0275] In one embodiment, the liquid overflow determination module 304 is further configured to:
[0276] The volume of the liquid poured into the second virtual container is obtained by detecting the inclination angle of the cylinder of the first virtual container.
[0277] In one embodiment, the dumping module 303 is further used to:
[0278] The cylindrical inclination angle of the first virtual container is calculated according to the positioning angle of the virtual handle.
[0279] In one embodiment, the liquid overflow determination module 304 is further configured to:
[0280] Acquire the cylinder height of the second virtual container;
[0281] Calculating the height of the liquid in the second virtual container according to the volume of the liquid poured into the second virtual container;
[0282] When the height of the liquid in the second virtual container is greater than the height of the cylinder of the second virtual container, it is determined that the liquid in the second virtual container overflows.
[0283] The embodiment of the present invention achieves the following technical effects: controlling the virtual handle in the three-dimensional space to grab the first virtual container containing the liquid to be poured; displaying the virtual handle to simulate grabbing the first virtual container containing the liquid to be poured according to the position of the operating handle in the three-dimensional space; obtaining the distance between the first virtual container and the second virtual container in real time during the movement of the virtual handle, and the second virtual container is used to receive the liquid; when it is judged by the distance that the first virtual container can pour the liquid into the second virtual container, simulating the inclination of the first virtual container according to the inclination state of the virtual handle, simulating the process of the first virtual container pouring the liquid into the second virtual container; obtaining the volume of the liquid poured into the second virtual container in real time, and when it is judged that the liquid in the second virtual container overflows according to the liquid volume, prompting to stop the liquid pouring process. Through the method of the present application, the user can truly simulate the process of pouring liquid in a virtual environment to enhance the interactivity and realism of virtual reality technology, and can promote the user's understanding of fields such as fluid dynamics and physical simulation, which has important educational and training significance. Therefore, the present application can provide users with a highly interactive virtual reality experience, enrich the application field of VR virtual reality technology, and bring users a more in-depth and vivid virtual experience.
[0284] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present invention are not limited to any specific combination of hardware and software.
[0285] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A liquid pouring simulation method based on virtual reality, It is characterized in that include: According to the position of the operating handle in the three-dimensional space, displaying a virtual handle to simulate grabbing a first virtual container containing the liquid to be poured; In the process of moving the virtual handle, obtaining in real time the distance between the first virtual container and a second virtual container, where the second virtual container is used to receive the liquid; When it is determined by the distance that the first virtual container can pour liquid into the second virtual container, simulating the tilting of the first virtual container according to the tilting state of the virtual handle, and simulating the process of the first virtual container pouring liquid into the second virtual container; The method of simulating the tilting of the first virtual container according to the tilting state of the virtual handle and simulating the process of the first virtual container pouring liquid into the second virtual container includes: simulating the tilting of the first virtual container by the tilting angle of the virtual handle; acquiring the cylinder bottom radius, cylinder height, liquid height and cylinder tilting angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface by using trigonometric functions based on the cylinder tilting angle, the cylinder bottom radius and the liquid height; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is determined that the liquid can be poured out, and then the process of pouring the liquid from the first virtual container into the second virtual container is simulated; acquiring the volume of the liquid poured into the second virtual container in real time, and prompting to stop the liquid pouring process when it is determined according to the liquid volume that the liquid in the second virtual container overflows; The method for simulating the process of pouring liquid from the first virtual container into the second virtual container includes: Define parameters of the first virtual container and the second virtual container: the first virtual container is container A, the second virtual container is container B, and the bottom radius and height of the two containers are defined respectively; Define liquid parameters: initial liquid level h; Define calculation accuracy: Calculation accuracy is the degree of subdivision during numerical integration, which is used to calculate the liquid volume more accurately; Define the parameters related to the tilt angle: initial tilt angle, tilt speed and current tilt angle; Liquid level tracking: Track the current liquid level in container A and the current liquid level in container A respectively; Execute the Start() method, initialize the tilt angle to the initial angle, and set the initial liquid level heights of the two containers, where container A is filled to height h and container B is empty; Execute the Update() method every frame to adjust the current tilt angle according to the virtual handle rotation information and ensure that the angle is between 0° and 90°; Call CalculateLiquidVolume to calculate the volume of liquid that has flowed out due to the tilt; update the liquid levels in the two containers: remove the amount of liquid level drop caused by the calculated volume from container A, and add the same volume to the liquid level of container B; output the current tilt angle, the volume of liquid that has been poured out, and the liquid levels of the two containers to the console; Execute the GetControllerRotation() method to obtain the rotation angle of the virtual handle to control the tilt of the container; execute the CalculateLiquidVolume (float angle) method to calculate the volume of liquid that can flow out of container A at a given tilt angle; calculate the liquid height by converting the angle into radians, and then use the numerical integration method to gradually accumulate small volume slices to obtain the total volume; Execute the CalculateDeltaHeightA(float angle) method to calculate the vertical distance from the liquid surface in container A to the bottom of the container according to the inclination angle. This vertical distance is used to update the liquid surface height in subsequent processing.
2. The virtual reality-based liquid pouring simulation method according to claim 1, It is characterized in that The real-time acquisition of the distance between the first virtual container and the second virtual container includes: Acquire the first position coordinates of the first virtual container in the virtual handle in the three-dimensional space through the API in VRTK; Acquire second position coordinates of the second virtual container in the three-dimensional space; The distance between the first virtual container and the second virtual container is calculated according to the first position coordinates and the second position coordinates.
3. The virtual reality-based liquid pouring simulation method as claimed in claim 2, It is characterized in that The determining, based on the distance, that the first virtual container can pour liquid into the second virtual container includes: Presetting the shortest approach distance between the first virtual container and the second virtual container; When the distance between the first virtual container and the second virtual container is less than the shortest approach distance, performing contact detection of the model grid; When the hollow ring mesh model at the top of the container opening of the first virtual container overlaps with the hollow ring mesh model at the top of the container opening of the second virtual container, it is determined that the first virtual container can pour liquid into the second virtual container.
4. The virtual reality-based liquid pouring simulation method according to claim 1, It is characterized in that The obtaining the volume of the liquid poured into the second virtual container comprises: The volume of the liquid poured into the second virtual container is obtained by detecting the inclination angle of the cylinder of the first virtual container.
5. The virtual reality-based liquid pouring simulation method as claimed in claim 1 or 4, It is characterized in that The cylindrical inclination angle of the first virtual container is calculated according to the positioning angle of the virtual handle.
6. The virtual reality-based liquid pouring simulation method according to claim 1, It is characterized in that The step of determining, according to the liquid volume, that the liquid in the second virtual container overflows, comprises: Acquire the cylinder height of the second virtual container; Calculating the height of the liquid in the second virtual container according to the volume of the liquid poured into the second virtual container; When the height of the liquid in the second virtual container is greater than the height of the cylinder of the second virtual container, it is determined that the liquid in the second virtual container overflows.
7. A liquid pouring simulation device based on virtual reality, It is characterized in that include: A grabbing module, used for displaying a virtual handle to simulate grabbing a first virtual container containing liquid to be poured according to the position of the operating handle in the three-dimensional space; A moving module, used for acquiring the distance between the first virtual container and a second virtual container in real time during the process of moving the virtual handle, wherein the second virtual container is used to receive the liquid; a pouring module, for simulating the inclination of the first virtual container according to the inclination state of the virtual handle, and simulating the process of the first virtual container pouring liquid into the second virtual container, when it is judged by the distance that the first virtual container can pour liquid into the second virtual container; the simulating the inclination of the first virtual container according to the inclination state of the virtual handle, and simulating the process of the first virtual container pouring liquid into the second virtual container, comprising: simulating the inclination of the first virtual container by the inclination angle of the virtual handle; acquiring the cylinder bottom radius, cylinder height, liquid height and cylinder inclination angle of the first virtual container in real time; calculating the angle between the inclined surface of the liquid and the horizontal surface by using trigonometric functions based on the cylinder inclination angle, the cylinder bottom radius and the liquid height; calculating the contact angle between the liquid and the wall of the first virtual container based on the angle and the contact angle of the horizontal plane; when the liquid height is greater than the cylinder height or the contact angle between the liquid and the wall of the first virtual container is less than zero, it is judged that the liquid can be poured out, and then the process of the first virtual container pouring liquid into the second virtual container is simulated; a liquid overflow judgment module, used for obtaining the volume of the liquid poured into the second virtual container in real time, and prompting to stop the liquid pouring process when it is judged that the liquid in the second virtual container overflows according to the liquid volume; The method for simulating the process of pouring liquid from the first virtual container into the second virtual container includes: Define parameters of the first virtual container and the second virtual container: the first virtual container is container A, the second virtual container is container B, and the bottom radius and height of the two containers are defined respectively; Define liquid parameters: initial liquid level h; Define calculation accuracy: Calculation accuracy is the degree of subdivision during numerical integration, which is used to calculate the liquid volume more accurately; Define the parameters related to the tilt angle: initial tilt angle, tilt speed and current tilt angle; Liquid level tracking: Track the current liquid level in container A and the current liquid level in container A respectively; Execute the Start() method, initialize the tilt angle to the initial angle, and set the initial liquid level heights of the two containers, where container A is filled to height h and container B is empty; Execute the Update() method every frame to adjust the current tilt angle according to the virtual handle rotation information and ensure that the angle is between 0° and 90°; Call CalculateLiquidVolume to calculate the volume of liquid that has flowed out due to the tilt; update the liquid levels in the two containers: remove the amount of liquid level drop caused by the calculated volume from container A, and add the same volume to the liquid level of container B; output the current tilt angle, the volume of liquid that has been poured out, and the liquid levels of the two containers to the console; Execute the GetControllerRotation() method to obtain the rotation angle of the virtual handle to control the tilt of the container; execute the CalculateLiquidVolume (float angle) method to calculate the volume of liquid that can flow out of container A at a given tilt angle; calculate the liquid height by converting the angle into radians, and then use the numerical integration method to gradually accumulate small volume slices to obtain the total volume; Execute the CalculateDeltaHeightA(float angle) method to calculate the vertical distance from the liquid surface in container A to the bottom of the container according to the inclination angle. This vertical distance is used to update the liquid surface height in subsequent processing.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the virtual reality-based liquid pouring simulation method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program for executing the virtual reality-based liquid pouring simulation method according to any one of claims 1 to 6.
