利用者:Romanp/GSoC Mantaflow Framework/Docs
目次
GSoC 2014, Mantaflow integration, Roman Pogribnyi
Following is the outline of my work during GSoC 2014.
During this project, I have started the integration of Mantaflow framework into Blender. My per-week progress can be seen here
Work Done
My main purpose was to integrate the framework as loosely as possible, to account for further expansion of Mantaflow, as it is currently under development.
User Interface configured for MantaFlow interaction
Currently, there is a checkbox for switching to Mantaflow framework functionality. User currently can specify start/end frames of simulation, plus settings of noise fields of emitter. Once hit "Create Manta Setup", python script with mantaflow settings will be created and simulation begins.
- Solver resolution parameter will be used to switch to 2D solver
- UVs Couns: how many textures are used for turbulence modeling in wavelets
- Noise settings: noise field for emitter. To deactivate, set "scale" to 0.
Scene transfer to MantaFlow
Setup Script
To begin simulation, Mantaflow needs a setup script. Each time the "Create Manta Setup" button is hit, or current frame is set to '0' with mantaflow "Use Mantaflow" enabled, a setup file is generated. Currently, script is written to manta_scene.py file, but later will be passed to manta module directly.
Scenarios
These are templates for Mantaflow setups that will be preprocessed. Currently, I'm integrating one for smoke. Since the Nodes
Geometry
Flow and Collision objects are exported to two files, manta_flow.obj and manta_coll.obj respectively. Objects are grouped by their type(flow or collision) and written to disk. Since domain sizes and "zero location"(0,0,0) are different, I introduced a repositioning and rescaling step each time geometry is exported. Meshes are linked as children to domain, and then the domain is scaled down to (1,1,1). The linking allows rotated meshes to be scaled on axes of domain, not their own. When loaded to Mantaflow, meshes are resized and repositioned accordingly.
SDF
When in Mantaflow, meshes must be transferred to grid representation. For that, signed distance field(SDF) function was added. Initial function used triangle centers and normals for SDF computation, which led to false results in highly-resolution domains with low-resolution meshes. After introducing a sampling factor, to check multiple vertices per triangle, problem was resolved.
Force Fields
External Blender forces are passed to Mantaflow on a per-step basis. This allows to account for animated force fields, which are not yet implemented in Mantaflow. On each step, a unified force grid is passed to manta sim, where it is accumulated to running simulation.
Running and getting data back
My first task was to be able to read simulations produced by Mantaflow and account for different dimension representation. After every step of simulation, Mantaflow setup script creates density files that are read by Blender. These are of format den%04d.uni for low-res smoke and densityXl_%04d.uni for wavelets smoke(den0001.uni and densityXl_0001.uni respectively)
Internal integration
For the best performance, Mantaflow had to be integrated as internal Blender module. It took time to solve the problems with compiling together, and then importing all Mantaflow classes during runtime. I added the option to include Mantaflow as external module(for update-during-compile possibility), if such necessity occurs.
Per-Step
I added the per-step simulation operation to mantaflow, to allow to stop sim mid-running, and also for further elimination of the "Bake" button.
Integration details
The code for Mantaflow library is taken from here. Among dependencies, currently:
- CUDA for some functions with vortex sheets
- Intel TBB/ OpenMP
- Zlib package(using version 1.2.8)
There are two options of building Mantaflow in Blender: from original sources and from preprocessed files. Both options are located in /source/blender/python/manta_pp and /source/blender/python/manta_full folders. When compiling, Mantaflow has a preprocessing step, which transforms some of the original files and adds them to final compile sources. There preprocessed files are used in compiling the manta library, and can be found in /pp folder.
For now, Blender uses preprocessed files directly. To compile with them, one has to build Mantaflow and add files manually. I included second version, i.e is compiling from original sources. This will later be used to make Mantaflow a cmake "external project", with possibility to update sources from Maktaflow repository during compile time.
Other
Other work included adding functions to Mantaflow for receiving information form Blender(force fields, SDFs), threading the simulation functions(to leave Blender responsive while sim is running) and fixing reported bugs.
Demo
Here is a short demo of what can currently be done with mantaflow:
Further work
Though I have integrated basic smoke functionality, there is still much to be done. Next step would be
- adding emission maps to Mantaflow setup
- integrating particle systems
- fluid simulations. From there, setting up fluid simulations and k-eps turbulence modeling can take place. * *automatically adjust SDF settings based on mesh triangulation.
- adding OpenMP
- would be nice to have fluids configurable with Nodes