remove bug and add spider - add advanced flow field debug vis

This commit is contained in:
Henrik Neumann 2025-02-23 19:13:40 +01:00
parent b9c94eeed6
commit 44280e9202
13 changed files with 33580 additions and 331 deletions

Binary file not shown.

View File

@ -1,11 +0,0 @@
Model Information:
* title: Bug
* source: https://sketchfab.com/3d-models/bug-3f3e2ed9e31c4fff9e44637173514d7b
* author: Miguel Atienza (https://sketchfab.com/miguelatienza93)
Model License:
* license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
* requirements: Author must be credited. Commercial use is allowed.
If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
This work is based on "Bug" (https://sketchfab.com/3d-models/bug-3f3e2ed9e31c4fff9e44637173514d7b) by Miguel Atienza (https://sketchfab.com/miguelatienza93) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)

Binary file not shown.

View File

@ -1,173 +0,0 @@
{
"accessors": [
{
"bufferView": 1,
"componentType": 5126,
"count": 49086,
"max": [
1.9926960468292236,
2.4550979137420654,
0.9601231217384338
],
"min": [
-1.9935812950134277,
-5.510632038116455,
-1.192002773284912
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 589032,
"componentType": 5126,
"count": 49086,
"max": [
0.9999630451202393,
0.9999982118606567,
0.9999945759773254
],
"min": [
-0.99997478723526,
-0.9999390244483948,
-0.999993085861206
],
"type": "VEC3"
},
{
"bufferView": 2,
"componentType": 5126,
"count": 49086,
"max": [
0.9882352948188782,
0.6352941393852234,
0.6431372761726379,
1.0
],
"min": [
0.0,
0.0,
0.0,
1.0
],
"type": "VEC4"
},
{
"bufferView": 0,
"componentType": 5125,
"count": 292026,
"type": "SCALAR"
}
],
"asset": {
"extras": {
"author": "Miguel Atienza (https://sketchfab.com/miguelatienza93)",
"license": "CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)",
"source": "https://sketchfab.com/3d-models/bug-3f3e2ed9e31c4fff9e44637173514d7b",
"title": "Bug"
},
"generator": "Sketchfab-12.68.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 1168104,
"name": "floatBufferViews",
"target": 34963
},
{
"buffer": 0,
"byteLength": 1178064,
"byteOffset": 1168104,
"byteStride": 12,
"name": "floatBufferViews",
"target": 34962
},
{
"buffer": 0,
"byteLength": 785376,
"byteOffset": 2346168,
"byteStride": 16,
"name": "floatBufferViews",
"target": 34962
}
],
"buffers": [
{
"byteLength": 3131544,
"uri": "scene.bin"
}
],
"materials": [
{
"doubleSided": true,
"name": "Scene_-_Root",
"pbrMetallicRoughness": {
"metallicFactor": 0.0,
"roughnessFactor": 0.6
}
}
],
"meshes": [
{
"name": "Object_0",
"primitives": [
{
"attributes": {
"COLOR_0": 2,
"NORMAL": 1,
"POSITION": 0
},
"indices": 3,
"material": 0,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
-2.220446049250313e-16,
-6.123234262925839e-17,
1.0,
0.0,
1.0,
1.6081226229577287e-16,
2.2204460492503136e-16,
0.0,
-1.6081226229577292e-16,
1.0,
6.123234262925839e-17,
0.0,
1.5273232460021973,
-8.953146193411835e-17,
1.5282138586044312,
1.0
],
"name": "Sketchfab_model"
},
{
"children": [
2
],
"name": "bug.OBJ.cleaner.materialmerger.gles"
},
{
"mesh": 0,
"name": "Object_2"
}
],
"scene": 0,
"scenes": [
{
"name": "Sketchfab_Scene",
"nodes": [
0
]
}
]
}

BIN
assets/spider/result.bin Normal file

Binary file not shown.

33434
assets/spider/result.gltf Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,13 +3,13 @@
importer="scene" importer="scene"
importer_version=1 importer_version=1
type="PackedScene" type="PackedScene"
uid="uid://be1j1x6skha50" uid="uid://bcsjr6kydgdqy"
path="res://.godot/imported/scene.gltf-40b9b7639a7cec48946880b758e17814.scn" path="res://.godot/imported/result.gltf-fa6e7d401ecc486ebc1efbad267cda09.scn"
[deps] [deps]
source_file="res://assets/bug/scene.gltf" source_file="res://assets/spider/result.gltf"
dest_files=["res://.godot/imported/scene.gltf-40b9b7639a7cec48946880b758e17814.scn"] dest_files=["res://.godot/imported/result.gltf-fa6e7d401ecc486ebc1efbad267cda09.scn"]
[params] [params]
@ -33,14 +33,19 @@ animation/import_rest_as_RESET=false
import_script/path="" import_script/path=""
_subresources={ _subresources={
"meshes": { "meshes": {
"Sketchfab_Scene_Object_0": { "result_Cube": {
"generate/lightmap_uv": 0, "generate/lightmap_uv": 0,
"generate/lods": 0, "generate/lods": 0,
"generate/shadow_meshes": 1, "generate/shadow_meshes": 1,
"lods/normal_merge_angle": 60.0, "lods/normal_merge_angle": 60.0,
"lods/normal_split_angle": 25.0, "lods/normal_split_angle": 25.0,
"save_to_file/enabled": true, "save_to_file/enabled": true,
"save_to_file/path": "res://assets/bug/bug_mesh.res" "save_to_file/path": "res://assets/spider/spider_mesh.res"
}
},
"nodes": {
"PATH:RootNode/SpiderArmature/Skeleton3D": {
"rest_pose/external_animation_library": null
} }
} }
} }

Binary file not shown.

View File

@ -1,24 +0,0 @@
extends Node3D
@onready var flow_field_navigation: FlowFieldNav = %FlowFieldNavigation
@export var move_speed = 3
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
DebugDraw3D.draw_sphere(position, .5)
var cell = flow_field_navigation.get_cell_from_pos(position)
if cell.flow_direction.length() > 0.0:
# Normalisierte Bewegung in Flow-Richtung
var movement = cell.flow_direction.normalized() * move_speed * delta
global_transform.origin += movement # Position aktualisierennormalized() * speed
# Rotation: Gegner schaut in Bewegungsrichtung (XZ-Ebene)
var target_rotation = Quaternion(Vector3.UP, atan2(-cell.flow_direction.x, -cell.flow_direction.z))
global_transform.basis = Basis(target_rotation)

View File

@ -1,80 +1,117 @@
extends Node3D extends Node3D
class_name FlowFieldNav class_name FlowFieldNav
@onready var player: Player = %player @export_category("Debug Visualization")
@export_group("Grid Center")
@export var show_grid_center: bool = false
@export_color_no_alpha var grid_center_color: Color = Color(1, 1, 1, 1)
@export var grid_center_size: float = 0.5
@export_group("Border")
@export var show_border: bool = false
@export_color_no_alpha var border_color: Color = Color(1, 1, 1, 1)
@export_group("Cells")
@export_subgroup("X Lines")
@export var show_x_lines: bool = false
@export_color_no_alpha var x_lines_color: Color = Color(1, 1, 1)
@export_subgroup("Z Lines")
@export var show_z_lines: bool = false
@export_color_no_alpha var z_lines_color: Color = Color(1, 1, 1)
@export_group("Arrows")
@export var show_arrows: bool = false
@export_color_no_alpha var cell_center_color: Color = Color(1, 1, 1)
@export var cell_center_size: float = 0.2
@export_category("Grid")
@export_group("Debug")
@export var debugVisu: bool = true
@export var line_color: Color = Color(1, 1, 1, 1)
@export_group("Grid")
@export var grid_size: int = 10
@export var cell_size: float = 1.0 @export var cell_size: float = 1.0
@export_group("Grid Size", "grid_size_")
@export var grid_size_x: int = 2
@export var grid_size_z: int = 5
var _cells: Dictionary var flow_direction_list: Array[Vector2] = []
var grid_offset: Vector3
var target_position: Vector3
var target_cell: FlowFieldCell
var lines: PackedVector3Array
func _ready() -> void: func _ready() -> void:
var half_size = (grid_size * cell_size) * 0.5 for x in range(grid_size_x):
grid_offset = Vector3(-half_size + (cell_size * 0.5), 0, -half_size + (cell_size * 0.5)) for z in range(grid_size_z):
create_grid() flow_direction_list.append(Vector2(0.0, 0.0))
# Vertikale Linien
for x in range(grid_size + 1):
var pos_x = x * cell_size + grid_offset.x - (cell_size * 0.5)
lines.append(Vector3(pos_x, 0, grid_offset.z - (cell_size * 0.5)))
lines.append(Vector3(pos_x, 0, grid_offset.z + grid_size * cell_size - (cell_size * 0.5)))
# Horizontale Linien
for z in range(grid_size + 1):
var pos_z = z * cell_size + grid_offset.z - (cell_size * 0.5)
lines.append(Vector3(grid_offset.x - (cell_size * 0.5), 0, pos_z))
lines.append(Vector3(grid_offset.x + grid_size * cell_size - (cell_size * 0.5), 0, pos_z))
func create_grid() -> void:
_cells.clear()
for x in range(grid_size):
for z in range(grid_size):
var cell = FlowFieldCell.new()
var world_x = x * cell_size + grid_offset.x
var world_z = z * cell_size + grid_offset.z
cell.position = Vector3(world_x, 0, world_z)
cell.cell_size = cell_size
_cells[Vector3(x, 0, z)] = cell # Dictionary mit Grid-Koordinaten als Key
func _process(delta: float) -> void: func _process(delta: float) -> void:
target_position = Vector3(player.position.x, 0, player.position.z) _draw_debug()
var new_target_cell = get_cell_from_pos(target_position)
if target_cell != null and target_cell != new_target_cell:
target_cell.is_target = false
new_target_cell.is_target = true
target_cell = new_target_cell
else:
target_cell = new_target_cell
target_cell.is_target = true
if debugVisu:
_debug_draw_grid()
for cell in _cells.values():
cell.debug_process()
for cell in _cells.values():
cell.update(target_position)
func _debug_draw_grid() -> void:
DebugDraw3D.draw_lines(lines, line_color)
func get_cell_from_pos(world_pos: Vector3) -> FlowFieldCell:
var grid_x = int((world_pos.x - grid_offset.x) / cell_size)
var grid_z = int((world_pos.z - grid_offset.z) / cell_size)
var cell_pos = Vector3(grid_x, 0, grid_z)
return _cells.get(cell_pos, null) func _draw_debug():
if show_grid_center:
DebugDraw3D.draw_sphere(position, grid_center_size, grid_center_color)
if show_border:
_draw_border()
if show_x_lines:
_draw_x_lines()
if show_z_lines:
_draw_z_lines()
if show_arrows:
_draw_arrows()
func _draw_border():
var half_size_x = (grid_size_x * cell_size) * 0.5
var half_size_z = (grid_size_z * cell_size) * 0.5
var top_left = position - Vector3(half_size_x, 0 , half_size_z)
var top_right = position + Vector3(half_size_x, 0, -half_size_z)
var bottom_left = position - Vector3(half_size_x, 0, -half_size_z)
var bottom_right = position + Vector3(half_size_x, 0, half_size_z)
var lines: PackedVector3Array
lines.append_array(PackedVector3Array([top_left, top_right]))
lines.append_array(PackedVector3Array([top_right, bottom_right]))
lines.append_array(PackedVector3Array([bottom_right, bottom_left]))
lines.append_array(PackedVector3Array([bottom_left, top_left]))
DebugDraw3D.draw_lines(lines, border_color)
func _draw_x_lines():
var half_size_x = (grid_size_x * cell_size) * 0.5
var half_size_z = (grid_size_z * cell_size) * 0.5
var lines: PackedVector3Array
for x in range(grid_size_x - 1):
var start = position - Vector3(half_size_x - ((x + 1) * cell_size), 0, half_size_z)
var end = position - Vector3(half_size_x - ((x + 1) * cell_size), 0, -half_size_z)
lines.append_array(PackedVector3Array([start, end]))
DebugDraw3D.draw_lines(lines, x_lines_color)
func _draw_z_lines():
var half_size_x = (grid_size_x * cell_size) * 0.5
var half_size_z = (grid_size_z * cell_size) * 0.5
var lines: PackedVector3Array
for z in range(grid_size_z - 1):
var start = position - Vector3(half_size_x, 0, half_size_z - ((z + 1) * cell_size))
var end = position - Vector3(-half_size_x, 0, half_size_z - ((z + 1) * cell_size))
lines.append_array(PackedVector3Array([start, end]))
DebugDraw3D.draw_lines(lines, z_lines_color)
func _draw_arrows():
var half_size_x = (grid_size_x * cell_size) * 0.5
var half_size_z = (grid_size_z * cell_size) * 0.5
var points: PackedVector3Array
for x in range(grid_size_x):
for z in range(grid_size_z):
var cell_center = position + Vector3(
(-half_size_x + (x * cell_size) + (cell_size * 0.5)),
0,
(-half_size_z + (z * cell_size) + (cell_size * 0.5))
)
points.append(cell_center)
#var index = z * grid_size_x + x
#if flow_direction_list[index].length() > 0.0:
#pass #zeichne pfeil
#else:
#DebugDraw3D.draw_sphere(cell_center, cell_center_size, cell_center_color)
DebugDraw3D.draw_points(points, DebugDraw3D.POINT_TYPE_SQUARE, cell_center_size, cell_center_color)
func _get_index_from_position(position: Vector3) -> int:
return 0
func get_direction_from_position(position: Vector3) -> Vector3:
var index = _get_index_from_position(position)
return Vector3(flow_direction_list[index].x, 0, flow_direction_list[index].y)

View File

@ -1,14 +1,19 @@
extends MultiMeshInstance3D extends MultiMeshInstance3D
@export var speed = 5; @export var move_speed = 2
@export var number: int = 100 @export var number: int = 100
@export var stretch: int = 2
@onready var flow_field_navigation: FlowFieldNav = %FlowFieldNavigation
@onready var player: Player = %player
func _ready() -> void: func _ready() -> void:
for x in range(number): for x in range(number):
for z in range(number): for z in range(number):
var index = z * number + x var index = z * number + x
self.multimesh.set_instance_transform(index, Transform3D(Basis(), Vector3(x, 0.0, -z))) self.multimesh.set_instance_transform(index, Transform3D(Basis(), Vector3(x * stretch, 0.0, -z * stretch)))
func _process(delta: float) -> void: func _process(delta: float) -> void:
for x in range(number): for x in range(number):
@ -16,8 +21,16 @@ func _process(delta: float) -> void:
var index = z * number + x var index = z * number + x
var current_trans = self.multimesh.get_instance_transform(index) var current_trans = self.multimesh.get_instance_transform(index)
# Rotation um die Y-Achse (delta für gleichmäßige Drehung) var cell = flow_field_navigation.get_cell_from_pos(current_trans.origin)
var rotation_amount = deg_to_rad(10) * delta # 10 Grad pro Sekunde if cell != null and cell.flow_direction.length() > 0.0:
current_trans.basis = current_trans.basis.rotated(Vector3.UP, rotation_amount) var movement = cell.flow_direction.normalized() * move_speed * delta
current_trans.origin += movement
var direction_to_player = (player.position - current_trans.origin).normalized()
var target_rotation_y = Quaternion(Vector3.UP, atan2(-direction_to_player.x, -direction_to_player.z))
var fix_rotation_x = Quaternion(Vector3.RIGHT, deg_to_rad(-90))
var fix_rotation_y_180 = Quaternion(Vector3.UP, deg_to_rad(180))
var final_rotation = fix_rotation_y_180 * target_rotation_y * fix_rotation_x
current_trans.basis = Basis(final_rotation)
self.multimesh.set_instance_transform(index, current_trans) self.multimesh.set_instance_transform(index, current_trans)

File diff suppressed because one or more lines are too long

View File

@ -1,11 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://ck0ymixmnj446"]
[ext_resource type="Script" path="res://swarm_engine/bug.gd" id="1_ql2rg"]
[ext_resource type="PackedScene" uid="uid://be1j1x6skha50" path="res://assets/bug/scene.gltf" id="2_0pswm"]
[node name="Bug" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.85631, 13.4907)
script = ExtResource("1_ql2rg")
[node name="Sketchfab_Scene" parent="." instance=ExtResource("2_0pswm")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -1.5, 0, -1.5)