Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Sources/UntoldEngine/Scenes/SceneSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1311,21 +1311,24 @@ public func serializeScene() -> SceneData {
var shouldApplyIBL = applyIBL

if hdrURL.isEmpty == false {
var hdrExists = false

// Check in user's asset base path (HDR folder)
if let basePath = assetBasePath {
let hdrPath = basePath.appendingPathComponent("HDR").appendingPathComponent(hdrURL)
hdrExists = FileManager.default.fileExists(atPath: hdrPath.path)
// Resolve through the same search LoadingSystem/generateHDR already use
// (assetBasePath/HDR, app bundle, engine bundle) rather than only checking
// assetBasePath/HDR directly. The active HDR may legitimately be one of the
// engine's built-in defaults (e.g. teatro_massimo_2k.hdr), which lives in the
// engine's resource bundle, not the project's asset folder -- checking only
// assetBasePath/HDR falsely reported those as "not found" and disabled IBL.
let nsName = hdrURL as NSString
let providedExtension = nsName.pathExtension
let candidates: [(base: String, ext: String)] = providedExtension.isEmpty
? ["hdr", "exr", "png"].map { (hdrURL, $0) }
: [(nsName.deletingPathExtension, providedExtension)]

let hdrExists = candidates.contains { candidate in
LoadingSystem.shared.resourceURL(forResource: candidate.base, withExtension: candidate.ext, subResource: nil) != nil
}

if !hdrExists {
Logger.logWarning(message: "[SceneSerializer] HDR file not found in assets: \(hdrURL), disabling IBL")
validatedHDR = nil
shouldApplyIBL = false
}
} else {
// No asset base path set, can't validate
Logger.logWarning(message: "[SceneSerializer] No asset base path set, cannot validate HDR")
if !hdrExists {
Logger.logWarning(message: "[SceneSerializer] HDR file not found in assets: \(hdrURL), disabling IBL")
validatedHDR = nil
shouldApplyIBL = false
}
Expand Down Expand Up @@ -1623,12 +1626,14 @@ public func deserializeScene(
hdrURL = hdr
} else {
hdrURL = ""
hdrDirectoryURL = nil
}
} else {
applyIBL = false
renderEnvironment = false
ambientIntensity = 0.4
hdrURL = ""
hdrDirectoryURL = nil
}

if let colorGrading = sceneData.colorGrading {
Expand Down
10 changes: 10 additions & 0 deletions Sources/UntoldEngine/Systems/LoadingSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ public func getResourceURL(resourceName: String, ext: String, subName: String?)

// Flat layout (no top-level "Assets")
var searchPaths: [[String]] = [
// Nested form (Models/<name>/<name>.<ext>) is checked first, then the flat
// form (Models/<name>.<ext>) the Editor's asset exporter actually writes --
// it cooks the runtime asset into the category root, beside the per-model
// support folder, rather than inside it. See RuntimeExportLocation.swift.
["Models", resourceName, "\(resourceName).\(ext)"],
["Models", "\(resourceName).\(ext)"],
["StreamModels", resourceName, "\(resourceName).\(ext)"],
["StreamModels", "\(resourceName).\(ext)"],
["Animations", resourceName, "\(resourceName).\(ext)"],
["Animations", "\(resourceName).\(ext)"],
["HDR", "\(resourceName).\(ext)"],
["Gaussians", "\(resourceName).\(ext)"],
["Scripts", "\(resourceName).\(ext)"],
Expand All @@ -132,8 +139,11 @@ public func getResourceURL(resourceName: String, ext: String, subName: String?)
// Then try structured subdirectories
let searchPaths: [[String]] = [
["Models", resourceName, "\(resourceName).\(ext)"],
["Models", "\(resourceName).\(ext)"],
["StreamModels", resourceName, "\(resourceName).\(ext)"],
["StreamModels", "\(resourceName).\(ext)"],
["Animations", resourceName, "\(resourceName).\(ext)"],
["Animations", "\(resourceName).\(ext)"],
["HDR", "\(resourceName).\(ext)"],
["Gaussians", "\(resourceName).\(ext)"],
["Scripts", "\(resourceName).\(ext)"],
Expand Down
6 changes: 5 additions & 1 deletion Sources/UntoldEngine/Utils/FuncUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private func makeHDRTexture(width: Int, height: Int, label: String) throws -> MT
1 + floorf(log2f(fmaxf(Float(width), Float(height))))
)

guard let texture = renderInfo.device.makeTexture(descriptor: descriptor) else {
guard let device = renderInfo.device, let texture = device.makeTexture(descriptor: descriptor) else {
throw LoadError.textureCreationFailed
}
texture.label = label
Expand Down Expand Up @@ -154,6 +154,10 @@ public func loadTexture(
}

public func loadImage(_ textureName: String, from directory: URL? = nil) throws -> URL {
guard !textureName.isEmpty else {
throw LoadError.urlCreationFailed(textureName)
}

if let directory {
let fileURL = directory.appendingPathComponent(textureName)
if FileManager.default.fileExists(atPath: fileURL.path) {
Expand Down
Loading