viber3d

repository·main·Indexed 20 days ago

https://github.com/instructa/viber3d

A modern starter kit for building 3D browser games using React 19, React Three Fiber, and an Entity Component System (ECS) powered by the koota library. The stack includes Vite, TailwindCSS, Zustand, and React Three Rapier for physics. It features a dedicated CLI for project scaffolding and is optimized for AI-assisted development with predefined rules for editors like Cursor, GitHub Copilot, and Windsurf.

Tokens
32.7K
Snippets
89
Records
134
Agent score
68%

What's inside viber3d

  1. Overview of Viber3D features and core concepts

    main

    Viber3D is a modern 3D game starter kit for the web designed for creating immersive games and interactive experiences. It provides a high-performance foundation with several integrated systems:

    Key Features

    • Physics Engine: Built-in engine for realistic object interactions and collisions.
    • Game Systems: Comprehensive handling for input, audio, and networking.
    • Component Architecture: Flexible entity-component architecture for complex game objects.
    • Performance: Optimized for modern browsers with efficient rendering.
    • TypeScript Support: Full type-safe development.
    • Asset Management: System for loading 3D models, textures, and audio.

    Core Concepts

    • Entity Component System (ECS): A data-driven architecture for building game objects.
    • Scene Management: System for organizing game worlds.
    • Asset Pipeline: Efficient loading and management of game assets.
    • Input System: Handling for keyboard, mouse, and touch.
    • Physics System: Built-in engine for realistic interactions.
    • Rendering Pipeline: Modern WebGL-based rendering utilizing React Three Fiber.
    • Audio System: Support for spatial audio.
    • Networking: Built-in capabilities for multiplayer games.
    • Development Tools: Debugging and performance monitoring tools.
  2. Overview of Viber3D documentation structure

    main

    The Viber3D documentation is organized into several key areas to help you understand and use the 3D game starter kit:

    • Introduction: High-level overview of Viber3D and its features.
    • Getting Started: Instructions for installation and basic usage.
    • Core Concepts: Explanations of the underlying architecture, including the Entity Component System (ECS), Entities, Traits, Systems, and Components.
    • Systems: Detailed technical information regarding the built-in systems provided by the kit.
  3. Overview of viber3d features

    main

    viber3d is a modern starter kit for 3D browser games. The stack includes:

    • React 19: Utilizing concurrent rendering.
    • React Three Fiber: For declarative Three.js usage.
    • Vite: For fast development server and bundling.
    • TailwindCSS: For UI styling.
    • Zustand: For lightweight state management.
    • React Three Rapier: For physics engine integration.
    • TypeScript: For type safety.
    • AI Integration: Includes predefined rules for AI code editors.
  4. Overview of Viber3D features

    main

    Viber3D is a 3D game starter kit designed for modern web browsers. Key features include:

    • 3D Physics: Built-in engine for realistic object interactions and collisions.
    • Game Systems: Includes input handling, audio, and networking.
    • Modern Architecture: Optimized for performance using modern web technologies.
    • TypeScript: Provides a fully typed development experience.
    • Component System: A flexible, component-based architecture for building complex game objects.
    • Documentation: Comprehensive guides, tutorials, and references.
  5. Key features demonstrated in the Viber3D Demo

    main

    The Viber3D demo showcases the following core engine capabilities:

    • 3D Rendering: High-performance rendering with dynamic lighting and effects.
    • Physics Engine: Realistic physics interactions between game objects.
    • Input Controls: A responsive input system supporting keyboard and mouse controls.
    • Game Systems: The Entity Component System (ECS) managing various game mechanics.
  6. Why use Viber3D

    main

    Viber3D is designed for rapid 3D environment setup and game development with the following core advantages:

    • Quick Setup: Minimal configuration required to get a 3D environment running.
    • ECS Architecture: Uses an Entity Component System (ECS) approach, providing a flexible way to manage game logic.
    • React Integration: Leverages the expressiveness of React and react-three-fiber while minimizing boilerplate.
    • Scope Flexibility: Optimized for small to medium-scale 3D projects, such as shooters or exploration games.
  7. viber3d core features and stack

    main

    viber3d is a modern starter kit for 3D browser games built with the following stack:

    • Core Engine: React 19, React Three Fiber (declarative Three.js), and Drei (helpers).
    • Physics: React Three Rapier for physics simulations.
    • Architecture: Entity Component System (ECS) powered by the koota library.
    • State Management: Zustand.
    • Build Tooling: Vite for fast development and builds.
    • Styling: TailwindCSS for utility-first CSS.
    • Language: TypeScript for type safety.
    • Design: Responsive design for all devices.
  8. Optimize rendering with Batch Mesh

    main

    When rendering large numbers of identical or similar objects (e.g., crates, bullets, environment props), using individual Three.js Mesh objects can cause performance bottlenecks due to high draw call counts.

    Batch Mesh solves this by combining many objects into a single Three.js mesh. This reduces draw calls—often to just one—while still allowing you to manipulate individual "instances" using per-instance transform data.

  9. Understand the Entity Component System (ECS) architecture

    main

    Viber3D uses an Entity Component System (ECS) architecture powered by the koota library. This data-driven design separates data from logic to improve performance and flexibility in real-time and XR applications.

    Core abstractions include:

    • Entities: Unique identifiers representing objects (e.g., players, bullets).
    • Traits: Pure data containers attached to entities (equivalent to 'components' in other ECS frameworks).
    • Systems: Logic blocks that query entities with specific traits and process them.

    This approach favors composition over inheritance, allowing you to build complex behaviors by combining small, focused traits rather than using rigid class hierarchies.

  10. Choose between SoA and AoS trait storage

    main

    Koota supports two storage strategies for traits, which impact performance and data structure:

    1. Schema-based (SoA - Structure of Arrays): Define a trait using an object literal. Each property is stored in its own array. This is highly optimized for numeric fields that are updated frequently (e.g., Position, Velocity).

      const Position = trait({ x: 0, y: 0, z: 0 })
    2. Callback-based (AoS - Array of Structures): Define a trait using a callback function. The entire trait is stored as a single object in an array. This is best for complex objects or class instances (e.g., THREE.Mesh, Vector3).

      const Mesh = trait(() => new THREE.Mesh())
    // SoA Example
    const Position = trait({ x: 0, y: 0, z: 0 })
    
    // AoS Example
    const Mesh = trait(() => new THREE.Mesh())
  11. How ECS works in Viber3D

    main

    Viber3D uses an Entity-Component-System (ECS) architecture powered by koota. This pattern decouples data from logic to improve modularity and performance:

    • Traits (Components): Hold the data (e.g., Position, Velocity, Health).
    • Entities: Unique IDs that act as containers for various traits.
    • Systems: The logic layer. Systems run every frame (or on demand) and process groups of entities that possess a specific set of traits (e.g., a movementSystem processes all entities with both Position and Velocity).

    This separation allows you to add or remove features by simply attaching or removing traits from entities without modifying existing logic.

  12. Manage Bounding Volumes for Culling

    main

    Three.js uses bounding volumes (Box or Sphere) for frustum culling. Because a BatchedMesh is a single object, it typically uses one overall bounding volume for all its instances.

    Crucial: You must recompute the bounding volume (e.g., batchedMesh.computeBoundingBox() and batchedMesh.computeBoundingSphere()) whenever you add or remove instances to ensure objects are not incorrectly culled from the scene.