Implement cubemap skybox, multi-active skyboxes, and 2D scene backgrounds
- Server: Add SkyboxType + 6 CubeUrl fields to SkyboxDefinition entity - Server: EF migration AddSkyboxCubemapType - Server: GetSkyboxConfigResponse now returns array of all active skyboxes - Admin: SkyboxManagerPage supports Panoramic/AnimatedPanorama/Cubemap types, 6 face URL fields for cubemap, and independent per-skybox active toggle - Client: ContentCache fetches + caches skyboxes; adds get_random_skybox, get_skybox_bg_url, load_texture_async, apply_scene_background helpers - Client: game_screen replaces _fetch_skybox with ContentCache-based approach; adds _load_cubemap_skybox / _apply_cubemap_images / _apply_cubemap_material - Client: 12 2D scene scripts call ContentCache.apply_scene_background(self) in _ready() to replace solid-color backgrounds with CDN skybox images Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -340,7 +340,7 @@ func _setup_environment() -> void:
|
||||
_setup_live_skybox(env)
|
||||
"cdn":
|
||||
_setup_procedural_sky(env)
|
||||
_fetch_skybox()
|
||||
_apply_skybox_from_cache()
|
||||
_: # "off" or any unknown value
|
||||
_setup_procedural_sky(env)
|
||||
|
||||
@@ -410,7 +410,7 @@ func _on_skybox_setting_changed() -> void:
|
||||
_setup_live_skybox(env)
|
||||
"cdn":
|
||||
_setup_procedural_sky()
|
||||
_fetch_skybox()
|
||||
_apply_skybox_from_cache()
|
||||
_:
|
||||
_setup_procedural_sky()
|
||||
|
||||
@@ -517,30 +517,79 @@ func _clear_stars() -> void:
|
||||
|
||||
# ── CDN skybox helpers ─────────────────────────────────────────────────────────
|
||||
|
||||
func _fetch_skybox() -> void:
|
||||
Network.request("content.get_skybox_config", {},
|
||||
func(_type: String, resp: Variant) -> void:
|
||||
var d := resp as Dictionary
|
||||
# Use a Variant to safely detect null before treating as Dictionary.
|
||||
var skybox_raw : Variant = d.get("skybox", null)
|
||||
if skybox_raw == null or not skybox_raw is Dictionary:
|
||||
print("[GameScreen] No active skybox configured — keeping procedural sky.")
|
||||
return
|
||||
var skybox := skybox_raw as Dictionary
|
||||
var cdn_path : String = str(skybox.get("cdnPath", ""))
|
||||
var is_animated : bool = bool(skybox.get("isAnimated", false))
|
||||
var frame_count : int = int(skybox.get("frameCount", 1))
|
||||
var fps : float = float(skybox.get("fps", 24.0))
|
||||
if cdn_path.is_empty():
|
||||
push_warning("[GameScreen] Skybox has empty cdnPath — skipping.")
|
||||
return
|
||||
print("[GameScreen] Loading CDN skybox: animated=%s url=%s" % [is_animated, cdn_path])
|
||||
if is_animated:
|
||||
_load_animated_skybox(cdn_path, frame_count, fps)
|
||||
else:
|
||||
_load_static_skybox(cdn_path),
|
||||
func(code: String, msg: String) -> void:
|
||||
push_warning("[GameScreen] Skybox fetch failed — %s: %s" % [code, msg]))
|
||||
func _apply_skybox_from_cache() -> void:
|
||||
var skybox := ContentCache.get_random_skybox()
|
||||
if skybox.is_empty():
|
||||
print("[GameScreen] No active skybox — keeping procedural sky.")
|
||||
return
|
||||
var sky_type := str(skybox.get("type", "Panoramic"))
|
||||
print("[GameScreen] Applying skybox type=%s" % sky_type)
|
||||
if sky_type == "Cubemap":
|
||||
_load_cubemap_skybox(skybox)
|
||||
elif bool(skybox.get("isAnimated", false)) or sky_type == "AnimatedPanorama":
|
||||
_load_animated_skybox(
|
||||
str(skybox.get("cdnPath", "")),
|
||||
int(skybox.get("frameCount", 1)),
|
||||
float(skybox.get("fps", 24.0)))
|
||||
else:
|
||||
_load_static_skybox(str(skybox.get("cdnPath", "")))
|
||||
|
||||
func _load_cubemap_skybox(skybox: Dictionary) -> void:
|
||||
# Face order for Godot 4 Cubemap.create_from_images():
|
||||
# index 0=+X(Right) 1=-X(Left) 2=+Y(Top) 3=-Y(Bottom) 4=+Z(Front) 5=-Z(Back)
|
||||
var urls := [
|
||||
str(skybox.get("cubePxUrl", "")),
|
||||
str(skybox.get("cubeNxUrl", "")),
|
||||
str(skybox.get("cubePyUrl", "")),
|
||||
str(skybox.get("cubeNyUrl", "")),
|
||||
str(skybox.get("cubePzUrl", "")),
|
||||
str(skybox.get("cubeNzUrl", "")),
|
||||
]
|
||||
var images: Array = []
|
||||
images.resize(6)
|
||||
var pending := 6
|
||||
for i in 6:
|
||||
var idx := i
|
||||
var url := urls[idx]
|
||||
if url.is_empty():
|
||||
images[idx] = null
|
||||
pending -= 1
|
||||
if pending == 0:
|
||||
_apply_cubemap_images(images)
|
||||
continue
|
||||
ContentCache.load_texture_async(url, func(tex: Texture2D):
|
||||
images[idx] = tex.get_image() if tex != null else null
|
||||
pending -= 1
|
||||
if pending == 0:
|
||||
_apply_cubemap_images.call_deferred(images))
|
||||
|
||||
func _apply_cubemap_images(images: Array) -> void:
|
||||
for i in 6:
|
||||
if images[i] == null:
|
||||
var img := Image.create(1, 1, false, Image.FORMAT_RGB8)
|
||||
img.fill(Color.BLACK)
|
||||
images[i] = img
|
||||
else:
|
||||
(images[i] as Image).convert(Image.FORMAT_RGB8)
|
||||
var cubemap := Cubemap.new()
|
||||
cubemap.create_from_images(images)
|
||||
_apply_cubemap_material(cubemap)
|
||||
|
||||
func _apply_cubemap_material(cubemap: Cubemap) -> void:
|
||||
var shader := Shader.new()
|
||||
shader.code = """
|
||||
shader_type sky;
|
||||
uniform samplerCube environment : filter_linear, repeat_disable;
|
||||
void sky() { COLOR = texture(environment, EYEDIR).rgb; }
|
||||
"""
|
||||
var mat := ShaderMaterial.new()
|
||||
mat.shader = shader
|
||||
mat.set_shader_parameter("environment", cubemap)
|
||||
var sky := Sky.new()
|
||||
sky.sky_material = mat
|
||||
$WorldEnvironment.environment.sky = sky
|
||||
$WorldEnvironment.environment.background_mode = Environment.BG_SKY
|
||||
print("[GameScreen] Cubemap sky applied.")
|
||||
|
||||
func _load_static_skybox(url: String) -> void:
|
||||
var http := HTTPRequest.new()
|
||||
|
||||
Reference in New Issue
Block a user