A c++ voxel engine module for godot.

Voxelman

A voxel engine module for godot, focusing more on editor integration, gameplay-related features, and extendability (even from gdscript), without sacrificing too much speed.

This is an engine module! Which means that you will need to compile it into Godot! See the compiling section here.

You can find a demonstration project here: https://github.com/Relintai/the_tower

It supports both godot 3.2 and 4.0 (master last tested commit). Note that since 4.0 is still in very early stages I only check whether it works from time to time.

Optional Dependencies

https://github.com/Relintai/thread_pool: Threaded chunk generation. Without this Voxelman is single threaded!
https://github.com/Relintai/texture_packer: You get access to VoxelmanLibraryMerger.
https://github.com/Relintai/mesh_data_resource: You get access to a bunch of properties, and methods that can manipulate meshes.
https://github.com/Relintai/props: You get access to a bunch of properties, and methods that can manipulate, and use props.
https://github.com/Relintai/mesh_utils: Lets you use lod levels higher than 4 by default.

Pre-built binaries

You can grab a pre-built editor binary from the Broken Seals repo, should you want to. It contains all my modules.

Usage

First create a scene, and add a VoxelWorldBlocky node into it. Create a VoxelmanLibrary, and assign it to the Library property. Also, add a VoxelSurface into your library.

(VoxelWorldBlocky is the only one that works properly for now, this will soon be fixed!)

Tick the editable property, deselect, then select the world again, and click the insert button at the top toolbar, or press B to insert a voxel at the inspector's camera's location.

Select the add button, and now you can just add voxels with the mouse, by clicking on the newly added voxel.

VoxelmanLibrary

This class stores the materials, and the VoxelSurfaces.

Note: If you want lods, assign equal (or more) materials than your maximum lod level. If you only want one material just assign it multiple times. If you don't then your meshes won't have materials (They will be white).

VoxelmanLibrarySimple

The simplest library, just assign a material with a texture, and using the atlas_rows and atlas_culomns properties to tell the system how the UVs should be divided.

VoxelmanLibraryMerger

You will only have this if your godot also contains https://github.com/Relintai/texture_packer

You can assign any texture to your surfaces with this, and it will merge them together.

Worlds

The 2 base classes:

VoxelWorld: Basic world, does not do anything until you implemnent the required virtual methods!
VoxelWorldDefault: This adds threading, and LoD storage support to VoxelWorld. Will not create meshes for you!

VoxelWorldBlocky

The most basic world. It is the Minecraft-style world.

VoxelWorldMarchingCubes

A marching cubes based Voxel World. Actually it uses a modified version of the Transvoxel tables. It is UV mapped.

VoxelWorldCubic

This is my own meshing algorithm, it's basicly a Minecraft style mesher that can take isolevel into account.

Level generation

Assign a VoxelManLevelGenerator to the World's Level Generator property.

You can write your own algorithm by implementing the void _generate_chunk(chunk: VoxelChunk) virtual method.

VoxelManLevelGeneratorFlat is also available, it will generate a floor for you, if you use it.

VoxelJobs

Producing just a terrarin mesh for a chunk is not that hard by itself. However when you start adding layers/features like lod generation, collision meshes (especially since manipulating the physics server is not threadsafe), vertex volumetric lights, props, snapping props, props with vertex lights, etc chunk mesh generation can quicly become a serious mess.

VoxelJobs are meant to solve the issue with this complexity.

They also provide a way to easily modularize mesh generation.

VoxelJob

Base class for jobs.

If the (thread pool)[https://github.com/Relintai/thread_pool] module is present, this is inherited from ThreadPoolJob, else it implements the same api as ThreadPoolJob, but it's not going to use threading.

A job has a reference to it's owner chunk.

If you implement your own jobs, when your job finishes call next_job().

VoxelLightJob

This is the job that will generate vertex light based ao, random ao, and will bake your VoxelLights.

VoxelTerrarinJob

This will generate your terrarin collider and mesh (with lods) for you, using the meshers that you add into it.

VoxelPropJob

This will generate your prop meshes (with lods).

Internal workings

VoxelWorld

Whenever you want to spawn a chunk your World will create it using the VoxelChunk _create_chunk(x: int, y: int, z: int, chunk: VoxelChunk) virtual method.

Since properly initializing a chunk usually takes quite a few steps that you probably don't want to repeat everywhere the chunk parameter was added. This means you can just call the super _create_chunk methods, and you won't need to worry about your chunk getting overridden. Like:

Note that _create_chunk is also responsible for initializing chunks if you have them stored inside a scene. This is done by setup_chunk(shunk) in VoxelWorld.

    func _create_chunk(x : int, y : int, z : int, chunk : VoxelChunk) -> VoxelChunk:
        if !chunk:
            chunk = MyChunk.new()

        # We need to check whether or not we need to initialize jobs
        if chunk.job_get_count() == 0:
            # Setup a blocky (minecratf like) mesher job
            var tj : VoxelTerrarinJob = VoxelTerrarinJob.new()

            tj.add_mesher(VoxelMesherBlocky.new())
            tj.add_liquid_mesher(VoxelMesherLiquidBlocky.new())

            chunk.job_add(tj);

        #setup your chunk here

        return ._create_chunk(x, y, z, chunk)

VoxelChunk

Stores terrarin data, prop data. And mesh data (VoxelChunkDefault), and the mesh generation jobs.

When it starts building meshes it will start submitting jobs to thread_pool (if present) one by one.

VoxelMesher

If you want to implement your own meshing algorithm you can do so by overriding void _add_chunk(chunk: VoxelChunk) virtual.

VoxelMesher works similarly to SurfaceTool, so first you need to set colors, uvs, etc and then call add_vertex. They won't get reset, so for exaple if you want all your vertices to have a certain color, you can get away with setting it only once.

Compiling

First make sure that you can compile godot. See the official docs: https://docs.godotengine.org/en/3.2/development/compiling/index.html

  1. Clone the engine if you haven't already:

If you want Godot 3.2: git clone -b 3.2 https://github.com/godotengine/godot.git godot

If you want Godot 4.0: git clone https://github.com/godotengine/godot.git godot

  1. go into the modules folder inside the engine's directory:

cd godot
cd modules

  1. clone this repository

git clone https://github.com/Relintai/voxelman.git voxelman

(the folder needs to be named voxelman!)

  1. If you want the optional dependencies run these commands aswell:

git clone https://github.com/Relintai/texture_packer.git texture_packer
git clone https://github.com/Relintai/mesh_data_resource.git mesh_data_resource

  1. Go up one folder

cd ..

  1. Compile godot.

For example:

scons p=x11 t=release_debug tools=yes

Comments
  • Voxelman assume library has at least 4 materials

    Voxelman assume library has at least 4 materials

    image

    Errors will go away once you have 4 materials.

    I think is coming from TerrarinJob. I see a lot of material_get() with values 0 , 1, 2 and 3 in there. Maybe start off with 4 opaque white ShaderMaterial COLOR = vec4(1,1,1,1) fragment by default when creating a new library?

    Also is TerrarinJob a typo? Should it be TerrainJob?

  • Proposal to rename Voxelman to Voxel

    Proposal to rename Voxelman to Voxel

    I'm testing this out right now. Thank you for the work and making this available for us to use.

    I would like to propose changing Voxelman to Voxel or VOXELMAN to VOXEL. Seems like a strange name Voxelman. If anything it makes it less clear that this is a voxel module. I originally thought of voxel characters or models creator (ie makes voxel men) rather than a minecraft type voxelized world.

    So i went ahead and renamed it that way . Looks neater from within Godot more in line with the naming convention of all other tools image

    image

    I had to rename VoxelmanLight to PropVoxelLight which is closer to what it actually is , a voxel light prop. Feel free to close this but I think both this module and the terrain one should be renamed to somethin more sensible Voxel and Terrain . Simple.

    Either way been testing it more and is pretty fun. It has a numbr of issues I identified tho. Thank you for this!

  • get_palette_split() is not a member of SpatialEditor

    get_palette_split() is not a member of SpatialEditor

    SpatialEditor does not contain get_palette_split() . Maybe is Godot 4 api?

    modules\voxel\world\voxel_world_editor.cpp(334): error C2039: 'get_palette_split': is not a member of 'SpatialEditor' modules\voxel\world\voxel_world_editor.cpp(337): error C2039: 'get_palette_split': is not a member of 'SpatialEditor'

  • reset_stages was not declared

    reset_stages was not declared

    I get the following error with latest sources (building without additional dependencies):

    modules/voxelman/world/jobs/voxel_terrarin_job.cpp: In member function 'void VoxelTerrarinJob::phase_terrarin_mesh()':
    modules/voxelman/world/jobs/voxel_terrarin_job.cpp:366:3: error: 'reset_stages' was not declared in this scope; did you mean 'set_stage'?
      366 |   reset_stages();
          |   ^~~~~~~~~~~~
    

    However, when including optional dependencies, this error does not show.

  • 1.0 Release tracker

    1.0 Release tracker

    This issue tracks the things that needs to be done for the first stable release.

    • [ ] Port everything from Broken Seals (transvoxel mesher implementation for example, VoxelWorld has quite a few things there, etc).
    • [x] Rename the current transvoxel mesher, because of smaller changes. E.g. The tables are modified, to support standard uv mapping.
    • [x] Add the original transvoxel tables as well.
    • [x] Organize meshers into folders.
    • [ ] Ability to exclude meshers at compile time.
    • [x] Fix multithreaded generation.
    • [ ] Finish clutter support. (Grass for example)
    • [ ] Liquid meshing support. (Static for now).
    • [ ] Clean up things that are no longer needed.
    • [ ] Documentation (Sphinx)
    • [ ] Class docs (XML) - At least the things that are not self explanatory.
    • [x] Make sure, that dependencies to my other modules optional.
    • [x] VoxelChunk's, and VoxelMesher's api will probably need some cleanups.
    • [x] Updateable, and scriptable block support for things like crops, or in world effects.

    I'm doing these as part of an assignment (I'm really glad that they let me), so these will be done in about 1-2 months.

    • [x] Chunk serialization, and deserialization.
    • [x] Make sure something is available to compress chunk data.
    • [x] Editor tools for in-editor voxel editing. Think of GridMap. It should support fill values as well.
    • [x] Simple Minecraft-like voxel mesher.
  • Voxel edit menu items always show when editor starts

    Voxel edit menu items always show when editor starts

    The following items will appear by default when editor starts regardless if you have edit mode on or if the nodes have been clicked: image

    To remove these menu items you need to turn edit mode on on a voxel node, then click away. Note the last menu item the slider does not show up by default.

    Also thank you for the recent changes. I have updated my build and works well thus far.

  • props module not optional

    props module not optional

    props seems to be non optional too:

    modules/voxelman/world/voxel_chunk.cpp: In member function 'int VoxelChunk::mesh_data_resource_addv(const Vector3&, const Ref<MeshDataResource>&, const Ref<Texture2D>&, const Color&, bool)':
    modules/voxelman/world/voxel_chunk.cpp:727:30: error: 'class VoxelmanLibrary' has no member named 'get_prop_uv_rect'
      727 |   e.uv_rect = get_library()->get_prop_uv_rect(texture);
          |                              ^~~~~~~~~~~~~~~~
    
  • Ideas for Voxelman to move it forward in a sensible direction, properties

    Ideas for Voxelman to move it forward in a sensible direction, properties

    Voxel Properties

    Naming: States, Properties, Params

    Properties/params are int, bool, enum, string variables that are manually defined for specific Voxel ids using a property_name keyword. Properties are used to define custom behavior or looks for Voxels and although are associated with an id, are actually stored per x,y,z Voxel in the VoxelChunk.

    A dictionary with key params["x,y,z:property_name"] can be used to store properties in addition to the ch[] array used for Voxels.

    Examples:

    • rotating block facing_enum property
    • block look property to change texture
    • buttons or switches pressed
    • furnace lit

    References: Forge Blockstates Minecraft Wiki Block states Minetest Wiki for register_node

    Voxels can rotate

    Naming: dir, direction, facing, facedir, orientation

    With the implementation of properties/params above, we can now add more customization to specific Voxels. Adding a facing int property allows Voxels to specify a texture rotation. Mesher can now render the texture to follow the facing specified by the property. By default all Voxels face NORTH.

    A utility class Facing stores all the facings for example Facing.NORTH, Facing.SOUTH, Facing.EAST, Facing.WEST, Facing.UP, Facing.DOWN and also allows for additional functions such as rotate(Vector3, Facing.LEFT), give a Vector3 for a facing Facing.to_vec3(Facing.NORTH) etc.

    Voxels can change material/look/texture

    Naming: look, texture, tex, alt, mat, material

    When a voxel has a look string property defined, the mesher will use that string as the material for that specific Voxel. This parameter can be dynamically updated from Script.

    Look would store only a name and not the full path. A material path can now be declared per Voxel id.

    Voxels can use custom 3D meshes

    A property/param called mesh defines the name of the 3D mesh that the meshes will use instead of the regular block/marching cube mesher. Such a voxel is declared as being transparent internally and is not processed by the mesher and will not mix in with the rest of regular voxel terrain.

    A mesh path can now be declared per Voxel id.

    I know that there is a mesh_data_tool support which appears to allow for custom meshing but perhaps built in meshes .tres meshes should also be supported by default as is simply adding a mesh into the world as is without any rotation at a specific x,y,z location. So is upt to the user to manipualte this mesh so it looks good at 1:1 scaling and correct rotation.

    Conclusion

    Thank you for reading and for all your contribution and work thus far. And sorry for the long post. Just wanted to be thorough.

Scalable Distributed Game Server Engine with Hot Swapping in Golang
Scalable Distributed Game Server Engine with Hot Swapping in Golang

GoWorld Scalable Distributed Game Server Engine with Hot Reload in Golang Features Architecture Introduction Get GoWorld Manage GoWorld Servers Demos

Dec 25, 2022
A pure Go game engine
A pure Go game engine

Oak A pure Go game engine Table of Contents Installation Motivation Features Support Quick Start Implementation and Examples Finished Games Installati

Jan 8, 2023
Terminal-based game engine for Go, built on top of Termbox
Terminal-based game engine for Go, built on top of Termbox

Termloop Termloop is a pure Go game engine for the terminal, built on top of the excellent Termbox. It provides a simple render loop for building game

Dec 29, 2022
Tile is a 2D grid engine, built with data and cache friendly ways, includes pathfinding and observers.
Tile is a 2D grid engine, built with data and cache friendly ways, includes pathfinding and observers.

Tile: Data-Oriented 2D Grid Engine This repository contains a 2D tile map engine which is built with data and cache friendly ways. My main goal here i

Dec 26, 2022
A chess engine written in golang
A chess engine written in golang

Weasel Art graciously provided by Alex Table of Contents: About Installing and Compiling from Source Contributing License About Weasel is an 0x88 and

Dec 30, 2022
A 2D ARPG game engine.
A 2D ARPG game engine.

Abyss Engine is an ARPG game engine in the same vein of the 2000's games, and supports playing games similar to Diablo 2. The engine is written in golang and is cross platform. This engine does not ship with game specific files, and will require a game's assets in order to run.

Dec 24, 2022
A small fantasy game engine in WASM using GoLang
A small fantasy game engine in WASM using GoLang

The GoLang Fantasy Engine (GoLF Engine) is a retro game engine. It draws inspiration from fantasy console projects like pico-8, tic-80, and pyxle. Like those projects it is designed to be a retro-feeling game creation/playing tool. Unlike those projects GoLF is more minimal in scope and only provides an API and a small set of tools to help you create your games. Tools like an image editor and code editor are not built in. Despite this minimalism creating games in GoLF is still easy and should still maintain the retro game feel.

Jul 16, 2022
Currently in beta testing. A chess engine written in golang
Currently in beta testing. A chess engine written in golang

Weasel Art graciously provided by Alex Table of Contents: About Installing and Compiling from Source Contributing License About Weasel is an 0x88 and

Dec 30, 2022
golang powered game engine
golang powered game engine

Gobatch Go powered engine that offers features from low level opengl abstraction to UI framework. I created this to separate lot of logic from game am

Nov 13, 2022
Arkanoid game in Go using Ebiten game engine with ECS.
Arkanoid game in Go using Ebiten game engine with ECS.

Arkanoid-go Arkanoid game in Go using Ebiten game engine with ECS. You must have Git LFS installed when cloning the repository to download assets. See

Oct 9, 2022
spx - A 2D Game Engine for learning Go+
spx - A 2D Game Engine for learning Go+

spx - A 2D Game Engine for learning Go+ Tutorials How to run spx tutorials? Download Go+ and build it. See https://github.com/goplus/gop#how-to-build.

Dec 1, 2022
Blunder is an open-source UCI compatible chess engine.

A UCI compatible chess engine written in Golang

Dec 30, 2022
Go Game Engine using SDL for fun

nMage nMage is a (hopefully!) high performance 3D Game Engine written in Go being developed live, with recordings posted on YouTube. This project is b

Nov 30, 2022
HelloSpx - Hello world of Go+ spx game engine
HelloSpx - Hello world of Go+ spx game engine

HelloSpx - Hello world of Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this game

Nov 27, 2021
HelloWorldForSpx - Hello world of Go+ spx game engine
 HelloWorldForSpx - Hello world of Go+ spx game engine

HelloWorldForSpx - Hello world of Go+ spx game engineHelloWorldForSpx - Hello world of Go+ spx game engine

Nov 22, 2021
AircraftWar - a game powered by Go+ spx game engine
AircraftWar - a game powered by Go+ spx game engine

AircraftWar - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download thi

Jan 5, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
MazePlay - a game powered by Go+ spx game engine
MazePlay - a game powered by Go+ spx game engine

MazePlay - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this g

Dec 16, 2021