MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

DivineVoxelEngine 技术深度解析与应用评述

项目背景与痛点

在 3D 引擎领域,特别是针对大规模场景的构建,像 Minecraft 这样的世界是由无数的方块(voxel)构成的。在这样的背景下,DivineVoxelEngine 应运而生。它提供了一个多线程、渲染器独立且可高度定制的 TypeScript 体素引擎,旨在解决构建高效且可扩展的体素环境时面临的复杂挑战。

核心技术揭秘

DivineVoxelEngine 利用了多线程和渲染器独立的设计来提升性能。它的核心技术栈包括 TypeScript 编程语言、WebGL 渲染层以及一系列数据流处理机制。

设计思想

这个项目的设计思想在于提供一个稳定、高效、可扩展的体素引擎。它不仅兼容多种渲染器,还支持多线程并行处理,以确保性能的同时又能保证稳定性。以下是一个示意的数据流图,展示了该引擎的核心架构。

graph TD A[用户操作] --> B[事件处理] B --> C{"NDC 转换"} C -->|"多线程处理"| D[几何数据生成] C -->|"单线程处理"| E[几何数据前置] D --> F[网格渲染] E --> F F --> G[绘制结果]

技术实现

  • 多线程:通过利用现代 CPU 多核处理器,实现了高效率的数据处理和渲染操作。
  • 渲染器独立:通过抽象层,可以接入各种渲染器,包括 OpenGL、WebGL 等。
  • TypeScript 编程语言:提供了强类型保证,并支持静态检查,便于复杂应用的构建。

功能亮点与差异

与其他体素引擎相比,DivineVoxelEngine 在灵活性和可扩展性方面具有显著优势。它不仅支持高度可定制的渲染逻辑,还提供了丰富的 API 供用户灵活使用。此外,其多线程设计为大规模场景渲染提供了性能保障,降低了单线程系统中容易出现的瓶颈。

应用场景与落地建议

在生产环境使用 DivineVoxelEngine 时,开发者应注意以下几点:

  • 线程同步:由于多线程的存在,注意同步问题,避免数据竞争。
  • 资源管理:合理分配和管理内存及 GPU 资源,提高渲染效率。
  • 性能优化:针对具体的使用场景进行针对性优化,提升用户体验。

适用场景包括但不限于:

  • 大规模模拟环境模拟
  • 虚拟现实游戏开发
  • 模拟器及训练平台

综合评价

DivineVoxelEngine 作为一款多线程、渲染器独立且高度可定制的 TypeScript 体素引擎,在性能、灵活性和扩展性方面具有明显优势。但也需要注意到同步与资源管理的挑战。总之,对于需要高效处理大规模体素数据的开发者,DivineVoxelEngine 是一个值得关注的选择。

关于

GitHub 原始描述(英文)

A multi-threaded, renderer independent, fully customizable TypeScript voxel engine.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
317
价值分
164
活跃状态
活跃

语言占比

CSS
HTML
JavaScript
TypeScript

README

⛯ Divine Voxel Engine ⛯

A multi-threaded, renderer-independent voxel engine in TypeScript.
Build Minecraft-style voxel worlds and games that run in the browser.

npm version npm version npm version npm version

license stars Discord


DVE 1

Try the live demo  ·  Browse the Vlox demos  ·  Getting Started guide

Quick Start

Install the core, the Babylon renderer, and the Amodx suite:

npm install @babylonjs/core
npm install @amodx/suite @divinevoxel/vlox @divinevoxel/vlox-babylon

Then follow GETTING_STARTED.md to go from an empty project to generating and rendering a world.

Features

  • Renderer-independent core. The voxel engine lives in @divinevoxel/vlox and knows nothing about a specific renderer. Official renderers exist for Babylon.js (Classic and PBR shaders), with Three.js and WebGPU renderers in development.
  • Multi-threaded by design. Meshing, world generation, and world updates all run in parallel across web workers. Shared memory (SharedArrayBuffer) is on by default and can be turned off.
  • Fast meshing via precomputed rules. Voxel models are exploded into faces, and every culling and ambient-occlusion relationship is computed once at registration into flat lookup tables. At mesh time the hot loop is cheap array lookups against those tables.
  • JSON-driven model & geometry system. Describe voxel shapes as reusable geometry (boxes, quads, triangles) and wire them into models with JSON. AO, lighting, and culling are handled automatically. Reuse one model across many voxels, and expose many looks through the state (geometry) and mod (inputs) layers.
  • Rich voxel behavior. Sunlight and light propagation, liquid flow, level states, light-emitting voxels, transparency, and secondary voxels in a single cell (water-logged blocks and the like).
  • Effectively infinite worlds. A world simulation keeps sectors loaded around one or more moving generators, running each new sector through a fixed pipeline (generation → decoration → sunlight → propagation → build). Supports multiple generators and multiple dimensions.
  • Two-pass world generation. A simple brush API paints terrain in a generate pass and features (grass, trees, ores) in a decorate pass that can read back what was already placed.
  • Saving & archiving. Pluggable world storage (with an IndexedDB example) streams sectors in and out as the player moves, and an archiving API exports whole regions and templates to compact binary or human-readable JSON.
  • Runtime building. VoxelBuildSpace places and erases voxels in a live world, with raycast picking, oriented placement, bounded edit regions, and update hooks. Work with many voxels at once through templates and selections.
  • Flexible textures. Atlases with named tiles, per-id variations, animated textures, and an option to pre-compact everything into a single atlas + JSON.

Packages

Core

  • @divinevoxel/vlox — the renderer-independent voxel engine: data handling, meshing, lighting and flow, the JSON model system, the world simulation, and the archiving API.
  • @divinevoxel/vlox-babylon — the Babylon.js renderer for Vlox, with Classic and PBR shaders.

Game development

  • @dvegames/vlox — components for building games with Babylon.js and @divinevoxel/vlox.
  • @dvegames/vlox-tools — a library for creating tool panels for any @divinevoxel/vlox project.
Shared Memory Originally the engine was built to use SharedArrayBuffers but that caused some issues. You can now turn off shared memory usage like this:
import { StartRenderer } from "@divinevoxel/vlox/Init/StartRenderer";
//...
  const DVER = await StartRenderer({
    renderer,
    worldWorker,
    mesherWorkers,
    generatorWorkers,
    voxels: DVEVoxelData,
    memoryAndCPU: {
      useSharedMemory: false,
    },
  });

With useSharedMemory set to false you will only have access to world data in the World thread.

In Dev Packages These packages have not been worked on in a while and may be worked on in future if there is demand for them.
  • @divinevoxel/vlox-three

    • Renderer for DVE Vlox using Three.js, including Classic and PBR shaders
  • @divinevoxel/vlox-quantum

    • Custom renderer for DVE Vlox using WebGPU

Games & Demos

Crystalline Bliss

A 3D puzzle game with environments built using the engine.

Play on itch.io  ·  Buy on Steam

Crystalline Bliss 1 Crystalline Bliss 2

Divine Craft

A demo showing off biome-based infinite world generation.

Play in browser  ·  GitHub repo

Divine Craft 1 Divine Craft 2

Screenshots

Vlox Babylon

PBR

DVE PBR 1 DVE PBR 2 DVE PBR 3 DVE PBR 4 DVE PBR 5 DVE PBR 6

Classic

DVE Classic 1 DVE Classic 2 DVE Classic 3 DVE Classic 4 DVE Classic 5

Developing DVE (Monorepo Setup)

You only need the Quick Start above to build with DVE. The steps below are for working on the engine itself.

This project is a monorepo that holds all the Divine Voxel Engine packages and required libraries from Amodx. To initialize the project, run the following commands:

git clone https://github.com/Divine-Star-Software/DivineVoxelEngine.git
cd ./DivineVoxelEngine
git lfs pull
git submodule update --init --recursive
git submodule foreach git checkout main
git submodule foreach git pull
npm run init:all
npm install --workspaces=false
cd ./demos/Vlox
npm run start

Community

Join the Divine Star community to get updates: Discord.

See development videos on the Divine Star Software YouTube channel.

评论

暂无评论