How mnmxmx/fluid-three works
Main Components
• User Interface & Entry Point: Represent the “dist/index.html” as the web page that hosts the simulation’s WebGL canvas.
• WebGL Context & Core Rendering: Illustrate the “WebGL.js” module as the central piece that creates and manages the WebGL context. Also include the “ShaderPass.js” which likely encapsulates the logic for applying shaders during rendering.
• Simulation Engine: Group the simulation-related modules (Advection.js, Divergence.js, ExternalForce.js, Pressure.js, Poisson.js, Viscous.js) as processing stages. The “Simulation.js” module should appear as the orchestrator that sequentially calls these simulation steps.
• User Interaction and Controls: Include modules like “Controls.js” and “Mouse.js” to show how user input is handled and fed into the simulation (e.g., triggering ExternalForce).
• Utility and Event Handling: Show supporting modules such as “EventBus.js”, “math.js” and “utils.js”, which are used for communication between components and to perform mathematical operations required in the simulation.
Relationships and Interactions
• Simulation Loop: From “Simulation.js”, create a sequential flow that runs the simulation steps:
• Data flows from “Advection.js” → “Divergence.js” → “Pressure.js” → “Poisson.js” → “Viscous.js”.
• User Input: Show “Mouse.js” and “Controls.js” feeding data (like external forces) into the simulation loop (e.g., input going to “ExternalForce.js”).
Architectural Patterns
• Modular Design: Emphasize the separation of concerns where each simulation step is isolated in its own module.
• Data Flow/Processing Pipeline: Show iterative arrowed flow from one stage to the next within the simulation.
• GPU Offloading: Clearly delineate between JavaScript modules managing application logic and the GLSL shader modules managing GPU-accelerated computations.
• Build & Deployment: Indicate that the project is built using Webpack (webpack.config.js) and uses package management (package.json) to run the Node.js environment with Yarn for dependency management.