GithubHelp home page GithubHelp logo

metanoder / godot-fluid-sim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thompsop1sou/godot-fluid-sim

0.0 0.0 0.0 37.23 MB

Real-time fluid simulation in Godot

License: MIT License

C++ 55.91% Python 3.28% C# 15.99% GDScript 24.81%

godot-fluid-sim's Introduction

Fluid Simulation in Godot

Created using the Godot game engine with the Godot Jolt addon.

This is a real-time fluid simulation that uses Godot's built-in RigidBody3D nodes as individual droplets of fluid. The main contribution that this project makes is the inclusion of a "droplet server". This server applies cohesive forces to attract the droplets to each other. This helps to sell the illusion that the fluid has surface tension and viscosity.

fluid_sim_demo_2.mp4

The Droplet Server

There are two different versions of the droplet server written in two different programming languages:

  • C#: officially supported by Godot (see here)
  • C++: can be used with GDExtension (without needing to edit the source code)

The code for these servers is basically equivalent. In essence, they loop over each pair of droplets and, if any two are close enough to each other, will apply a cohesive force to pull the droplets closer.

Note: This project used to contain a version of the droplet server written in GDScript. This version was removed due to inadequate performance.

Example Scene

The main scene of this project, main.tscn, provides an example of how the droplet servers can be used. In particular, check out the DropletGenerator node and its script, droplet_generator.gd.

When the scene is run, this node/script will generate droplets at regular time intervals in random positions near the center of the scene. While it's running, you can also change the direction of gravity using the arrow keys and watch the "fluid" move around.

The DropletGenerator node has several exported properties that can be configured from the inspector:

  • droplet_server_type: Whether to use the C# or the C++ server (see above).
  • droplet_object_type: Whether to create droplets from scenes or use the physics and rendering servers with RIDs.
    • Scenes are easier to work with but slower.
    • The physics and rendering servers are harder to work with but faster.
  • generation_interval: When generating droplets, how much time should elapse between each successive droplet.
  • droplets_to_generate: How many total droplets to generate.

Performance

I ran a few quick tests on my own laptop, which has 8 GB of RAM and an 8-core processor. I was able to spawn the following number of droplets (approximately) before dropping below 60 frames-per-second:

Server Type Object Type Built-In Physics Jolt Physics
C# Scene ~1000 droplets ~2000 droplets
C# Server RID ~1100 droplets ~2400 droplets
C++ Scene ~1100 droplets ~2700 droplets
C++ Server RID ~1200 droplets ~3200 droplets

Of course, take these results with a grain of salt. But in general:

  • Using the physics/rendering servers is faster than using scenes. (Small Impact)
  • The C++ droplet server is faster than the C# droplet server. (Medium Impact)
  • Jolt physics is faster than the built-in physics. (Large Impact)

Running the Project

To run this project, you will need a copy of Godot version 4.2 with .NET support. This can be downloaded from Godot's official download page.

Currently, the C++ server has only been compiled for Windows. If you want to run the project on a different system, you will first need to compile the source code.

To do this, first make sure that you have the godot-cpp submodule cloned and set up correctly (check out the first few sections in this doc). Then, run the following from the root directory (replacing <your_platform> with windows, linux, or macos):

scons platform=<your_platform>

godot-fluid-sim's People

Contributors

petermthompson avatar thompsop1sou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.