A 3D voxel mining example built with the Defold Game Engine. This project includes mesh generation, collision detection, and performance monitoring.
Play the demo here: https://cenullum.itch.io/cubemining
- Greedy Meshing Algorithm: Reduces vertex count and draw calls by merging adjacent faces into quads.
- Swept AABB Collision System: Collision detection and resolution with sub-stepping to prevent tunneling.
- Runtime Sprite-to-Mesh Voxelization: Converts 2D pixel art sprites into 3D voxel meshes at runtime.
- Vertex-based Ambient Occlusion: Calculated per-vertex to darken corners and edges. Toggleable with 'O'.
- Distance-based Fog: Distance-based fog applied to terrain and voxelized items.
- Dynamic Item System: A variety of holdable items including blocks, tools (pickaxes, swords), and guns (pistol, submachine gun with ammo/reload mechanics).
- Block Health & Mining Power: Blocks have varying durability, and tools have distinct mining/damage power.
- Sound System: Spatial and triggered sound effects for interactions, placing, breaking, and weapon mechanics.
- Throwables: Physics-based items like throwable bombs with screen shake effects.
- Voxel Interaction: Block destruction and placement with mesh updates.
- Performance Monitoring: Overlay showing FPS, 1% low frames, RAM usage, mesh statistics, and player position.
- Shader-based UV Mapping: Texture tiling and atlas-based UV wrapping for voxel surfaces.
- WASD: Move around
- Shift: Sprint (Move faster)
- Space: Jump / Ascend
- Ctrl: Descend
- Left Click: Break / Shoot
- Right Click: Place / ADS (Aim Down Sights)
- 1 / 2: Next / Previous active item
- R: Reload weapon
- M: Toggle Performance Overlay (Off / Text / Graph)
- O: Toggle Ambient Occlusion
- P: Toggle Fly / Walk mode
- T: Spawn mouse at targeted block
- Y: Spawn mice rapidly (Hold)
- Scale: The project is focused on a single 16x16x16 voxel cube. It does not implement a chunking system or procedural terrain generation.
- Threading: Mesh generation and GPU buffer updates are handled on the main thread.
- Culling: Surfaces that are not visible (touching another solid block) are excluded from the mesh. Faces are added when "holes" are created.
- Item Voxelization: Analyzes sprite transparency to extrude edges. Generates mesh with front/back quads and side faces for solid pixels.
This project was inspired by the Meshes-In-Defold repository. While it served as a starting point, most of the original code has been substantially rewritten to implement greedy meshing, optimize performance.
- generate_voxel.script: Manages the voxel grid state, implements greedy meshing, and handles GPU buffer updates.
- voxelizer.script: Converts 2D sprite data into 3D meshes at runtime.
- physics.lua: Shared physics module implementing AABB collision detection and resolution.
- character_controller.script: Manages player movement, input handling, and camera logic.
- hand_slot_manager.script: Manages the player's active hand item, inventory, and dynamic switching.
- performance_overlay.script: Provides a visual debugger for FPS, RAM usage, and camera state.
- cube_cursor.script: Manages 3D cursor interaction for targeting and modifying the voxel world.
- sound_manager.lua: Optimizes and handles audio playback, throttling, and spatial sounds.
- items.lua: Defines available blocks, tools, and weapons with their properties (health, sound, damage).
- world.lua: Centralized world data management, providing shared access to the voxel grid and dimensions.
- block_data.lua: Extensible system for defining block properties, transparency, and UV metadata.
- npc.lua: Base module for NPC logic and AI movement within the voxel world.
- Textures & Models: All textures and models are made by cenullum and are licensed under CC0 (Public Domain).
- Sound Effects (Sourced from Pixabay):
Contributions are welcome! Whether it's optimization, new features, or bug fixes, feel free to fork the repository and submit a pull request.
If you find this project helpful and would like to support its development, you can make a donation here: https://cenullum.com/donation
This project is licensed under the MIT License - see the LICENSE file for details.


