Skip to content

corentin-ryr/Boat-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buoyancy simulation

This is a simulation of the buoyancy on mesh objects. This method is applicable to any mesh to simulate a floating behaviour. This method works for a moving water surface.

floatingSceneDemo.mp4

Usage

The buoyancy system requires two elements:

  • The water
  • The floating object

Water

The system needs a water manager in the scene (of type WaterManager) and a water object that implements the IWater interface. This interface only needs the object to have a transform and a GetHeight method (that returns the water height at a given position).

Floater

The floating object needs the PressureFloater component. This component requires a meshCollider with convex set to true and a RigidBody with gravity enabled. By default the floter component uses the collider mesh as the hull of the floating object. For complex meshes, it is good practice to give the floater a simpler mesh as the hull (through the public attribute). For a boat mesh, the system will assume that anything outside the mesh is water (so act as if the boat was filled with water).

The method

To simulate the buoyancy, we need to apply two forces, the gravity at the center of mass and the buoyant force at the geometric center of the immersed part of the object and oriented toward the normal of the water surface.

To find the immersed part of the mesh, we compute the intersection between the water mesh and the floating object's mesh. The intersection finding is based on [1], this allows to find an accurate chain of points that are exactly at the intersection.

From this chain, we can get the triangles of the floating mesh that are bellow the water line and we can triangulate the chain to have the surface of the displaced water. We compute a third set of triangles made of the triangles cut by the intersection line.

We then compute the goemetric center and the volume of the intersection mesh [2].

The drag simulation from unity is limited. It requires the user to set the drag values by hand and doesn't adapt to the different fluid the object interacts with. Consequently, we use our own simulation of drag based on physics [3]. For each triangle, we compute the friction torque (the drag generated by the pressure of the fluid on the triangle due to the speed of the triangle) and the linear drag as well as the shear stress. The approximation we make for the first two is a constant drag coefficient (named C) and that the pressure is applied to the surface projected on the direction of motion. For the shear stress, we assume an infinite distance between the surface of the object and the borders of the water (the wall of the pool on the video example or the ocean floor in a realistic setting). After computing these values for each triangles, we add them and apply the final torque and force to the object.

Performances

This algorithm is more computationaly expensive than some simpler approximations. To improve performance, part of the algorithm is parralelized on the GPU. With the sphere and 20*20 water, it runs at 30fps in the Unity Editor.

References

  • [1] S. H. Lo and W. X. Wang. 2004. A fast robust algorithm for the intersection of triangulated surfaces. Eng. with Comput. 20, 1 (March 2004), 11–21.
  • [2] Cha Zhang and Tsuhan Chen, "Efficient feature extraction for 2D/3D objects in mesh representation," Proceedings 2001 International Conference on Image Processing (Cat. No.01CH37205), 2001, pp. 935-938 vol.3, doi: 10.1109/ICIP.2001.958278.
  • [3] White, F. M. (1974). Viscous fluid flow. New York: McGraw-Hill.
  • [4] https://alexanderameye.github.io/notes/stylized-water-shader/

About

Buoyancy simulation with mesh intersection in Unity.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published