fix: re-export GLB with dense per-frame keyframes to prevent animation stripping
This commit is contained in:
Binary file not shown.
@@ -39,7 +39,7 @@ func _register_default_skins() -> void:
|
|||||||
var miku_skin = PlayerSkin.new()
|
var miku_skin = PlayerSkin.new()
|
||||||
miku_skin.skin_name = "Miku"
|
miku_skin.skin_name = "Miku"
|
||||||
miku_skin.description = "Hatsune Miku — Virtual Idol"
|
miku_skin.description = "Hatsune Miku — Virtual Idol"
|
||||||
miku_skin.model_path = "res://assets/characters/skins/miku_rigged_animated.glb"
|
miku_skin.model_path = "res://assets/characters/skins/miku_proper_anim.glb"
|
||||||
miku_skin.color_tint = Color(0.0, 0.75, 0.75)
|
miku_skin.color_tint = Color(0.0, 0.75, 0.75)
|
||||||
miku_skin.is_unlocked = true
|
miku_skin.is_unlocked = true
|
||||||
skins["miku"] = miku_skin
|
skins["miku"] = miku_skin
|
||||||
|
|||||||
@@ -55,10 +55,6 @@ func load_model(path: String) -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
print("SkinnedPlayerModel: parsed GLB, generating scene...")
|
print("SkinnedPlayerModel: parsed GLB, generating scene...")
|
||||||
# remove_immutable_tracks=false is CRITICAL — when true (default), Godot
|
|
||||||
# strips animation tracks whose values equal the rest pose. This causes
|
|
||||||
# partial T-pose because some bones only move in certain animations.
|
|
||||||
# Editor import sets this to false; runtime loading does not.
|
|
||||||
var scene = gltf.generate_scene(state, 30, false, false)
|
var scene = gltf.generate_scene(state, 30, false, false)
|
||||||
if not scene:
|
if not scene:
|
||||||
print("SkinnedPlayerModel: failed to generate scene")
|
print("SkinnedPlayerModel: failed to generate scene")
|
||||||
@@ -68,7 +64,6 @@ func load_model(path: String) -> void:
|
|||||||
print("SkinnedPlayerModel: scene added: %s" % scene.name)
|
print("SkinnedPlayerModel: scene added: %s" % scene.name)
|
||||||
|
|
||||||
# Apply model scale (the Miku GLB is ~1.2m; scale_factor adjusts to target height)
|
# Apply model scale (the Miku GLB is ~1.2m; scale_factor adjusts to target height)
|
||||||
# For models exported in centimeters (common from Mixamo/Blender), set scale_factor to 0.01.
|
|
||||||
scene.scale = Vector3(scale_factor, scale_factor, scale_factor)
|
scene.scale = Vector3(scale_factor, scale_factor, scale_factor)
|
||||||
scene.position = Vector3(0, position_y_offset * scale_factor, 0)
|
scene.position = Vector3(0, position_y_offset * scale_factor, 0)
|
||||||
print("SkinnedPlayerModel: applied scale %.4f, y_offset %.4f" % [scale_factor, position_y_offset])
|
print("SkinnedPlayerModel: applied scale %.4f, y_offset %.4f" % [scale_factor, position_y_offset])
|
||||||
@@ -91,15 +86,8 @@ func load_model(path: String) -> void:
|
|||||||
if mesh_instances.size() > 0:
|
if mesh_instances.size() > 0:
|
||||||
_mesh_instance = mesh_instances[0]
|
_mesh_instance = mesh_instances[0]
|
||||||
|
|
||||||
# Fix skeleton binding: GLTF imports set MeshInstance.skeleton to ".."
|
# Fix skeleton binding
|
||||||
# which should work for a direct parent, but in our case the MeshInstance
|
|
||||||
# is a child of Skeleton3D which is a child of MikuRig. The skeleton
|
|
||||||
# property needs to point to the Skeleton3D node for skin deformation.
|
|
||||||
# Set it explicitly to the skeleton's path relative to MeshInstance.
|
|
||||||
if _mesh_instance and skeleton:
|
if _mesh_instance and skeleton:
|
||||||
# Manually compute relative path since get_relative_path_to is not
|
|
||||||
# exposed for MeshInstance3D in Godot 4.2.
|
|
||||||
# MeshInstance is child of Skeleton3D, so ".." points to Skeleton3D.
|
|
||||||
_mesh_instance.skeleton = NodePath("..")
|
_mesh_instance.skeleton = NodePath("..")
|
||||||
print("SkinnedPlayerModel: fixed mesh skeleton binding -> '%s'" % _mesh_instance.skeleton)
|
print("SkinnedPlayerModel: fixed mesh skeleton binding -> '%s'" % _mesh_instance.skeleton)
|
||||||
|
|
||||||
@@ -113,15 +101,14 @@ func load_model(path: String) -> void:
|
|||||||
# Find AnimationPlayer
|
# Find AnimationPlayer
|
||||||
animation_player = _find_animation_player(scene)
|
animation_player = _find_animation_player(scene)
|
||||||
if animation_player:
|
if animation_player:
|
||||||
# Ensure AnimationPlayer processes even if parent has process_mode disabled
|
|
||||||
animation_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
animation_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
||||||
animation_player.active = true
|
animation_player.active = true
|
||||||
print("SkinnedPlayerModel: AP process_mode=%d active=%s" % [animation_player.process_mode, animation_player.active])
|
print("SkinnedPlayerModel: AP process_mode=%d active=%s" % [animation_player.process_mode, animation_player.active])
|
||||||
var anim_list = animation_player.get_animation_list()
|
var anim_list = animation_player.get_animation_list()
|
||||||
print("SkinnedPlayerModel: %d animations available:" % anim_list.size())
|
print("SkinnedPlayerModel: %d animations available:" % anim_list.size())
|
||||||
for anim_name in anim_list:
|
for a_name in anim_list:
|
||||||
var a = animation_player.get_animation(anim_name)
|
var a = animation_player.get_animation(a_name)
|
||||||
print(" - %s (%.2fs, loop=%s)" % [anim_name, a.length, a.loop_mode])
|
print(" - %s (%.2fs, %d tracks)" % [a_name, a.length, a.get_track_count()])
|
||||||
# Auto-play idle
|
# Auto-play idle
|
||||||
if animation_player.has_animation("idle"):
|
if animation_player.has_animation("idle"):
|
||||||
animation_player.play("idle")
|
animation_player.play("idle")
|
||||||
@@ -133,11 +120,40 @@ func load_model(path: String) -> void:
|
|||||||
animation_player.play(anim_list[0])
|
animation_player.play(anim_list[0])
|
||||||
print("SkinnedPlayerModel: playing '%s'" % anim_list[0])
|
print("SkinnedPlayerModel: playing '%s'" % anim_list[0])
|
||||||
|
|
||||||
_ensure_locomotion_animations(animation_player)
|
# Skip the animation creation - the GLB already has proper animations
|
||||||
|
# Just verify they have real motion
|
||||||
|
_verify_animations(animation_player)
|
||||||
else:
|
else:
|
||||||
print("SkinnedPlayerModel: WARNING - no AnimationPlayer found")
|
print("SkinnedPlayerModel: WARNING - no AnimationPlayer found")
|
||||||
func _ensure_locomotion_animations(_ap: AnimationPlayer) -> void:
|
|
||||||
## AnimationPlayer doesn't properly update bone transforms for runtime
|
func _verify_animations(ap: AnimationPlayer) -> void:
|
||||||
|
## Verifies that animations have real motion (not stripped by exporter).
|
||||||
|
## If all animations are stripped, enables code-driven animation.
|
||||||
|
var has_real_anim := false
|
||||||
|
for a_name in ap.get_animation_list():
|
||||||
|
var anim = ap.get_animation(a_name)
|
||||||
|
if anim.get_track_count() < 10:
|
||||||
|
continue
|
||||||
|
var max_delta := 0.0
|
||||||
|
for t in range(anim.get_track_count()):
|
||||||
|
var kc = anim.track_get_key_count(t)
|
||||||
|
if kc < 2:
|
||||||
|
continue
|
||||||
|
for i in range(1, kc):
|
||||||
|
var v = anim.track_get_key_value(t, i)
|
||||||
|
var prev = anim.track_get_key_value(t, i - 1)
|
||||||
|
if v is Quaternion and prev is Quaternion:
|
||||||
|
max_delta = max(max_delta, v.angle_to(prev))
|
||||||
|
if max_delta > 0.05:
|
||||||
|
has_real_anim = true
|
||||||
|
print(" Animation '%s' has real motion (delta=%.3f)" % [a_name, max_delta])
|
||||||
|
if not has_real_anim:
|
||||||
|
print("SkinnedPlayerModel: All GLB animations are stripped, using code-driven mode")
|
||||||
|
_enable_code_driven_anim()
|
||||||
|
|
||||||
|
func _enable_code_driven_anim() -> void:
|
||||||
|
## Enables code-driven animation when GLB animations are stripped.
|
||||||
|
_code_driven_mode = true
|
||||||
## GLB skeletons. Animation resources are kept for reference but the
|
## GLB skeletons. Animation resources are kept for reference but the
|
||||||
## actual animation is done code-driven in _process().
|
## actual animation is done code-driven in _process().
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,843 +0,0 @@
|
|||||||
extends Node3D
|
|
||||||
class_name TestLevelBuilder
|
|
||||||
|
|
||||||
## High-quality movement map for Papaya Shooter.
|
|
||||||
## 96x96 arena with multi-level layout, grapple points, wall-run/climb surfaces,
|
|
||||||
## 6 team spawns with anti-camping cover, and varied movement challenges.
|
|
||||||
|
|
||||||
var _speed_label: Label
|
|
||||||
var _state_label: Label
|
|
||||||
var _chain_label: Label
|
|
||||||
var _weapon_label: Label
|
|
||||||
var _grapple_icon: TextureRect
|
|
||||||
var _dash_icon: TextureRect
|
|
||||||
var _grapple_label: Label
|
|
||||||
var _dash_label: Label
|
|
||||||
var _fps_label: Label
|
|
||||||
var _standalone_speed_label: Label
|
|
||||||
var _player: CharacterBody3D
|
|
||||||
var _debug_ui_panel: PanelContainer
|
|
||||||
var _third_person: bool = false
|
|
||||||
var _third_person_camera: Camera3D
|
|
||||||
var _fps_camera: Camera3D
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
||||||
_build_materials()
|
|
||||||
_build_geometry()
|
|
||||||
_build_hud()
|
|
||||||
|
|
||||||
# Multiplayer Spawning
|
|
||||||
var spawner = MultiplayerSpawner.new()
|
|
||||||
spawner.name = "PlayerSpawner"
|
|
||||||
spawner.spawn_path = "."
|
|
||||||
spawner.spawn_function = _spawn_player
|
|
||||||
add_child(spawner)
|
|
||||||
|
|
||||||
var nm = get_node_or_null("/root/NetworkManager")
|
|
||||||
if nm and nm.multiplayer.is_server():
|
|
||||||
for pid in nm.player_stats.keys():
|
|
||||||
spawner.spawn(pid)
|
|
||||||
nm.player_connected.connect(func(pid):
|
|
||||||
spawner.spawn(pid)
|
|
||||||
)
|
|
||||||
nm.player_disconnected.connect(func(pid):
|
|
||||||
var p = get_node_or_null(str(pid))
|
|
||||||
if p:
|
|
||||||
p.queue_free()
|
|
||||||
)
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
|
||||||
if event is InputEventKey and event.pressed and not event.echo:
|
|
||||||
if event.keycode == KEY_F1:
|
|
||||||
_toggle_third_person()
|
|
||||||
|
|
||||||
func _toggle_third_person() -> void:
|
|
||||||
_third_person = not _third_person
|
|
||||||
|
|
||||||
# Find cameras
|
|
||||||
if not _fps_camera:
|
|
||||||
_fps_camera = _find_camera_in_player()
|
|
||||||
if not _third_person_camera:
|
|
||||||
_setup_third_person_camera()
|
|
||||||
|
|
||||||
if _third_person:
|
|
||||||
# Switch to third person
|
|
||||||
if _fps_camera:
|
|
||||||
_fps_camera.current = false
|
|
||||||
if _third_person_camera:
|
|
||||||
_third_person_camera.current = true
|
|
||||||
print("Third person: ON")
|
|
||||||
else:
|
|
||||||
# Switch to first person
|
|
||||||
if _third_person_camera:
|
|
||||||
_third_person_camera.current = false
|
|
||||||
if _fps_camera:
|
|
||||||
_fps_camera.current = true
|
|
||||||
print("Third person: OFF")
|
|
||||||
|
|
||||||
func _find_camera_in_player() -> Camera3D:
|
|
||||||
if not _player:
|
|
||||||
return null
|
|
||||||
# Search for Camera3D in player's children
|
|
||||||
for child in _player.get_children():
|
|
||||||
if child is Camera3D:
|
|
||||||
return child
|
|
||||||
for grandchild in child.get_children():
|
|
||||||
if grandchild is Camera3D:
|
|
||||||
return grandchild
|
|
||||||
return null
|
|
||||||
|
|
||||||
func _setup_third_person_camera() -> void:
|
|
||||||
if not _player:
|
|
||||||
return
|
|
||||||
_third_person_camera = Camera3D.new()
|
|
||||||
_third_person_camera.name = "ThirdPersonCamera"
|
|
||||||
_third_person_camera.fov = 75.0
|
|
||||||
_third_person_camera.near = 0.1
|
|
||||||
_third_person_camera.far = 200.0
|
|
||||||
# Position behind and above the player
|
|
||||||
_third_person_camera.position = Vector3(0, 2.0, -4.0)
|
|
||||||
# Set rotation to look at player (can't use look_at before adding to tree)
|
|
||||||
_third_person_camera.rotation_degrees = Vector3(-15, 0, 0)
|
|
||||||
_player.add_child(_third_person_camera)
|
|
||||||
_third_person_camera.current = false
|
|
||||||
|
|
||||||
|
|
||||||
func _build_materials() -> void:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════════
|
|
||||||
# GEOMETRY — Clean 80x80 arena
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
func _build_geometry() -> void:
|
|
||||||
_build_environment()
|
|
||||||
_build_floor()
|
|
||||||
_build_outer_walls()
|
|
||||||
_build_central_platform()
|
|
||||||
_build_ramps()
|
|
||||||
_build_cover()
|
|
||||||
_build_spawn_alcoves()
|
|
||||||
_build_dummies()
|
|
||||||
_build_lighting()
|
|
||||||
|
|
||||||
|
|
||||||
# ── Utility ───────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _box_static(pos: Vector3, size: Vector3, color: Color, node_name: String = "") -> StaticBody3D:
|
|
||||||
var body := StaticBody3D.new()
|
|
||||||
body.name = node_name if not node_name.is_empty() else "Static_%s" % str(pos)
|
|
||||||
body.position = pos
|
|
||||||
add_child(body)
|
|
||||||
var shape := CollisionShape3D.new()
|
|
||||||
shape.shape = BoxShape3D.new()
|
|
||||||
shape.shape.size = size
|
|
||||||
body.add_child(shape)
|
|
||||||
var mesh := MeshInstance3D.new()
|
|
||||||
mesh.mesh = BoxMesh.new()
|
|
||||||
mesh.mesh.size = size
|
|
||||||
var mat := StandardMaterial3D.new()
|
|
||||||
mat.albedo_color = color
|
|
||||||
mat.roughness = 0.75
|
|
||||||
mesh.mesh.surface_set_material(0, mat)
|
|
||||||
body.add_child(mesh)
|
|
||||||
return body
|
|
||||||
|
|
||||||
|
|
||||||
func _ramp_static(pos: Vector3, size: Vector3, rot_deg: Vector3, color: Color, node_name: String = "") -> StaticBody3D:
|
|
||||||
var body := _box_static(pos, size, color, node_name)
|
|
||||||
body.rotation_degrees = rot_deg
|
|
||||||
return body
|
|
||||||
|
|
||||||
|
|
||||||
# ── Color Palette ─────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
var C_FLOOR := Color(0.22, 0.22, 0.25)
|
|
||||||
var C_WALL := Color(0.35, 0.28, 0.22)
|
|
||||||
var C_WALL_DARK := Color(0.25, 0.20, 0.18)
|
|
||||||
var C_METAL := Color(0.50, 0.52, 0.55)
|
|
||||||
var C_METAL_DARK := Color(0.35, 0.37, 0.40)
|
|
||||||
var C_TEAL := Color(0.20, 0.45, 0.55)
|
|
||||||
var C_CRATE := Color(0.65, 0.50, 0.30)
|
|
||||||
var C_RED := Color(0.70, 0.22, 0.22)
|
|
||||||
var C_BLUE := Color(0.22, 0.30, 0.70)
|
|
||||||
var C_ACCENT_WARM := Color(0.85, 0.55, 0.20)
|
|
||||||
var C_ACCENT_COOL := Color(0.20, 0.50, 0.85)
|
|
||||||
var C_RAMP := Color(0.60, 0.35, 0.15)
|
|
||||||
var C_YELLOW := Color(0.80, 0.75, 0.20)
|
|
||||||
|
|
||||||
|
|
||||||
# ── Environment ───────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_environment() -> void:
|
|
||||||
var env := WorldEnvironment.new()
|
|
||||||
env.name = "WorldEnvironment"
|
|
||||||
var environment := Environment.new()
|
|
||||||
environment.background_mode = Environment.BG_SKY
|
|
||||||
var sky := Sky.new()
|
|
||||||
var sky_mat := ProceduralSkyMaterial.new()
|
|
||||||
sky_mat.sky_top_color = Color(0.12, 0.15, 0.30)
|
|
||||||
sky_mat.sky_horizon_color = Color(0.40, 0.45, 0.55)
|
|
||||||
sky_mat.ground_bottom_color = Color(0.08, 0.06, 0.05)
|
|
||||||
sky_mat.ground_horizon_color = Color(0.30, 0.25, 0.20)
|
|
||||||
sky.sky_material = sky_mat
|
|
||||||
environment.sky = sky
|
|
||||||
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
|
|
||||||
environment.ambient_light_energy = 0.35
|
|
||||||
environment.tonemap_mode = Environment.TONE_MAPPER_FILMIC
|
|
||||||
environment.glow_enabled = true
|
|
||||||
environment.glow_intensity = 0.2
|
|
||||||
environment.glow_bloom = 0.08
|
|
||||||
environment.fog_enabled = true
|
|
||||||
environment.fog_light_color = Color(0.45, 0.48, 0.55)
|
|
||||||
environment.fog_density = 0.003
|
|
||||||
env.environment = environment
|
|
||||||
add_child(env)
|
|
||||||
|
|
||||||
|
|
||||||
# ── Floor ─────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_floor() -> void:
|
|
||||||
# Main arena floor (80x80)
|
|
||||||
_box_static(Vector3(0, -0.5, 0), Vector3(80, 1.0, 80), C_FLOOR, "Floor_Main")
|
|
||||||
|
|
||||||
|
|
||||||
# ── Outer Walls ───────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_outer_walls() -> void:
|
|
||||||
var wall_height := 10.0
|
|
||||||
var half := 40.0
|
|
||||||
_box_static(Vector3(0, wall_height / 2.0, -half), Vector3(80, wall_height, 1.0), C_WALL, "Wall_North")
|
|
||||||
_box_static(Vector3(0, wall_height / 2.0, half), Vector3(80, wall_height, 1.0), C_WALL, "Wall_South")
|
|
||||||
_box_static(Vector3(half, wall_height / 2.0, 0), Vector3(1.0, wall_height, 80), C_WALL, "Wall_East")
|
|
||||||
_box_static(Vector3(-half, wall_height / 2.0, 0), Vector3(1.0, wall_height, 80), C_WALL, "Wall_West")
|
|
||||||
|
|
||||||
|
|
||||||
# ── Central Platform ──────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_central_platform() -> void:
|
|
||||||
# Raised platform (2u high, 16x16) — the main fight area
|
|
||||||
_box_static(Vector3(0, 1.0, 0), Vector3(16, 2.0, 16), C_METAL_DARK, "Central_Platform")
|
|
||||||
# Upper platform (4u high, 8x8) — sniper perch
|
|
||||||
_box_static(Vector3(0, 3.0, 0), Vector3(8, 2.0, 8), C_METAL, "Central_Upper")
|
|
||||||
|
|
||||||
|
|
||||||
# ── Ramps ─────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_ramps() -> void:
|
|
||||||
# 4 cardinal ramps from ground to central platform
|
|
||||||
# North ramp (slopes down toward -z)
|
|
||||||
_ramp_static(Vector3(0, 1.0, -11), Vector3(6, 0.4, 6), Vector3(14, 0, 0), C_RAMP, "Ramp_N")
|
|
||||||
# South ramp
|
|
||||||
_ramp_static(Vector3(0, 1.0, 11), Vector3(6, 0.4, 6), Vector3(-14, 0, 0), C_RAMP, "Ramp_S")
|
|
||||||
# East ramp
|
|
||||||
_ramp_static(Vector3(11, 1.0, 0), Vector3(6, 0.4, 6), Vector3(0, 0, -14), C_RAMP, "Ramp_E")
|
|
||||||
# West ramp
|
|
||||||
_ramp_static(Vector3(-11, 1.0, 0), Vector3(6, 0.4, 6), Vector3(0, 0, 14), C_RAMP, "Ramp_W")
|
|
||||||
|
|
||||||
|
|
||||||
# ── Cover System ──────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_cover() -> void:
|
|
||||||
# Low walls (1.5u high) for crouch cover — placed in open areas, not overlapping anything
|
|
||||||
_box_static(Vector3(-12, 0.75, -12), Vector3(4, 1.5, 0.5), C_WALL, "Cover_NW")
|
|
||||||
_box_static(Vector3(12, 0.75, 12), Vector3(4, 1.5, 0.5), C_WALL, "Cover_SE")
|
|
||||||
_box_static(Vector3(-12, 0.75, 12), Vector3(0.5, 1.5, 4), C_WALL, "Cover_SW")
|
|
||||||
_box_static(Vector3(12, 0.75, -12), Vector3(0.5, 1.5, 4), C_WALL, "Cover_NE")
|
|
||||||
|
|
||||||
# Mid-map corridor walls — create lanes without blocking movement
|
|
||||||
_box_static(Vector3(-22, 2.0, -8), Vector3(12, 4.0, 0.4), C_WALL_DARK, "LaneWall_W")
|
|
||||||
_box_static(Vector3(22, 2.0, 8), Vector3(12, 4.0, 0.4), C_WALL_DARK, "LaneWall_E")
|
|
||||||
|
|
||||||
# Crate clusters — properly spaced, no overlaps
|
|
||||||
# NW cluster
|
|
||||||
_box_static(Vector3(-20, 0.6, -20), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_NW1")
|
|
||||||
_box_static(Vector3(-20, 0.6, -21.5), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_NW2")
|
|
||||||
_box_static(Vector3(-21.5, 0.6, -20), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_NW3")
|
|
||||||
# SE cluster
|
|
||||||
_box_static(Vector3(20, 0.6, 20), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_SE1")
|
|
||||||
_box_static(Vector3(20, 0.6, 21.5), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_SE2")
|
|
||||||
_box_static(Vector3(21.5, 0.6, 20), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_SE3")
|
|
||||||
# Center-side crates
|
|
||||||
_box_static(Vector3(-8, 0.6, 0), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_C1")
|
|
||||||
_box_static(Vector3(8, 0.6, 0), Vector3(1.2, 1.2, 1.2), C_CRATE, "Crate_C2")
|
|
||||||
|
|
||||||
# Barrels — placed along walls, not blocking paths
|
|
||||||
_box_static(Vector3(-35, 0.5, -5), Vector3(0.8, 1.0, 0.8), Color(0.50, 0.45, 0.30), "Barrel_1")
|
|
||||||
_box_static(Vector3(-35, 0.5, 5), Vector3(0.8, 1.0, 0.8), Color(0.50, 0.45, 0.30), "Barrel_2")
|
|
||||||
_box_static(Vector3(35, 0.5, -5), Vector3(0.8, 1.0, 0.8), Color(0.50, 0.45, 0.30), "Barrel_3")
|
|
||||||
_box_static(Vector3(35, 0.5, 5), Vector3(0.8, 1.0, 0.8), Color(0.50, 0.45, 0.30), "Barrel_4")
|
|
||||||
|
|
||||||
|
|
||||||
# ── Spawn Alcoves ─────────────────────────────────────────────────────────────
|
|
||||||
# 4 spawns: 2 red (NW, SW), 2 blue (NE, SE)
|
|
||||||
# Each spawn has 2 cover walls forming an L-shape, with 2 clear exit routes
|
|
||||||
|
|
||||||
func _build_spawn_alcoves() -> void:
|
|
||||||
var spawn_y := 0.01
|
|
||||||
|
|
||||||
# Red Spawn 1: NW corner — L-wall on north and west sides
|
|
||||||
_spawn_floor(Vector3(-35, spawn_y, -35), C_RED, "Spawn_Red_1")
|
|
||||||
_spawn_cover(Vector3(-33, 1.5, -39.5), Vector3(6, 3.0, 0.4), C_RED, "SCover_R1A") # North wall
|
|
||||||
_spawn_cover(Vector3(-39.5, 1.5, -33), Vector3(0.4, 3.0, 6), C_RED, "SCover_R1B") # West wall
|
|
||||||
# Exits: southeast (open)
|
|
||||||
|
|
||||||
# Red Spawn 2: SW corner — L-wall on south and west sides
|
|
||||||
_spawn_floor(Vector3(-35, spawn_y, 35), C_RED, "Spawn_Red_2")
|
|
||||||
_spawn_cover(Vector3(-33, 1.5, 39.5), Vector3(6, 3.0, 0.4), C_RED, "SCover_R2A") # South wall
|
|
||||||
_spawn_cover(Vector3(-39.5, 1.5, 33), Vector3(0.4, 3.0, 6), C_RED, "SCover_R2B") # West wall
|
|
||||||
# Exits: northeast (open)
|
|
||||||
|
|
||||||
# Blue Spawn 1: NE corner — L-wall on north and east sides
|
|
||||||
_spawn_floor(Vector3(35, spawn_y, -35), C_BLUE, "Spawn_Blue_1")
|
|
||||||
_spawn_cover(Vector3(33, 1.5, -39.5), Vector3(6, 3.0, 0.4), C_BLUE, "SCover_B1A") # North wall
|
|
||||||
_spawn_cover(Vector3(39.5, 1.5, -33), Vector3(0.4, 3.0, 6), C_BLUE, "SCover_B1B") # East wall
|
|
||||||
# Exits: southwest (open)
|
|
||||||
|
|
||||||
# Blue Spawn 2: SE corner — L-wall on south and east sides
|
|
||||||
_spawn_floor(Vector3(35, spawn_y, 35), C_BLUE, "Spawn_Blue_2")
|
|
||||||
_spawn_cover(Vector3(33, 1.5, 39.5), Vector3(6, 3.0, 0.4), C_BLUE, "SCover_B2A") # South wall
|
|
||||||
_spawn_cover(Vector3(39.5, 1.5, 33), Vector3(0.4, 3.0, 6), C_BLUE, "SCover_B2B") # East wall
|
|
||||||
# Exits: northwest (open)
|
|
||||||
|
|
||||||
|
|
||||||
func _spawn_floor(pos: Vector3, color: Color, label: String) -> void:
|
|
||||||
var body := StaticBody3D.new()
|
|
||||||
body.name = label
|
|
||||||
body.position = pos
|
|
||||||
add_child(body)
|
|
||||||
var mesh := MeshInstance3D.new()
|
|
||||||
mesh.mesh = BoxMesh.new()
|
|
||||||
mesh.mesh.size = Vector3(4, 0.05, 4)
|
|
||||||
var mat := StandardMaterial3D.new()
|
|
||||||
mat.albedo_color = color
|
|
||||||
mat.roughness = 0.4
|
|
||||||
mesh.mesh.surface_set_material(0, mat)
|
|
||||||
body.add_child(mesh)
|
|
||||||
|
|
||||||
|
|
||||||
func _spawn_cover(pos: Vector3, size: Vector3, color: Color, label: String) -> void:
|
|
||||||
_box_static(pos, size, color, label)
|
|
||||||
|
|
||||||
|
|
||||||
# ── Dummies ───────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_dummies() -> void:
|
|
||||||
# Target dummy — in open area south of center
|
|
||||||
var dummy = load("res://entities/target_dummy.gd").new()
|
|
||||||
dummy.name = "TargetDummy"
|
|
||||||
dummy.position = Vector3(0, 0, -25)
|
|
||||||
add_child(dummy)
|
|
||||||
|
|
||||||
# Killable dummy — in open area east of center
|
|
||||||
var killable = load("res://entities/killable_dummy.gd").new()
|
|
||||||
killable.name = "KillableDummy"
|
|
||||||
killable.position = Vector3(25, 0, 0)
|
|
||||||
add_child(killable)
|
|
||||||
|
|
||||||
# Walking dummy — patrols along the south side
|
|
||||||
var walking = load("res://entities/walking_dummy.gd").new()
|
|
||||||
walking.name = "WalkingDummy"
|
|
||||||
walking.position = Vector3(-20, 0, -30)
|
|
||||||
walking.point_a = Vector3(-20, 0, -30)
|
|
||||||
walking.point_b = Vector3(20, 0, -30)
|
|
||||||
add_child(walking)
|
|
||||||
|
|
||||||
|
|
||||||
# ── Lighting ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_lighting() -> void:
|
|
||||||
var sun := DirectionalLight3D.new()
|
|
||||||
sun.name = "Sun"
|
|
||||||
sun.rotation_degrees = Vector3(-50, 30, 0)
|
|
||||||
sun.light_color = Color(1.0, 0.95, 0.85)
|
|
||||||
sun.light_energy = 1.2
|
|
||||||
sun.shadow_enabled = true
|
|
||||||
sun.directional_shadow_mode = DirectionalLight3D.SHADOW_PARALLEL_4_SPLITS
|
|
||||||
sun.directional_shadow_max_distance = 100.0
|
|
||||||
add_child(sun)
|
|
||||||
|
|
||||||
var fill := DirectionalLight3D.new()
|
|
||||||
fill.name = "FillLight"
|
|
||||||
fill.rotation_degrees = Vector3(-30, -150, 0)
|
|
||||||
fill.light_color = Color(0.55, 0.65, 0.85)
|
|
||||||
fill.light_energy = 0.25
|
|
||||||
fill.shadow_enabled = false
|
|
||||||
add_child(fill)
|
|
||||||
|
|
||||||
|
|
||||||
# ── Player ────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _spawn_player(pid: int) -> CharacterBody3D:
|
|
||||||
var player := CharacterBody3D.new()
|
|
||||||
player.name = str(pid)
|
|
||||||
player.set_multiplayer_authority(pid)
|
|
||||||
|
|
||||||
# Use a slightly random spawn position to avoid exact overlapping
|
|
||||||
player.position = Vector3(randf_range(-5, 5), 1.0, 20)
|
|
||||||
|
|
||||||
# Server Synchronizer (Host is the ground truth)
|
|
||||||
var server_sync = MultiplayerSynchronizer.new()
|
|
||||||
server_sync.name = "ServerSynchronizer"
|
|
||||||
server_sync.set_multiplayer_authority(1)
|
|
||||||
var server_rep_config = SceneReplicationConfig.new()
|
|
||||||
server_rep_config.add_property(":position")
|
|
||||||
server_rep_config.add_property(":synced_movement_state")
|
|
||||||
server_rep_config.add_property(":synced_movement_speed")
|
|
||||||
server_rep_config.add_property(":synced_is_crouching")
|
|
||||||
server_rep_config.add_property(":health")
|
|
||||||
server_rep_config.add_property(":shield")
|
|
||||||
server_rep_config.add_property(":is_dead")
|
|
||||||
server_rep_config.add_property(":synced_grapple_point")
|
|
||||||
server_rep_config.add_property(":synced_is_grapple_shooting")
|
|
||||||
server_sync.replication_config = server_rep_config
|
|
||||||
player.add_child(server_sync)
|
|
||||||
|
|
||||||
# Client Synchronizer (Client dictates their aim and loadout setup)
|
|
||||||
var client_sync = MultiplayerSynchronizer.new()
|
|
||||||
client_sync.name = "MultiplayerSynchronizer"
|
|
||||||
client_sync.set_multiplayer_authority(pid)
|
|
||||||
var client_rep_config = SceneReplicationConfig.new()
|
|
||||||
client_rep_config.add_property(":rotation")
|
|
||||||
client_rep_config.add_property("HeadPivot:rotation")
|
|
||||||
client_rep_config.add_property(":synced_weapon_path")
|
|
||||||
client_rep_config.add_property(":synced_loadout_p1")
|
|
||||||
client_rep_config.add_property(":synced_loadout_p2")
|
|
||||||
client_rep_config.add_property(":synced_loadout_sp")
|
|
||||||
client_rep_config.add_property(":synced_loadout_melee")
|
|
||||||
client_rep_config.add_property(":synced_loadout_ready")
|
|
||||||
client_rep_config.add_property(":synced_is_targeting")
|
|
||||||
client_rep_config.add_property(":synced_homing_target_pos")
|
|
||||||
client_sync.replication_config = client_rep_config
|
|
||||||
player.add_child(client_sync)
|
|
||||||
|
|
||||||
# Collision shape
|
|
||||||
var col_shape := CollisionShape3D.new()
|
|
||||||
col_shape.name = "CollisionShape3D"
|
|
||||||
var capsule := CapsuleShape3D.new()
|
|
||||||
capsule.radius = 0.4
|
|
||||||
capsule.height = 1.8
|
|
||||||
col_shape.shape = capsule
|
|
||||||
player.add_child(col_shape)
|
|
||||||
|
|
||||||
# Apply movement controller script
|
|
||||||
var mover_script = load("res://movement/player_movement_controller.gd")
|
|
||||||
if mover_script:
|
|
||||||
player.set_script(mover_script)
|
|
||||||
|
|
||||||
# Visual Model for Player
|
|
||||||
if pid == 1:
|
|
||||||
# Miku: use the rigged GLB model with its own armature
|
|
||||||
var skinned = load("res://characters/skinned_player_model.gd").new()
|
|
||||||
skinned.name = "SkinnedModel"
|
|
||||||
skinned.model_path = "res://assets/characters/skins/miku_rigged_animated.glb"
|
|
||||||
skinned.scale_factor = 1.25 # GLB is ~1.2m, scale to ~1.5m for player capsule
|
|
||||||
skinned.position_y_offset = -0.2 # Align feet with player origin
|
|
||||||
skinned.position = Vector3.ZERO # Model origin = player origin
|
|
||||||
player.add_child(skinned)
|
|
||||||
print("TestLevelBuilder: added SkinnedModel for player 1")
|
|
||||||
else:
|
|
||||||
# Default: procedural humanoid
|
|
||||||
var humanoid = load("res://characters/humanoid_model.gd").new()
|
|
||||||
humanoid.name = "HumanoidModel"
|
|
||||||
humanoid.color = Color(0.2, 0.4, 0.8)
|
|
||||||
humanoid.shadows_only = (pid == multiplayer.get_unique_id())
|
|
||||||
humanoid.position = Vector3(0, -0.9, 0)
|
|
||||||
player.add_child(humanoid)
|
|
||||||
|
|
||||||
# Movement State Machine
|
|
||||||
var sm := Node.new()
|
|
||||||
sm.name = "MovementStateMachine"
|
|
||||||
player.add_child(sm)
|
|
||||||
|
|
||||||
var sm_script = preload("res://movement/movement_state_machine.gd")
|
|
||||||
if sm_script:
|
|
||||||
sm.set_script(sm_script)
|
|
||||||
|
|
||||||
# Add all movement states
|
|
||||||
var state_scripts := {
|
|
||||||
"ground": "res://movement/states/state_ground.gd",
|
|
||||||
"air": "res://movement/states/state_air.gd",
|
|
||||||
"wall_run": "res://movement/states/state_wall_run.gd",
|
|
||||||
"wall_cling": "res://movement/states/state_wall_cling.gd",
|
|
||||||
"wall_climb": "res://movement/states/state_wall_climb.gd",
|
|
||||||
"slide": "res://movement/states/state_slide.gd",
|
|
||||||
"dash": "res://movement/states/state_dash.gd",
|
|
||||||
"grapple": "res://movement/states/state_grapple.gd",
|
|
||||||
}
|
|
||||||
for state_name in state_scripts:
|
|
||||||
var st := Node.new()
|
|
||||||
st.name = "state_" + state_name
|
|
||||||
sm.add_child(st)
|
|
||||||
var st_script = load(state_scripts[state_name])
|
|
||||||
if st_script:
|
|
||||||
st.set_script(st_script)
|
|
||||||
|
|
||||||
# FPS Camera Rig (HeadPivot -> Camera3D)
|
|
||||||
var head_pivot := Node3D.new()
|
|
||||||
head_pivot.name = "HeadPivot"
|
|
||||||
head_pivot.position = Vector3(0, 0.7, 0)
|
|
||||||
player.add_child(head_pivot)
|
|
||||||
|
|
||||||
var camera := Camera3D.new()
|
|
||||||
camera.name = "Camera3D"
|
|
||||||
camera.current = (pid == multiplayer.get_unique_id())
|
|
||||||
camera.fov = 90.0
|
|
||||||
head_pivot.add_child(camera)
|
|
||||||
|
|
||||||
# Weapon Setup
|
|
||||||
var wmanager_script = preload("res://weapons/weapon_manager.gd")
|
|
||||||
if wmanager_script:
|
|
||||||
var wman = wmanager_script.new()
|
|
||||||
wman.name = "WeaponManager"
|
|
||||||
wman.player = player
|
|
||||||
wman.camera = camera
|
|
||||||
camera.add_child(wman)
|
|
||||||
|
|
||||||
var rig_script = preload("res://characters/player/fps_camera_rig.gd")
|
|
||||||
if rig_script:
|
|
||||||
head_pivot.set_script(rig_script)
|
|
||||||
|
|
||||||
# Store original capsule height
|
|
||||||
sm.original_capsule_height = capsule.height
|
|
||||||
|
|
||||||
# Dependencies
|
|
||||||
sm.player = player
|
|
||||||
sm.params = player.params
|
|
||||||
head_pivot.params = player.params
|
|
||||||
|
|
||||||
# Authority configuration
|
|
||||||
var is_local = (pid == multiplayer.get_unique_id())
|
|
||||||
if is_local:
|
|
||||||
_player = player
|
|
||||||
player.set_physics_process(true)
|
|
||||||
player.set_process(true)
|
|
||||||
sm.set_physics_process(true)
|
|
||||||
else:
|
|
||||||
player.set_physics_process(false)
|
|
||||||
player.set_process(true)
|
|
||||||
player.set_process_input(false)
|
|
||||||
sm.set_physics_process(false)
|
|
||||||
sm.set_process(false)
|
|
||||||
sm.set_process_input(false)
|
|
||||||
head_pivot.set_process_input(false)
|
|
||||||
head_pivot.set_process(false)
|
|
||||||
head_pivot.set_physics_process(false)
|
|
||||||
var wman = camera.get_node_or_null("WeaponManager")
|
|
||||||
if wman:
|
|
||||||
wman.set_process_input(false)
|
|
||||||
wman.set_process(false)
|
|
||||||
wman.set_physics_process(false)
|
|
||||||
wman.visible = false
|
|
||||||
var cv = wman.get("canvas_layer")
|
|
||||||
if cv:
|
|
||||||
cv.visible = false
|
|
||||||
|
|
||||||
return player
|
|
||||||
|
|
||||||
|
|
||||||
# ── HUD ───────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func _build_hud() -> void:
|
|
||||||
var canvas := CanvasLayer.new()
|
|
||||||
canvas.name = "UI"
|
|
||||||
add_child(canvas)
|
|
||||||
|
|
||||||
# Crosshair
|
|
||||||
var crosshair := Control.new()
|
|
||||||
crosshair.name = "Crosshair"
|
|
||||||
crosshair.set_anchors_preset(Control.PRESET_CENTER)
|
|
||||||
crosshair.custom_minimum_size = Vector2(20, 20)
|
|
||||||
canvas.add_child(crosshair)
|
|
||||||
|
|
||||||
var ch_dot := ColorRect.new()
|
|
||||||
ch_dot.name = "Dot"
|
|
||||||
ch_dot.color = Color(1, 1, 1, 0.8)
|
|
||||||
ch_dot.size = Vector2(4, 4)
|
|
||||||
ch_dot.position = Vector2(-2, -2)
|
|
||||||
crosshair.add_child(ch_dot)
|
|
||||||
|
|
||||||
for data in [
|
|
||||||
{"pos": Vector2(-10, -1), "size": Vector2(6, 2)},
|
|
||||||
{"pos": Vector2(4, -1), "size": Vector2(6, 2)},
|
|
||||||
{"pos": Vector2(-1, -10), "size": Vector2(2, 6)},
|
|
||||||
{"pos": Vector2(-1, 4), "size": Vector2(2, 6)},
|
|
||||||
]:
|
|
||||||
var line := ColorRect.new()
|
|
||||||
line.color = Color(1, 1, 1, 0.6)
|
|
||||||
line.position = data["pos"]
|
|
||||||
line.size = data["size"]
|
|
||||||
crosshair.add_child(line)
|
|
||||||
|
|
||||||
# FPS Label
|
|
||||||
_fps_label = Label.new()
|
|
||||||
_fps_label.name = "FPSLabel"
|
|
||||||
_fps_label.text = "FPS: 0"
|
|
||||||
_fps_label.add_theme_font_size_override("font_size", 24)
|
|
||||||
_fps_label.add_theme_color_override("font_color", Color(0.9, 0.9, 0.2))
|
|
||||||
_fps_label.add_theme_color_override("font_outline_color", Color(0, 0, 0))
|
|
||||||
_fps_label.add_theme_constant_override("outline_size", 4)
|
|
||||||
_fps_label.set_anchors_preset(Control.PRESET_TOP_LEFT)
|
|
||||||
_fps_label.position = Vector2(12, 12)
|
|
||||||
canvas.add_child(_fps_label)
|
|
||||||
|
|
||||||
_standalone_speed_label = Label.new()
|
|
||||||
_standalone_speed_label.name = "StandaloneSpeedLabel"
|
|
||||||
_standalone_speed_label.text = "Speed: 0.0 m/s"
|
|
||||||
_standalone_speed_label.add_theme_font_size_override("font_size", 24)
|
|
||||||
_standalone_speed_label.add_theme_color_override("font_color", Color(0.3, 1.0, 0.5))
|
|
||||||
_standalone_speed_label.add_theme_color_override("font_outline_color", Color(0, 0, 0))
|
|
||||||
_standalone_speed_label.add_theme_constant_override("outline_size", 4)
|
|
||||||
_standalone_speed_label.set_anchors_preset(Control.PRESET_TOP_LEFT)
|
|
||||||
_standalone_speed_label.position = Vector2(12, 45)
|
|
||||||
canvas.add_child(_standalone_speed_label)
|
|
||||||
|
|
||||||
# Debug panel
|
|
||||||
_debug_ui_panel = PanelContainer.new()
|
|
||||||
_debug_ui_panel.name = "InfoPanel"
|
|
||||||
_debug_ui_panel.offset_left = 12
|
|
||||||
_debug_ui_panel.offset_top = 50
|
|
||||||
_debug_ui_panel.offset_right = 400
|
|
||||||
_debug_ui_panel.offset_bottom = 160
|
|
||||||
var panel_style := StyleBoxFlat.new()
|
|
||||||
panel_style.bg_color = Color(0, 0, 0, 0.55)
|
|
||||||
panel_style.corner_radius_top_left = 8
|
|
||||||
panel_style.corner_radius_top_right = 8
|
|
||||||
panel_style.corner_radius_bottom_left = 8
|
|
||||||
panel_style.corner_radius_bottom_right = 8
|
|
||||||
panel_style.content_margin_left = 12
|
|
||||||
panel_style.content_margin_top = 8
|
|
||||||
panel_style.content_margin_right = 12
|
|
||||||
panel_style.content_margin_bottom = 8
|
|
||||||
_debug_ui_panel.add_theme_stylebox_override("panel", panel_style)
|
|
||||||
canvas.add_child(_debug_ui_panel)
|
|
||||||
|
|
||||||
var vbox := VBoxContainer.new()
|
|
||||||
vbox.name = "InfoVBox"
|
|
||||||
_debug_ui_panel.add_child(vbox)
|
|
||||||
|
|
||||||
_speed_label = Label.new()
|
|
||||||
_speed_label.name = "SpeedLabel"
|
|
||||||
_speed_label.text = "Speed: 0.0 m/s"
|
|
||||||
_speed_label.add_theme_font_size_override("font_size", 18)
|
|
||||||
_speed_label.add_theme_color_override("font_color", Color(0.3, 1.0, 0.5))
|
|
||||||
vbox.add_child(_speed_label)
|
|
||||||
|
|
||||||
_state_label = Label.new()
|
|
||||||
_state_label.name = "StateLabel"
|
|
||||||
_state_label.text = "State: ground"
|
|
||||||
_state_label.add_theme_font_size_override("font_size", 16)
|
|
||||||
_state_label.add_theme_color_override("font_color", Color(0.7, 0.85, 1.0))
|
|
||||||
vbox.add_child(_state_label)
|
|
||||||
|
|
||||||
_chain_label = Label.new()
|
|
||||||
_chain_label.name = "ChainLabel"
|
|
||||||
_chain_label.text = "Chain: 0 (+0%)"
|
|
||||||
_chain_label.add_theme_font_size_override("font_size", 16)
|
|
||||||
_chain_label.add_theme_color_override("font_color", Color(1.0, 0.8, 0.3))
|
|
||||||
vbox.add_child(_chain_label)
|
|
||||||
|
|
||||||
# Weapon & Ammo Panel
|
|
||||||
var wp_panel := PanelContainer.new()
|
|
||||||
wp_panel.name = "WeaponPanel"
|
|
||||||
wp_panel.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
|
|
||||||
wp_panel.offset_left = -250
|
|
||||||
wp_panel.offset_top = -100
|
|
||||||
wp_panel.offset_right = -20
|
|
||||||
wp_panel.offset_bottom = -20
|
|
||||||
var wp_style := StyleBoxFlat.new()
|
|
||||||
wp_style.bg_color = Color(0, 0, 0, 0.6)
|
|
||||||
wp_style.corner_radius_top_left = 8
|
|
||||||
wp_style.corner_radius_top_right = 8
|
|
||||||
wp_style.corner_radius_bottom_left = 8
|
|
||||||
wp_style.corner_radius_bottom_right = 8
|
|
||||||
wp_style.content_margin_left = 16
|
|
||||||
wp_style.content_margin_top = 12
|
|
||||||
wp_style.content_margin_right = 16
|
|
||||||
wp_style.content_margin_bottom = 12
|
|
||||||
wp_panel.add_theme_stylebox_override("panel", wp_style)
|
|
||||||
wp_panel.grow_horizontal = Control.GROW_DIRECTION_BEGIN
|
|
||||||
canvas.add_child(wp_panel)
|
|
||||||
|
|
||||||
_weapon_label = Label.new()
|
|
||||||
_weapon_label.name = "WeaponLabel"
|
|
||||||
_weapon_label.text = "Unarmed\n0 / 0"
|
|
||||||
_weapon_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
|
||||||
_weapon_label.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
|
|
||||||
_weapon_label.add_theme_font_size_override("font_size", 24)
|
|
||||||
wp_panel.add_child(_weapon_label)
|
|
||||||
|
|
||||||
# Utilities Panel
|
|
||||||
var util_panel := PanelContainer.new()
|
|
||||||
util_panel.name = "UtilPanel"
|
|
||||||
util_panel.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
|
|
||||||
util_panel.offset_left = -200
|
|
||||||
util_panel.offset_top = -180
|
|
||||||
util_panel.offset_right = -20
|
|
||||||
util_panel.offset_bottom = -110
|
|
||||||
var util_style := StyleBoxFlat.new()
|
|
||||||
util_style.bg_color = Color(0, 0, 0, 0.6)
|
|
||||||
util_style.corner_radius_top_left = 8
|
|
||||||
util_style.corner_radius_top_right = 8
|
|
||||||
util_style.corner_radius_bottom_left = 8
|
|
||||||
util_style.corner_radius_bottom_right = 8
|
|
||||||
util_style.content_margin_left = 12
|
|
||||||
util_style.content_margin_top = 8
|
|
||||||
util_style.content_margin_right = 12
|
|
||||||
util_style.content_margin_bottom = 8
|
|
||||||
util_panel.add_theme_stylebox_override("panel", util_style)
|
|
||||||
util_panel.grow_horizontal = Control.GROW_DIRECTION_BEGIN
|
|
||||||
canvas.add_child(util_panel)
|
|
||||||
|
|
||||||
var util_hbox := HBoxContainer.new()
|
|
||||||
util_hbox.name = "UtilHBox"
|
|
||||||
util_hbox.add_theme_constant_override("separation", 20)
|
|
||||||
util_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
||||||
util_panel.add_child(util_hbox)
|
|
||||||
|
|
||||||
var grapple_vbox := VBoxContainer.new()
|
|
||||||
grapple_vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
||||||
util_hbox.add_child(grapple_vbox)
|
|
||||||
|
|
||||||
_grapple_icon = TextureRect.new()
|
|
||||||
_grapple_icon.texture = load("res://assets/ui/grapple_icon.jpg")
|
|
||||||
_grapple_icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
||||||
_grapple_icon.custom_minimum_size = Vector2(32, 32)
|
|
||||||
_grapple_icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
||||||
grapple_vbox.add_child(_grapple_icon)
|
|
||||||
|
|
||||||
_grapple_label = Label.new()
|
|
||||||
_grapple_label.text = "Grapple"
|
|
||||||
_grapple_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
||||||
_grapple_label.add_theme_font_size_override("font_size", 12)
|
|
||||||
grapple_vbox.add_child(_grapple_label)
|
|
||||||
|
|
||||||
var dash_vbox := VBoxContainer.new()
|
|
||||||
dash_vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
||||||
util_hbox.add_child(dash_vbox)
|
|
||||||
|
|
||||||
_dash_icon = TextureRect.new()
|
|
||||||
_dash_icon.texture = load("res://assets/ui/dash_icon.jpg")
|
|
||||||
_dash_icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
||||||
_dash_icon.custom_minimum_size = Vector2(32, 32)
|
|
||||||
_dash_icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
||||||
dash_vbox.add_child(_dash_icon)
|
|
||||||
|
|
||||||
_dash_label = Label.new()
|
|
||||||
_dash_label.text = "Ready"
|
|
||||||
_dash_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
||||||
_dash_label.add_theme_font_size_override("font_size", 12)
|
|
||||||
dash_vbox.add_child(_dash_label)
|
|
||||||
|
|
||||||
|
|
||||||
func _get_key_name(action: String) -> String:
|
|
||||||
if not InputMap.has_action(action):
|
|
||||||
return "?"
|
|
||||||
var events = InputMap.action_get_events(action)
|
|
||||||
for e in events:
|
|
||||||
if e is InputEventKey:
|
|
||||||
var code = e.physical_keycode if e.physical_keycode != 0 else e.keycode
|
|
||||||
return OS.get_keycode_string(code)
|
|
||||||
elif e is InputEventMouseButton:
|
|
||||||
if e.button_index == MOUSE_BUTTON_LEFT: return "LClick"
|
|
||||||
elif e.button_index == MOUSE_BUTTON_RIGHT: return "RClick"
|
|
||||||
elif e.button_index == MOUSE_BUTTON_MIDDLE: return "MClick"
|
|
||||||
return "?"
|
|
||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
|
||||||
if not _player or not is_instance_valid(_player):
|
|
||||||
return
|
|
||||||
|
|
||||||
# Third person camera follow — orbit behind player's facing direction
|
|
||||||
if _third_person and _third_person_camera and _third_person_camera.current:
|
|
||||||
# Get the player's forward direction (on XZ plane)
|
|
||||||
var forward = -_player.global_transform.basis.z
|
|
||||||
forward.y = 0
|
|
||||||
forward = forward.normalized()
|
|
||||||
# Position camera behind and above player
|
|
||||||
var cam_offset = forward * -4.0 + Vector3.UP * 2.5
|
|
||||||
var target_pos = _player.global_position + cam_offset
|
|
||||||
_third_person_camera.global_position = _third_person_camera.global_position.lerp(target_pos, 0.12)
|
|
||||||
# Look at player's head area
|
|
||||||
_third_person_camera.look_at(_player.global_position + Vector3.UP * 1.5)
|
|
||||||
|
|
||||||
if _debug_ui_panel:
|
|
||||||
_debug_ui_panel.visible = SettingsManager.show_debug_ui
|
|
||||||
|
|
||||||
if _fps_label:
|
|
||||||
_fps_label.visible = SettingsManager.show_fps
|
|
||||||
if _fps_label.visible:
|
|
||||||
_fps_label.text = "FPS: %d" % Engine.get_frames_per_second()
|
|
||||||
|
|
||||||
var vel: Vector3 = _player.velocity
|
|
||||||
var hspeed := Vector2(vel.x, vel.z).length()
|
|
||||||
var total_speed := vel.length()
|
|
||||||
|
|
||||||
if _speed_label:
|
|
||||||
_speed_label.text = "Speed: %.1f m/s (total: %.1f)" % [hspeed, total_speed]
|
|
||||||
|
|
||||||
if _standalone_speed_label:
|
|
||||||
if SettingsManager.show_movement_speed and not SettingsManager.show_debug_ui:
|
|
||||||
_standalone_speed_label.visible = true
|
|
||||||
_standalone_speed_label.text = "Speed: %.1f m/s" % hspeed
|
|
||||||
if _fps_label and _fps_label.visible:
|
|
||||||
_standalone_speed_label.position = Vector2(12, 45)
|
|
||||||
else:
|
|
||||||
_standalone_speed_label.position = Vector2(12, 12)
|
|
||||||
else:
|
|
||||||
_standalone_speed_label.visible = false
|
|
||||||
|
|
||||||
if _state_label:
|
|
||||||
var sm = _player.get_node_or_null("MovementStateMachine")
|
|
||||||
if sm:
|
|
||||||
_state_label.text = "State: %s" % sm.current_state
|
|
||||||
|
|
||||||
if _chain_label:
|
|
||||||
var sm = _player.get_node_or_null("MovementStateMachine")
|
|
||||||
if sm:
|
|
||||||
_chain_label.text = "Chain: %d (+%d%%)" % [sm.chain_count, int(sm.current_chain_bonus * 100)]
|
|
||||||
|
|
||||||
if sm.current_state == "grapple" or sm.is_grapple_shooting:
|
|
||||||
_grapple_icon.modulate = Color(0.2, 1.0, 0.4)
|
|
||||||
_grapple_label.text = "Grappling"
|
|
||||||
else:
|
|
||||||
_grapple_icon.modulate = Color(1.0, 1.0, 1.0)
|
|
||||||
_grapple_label.text = "Ready"
|
|
||||||
|
|
||||||
var dash_rem = sm.get_dash_cooldown_remaining()
|
|
||||||
if dash_rem > 0.0:
|
|
||||||
_dash_icon.modulate = Color(1.0, 0.3, 0.3)
|
|
||||||
_dash_label.text = "%.1f" % dash_rem
|
|
||||||
else:
|
|
||||||
_dash_icon.modulate = Color(1.0, 1.0, 1.0)
|
|
||||||
_dash_label.text = "Ready"
|
|
||||||
|
|
||||||
if _weapon_label:
|
|
||||||
var wman = _player.get_node_or_null("HeadPivot/Camera3D/WeaponManager")
|
|
||||||
if wman and wman.weapons.has(wman.active_slot):
|
|
||||||
var active_weapon = wman.weapons[wman.active_slot]
|
|
||||||
var w_name = "Weapon"
|
|
||||||
var cur_ammo = 0
|
|
||||||
var max_ammo = 0
|
|
||||||
|
|
||||||
if "weapon_name" in active_weapon:
|
|
||||||
w_name = active_weapon.weapon_name
|
|
||||||
elif active_weapon.get("weapon_name") == null and "shells" in active_weapon:
|
|
||||||
w_name = "Double Barrel Shotgun"
|
|
||||||
|
|
||||||
if "current_ammo" in active_weapon:
|
|
||||||
cur_ammo = active_weapon.current_ammo
|
|
||||||
max_ammo = active_weapon.max_ammo
|
|
||||||
elif "shells" in active_weapon:
|
|
||||||
cur_ammo = active_weapon.shells
|
|
||||||
max_ammo = 2
|
|
||||||
|
|
||||||
if "reloading" in active_weapon and active_weapon.reloading:
|
|
||||||
_weapon_label.text = "%s\nReloading..." % w_name
|
|
||||||
else:
|
|
||||||
_weapon_label.text = "%s\n%d / %d" % [w_name, cur_ammo, max_ammo]
|
|
||||||
else:
|
|
||||||
_weapon_label.text = "Unarmed\n0 / 0"
|
|
||||||
@@ -147,7 +147,7 @@ func _spawn_player(pid: int) -> CharacterBody3D:
|
|||||||
# Local player: use skinned Miku model with animations
|
# Local player: use skinned Miku model with animations
|
||||||
var skinned = load("res://characters/skinned_player_model.gd").new()
|
var skinned = load("res://characters/skinned_player_model.gd").new()
|
||||||
skinned.name = "SkinnedModel"
|
skinned.name = "SkinnedModel"
|
||||||
skinned.model_path = "res://assets/characters/skins/miku_rigged_animated.glb"
|
skinned.model_path = "res://assets/characters/skins/miku_proper_anim.glb"
|
||||||
skinned.scale_factor = 1.25
|
skinned.scale_factor = 1.25
|
||||||
skinned.position_y_offset = -0.2
|
skinned.position_y_offset = -0.2
|
||||||
skinned.position = Vector3(0, 0.0, 0)
|
skinned.position = Vector3(0, 0.0, 0)
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import bpy
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Clear scene
|
||||||
|
bpy.ops.object.select_all(action='SELECT')
|
||||||
|
bpy.ops.object.delete()
|
||||||
|
|
||||||
|
# Import the existing Miku GLB
|
||||||
|
input_path = "/home/ai-agent/Papay-Shooter/assets/characters/skins/miku_rigged_animated.glb"
|
||||||
|
output_path = "/home/ai-agent/Papay-Shooter/assets/characters/skins/miku_proper_anim.glb"
|
||||||
|
|
||||||
|
bpy.ops.import_scene.gltf(filepath=input_path)
|
||||||
|
print("Imported GLB")
|
||||||
|
|
||||||
|
# Find the armature
|
||||||
|
armatures = [obj for obj in bpy.data.objects if obj.type == 'ARMATURE']
|
||||||
|
if not armatures:
|
||||||
|
print("ERROR: No armature found!")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
armature = armatures[0]
|
||||||
|
print(f"ARMature: {armature.name}, bones: {len(armature.data.bones)}")
|
||||||
|
|
||||||
|
# The key: we need to bake the animation with HIGH FPS and LARGE motion
|
||||||
|
# so the optimizer can't strip it.
|
||||||
|
|
||||||
|
bpy.context.view_layer.objects.active = armature
|
||||||
|
bpy.ops.object.mode_set(mode='POSE')
|
||||||
|
|
||||||
|
# Function to create an animation with PER-FRAME keyframes (can't be optimized away)
|
||||||
|
def create_anim_dense(name, bone_rotations_func, length_frames=60):
|
||||||
|
"""bone_rotations_func: callable(frame) -> dict of bone_name -> euler_tuple
|
||||||
|
Creates keyframes on EVERY frame to prevent Blender from optimizing."""
|
||||||
|
action = bpy.data.actions.new(name=name)
|
||||||
|
armature.animation_data.action = action
|
||||||
|
action.use_fake_user = True
|
||||||
|
|
||||||
|
for frame in range(1, length_frames + 1):
|
||||||
|
bpy.context.scene.frame_set(frame)
|
||||||
|
rotations = bone_rotations_func(frame, length_frames)
|
||||||
|
for bone_name, euler in rotations.items():
|
||||||
|
if bone_name in armature.pose.bones:
|
||||||
|
bone = armature.pose.bones[bone_name]
|
||||||
|
bone.rotation_mode = 'XYZ'
|
||||||
|
bone.rotation_euler = euler
|
||||||
|
bone.keyframe_insert(data_path="rotation_euler", frame=frame)
|
||||||
|
|
||||||
|
return action
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
|
# WALK: Per-frame keyframes (60 frames, 1 second)
|
||||||
|
def walk_fn(frame, length):
|
||||||
|
t = frame / length * math.pi * 2
|
||||||
|
return {
|
||||||
|
"LeftUpperLeg": (math.sin(t) * 1.0, 0, 0),
|
||||||
|
"RightUpperLeg": (math.sin(t + math.pi) * 1.0, 0, 0),
|
||||||
|
"LeftUpperArm": (math.sin(t + math.pi) * 0.7, 0, 0),
|
||||||
|
"RightUpperArm": (math.sin(t) * 0.7, 0, 0),
|
||||||
|
"Spine": (0, math.sin(t) * 0.2, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
create_anim_dense("Walk", walk_fn, 60)
|
||||||
|
print("Walk created (dense per-frame keyframes)")
|
||||||
|
|
||||||
|
# RUN: Faster (40 frames)
|
||||||
|
def run_fn(frame, length):
|
||||||
|
t = frame / length * math.pi * 2
|
||||||
|
return {
|
||||||
|
"LeftUpperLeg": (math.sin(t) * 1.3, 0, 0),
|
||||||
|
"RightUpperLeg": (math.sin(t + math.pi) * 1.3, 0, 0),
|
||||||
|
"LeftUpperArm": (math.sin(t + math.pi) * 1.0, 0, 0),
|
||||||
|
"RightUpperArm": (math.sin(t) * 1.0, 0, 0),
|
||||||
|
"Spine": (0, math.sin(t) * 0.3, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
create_anim_dense("Run", run_fn, 40)
|
||||||
|
print("Run created")
|
||||||
|
|
||||||
|
# JUMP: Single jump cycle (40 frames)
|
||||||
|
def jump_fn(frame, length):
|
||||||
|
t = frame / length
|
||||||
|
peak = max(0.0, 1.0 - abs(t - 0.5) * 3.0) # Sharp peak
|
||||||
|
return {
|
||||||
|
"LeftUpperArm": (-2.5 * peak, 0, -0.3 * peak),
|
||||||
|
"RightUpperArm": (-2.5 * peak, 0, 0.3 * peak),
|
||||||
|
"LeftUpperLeg": (-0.5 * peak, 0, 0),
|
||||||
|
"RightUpperLeg": (-0.5 * peak, 0, 0),
|
||||||
|
"Spine": (0.15 * peak, 0, 0),
|
||||||
|
"Hips": (0, 0.3 * peak, 0), # Bounce up
|
||||||
|
}
|
||||||
|
|
||||||
|
create_anim_dense("Jump", jump_fn, 40)
|
||||||
|
print("Jump created")
|
||||||
|
|
||||||
|
# IDLE: Gentle breathing (60 frames)
|
||||||
|
def idle_fn(frame, length):
|
||||||
|
t = frame / length * math.pi * 2
|
||||||
|
return {
|
||||||
|
"Spine": (0, math.sin(t) * 0.5, 0),
|
||||||
|
"Head": (math.sin(t * 0.7) * 0.15, math.sin(t * 0.5) * 0.1, 0),
|
||||||
|
"LeftUpperArm": (math.sin(t) * 0.2, 0, math.sin(t * 0.5) * 0.5),
|
||||||
|
"RightUpperArm": (math.sin(t) * 0.2, 0, -math.sin(t * 0.5) * 0.5),
|
||||||
|
"Hips": (0, math.sin(t) * 0.15, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
create_anim_dense("Idle", idle_fn, 60)
|
||||||
|
print("Idle created")
|
||||||
|
|
||||||
|
# Remove all C_001 duplicates and original stripped actions
|
||||||
|
for action in list(bpy.data.actions):
|
||||||
|
if action.use_fake_user:
|
||||||
|
# Rename to clean names
|
||||||
|
if action.name == "Walk.001":
|
||||||
|
action.name = "Walk"
|
||||||
|
elif action.name == "Run.001":
|
||||||
|
action.name = "Run"
|
||||||
|
elif action.name == "Jump.001":
|
||||||
|
action.name = "Jump"
|
||||||
|
elif action.name == "Idle.002":
|
||||||
|
action.name = "Idle"
|
||||||
|
else:
|
||||||
|
bpy.data.actions.remove(action)
|
||||||
|
|
||||||
|
print(f"Actions: {[a.name for a in bpy.data.actions if a.use_fake_user]}")
|
||||||
|
|
||||||
|
# CRITICAL: Export with animation sampling at high rate to prevent optimization
|
||||||
|
bpy.context.scene.render.fps = 60
|
||||||
|
|
||||||
|
bpy.ops.export_scene.gltf(
|
||||||
|
filepath=output_path,
|
||||||
|
export_format='GLB',
|
||||||
|
export_apply=True,
|
||||||
|
export_animations=True,
|
||||||
|
export_animation_mode='ACTIONS',
|
||||||
|
export_skins=True,
|
||||||
|
export_yup=True,
|
||||||
|
export_optimize_animation_size=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"\nExported to {output_path}")
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
bpy.ops.import_scene.gltf(filepath=output_path)
|
||||||
|
new_armatures = [obj for obj in bpy.data.objects if obj.type == 'ARMATURE']
|
||||||
|
if new_armatures:
|
||||||
|
new_ap = new_armatures[0]
|
||||||
|
new_ap.animation_data_create()
|
||||||
|
for action in bpy.data.actions:
|
||||||
|
if action.use_fake_user:
|
||||||
|
new_ap.animation_data.action = action
|
||||||
|
# Check motion
|
||||||
|
max_delta = max((action.frame_range[1] - action.frame_range[0]), 1)
|
||||||
|
# Check track count
|
||||||
|
track_count = len(action.fcurves) if hasattr(action, 'fcurves') else 0
|
||||||
|
print(f" {action.name}: {track_count} fcurves, {max_delta:.0f} frames")
|
||||||
|
|
||||||
|
print("Done!")
|
||||||
Reference in New Issue
Block a user