новый рендер

This commit is contained in:
2026-06-27 12:13:11 +04:00
parent af5e1f4d6c
commit 1b8d15f2e4
16 changed files with 2562 additions and 443 deletions
@@ -0,0 +1,218 @@
extends CharacterBody3D
const TILE_SIZE := 533.33333
const CHUNK_SIZE := TILE_SIZE / 16.0
const UNIT_SIZE := CHUNK_SIZE / 8.0
@export var extracted_dir: String = "res://data/extracted"
@export var map_name: String = "Azeroth"
@export var spawn_tile_x: int = 42
@export var spawn_tile_y: int = 28
@export var spawn_at_tile_center: bool = true
@export var run_speed: float = 7.0
@export var backward_speed: float = 4.5
@export var strafe_speed: float = 4.5
@export var sprint_multiplier: float = 6.0
@export var acceleration: float = 28.0
@export var mouse_sensitivity: float = 0.003
@export var camera_pitch_min: float = deg_to_rad(-65.0)
@export var camera_pitch_max: float = deg_to_rad(35.0)
@export var camera_height: float = 1.7
@export var camera_distance: float = 8.0
@export var ground_offset: float = 0.05
@export var ground_snap_speed: float = 24.0
@export var camera_pivot_path: NodePath = NodePath("CameraPivot")
@export var camera_path: NodePath = NodePath("CameraPivot/Camera3D")
@export var visual_path: NodePath = NodePath("Visual")
var _camera_pivot: Node3D
var _camera: Camera3D
var _visual: Node3D
var _captured := false
var _yaw := 0.0
var _pitch := deg_to_rad(-18.0)
var _horizontal_velocity := Vector3.ZERO
var _adt_cache: Dictionary = {}
func _ready() -> void:
_camera_pivot = get_node_or_null(camera_pivot_path) as Node3D
_camera = get_node_or_null(camera_path) as Camera3D
_visual = get_node_or_null(visual_path) as Node3D
if _camera:
_camera.current = true
_camera.far = 50000.0
if spawn_at_tile_center:
global_position.x = (float(spawn_tile_x) + 0.5) * TILE_SIZE
global_position.z = (float(spawn_tile_y) + 0.5) * TILE_SIZE
var ground := _sample_ground_height(global_position)
if is_finite(ground):
global_position.y = ground + ground_offset
_yaw = rotation.y
_apply_camera_transform()
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT:
_captured = event.pressed
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if _captured else Input.MOUSE_MODE_VISIBLE
elif event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE:
_captured = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
if _captured and event is InputEventMouseMotion:
_yaw -= event.relative.x * mouse_sensitivity
_pitch = clampf(_pitch - event.relative.y * mouse_sensitivity, camera_pitch_min, camera_pitch_max)
rotation.y = _yaw
_apply_camera_transform()
func _physics_process(delta: float) -> void:
var input_dir := _get_input_dir()
var target_velocity := Vector3.ZERO
if input_dir.length_squared() > 0.0:
target_velocity = _movement_vector(input_dir)
_horizontal_velocity = _horizontal_velocity.move_toward(target_velocity, acceleration * delta)
global_position += _horizontal_velocity * delta
var ground := _sample_ground_height(global_position)
if is_finite(ground):
var target_y := ground + ground_offset
global_position.y = lerpf(global_position.y, target_y, clampf(ground_snap_speed * delta, 0.0, 1.0))
if _visual and _horizontal_velocity.length_squared() > 0.01:
_visual.global_rotation.y = atan2(-_horizontal_velocity.x, -_horizontal_velocity.z)
_apply_camera_transform()
func _get_input_dir() -> Vector2:
var dir := Vector2.ZERO
if Input.is_key_pressed(KEY_W):
dir.y -= 1.0
if Input.is_key_pressed(KEY_S):
dir.y += 1.0
if Input.is_key_pressed(KEY_A):
dir.x -= 1.0
if Input.is_key_pressed(KEY_D):
dir.x += 1.0
return dir.normalized()
func _movement_vector(input_dir: Vector2) -> Vector3:
var forward := -global_basis.z
var right := global_basis.x
forward.y = 0.0
right.y = 0.0
forward = forward.normalized()
right = right.normalized()
var speed_z := run_speed if input_dir.y < 0.0 else backward_speed
var speed_x := strafe_speed
var sprint := sprint_multiplier if Input.is_key_pressed(KEY_SHIFT) else 1.0
return (forward * -input_dir.y * speed_z + right * input_dir.x * speed_x) * sprint
func _apply_camera_transform() -> void:
if _camera_pivot:
_camera_pivot.position = Vector3(0.0, camera_height, 0.0)
_camera_pivot.rotation.x = _pitch
if _camera:
_camera.position = Vector3(0.0, 0.0, camera_distance)
_camera.rotation = Vector3.ZERO
func _sample_ground_height(world_pos: Vector3) -> float:
var tx := int(floor(world_pos.x / TILE_SIZE))
var ty := int(floor(world_pos.z / TILE_SIZE))
var data := _load_adt(tx, ty)
if data.is_empty():
return NAN
var tile_origin := _get_tile_origin(data)
var local := world_pos - tile_origin
var chunk_x := clampi(int(floor(local.x / CHUNK_SIZE)), 0, 15)
var chunk_y := clampi(int(floor(local.z / CHUNK_SIZE)), 0, 15)
var chunk := _find_chunk(data, chunk_x, chunk_y, tile_origin)
if chunk.is_empty():
return NAN
var origin: Vector3 = chunk.get("origin", Vector3.ZERO)
var chunk_local := world_pos - origin
var gx := clampf(chunk_local.x / UNIT_SIZE, 0.0, 8.0)
var gz := clampf(chunk_local.z / UNIT_SIZE, 0.0, 8.0)
var x0 := clampi(int(floor(gx)), 0, 8)
var z0 := clampi(int(floor(gz)), 0, 8)
var x1 := mini(x0 + 1, 8)
var z1 := mini(z0 + 1, 8)
var fx := gx - float(x0)
var fz := gz - float(z0)
var heights: PackedFloat32Array = chunk.get("heights", PackedFloat32Array())
if heights.size() < 145:
return NAN
var h00 := heights[_outer(z0, x0)]
var h10 := heights[_outer(z0, x1)]
var h01 := heights[_outer(z1, x0)]
var h11 := heights[_outer(z1, x1)]
var hx0 := lerpf(h00, h10, fx)
var hx1 := lerpf(h01, h11, fx)
return origin.y + lerpf(hx0, hx1, fz)
func _load_adt(tx: int, ty: int) -> Dictionary:
var key := "%d_%d" % [tx, ty]
if _adt_cache.has(key):
return _adt_cache[key]
if not ClassDB.class_exists("ADTLoader"):
_adt_cache[key] = {}
return {}
var res_path := extracted_dir.path_join("World/Maps/%s/%s_%d_%d.adt" % [map_name, map_name, tx, ty])
var abs_path := ProjectSettings.globalize_path(res_path)
if not FileAccess.file_exists(abs_path):
_adt_cache[key] = {}
return {}
var loader = ClassDB.instantiate("ADTLoader")
var data: Dictionary = loader.call("load_adt", abs_path) if loader else {}
_adt_cache[key] = data
return data
func _find_chunk(data: Dictionary, chunk_x: int, chunk_y: int, tile_origin: Vector3) -> Dictionary:
for chunk in data.get("chunks", []) as Array:
if chunk.is_empty():
continue
var origin: Vector3 = chunk.get("origin", Vector3.ZERO)
var local := origin - tile_origin
var cx := clampi(int(round(local.x / CHUNK_SIZE)), 0, 15)
var cy := clampi(int(round(local.z / CHUNK_SIZE)), 0, 15)
if cx == chunk_x and cy == chunk_y:
return chunk
return {}
func _get_tile_origin(data: Dictionary) -> Vector3:
var found := false
var min_x := 0.0
var min_z := 0.0
for chunk in data.get("chunks", []) as Array:
if chunk.is_empty():
continue
var origin: Vector3 = chunk.get("origin", Vector3.ZERO)
if not found:
min_x = origin.x
min_z = origin.z
found = true
else:
min_x = minf(min_x, origin.x)
min_z = minf(min_z, origin.z)
return Vector3(min_x, 0.0, min_z) if found else Vector3.ZERO
func _outer(row: int, col: int) -> int:
return row * 17 + col
@@ -0,0 +1 @@
uid://ltn2ko5kxvo4
@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://f1nqi4emji47"]
[ext_resource type="Script" uid="uid://yi6lawwjgocg" path="res://src/scenes/streaming/streaming_world_loader.gd" id="1_stream"]
[ext_resource type="Script" uid="uid://bauggobg40psr" path="res://src/scenes/camera/fly_camera.gd" id="2_flycam"]
[ext_resource type="Script" path="res://src/scenes/player/third_person_wow_controller.gd" id="2_player"]
[sub_resource type="Sky" id="Sky_1"]
@@ -12,41 +12,82 @@ ambient_light_source = 3
ambient_light_color = Color(1, 1, 1, 1)
ambient_light_energy = 0.5
[sub_resource type="StandardMaterial3D" id="PlayerMaterial_1"]
albedo_color = Color(0.25, 0.42, 0.85, 1)
roughness = 0.65
[sub_resource type="CapsuleMesh" id="PlayerCapsuleMesh_1"]
material = SubResource("PlayerMaterial_1")
radius = 0.45
height = 2.1
[sub_resource type="CapsuleShape3D" id="PlayerCapsuleShape_1"]
radius = 0.45
height = 2.1
[node name="StreamingWorld" type="Node3D" unique_id=1063159974]
script = ExtResource("1_stream")
camera_path = NodePath("Camera3D")
camera_path = NodePath("ThirdPersonPlayer/CameraPivot/Camera3D")
quality_preset = "High"
update_interval = 0.1
tiles_per_tick = 1
max_concurrent_tile_tasks = 1
chunk_ops_per_tick = 16
tile_lod_remove_ops_per_tick = 1
tile_finalize_ops_per_tick = 1
detail_asset_ops_per_tick = 1
m2_build_groups_per_tick = 1
m2_multimesh_batch_size = 32
m2_mesh_finalize_ops_per_tick = 1
wmo_build_instances_per_tick = 1
wmo_render_group_ops_per_tick = 24
wmo_max_runtime_scene_mb = 8.0
prewarm_tile_margin = 2
retain_tile_margin = 3
boundary_prefetch_threshold = 0.4
streaming_tile_cache_dir = "res://data/cache/baked_terrain_stream_v1"
m2_multimesh_batch_size = 64
wmo_render_group_ops_per_tick = 16
cached_tile_mesh_limit = 48
wmo_render_cache_dir = "res://data/cache/wmo_render_v1"
terrain_quality_mesh_cache_limit = 128
lod0_radius_chunks = 10
lod1_radius_chunks = 20
lod2_radius_chunks = 40
lod2_tile_radius = 5
prewarm_tile_margin = 3
retain_tile_margin = 4
full_lod_prewarm_tiles = 1.5
boundary_prefetch_threshold = 0.42
auto_position_camera = false
enable_occlusion_culling = false
terrain_full_quality_radius_tiles = 5
terrain_control_splat_primary = true
terrain_control_splat_hide_fallback = true
terrain_control_splat_hide_fallback_radius_tiles = 0
terrain_control_splat_radius_tiles = 5
max_active_terrain_control_splat_tiles = 121
terrain_control_splat_cache_finalize_ops_per_tick = 8
terrain_splat_quality_enabled = false
enable_water = true
enable_wmo = true
m2_tile_radius = 3
wmo_tile_radius = 5
m2_visibility_range = 1600.0
wmo_visibility_range = 3600.0
terrain_quality_log_enabled = true
terrain_quality_log_interval = 1.0
hitch_profiler_enabled = true
hitch_profiler_threshold_ms = 20.0
[node name="Camera3D" type="Camera3D" parent="." unique_id=502573687]
transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 300, 300)
[node name="ThirdPersonPlayer" type="CharacterBody3D" parent="." unique_id=502573687]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 22666, 80, 15200)
script = ExtResource("2_player")
spawn_tile_x = 42
spawn_tile_y = 28
sprint_multiplier = 6.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="ThirdPersonPlayer"]
position = Vector3(0, 1.05, 0)
shape = SubResource("PlayerCapsuleShape_1")
[node name="Visual" type="MeshInstance3D" parent="ThirdPersonPlayer"]
position = Vector3(0, 1.05, 0)
mesh = SubResource("PlayerCapsuleMesh_1")
[node name="CameraPivot" type="Node3D" parent="ThirdPersonPlayer"]
position = Vector3(0, 1.7, 0)
[node name="Camera3D" type="Camera3D" parent="ThirdPersonPlayer/CameraPivot"]
position = Vector3(0, 0, 8)
current = true
far = 50000.0
script = ExtResource("2_flycam")
speed = 1200.0
fast_mult = 8.0
fov = 70.0
[node name="Sun" type="DirectionalLight3D" parent="." unique_id=1436804627]
transform = Transform3D(0.866025, -0.353553, 0.353553, 0, 0.707107, 0.707107, -0.5, -0.612372, 0.612372, 0, 0, 0)
File diff suppressed because it is too large Load Diff