Working naive voxel mesher.

This commit is contained in:
Joshua Bemenderfer 2020-10-06 22:11:14 -04:00
parent 0c64ddb7c6
commit c2df101161
31 changed files with 1634 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.import .import
.godot

View File

@ -1,19 +1,25 @@
extends Node extends Node
var tasks = {} var tasks = {}
onready var ConsoleService = $"/root/ConsoleService"
signal task_start;
signal task_complete
func start(name: String, message: String): func start(name: String, message: String):
var task = Task.new(name, message) var task = Task.new(name, message)
if not tasks[task.name]: tasks[task.name] = [] if not tasks.has(task.name): tasks[task.name] = []
tasks[task.name].append(task) tasks[task.name].append(task)
emit_signal('started:'+name, task) emit_signal('task_start', task)
ConsoleService.log("[TaskService] Started: "+name)
func complete(name: String): func complete(name: String):
if not tasks[name]: return if not tasks[name]: return
var task = tasks[name].pop_front() var task = tasks[name].pop_front()
if tasks[name].size() == 0: if tasks[name].size() == 0:
tasks.erase(name) tasks.erase(name)
emit_signal('completed:'+name, task) emit_signal('task_complete', task)
ConsoleService.log("[TaskService] Completed: "+name)
class Task: class Task:
var name = '' var name = ''

View File

@ -1,15 +1,23 @@
extends Node extends Node
onready var NetworkService = $"/root/NetworkService"
onready var ConsoleService = $"/root/ConsoleService"
onready var TaskService = $"/root/TaskService"
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
var NetworkService = $"/root/NetworkService"
if NetworkService.NETWORK_MODE == 'server': if NetworkService.NETWORK_MODE == 'server':
$"TabContainer/Singleplayer".queue_free() $"TabContainer/Singleplayer".queue_free()
var ConsoleService = $"/root/ConsoleService"
ConsoleService.connect("on_log", self, "update_log") ConsoleService.connect("on_log", self, "update_log")
ConsoleService.connect("on_error", self, "update_log") ConsoleService.connect("on_error", self, "update_log")
$"TabContainer/Logs/LogList".text = PoolStringArray(ConsoleService.log_messages).join("\n") $"TabContainer/Logs/LogList".text = PoolStringArray(ConsoleService.log_messages).join("\n")
$"TabContainer/Singleplayer/Start Game".connect("button_down", self, "start_game");
func update_log(log_messages): func update_log(log_messages):
$"TabContainer/Logs/LogList".text = PoolStringArray(log_messages).join("\n") $"TabContainer/Logs/LogList".text = PoolStringArray(log_messages).join("\n")
func start_game():
var scene_root = $"/root/Main/Scene"
scene_root.remove_child(self);
TaskService.start('start_game', "Singleplayer pressed.")

7
packages/voxel_mesher/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
target/*
!target/release
!target/debug
target/release/*
target/debug/*
!target/release/*.so
!target/debug/*.so

View File

@ -0,0 +1,244 @@
# Licensed under the MIT License.
# Copyright (c) 2018-2020 Jaccomo Lorenz (Maujoe)
extends Camera
# User settings:
# General settings
export var enabled = true setget set_enabled
# See https://docs.godotengine.org/en/latest/classes/class_input.html?highlight=Input#enumerations
export(int, "Visible", "Hidden", "Captured, Confined") var mouse_mode = Input.MOUSE_MODE_CAPTURED
enum Freelook_Modes {MOUSE, INPUT_ACTION, MOUSE_AND_INPUT_ACTION}
# Freelook settings
export var freelook = true
export (Freelook_Modes) var freelook_mode = 2
export (float, 0.0, 1.0) var sensitivity = 0.5
export (float, 0.0, 0.999, 0.001) var smoothness = 0.5 setget set_smoothness
export (int, 0, 360) var yaw_limit = 360
export (int, 0, 360) var pitch_limit = 360
# Pivot Settings
export(NodePath) var privot setget set_privot
export var distance = 5.0 setget set_distance
export var rotate_privot = false
export var collisions = true setget set_collisions
# Movement settings
export var movement = true
export (float, 0.0, 1.0) var acceleration = 1.0
export (float, 0.0, 0.0, 1.0) var deceleration = 0.1
export var max_speed = Vector3(1.0, 1.0, 1.0)
export var local = true
# Input Actions
export var rotate_left_action = ""
export var rotate_right_action = ""
export var rotate_up_action = ""
export var rotate_down_action = ""
export var forward_action = "ui_up"
export var backward_action = "ui_down"
export var left_action = "ui_left"
export var right_action = "ui_right"
export var up_action = "ui_page_up"
export var down_action = "ui_page_down"
export var trigger_action = ""
# Gui settings
export var use_gui = true
export var gui_action = "ui_cancel"
# Intern variables.
var _mouse_offset = Vector2()
var _rotation_offset = Vector2()
var _yaw = 0.0
var _pitch = 0.0
var _total_yaw = 0.0
var _total_pitch = 0.0
var _direction = Vector3(0.0, 0.0, 0.0)
var _speed = Vector3(0.0, 0.0, 0.0)
var _gui
var _triggered=false
const ROTATION_MULTIPLIER = 500
func _ready():
_check_actions([
forward_action,
backward_action,
left_action,
right_action,
gui_action,
up_action,
down_action,
rotate_left_action,
rotate_right_action,
rotate_up_action,
rotate_down_action
])
if privot:
privot = get_node(privot)
else:
privot = null
set_enabled(enabled)
if use_gui:
_gui = preload("camera_control_gui.gd")
_gui = _gui.new(self, gui_action)
add_child(_gui)
func _input(event):
if len(trigger_action)!=0:
if event.is_action_pressed(trigger_action):
_triggered=true
elif event.is_action_released(trigger_action):
_triggered=false
else:
_triggered=true
if freelook and _triggered:
if event is InputEventMouseMotion:
_mouse_offset = event.relative
_rotation_offset.x = Input.get_action_strength(rotate_right_action) - Input.get_action_strength(rotate_left_action)
_rotation_offset.y = Input.get_action_strength(rotate_down_action) - Input.get_action_strength(rotate_up_action)
if movement and _triggered:
_direction.x = Input.get_action_strength(right_action) - Input.get_action_strength(left_action)
_direction.y = Input.get_action_strength(up_action) - Input.get_action_strength(down_action)
_direction.z = Input.get_action_strength(backward_action) - Input.get_action_strength(forward_action)
func _process(delta):
if _triggered:
_update_views(delta)
func _update_views(delta):
if privot:
_update_distance()
if freelook:
_update_rotation(delta)
if movement:
_update_movement(delta)
func _physics_process(delta):
if _triggered:
_update_views_physics(delta)
func _update_views_physics(delta):
# Called when collision are enabled
_update_distance()
if freelook:
_update_rotation(delta)
var space_state = get_world().get_direct_space_state()
var obstacle = space_state.intersect_ray(privot.get_translation(), get_translation())
if not obstacle.empty():
set_translation(obstacle.position)
func _update_movement(delta):
var offset = max_speed * acceleration * _direction
_speed.x = clamp(_speed.x + offset.x, -max_speed.x, max_speed.x)
_speed.y = clamp(_speed.y + offset.y, -max_speed.y, max_speed.y)
_speed.z = clamp(_speed.z + offset.z, -max_speed.z, max_speed.z)
# Apply deceleration if no input
if _direction.x == 0:
_speed.x *= (1.0 - deceleration)
if _direction.y == 0:
_speed.y *= (1.0 - deceleration)
if _direction.z == 0:
_speed.z *= (1.0 - deceleration)
if local:
translate(_speed * delta)
else:
global_translate(_speed * delta)
func _update_rotation(delta):
var offset = Vector2();
if not freelook_mode == Freelook_Modes.INPUT_ACTION:
offset += _mouse_offset * sensitivity
if not freelook_mode == Freelook_Modes.MOUSE:
offset += _rotation_offset * sensitivity * ROTATION_MULTIPLIER * delta
_mouse_offset = Vector2()
_yaw = _yaw * smoothness + offset.x * (1.0 - smoothness)
_pitch = _pitch * smoothness + offset.y * (1.0 - smoothness)
if yaw_limit < 360:
_yaw = clamp(_yaw, -yaw_limit - _total_yaw, yaw_limit - _total_yaw)
if pitch_limit < 360:
_pitch = clamp(_pitch, -pitch_limit - _total_pitch, pitch_limit - _total_pitch)
_total_yaw += _yaw
_total_pitch += _pitch
if privot:
var target = privot.get_translation()
var dist = get_translation().distance_to(target)
set_translation(target)
rotate_y(deg2rad(-_yaw))
rotate_object_local(Vector3(1,0,0), deg2rad(-_pitch))
translate(Vector3(0.0, 0.0, dist))
if rotate_privot:
privot.rotate_y(deg2rad(-_yaw))
else:
rotate_y(deg2rad(-_yaw))
rotate_object_local(Vector3(1,0,0), deg2rad(-_pitch))
func _update_distance():
var t = privot.get_translation()
t.z -= distance
set_translation(t)
func _update_process_func():
# Use physics process if collision are enabled
if collisions and privot:
set_physics_process(true)
set_process(false)
else:
set_physics_process(false)
set_process(true)
func _check_actions(actions=[]):
if OS.is_debug_build():
for action in actions:
if not InputMap.has_action(action):
print('WARNING: No action "' + action + '"')
func set_privot(value):
privot = value
_update_process_func()
if len(trigger_action)!=0:
_update_views(0)
func set_collisions(value):
collisions = value
_update_process_func()
func set_enabled(value):
enabled = value
if enabled:
Input.set_mouse_mode(mouse_mode)
set_process_input(true)
_update_process_func()
else:
set_process(false)
set_process_input(false)
set_physics_process(false)
func set_smoothness(value):
smoothness = clamp(value, 0.001, 0.999)
func set_distance(value):
distance = max(0, value)

487
packages/voxel_mesher/Cargo.lock generated Normal file
View File

@ -0,0 +1,487 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "approx"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
dependencies = [
"num-traits",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bindgen"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443"
dependencies = [
"bitflags",
"cexpr",
"cfg-if",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cexpr"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clang-sys"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
"bitflags",
]
[[package]]
name = "euclid"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5337024b8293bdce5265dc9570ef6e608a34bfacbbc87fe1a5dcb5f1dac2f4e2"
dependencies = [
"num-traits",
]
[[package]]
name = "gdnative"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9137d4fb82ee8c99dc83e731397b93af8e3f1888129de822695b03c14d5977be"
dependencies = [
"gdnative-bindings",
"gdnative-core",
"gdnative-derive",
]
[[package]]
name = "gdnative-bindings"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74170e8ffffaedd11fda8265441b93e2182828417eddfc7c36620a73ab855527"
dependencies = [
"bitflags",
"gdnative-core",
"gdnative-sys",
"gdnative_bindings_generator",
"heck",
"libc",
]
[[package]]
name = "gdnative-core"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fc4d535703a6c37bf65626311ee3a7cd12d802a2e5bc3193acb66b9e8f385d5"
dependencies = [
"approx",
"bitflags",
"euclid",
"gdnative-impl-proc-macros",
"gdnative-sys",
"libc",
"parking_lot",
]
[[package]]
name = "gdnative-derive"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "003012dbab82bc59605bc28ce721bf76ca01132a6eb35e9eaa8033cbee6e934b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "gdnative-impl-proc-macros"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c81f5438e1ba0d312b73f5b7989fa6b705da0ce41d3912e9167e6f75883fdf91"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "gdnative-sys"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6241955cac73fbb43c0f6228b7e5c3061ce1d5d39bddf053ed10689587c40daf"
dependencies = [
"bindgen",
"libc",
"miniserde",
"proc-macro2",
"quote",
]
[[package]]
name = "gdnative_bindings_generator"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44209a7640f73301abb3afead3489fb47b548ffd0302a28a3c0596746c0739d5"
dependencies = [
"heck",
"miniserde",
"proc-macro2",
"quote",
"roxmltree",
"syn",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa7087f49d294270db4e1928fc110c976cd4b9e5a16348e0a1df09afa99e6c98"
[[package]]
name = "libloading"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "lock_api"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
dependencies = [
"scopeguard",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "mini-internal"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3fb39c72c84ffbed14f8ee8b1a0e52ecd323df2ee69499fd3400a95d7269aa"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniserde"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e021d8031f6e224438f402d4c59d26c997e6e13498bd34da1aa1f858bd3b2f43"
dependencies = [
"itoa",
"mini-internal",
"ryu",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
"autocfg",
]
[[package]]
name = "parking_lot"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
dependencies = [
"lock_api",
"parking_lot_core",
"rustc_version",
]
[[package]]
name = "parking_lot_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
dependencies = [
"cfg-if",
"cloudabi",
"libc",
"redox_syscall",
"rustc_version",
"smallvec",
"winapi",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "regex"
version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
[[package]]
name = "roxmltree"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17dfc6c39f846bfc7d2ec442ad12055d79608d501380789b965d22f9354451f2"
dependencies = [
"xmlparser",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "smallvec"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
dependencies = [
"maybe-uninit",
]
[[package]]
name = "syn"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "test"
version = "0.1.0"
dependencies = [
"gdnative",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xmlparser"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8"

View File

@ -0,0 +1,11 @@
[package]
name = "test"
version = "0.1.0"
authors = ["Joshua Bemenderfer <j.bemenderfer@creation.info>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
gdnative = "0.9.0"

View File

@ -0,0 +1,54 @@
extends MeshInstance
const chunk_dimensions = Vector3(16, 16, 16);
var chunk_data = PoolIntArray()
var voxel_name_index = PoolStringArray()
var voxels = {}
func _ready():
add_voxel("default:air", false, null)
add_voxel("default:dirt", true, preload("res://packages/voxel_mesher/materials/dirt.material"))
add_voxel("default:grass", true, preload("res://packages/voxel_mesher/materials/grass.material"))
add_voxel("default:glass", true, preload("res://packages/voxel_mesher/materials/glass.material"))
add_voxel("default:lamp", true, preload("res://packages/voxel_mesher/materials/lamp.material"))
func add_voxel(name, opaque, material):
voxels[name] = {
"name": name,
"opaque": opaque,
"material": material
}
voxel_name_index.append(name)
func generate_data():
var rng = RandomNumberGenerator.new()
var length = chunk_dimensions.x*chunk_dimensions.y*chunk_dimensions.z
chunk_data.resize(length)
for i in range(0, length):
chunk_data.set(i, rng.randi_range(0, voxel_name_index.size() - 1))
func mesh(mesher):
var start_time = OS.get_ticks_msec()
var surface_data = mesher.mesh(voxel_name_index, chunk_dimensions, chunk_data)
var end_time = OS.get_ticks_msec()
print("Elapsed: ", end_time - start_time)
# Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new()
for i in range(1, surface_data.size()):
var voxel = voxels[voxel_name_index[i]]
var mesh_data = surface_data[i]
var arrays = []
arrays.resize(ArrayMesh.ARRAY_MAX)
arrays[ArrayMesh.ARRAY_VERTEX] = mesh_data.vertices
arrays[ArrayMesh.ARRAY_NORMAL] = mesh_data.normals
arrays[ArrayMesh.ARRAY_TEX_UV] = mesh_data.uvs
arrays[ArrayMesh.ARRAY_TEX_UV2] = mesh_data.uvs
# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
arr_mesh.surface_set_material(i - 1, voxel.material)
self.mesh = arr_mesh
generate_data()

View File

@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://packages/voxel_mesher/voxel_mesher.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "VoxelMesher"
class_name = "VoxelMesher"
library = ExtResource( 1 )

View File

@ -0,0 +1,11 @@
extends Spatial
func _ready():
var mesher = $"VoxelMesher"
var chunks = [$"Chunk_1_1", $"Chunk_1_2", $"Chunk_1_3"]
for chunk in chunks:
chunk.generate_data()
chunk.mesh(mesher)

View File

@ -0,0 +1,85 @@
[gd_scene load_steps=11 format=2]
[ext_resource path="res://packages/voxel_mesher/VoxelMesher.gdns" type="Script" id=1]
[ext_resource path="res://packages/voxel_mesher/Camera.gd" type="Script" id=2]
[ext_resource path="res://packages/voxel_mesher/VoxelChunk.gd" type="Script" id=3]
[ext_resource path="res://packages/voxel_mesher/VoxelScene.gd" type="Script" id=4]
[sub_resource type="CapsuleMesh" id=1]
[sub_resource type="SpatialMaterial" id=2]
albedo_color = Color( 0.792157, 0.286275, 0.286275, 1 )
metallic = 0.74
metallic_specular = 0.56
roughness = 0.17
clearcoat_enabled = true
clearcoat = 1.0
clearcoat_gloss = 0.66
[sub_resource type="ProceduralSky" id=3]
[sub_resource type="Environment" id=4]
background_mode = 2
background_sky = SubResource( 3 )
ambient_light_color = Color( 0.784314, 0.666667, 0.666667, 1 )
fog_enabled = true
tonemap_mode = 2
auto_exposure_enabled = true
ss_reflections_enabled = true
ssao_enabled = true
ssao_intensity = 5.0
glow_enabled = true
glow_bicubic_upscale = true
[sub_resource type="PhysicsMaterial" id=5]
[sub_resource type="BoxShape" id=6]
[node name="VoxelScene" type="Spatial"]
script = ExtResource( 4 )
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 16, 0 )
script = ExtResource( 2 )
max_speed = Vector3( 10, 10, 10 )
forward_action = "move_forward"
backward_action = "move_back"
left_action = "move_left"
right_action = "move_right"
up_action = "move_up"
down_action = "move_down"
[node name="OmniLight" type="OmniLight" parent="Camera"]
visible = false
light_color = Color( 0.882353, 0.94902, 0.937255, 1 )
light_energy = 5.0
light_indirect_energy = 5.0
omni_range = 16.0
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.04274, 0.0241685, -13.8819 )
mesh = SubResource( 1 )
material/0 = SubResource( 2 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 4 )
[node name="VoxelMesher" type="Node" parent="."]
script = ExtResource( 1 )
[node name="StaticBody" type="StaticBody" parent="."]
physics_material_override = SubResource( 5 )
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 6 )
[node name="Chunk_1_1" type="MeshInstance" parent="."]
script = ExtResource( 3 )
[node name="Chunk_1_2" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -16, 0, -16 )
script = ExtResource( 3 )
[node name="Chunk_1_3" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -16, 0, 0 )
script = ExtResource( 3 )

View File

@ -0,0 +1,296 @@
# Licensed under the MIT License.
# Copyright (c) 2018-2020 Jaccomo Lorenz (Maujoe)
extends Control
# Constant Gui Settings
#*******************************************************************************
const GUI_POS = Vector2(10, 10)
const GUI_SIZE = Vector2(200, 0)
const DRAGGABLE = true
const CUSTOM_BACKGROUND = false
const BACKGROUND_COLOR = Color(0.15, 0.17, 0.23, 0.75)
const MAX_SPEED = 50
#*******************************************************************************
var camera
var shortcut
var node_list
var privot
var panel
var mouse_over = false
var mouse_pressed = false
func _init(camera, shortcut):
self.camera = camera
self.shortcut = shortcut
func _ready():
if camera.enabled:
set_process_input(true)
# Create Gui
panel = PanelContainer.new()
panel.set_begin(GUI_POS)
panel.set_custom_minimum_size(GUI_SIZE)
if CUSTOM_BACKGROUND:
var style = StyleBoxFlat.new()
style.set_bg_color(BACKGROUND_COLOR)
style.set_expand_margin_all(5)
panel.add_stylebox_override("panel", style)
var container = VBoxContainer.new()
var lbl_mouse = Label.new()
lbl_mouse.set_text("Mousemode")
var mouse = OptionButton.new()
mouse.add_item("Visible")
mouse.add_item("Hidden")
mouse.add_item("Captured")
mouse.add_item("Confined")
mouse.select(camera.mouse_mode)
mouse.connect("item_selected",self,"_on_opt_mouse_item_selected")
# Freelook
var freelook = CheckButton.new()
freelook.set_text("Freelook")
freelook.set_toggle_mode(true)
freelook.set_pressed(camera.freelook)
freelook.connect("toggled",self,"_on_btn_freelook_toggled")
var lbl_sensitivity = Label.new()
lbl_sensitivity.set_text("Sensitivity")
var sensitivity = HScrollBar.new()
sensitivity.set_max(1)
sensitivity.set_value(camera.sensitivity)
sensitivity.connect("value_changed",self,"_on_hsb_sensitivity_value_changed")
var lbl_smoothless = Label.new()
lbl_smoothless.set_text("Smoothness")
var smoothness = HScrollBar.new()
smoothness.set_max(0.999)
smoothness.set_min(0.5)
smoothness.set_value(camera.smoothness)
smoothness.connect("value_changed",self,"_on_hsb_smoothness_value_changed")
var lbl_privot = Label.new()
lbl_privot.set_text("Privot")
privot = OptionButton.new()
privot.set_text("Privot")
_update_privots(privot)
privot.connect("item_selected",self,"_on_opt_privot_item_selected")
privot.connect("pressed",self,"_on_opt_privot_pressed")
var btn_rot_privot = CheckButton.new()
btn_rot_privot.set_text("Rotate Privot")
btn_rot_privot.set_toggle_mode(true)
btn_rot_privot.set_pressed(camera.rotate_privot)
btn_rot_privot.connect("toggled",self,"_on_btn_rot_privot_toggled")
var lbl_distance = Label.new()
lbl_distance.set_text("Distance")
var distance = SpinBox.new()
distance.set_value(camera.distance)
distance.connect("value_changed",self,"_on_box_distance_value_changed")
var lbl_yaw = Label.new()
lbl_yaw.set_text("Yaw Limit")
var yaw = SpinBox.new()
yaw.set_max(360)
yaw.set_value(camera.yaw_limit)
yaw.connect("value_changed",self,"_on_box_yaw_value_changed")
var lbl_pitch = Label.new()
lbl_pitch.set_text("Pitch Limit")
var pitch = SpinBox.new()
pitch.set_max(360)
pitch.set_value(camera.pitch_limit)
pitch.connect("value_changed",self,"_on_box_pitch_value_changed")
var collisions = CheckButton.new()
collisions.set_text("Collisions")
collisions.set_toggle_mode(true)
collisions.set_pressed(camera.collisions)
collisions.connect("toggled",self,"_on_btn_collisions_toggled")
# Movement
var lbl_movement = Label.new()
lbl_movement.set_text("Movement")
var movement = CheckButton.new()
movement.set_pressed(camera.movement)
movement.connect("toggled",self,"_on_btn_movement_toggled")
var lbl_speed = Label.new()
lbl_speed.set_text("Max Speed")
var speed = HScrollBar.new()
speed.set_max(MAX_SPEED)
speed.set_value(camera.max_speed.x)
speed.connect("value_changed",self,"_on_hsb_speed_value_changed")
var lbl_acceleration = Label.new()
lbl_acceleration.set_text("Acceleration")
var acceleration = HScrollBar.new()
acceleration.set_max(1.0)
acceleration.set_value(camera.acceleration)
acceleration.connect("value_changed", self, "_in_hsb_acceleration_value_changed")
var lbl_deceleration = Label.new()
lbl_deceleration.set_text("Deceleration")
var deceleration = HScrollBar.new()
deceleration.set_max(1.0)
deceleration.set_value(camera.deceleration)
deceleration.connect("value_changed", self, "_in_hsb_deceleration_value_changed")
add_child(panel)
panel.add_child(container)
container.add_child(lbl_mouse)
container.add_child(mouse)
container.add_child(freelook)
container.add_child(lbl_sensitivity)
container.add_child(sensitivity)
container.add_child(lbl_smoothless)
container.add_child(smoothness)
container.add_child(lbl_privot)
container.add_child(privot)
container.add_child(btn_rot_privot)
container.add_child(lbl_distance)
container.add_child(distance)
container.add_child(lbl_yaw)
container.add_child(yaw)
container.add_child(lbl_pitch)
container.add_child(pitch)
container.add_child(collisions)
container.add_child(lbl_movement)
container.add_child(movement)
container.add_child(lbl_speed)
container.add_child(speed)
container.add_child(lbl_acceleration)
container.add_child(acceleration)
container.add_child(lbl_deceleration)
container.add_child(deceleration)
if DRAGGABLE:
panel.connect("mouse_entered", self, "_panel_entered")
panel.connect("mouse_exited", self, "_panel_exited")
container.connect("mouse_entered", self, "_panel_entered")
container.connect("mouse_exited", self, "_panel_exited")
self.hide()
else:
set_process_input(false)
func _input(event):
if event.is_action_pressed(shortcut):
if camera.enabled:
camera.enabled = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
self.show()
else:
camera.enabled = true
self.hide()
if DRAGGABLE:
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
mouse_pressed = event.pressed
elif event is InputEventMouseMotion and mouse_over and mouse_pressed:
panel.set_begin(panel.get_begin() + event.relative)
func _update_privots(privot):
privot.clear()
privot.add_item("None")
node_list = _get_spatials_recusiv(get_tree().get_root(), [get_name(), camera.get_name()])
var size = node_list.size()
for i in range(0, size):
var node = node_list[i]
privot.add_item(node.get_name())
if node == camera.privot:
privot.select(i+1)
if not camera.privot:
privot.select(0)
func _get_spatials_recusiv(node, exceptions=[]):
var list = []
for child in node.get_children():
if not child.get_name() in exceptions:
if child is Spatial:
list.append(child)
if not child.get_children().empty():
for subchild in _get_spatials_recusiv(child, exceptions):
list.append(subchild)
return list
func _panel_entered():
mouse_over = true
func _panel_exited():
mouse_over = false
func _on_opt_mouse_item_selected(id):
camera.mouse_mode = id
func _on_btn_freelook_toggled(pressed):
camera.freelook = pressed
func _on_hsb_sensitivity_value_changed(value):
camera.sensitivity = value
func _on_hsb_smoothness_value_changed(value):
camera.smoothness = value
func _on_opt_privot_pressed():
_update_privots(privot)
func _on_opt_privot_item_selected(id):
if id > 0:
camera.privot = node_list[id-1]
else:
camera.privot = null
privot.select(id)
func _on_btn_rot_privot_toggled(pressed):
camera.rotate_privot = pressed
func _on_box_distance_value_changed(value):
camera.distance = value
func _on_box_yaw_value_changed(value):
camera.yaw_limit = value
func _on_box_pitch_value_changed(value):
camera.pitch_limit = value
func _on_btn_collisions_toggled(pressed):
camera.collisions = pressed
func _on_btn_movement_toggled(pressed):
camera.movement = pressed
func _on_hsb_speed_value_changed(value):
camera.max_speed.x = value
camera.max_speed.y = value
camera.max_speed.z = value
func _in_hsb_acceleration_value_changed(value):
camera.acceleration = value
func _in_hsb_deceleration_value_changed(value):
camera.deceleration = value

@ -1 +0,0 @@
Subproject commit ddf67cc7b8274c5fb77a71c828bab2991f1ee12a

View File

@ -0,0 +1,22 @@
extends Node
onready var ConsoleService = $"/root/ConsoleService"
onready var TaskService = $"/root/TaskService"
const package = {
"name": "voxel_mesher",
"version": "0.1.0"
}
func init():
ConsoleService.log("[VoxelMesher] Mod Init")
TaskService.connect('task_start', self, 'task_monitor')
func task_monitor(task):
if task.name == 'start_game': start()
func start():
var scene_root = $"/root/Main/Scene"
var scene = preload("VoxelScene.tscn")
var scene_instance = scene.instance()
scene_root.add_child(scene_instance)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/dirt.png-8af1c65fe27c13dab9fdae9d91a53924.s3tc.stex"
path.etc2="res://.import/dirt.png-8af1c65fe27c13dab9fdae9d91a53924.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://packages/voxel_mesher/materials/dirt.png"
dest_files=[ "res://.import/dirt.png-8af1c65fe27c13dab9fdae9d91a53924.s3tc.stex", "res://.import/dirt.png-8af1c65fe27c13dab9fdae9d91a53924.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=false
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/glass.png-0d37c0e0ffcc302b4c968b49d87dcb11.s3tc.stex"
path.etc2="res://.import/glass.png-0d37c0e0ffcc302b4c968b49d87dcb11.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://packages/voxel_mesher/materials/glass.png"
dest_files=[ "res://.import/glass.png-0d37c0e0ffcc302b4c968b49d87dcb11.s3tc.stex", "res://.import/glass.png-0d37c0e0ffcc302b4c968b49d87dcb11.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=false
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/grass.png-e54cc488a93b6f678f43a532da5748f8.s3tc.stex"
path.etc2="res://.import/grass.png-e54cc488a93b6f678f43a532da5748f8.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://packages/voxel_mesher/materials/grass.png"
dest_files=[ "res://.import/grass.png-e54cc488a93b6f678f43a532da5748f8.s3tc.stex", "res://.import/grass.png-e54cc488a93b6f678f43a532da5748f8.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=false
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/lamp.png-1317a31813d383462a2bde47b8cba7d5.s3tc.stex"
path.etc2="res://.import/lamp.png-1317a31813d383462a2bde47b8cba7d5.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://packages/voxel_mesher/materials/lamp.png"
dest_files=[ "res://.import/lamp.png-1317a31813d383462a2bde47b8cba7d5.s3tc.stex", "res://.import/lamp.png-1317a31813d383462a2bde47b8cba7d5.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=false
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,197 @@
use gdnative::prelude::*;
// ```
// 0 1
// +-----+
// | / |
// | / |
// | / |
// +-----+
// 3 2
// ```
const FACES: [[usize; 4]; 6] = [
[5, 4, 0, 1],
[7, 6, 2, 3],
[6, 5, 1, 2],
[4, 7, 3, 0],
[6, 7, 4, 5],
[1, 0, 3, 2],
];
const FACE_ORDER: [usize; 6] = [2, 3, 1, 1, 3, 0];
const VERTICES: [[f32; 3]; 8] = [
[0., 0., 0.],
[1., 0., 0.],
[1., 0., 1.],
[0., 0., 1.],
[0., 1., 0.],
[1., 1., 0.],
[1., 1., 1.],
[0., 1., 1.],
];
const NORMALS: [[f32; 3]; 6] = [
[0., 0., -1.],
[0., 0., 1.],
[1., 0., 0.],
[-1., 0., 0.],
[0., 1., 0.],
[0., -1., 0.],
];
const UVS: [[f32; 2]; 4] = [
[0., 0.],
[1., 0.],
[1., 1.],
[0., 1.]
];
#[derive(Clone)]
struct MeshData {
voxels: i32,
vertices: TypedArray<Vector3>,
uvs: TypedArray<Vector2>,
normals: TypedArray<Vector3>
}
impl MeshData {
fn new() -> MeshData {
MeshData {
voxels: 0,
vertices: TypedArray::<Vector3>::new(),
uvs: TypedArray::<Vector2>::new(),
normals: TypedArray::<Vector3>::new()
}
}
fn resize (&mut self) {
self.vertices.resize(self.voxels * 36);
self.normals.resize(self.voxels * 36);
self.uvs.resize(self.voxels * 36);
}
fn to_dict (self) -> Dictionary<Unique> {
let dict = Dictionary::<Unique>::new();
dict.insert("vertices", self.vertices);
dict.insert("uvs", self.uvs);
dict.insert("normals", self.normals);
dict
}
}
struct SurfaceData {
surfaces: Vec<MeshData>
}
impl SurfaceData {
fn new(size: i32) -> SurfaceData {
let mut surfaces = Vec::<MeshData>::new();
surfaces.resize(size as usize, MeshData::new());
SurfaceData {
surfaces
}
}
fn get(&mut self, idx: usize) -> &mut MeshData {
&mut self.surfaces[idx]
}
fn to_array(self) -> VariantArray<Unique> {
let array = VariantArray::<Unique>::new();
for mesh_data in self.surfaces.into_iter() {
array.push(mesh_data.to_dict());
}
array
}
}
#[derive(NativeClass)]
#[inherit(Node)]
struct VoxelMesher;
#[gdnative::methods]
impl VoxelMesher {
fn new(_owner: &Node) -> Self {
VoxelMesher
}
#[export]
fn mesh(
&self,
_owner: &Node,
voxel_name_index: TypedArray<GodotString>,
chunk_dimensions: Vector3,
chunk_data: TypedArray<i32>
) -> VariantArray<Unique> {
let mut surface_data = SurfaceData::new(voxel_name_index.len());
let max_x = chunk_dimensions.x as i32;
let max_y = chunk_dimensions.y as i32;
for i in 0..chunk_data.len() {
let voxel_id = chunk_data.get(i);
if voxel_id == 0 { continue; }
let mut mesh_data = surface_data.get(voxel_id as usize);
mesh_data.voxels += 1;
}
for mesh_data in &mut surface_data.surfaces {
mesh_data.resize();
mesh_data.voxels = 0;
}
for i in 0..chunk_data.len() {
let voxel_id = chunk_data.get(i);
if voxel_id == 0 {
continue;
}
let mut mesh_data = surface_data.get(voxel_id as usize);
let z = i / (max_x * max_y);
let i2 = i - (z * max_x * max_y);
let y = i2 / max_x;
let x = i2 % max_x;
let pos: [i32; 3] = [x, y, z];
self.mesh_voxel(&mut mesh_data, pos);
mesh_data.voxels += 1;
}
surface_data.to_array()
}
fn mesh_voxel(
&self,
mesh_data: &mut MeshData,
position: [i32; 3]
) {
let voxel_offset = mesh_data.voxels * 36 as i32;
for i in 0..36 {
let idx = voxel_offset + i as i32;
let idx_vertex = i % 6;
let idx_face = (i - idx_vertex) / 6;
let idx_side = FACES[idx_face];
let idx_vertex_coords = FACE_ORDER[idx_vertex];
let mut vertices = VERTICES[idx_side[idx_vertex_coords]];
for j in 0..3 { vertices[j] += position[j] as f32; }
let normals = NORMALS[idx_face];
let uvs = UVS[idx_vertex_coords];
mesh_data.vertices.set(idx, Vector3::new(vertices[0], vertices[1], vertices[2]));
mesh_data.normals.set(idx, Vector3::new(normals[0], normals[1], normals[2]));
mesh_data.uvs.set(idx, Vector2::new(uvs[0], uvs[1]))
}
}
}
fn init(handle: InitHandle) {
handle.add_class::<VoxelMesher>();
}
godot_init!(init);

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,14 @@
[entry]
X11.64="res://packages/voxel_mesher/target/release/libtest.so"
[dependencies]
X11.64=[ ]
[general]
singleton=false
load_once=true
symbol_prefix="godot_"
reloadable=true

View File

@ -26,3 +26,37 @@ NetworkService="*res://Services/NetworkService.gd"
CLIService="*res://Services/CLIService.gd" CLIService="*res://Services/CLIService.gd"
ConsoleService="*res://Services/ConsoleService.gd" ConsoleService="*res://Services/ConsoleService.gd"
PackageService="*res://Services/PackageService.gd" PackageService="*res://Services/PackageService.gd"
TaskService="*res://Services/TaskService.gd"
[input]
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null)
]
}
move_forward={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null)
]
}
move_back={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
]
}