flux3d-engine
v0.1.0
Published
High Performance 100% GPU-Driven 3D WebGPU Engine
Readme
Flux3D Engine 🚀
Flux3D is a next-generation, high-performance 3D engine built from scratch for the Web and Desktop (via Tauri). Powered by WebGPU, it operates on a strict Data-Oriented Design (DOD) paradigm, completely avoiding JavaScript Garbage Collection (GC) stutters during runtime.
🌟 Key Features
- Zero GC Allocations in Game Loop: Uses pre-allocated
Float32Arraymemory pooling. Nonew Vector3()ornew Object3D()overheads. - 100% GPU-Driven Physics: Integrates WebGPU Compute Shaders to calculate transform arrays and physics on parallel GPU cores, leaving the CPU completely free.
- Native Matrix Math: A custom-built, dependency-free
Mat4library optimized for contiguous memory blocks. - Built for Tauri & Web: Write once, deploy as a blazing-fast native Windows/Mac/Linux app via Tauri or host it directly on the web.
📦 Installation
```bash npm install flux3d-engine ```
(Note: WebGPU is required in the browser)
🎮 Quick Start
The engine provides an extremely low-level and high-performance API. Here is a minimal example of rendering thousands of cubes:
```typescript import { EngineECS, Renderer, Mat4 } from 'flux3d-engine';
// 1. Initialize ECS and pre-allocate memory const ecs = new EngineECS(10000);
// 2. Setup the WebGPU Renderer const canvas = document.getElementById('gpu-canvas'); const renderer = new Renderer(); await renderer.init(canvas); renderer.createBuffers(ecs.transformData.byteLength);
// 3. Upload initial state renderer.uploadInitialTransforms(ecs.transformData); renderer.updateLight([1, 1, -1], [1, 1, 0.9], [0.2, 0.2, 0.3]);
// 4. Start the 100% GPU-Driven Game Loop const projectionMatrix = Mat4.create(); const viewMatrix = Mat4.create(); const viewProjMatrix = Mat4.create();
function gameLoop(time) { // Math & Camera (CPU) Mat4.perspective(projectionMatrix, Math.PI / 4, canvas.width / canvas.height, 0.1, 1000.0); Mat4.lookAt(viewMatrix, 0, 0, 250, 0, 0, 0, 0, 1, 0); Mat4.multiply(viewProjMatrix, projectionMatrix, viewMatrix); renderer.updateCamera(viewProjMatrix);
// Compute Shaders & Render (GPU)
renderer.compute(time, 16.0, 10000); // 10k entities simulated on GPU
renderer.render(10000);
requestAnimationFrame(gameLoop);} requestAnimationFrame(gameLoop); ```
🛠 Architecture
Flux3D rejects traditional Object-Oriented deep hierarchies (like Scene > Mesh > Geometry > Material).
Instead, everything is a flat array in memory (SoA - Structure of Arrays). The CPU just schedules the work, and the GPU does the heavy lifting via Compute Shaders and Instanced Draw Calls.
📄 License
MIT
