Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

visionOS export: Share app-icon export across Apple embedded platforms; add layered visionOS icon support

Ricardo Sanchez-Saezf9fbcd095912
diff --git a/editor/export/editor_export_platform_apple_embedded.cpp b/editor/export/editor_export_platform_apple_embedded.cpp
index 40563d6e341..a4bf05ea8c6 100644
--- a/editor/export/editor_export_platform_apple_embedded.cpp
+++ b/editor/export/editor_export_platform_apple_embedded.cpp
@@ -2125,7 +2125,7 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
}
}
- String iconset_dir = binary_dir + "/Images.xcassets/AppIcon.appiconset/";
+ String iconset_dir = binary_dir + "/Images.xcassets/" + _get_iconset_dir_name() + "/";
err = OK;
if (!tmp_app_path->dir_exists(iconset_dir)) {
err = tmp_app_path->make_dir_recursive(iconset_dir);
@@ -2353,6 +2353,162 @@ bool EditorExportPlatformAppleEmbedded::has_valid_export_configuration(const Ref
#endif // !(MODULE_MONO_ENABLED && !MACOS_ENABLED)
}
+Error EditorExportPlatformAppleEmbedded::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
+ String json_description = "{\"images\":[";
+ String sizes;
+
+ Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
+ if (da.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not open a directory at path \"%s\"."), p_iconset_dir));
+ return ERR_CANT_OPEN;
+ }
+
+ Color boot_bg_color = get_project_setting(p_preset, "application/boot_splash/bg_color");
+
+ enum IconColorMode {
+ ICON_NORMAL,
+ ICON_DARK,
+ ICON_TINTED,
+ ICON_MAX,
+ };
+
+ Vector<IconInfo> icon_infos = get_icon_infos();
+ bool first_icon = true;
+ for (int i = 0; i < icon_infos.size(); ++i) {
+ for (int color_mode = ICON_NORMAL; color_mode < ICON_MAX; color_mode++) {
+ IconInfo info = icon_infos[i];
+ int side_size = String(info.actual_size_side).to_int();
+ String key = info.preset_key;
+ String exp_name = info.export_name;
+ if (color_mode == ICON_DARK) {
+ key += "_dark";
+ exp_name += "_dark";
+ } else if (color_mode == ICON_TINTED) {
+ key += "_tinted";
+ exp_name += "_tinted";
+ }
+ exp_name += ".png";
+ String icon_path = p_preset->get(key);
+ bool resize_waning = true;
+ if (icon_path.is_empty()) {
+ // Load and resize base icon.
+ key = "icons/icon_1024x1024";
+ if (color_mode == ICON_DARK) {
+ key += "_dark";
+ } else if (color_mode == ICON_TINTED) {
+ key += "_tinted";
+ }
+ icon_path = p_preset->get(key);
+ resize_waning = false;
+ }
+ if (icon_path.is_empty()) {
+ if (color_mode != ICON_NORMAL) {
+ continue;
+ }
+ // Resize main app icon.
+ icon_path = get_project_setting(p_preset, "application/config/icon");
+ Error err = OK;
+ Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
+ if (err != OK || img.is_null() || img->is_empty()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
+ return ERR_UNCONFIGURED;
+ } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
+ img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
+ Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
+ new_img->fill(boot_bg_color);
+ _blend_and_rotate(new_img, img, false);
+ err = new_img->save_png(p_iconset_dir + exp_name);
+ } else {
+ img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
+ err = img->save_png(p_iconset_dir + exp_name);
+ }
+ if (err) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
+ return err;
+ }
+ } else {
+ // Load custom icon and resize if required.
+ Error err = OK;
+ Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
+ if (err != OK || img.is_null() || img->is_empty()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
+ return ERR_UNCONFIGURED;
+ } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
+ if (resize_waning) {
+ add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
+ }
+ img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
+ Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
+ new_img->fill(boot_bg_color);
+ _blend_and_rotate(new_img, img, false);
+ err = new_img->save_png(p_iconset_dir + exp_name);
+ } else if (img->get_width() != side_size || img->get_height() != side_size) {
+ if (resize_waning) {
+ add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s): '%s' has incorrect size %s and was automatically resized to %s.", info.preset_key, icon_path, img->get_size(), Vector2i(side_size, side_size)));
+ }
+ img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
+ err = img->save_png(p_iconset_dir + exp_name);
+ } else if (!icon_path.ends_with(".png")) {
+ err = img->save_png(p_iconset_dir + exp_name);
+ } else {
+ err = da->copy(icon_path, p_iconset_dir + exp_name);
+ }
+
+ if (err) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
+ return err;
+ }
+ }
+ sizes += String(info.actual_size_side) + "\n";
+ if (first_icon) {
+ first_icon = false;
+ } else {
+ json_description += ",";
+ }
+ json_description += String("{");
+ if (color_mode != ICON_NORMAL) {
+ json_description += String("\"appearances\":[{");
+ json_description += String("\"appearance\":\"luminosity\",");
+ if (color_mode == ICON_DARK) {
+ json_description += String("\"value\":\"dark\"");
+ } else if (color_mode == ICON_TINTED) {
+ json_description += String("\"value\":\"tinted\"");
+ }
+ json_description += String("}],");
+ }
+ json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
+ json_description += String("\"platform\":\"" + get_platform_name() + "\",");
+ json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
+ if (String(info.scale) != "1x") {
+ json_description += String("\"scale\":") + "\"" + info.scale + "\",";
+ }
+ json_description += String("\"filename\":") + "\"" + exp_name + "\"";
+ json_description += String("}");
+ }
+ }
+ json_description += "],\"info\":{\"author\":\"xcode\",\"version\":1}}";
+
+ Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
+ if (json_file.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json"));
+ return ERR_CANT_CREATE;
+ }
+
+ CharString json_utf8 = json_description.utf8();
+ json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
+
+ Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
+ if (sizes_file.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "sizes"));
+ return ERR_CANT_CREATE;
+ }
+
+ CharString sizes_utf8 = sizes.utf8();
+ sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
+
+ return OK;
+}
+
bool EditorExportPlatformAppleEmbedded::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
String err;
bool valid = true;
diff --git a/editor/export/editor_export_platform_apple_embedded.h b/editor/export/editor_export_platform_apple_embedded.h
index 55156f975f5..3437f0dba25 100644
--- a/editor/export/editor_export_platform_apple_embedded.h
+++ b/editor/export/editor_export_platform_apple_embedded.h
@@ -214,7 +214,10 @@ protected:
void _blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot);
virtual Error _export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) { return OK; }
- virtual Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) { return OK; }
+ virtual Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir);
+
+ // Asset-catalog dir name under Images.xcassets. visionOS overrides for layered icons.
+ virtual String _get_iconset_dir_name() const { return "AppIcon.appiconset"; }
virtual String get_platform_name() const = 0;
virtual String get_sdk_name() const = 0;
diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp
index ff407b8c812..9e3b0b55654 100644
--- a/platform/ios/export/export_plugin.cpp
+++ b/platform/ios/export/export_plugin.cpp
@@ -230,162 +230,6 @@ Vector<EditorExportPlatformAppleEmbedded::IconInfo> EditorExportPlatformIOS::get
};
}
-Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
- String json_description = "{\"images\":[";
- String sizes;
-
- Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
- if (da.is_null()) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not open a directory at path \"%s\"."), p_iconset_dir));
- return ERR_CANT_OPEN;
- }
-
- Color boot_bg_color = get_project_setting(p_preset, "application/boot_splash/bg_color");
-
- enum IconColorMode {
- ICON_NORMAL,
- ICON_DARK,
- ICON_TINTED,
- ICON_MAX,
- };
-
- Vector<IconInfo> icon_infos = get_icon_infos();
- bool first_icon = true;
- for (int i = 0; i < icon_infos.size(); ++i) {
- for (int color_mode = ICON_NORMAL; color_mode < ICON_MAX; color_mode++) {
- IconInfo info = icon_infos[i];
- int side_size = String(info.actual_size_side).to_int();
- String key = info.preset_key;
- String exp_name = info.export_name;
- if (color_mode == ICON_DARK) {
- key += "_dark";
- exp_name += "_dark";
- } else if (color_mode == ICON_TINTED) {
- key += "_tinted";
- exp_name += "_tinted";
- }
- exp_name += ".png";
- String icon_path = p_preset->get(key);
- bool resize_waning = true;
- if (icon_path.is_empty()) {
- // Load and resize base icon.
- key = "icons/icon_1024x1024";
- if (color_mode == ICON_DARK) {
- key += "_dark";
- } else if (color_mode == ICON_TINTED) {
- key += "_tinted";
- }
- icon_path = p_preset->get(key);
- resize_waning = false;
- }
- if (icon_path.is_empty()) {
- if (color_mode != ICON_NORMAL) {
- continue;
- }
- // Resize main app icon.
- icon_path = get_project_setting(p_preset, "application/config/icon");
- Error err = OK;
- Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
- if (err != OK || img.is_null() || img->is_empty()) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
- return ERR_UNCONFIGURED;
- } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
- img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
- Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
- new_img->fill(boot_bg_color);
- _blend_and_rotate(new_img, img, false);
- err = new_img->save_png(p_iconset_dir + exp_name);
- } else {
- img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
- err = img->save_png(p_iconset_dir + exp_name);
- }
- if (err) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
- return err;
- }
- } else {
- // Load custom icon and resize if required.
- Error err = OK;
- Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
- if (err != OK || img.is_null() || img->is_empty()) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
- return ERR_UNCONFIGURED;
- } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
- if (resize_waning) {
- add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
- }
- img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
- Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
- new_img->fill(boot_bg_color);
- _blend_and_rotate(new_img, img, false);
- err = new_img->save_png(p_iconset_dir + exp_name);
- } else if (img->get_width() != side_size || img->get_height() != side_size) {
- if (resize_waning) {
- add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s): '%s' has incorrect size %s and was automatically resized to %s.", info.preset_key, icon_path, img->get_size(), Vector2i(side_size, side_size)));
- }
- img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
- err = img->save_png(p_iconset_dir + exp_name);
- } else if (!icon_path.ends_with(".png")) {
- err = img->save_png(p_iconset_dir + exp_name);
- } else {
- err = da->copy(icon_path, p_iconset_dir + exp_name);
- }
-
- if (err) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
- return err;
- }
- }
- sizes += String(info.actual_size_side) + "\n";
- if (first_icon) {
- first_icon = false;
- } else {
- json_description += ",";
- }
- json_description += String("{");
- if (color_mode != ICON_NORMAL) {
- json_description += String("\"appearances\":[{");
- json_description += String("\"appearance\":\"luminosity\",");
- if (color_mode == ICON_DARK) {
- json_description += String("\"value\":\"dark\"");
- } else if (color_mode == ICON_TINTED) {
- json_description += String("\"value\":\"tinted\"");
- }
- json_description += String("}],");
- }
- json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
- json_description += String("\"platform\":\"" + get_platform_name() + "\",");
- json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
- if (String(info.scale) != "1x") {
- json_description += String("\"scale\":") + "\"" + info.scale + "\",";
- }
- json_description += String("\"filename\":") + "\"" + exp_name + "\"";
- json_description += String("}");
- }
- }
- json_description += "],\"info\":{\"author\":\"xcode\",\"version\":1}}";
-
- Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
- if (json_file.is_null()) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json"));
- return ERR_CANT_CREATE;
- }
-
- CharString json_utf8 = json_description.utf8();
- json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
-
- Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
- if (sizes_file.is_null()) {
- add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "sizes"));
- return ERR_CANT_CREATE;
- }
-
- CharString sizes_utf8 = sizes.utf8();
- sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
-
- return OK;
-}
-
String EditorExportPlatformIOS::_process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing) {
// Do iOS specific processing first, and call super implementation if there are no matches
diff --git a/platform/ios/export/export_plugin.h b/platform/ios/export/export_plugin.h
index 6758f0333a1..103ce1c7096 100644
--- a/platform/ios/export/export_plugin.h
+++ b/platform/ios/export/export_plugin.h
@@ -49,7 +49,6 @@ class EditorExportPlatformIOS : public EditorExportPlatformAppleEmbedded {
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
virtual Error _export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) override;
- virtual Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) override;
virtual HashMap<String, Variant> get_custom_project_settings(const Ref<EditorExportPreset> &p_preset) const override;
virtual String _process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing) override;
diff --git a/platform/visionos/doc_classes/EditorExportPlatformVisionOS.xml b/platform/visionos/doc_classes/EditorExportPlatformVisionOS.xml
index 4737e38b7bf..204ad2fc27d 100644
--- a/platform/visionos/doc_classes/EditorExportPlatformVisionOS.xml
+++ b/platform/visionos/doc_classes/EditorExportPlatformVisionOS.xml
@@ -127,6 +127,15 @@
<member name="icons/icon_1024x1024_tinted" type="String" setter="" getter="">
Base application icon used to generate other icons, tinted version. See [url=https://developer.apple.com/design/human-interface-guidelines/foundations/app-icons]App icons[/url].
</member>
+ <member name="icons/icon_back_layer_1024x1024" type="String" setter="" getter="">
+ Back layer of the visionOS app icon. visionOS app icons are composed of three stacked layers (front/middle/back) rendered with parallax. Should be a 1024x1024 image. See [url=https://developer.apple.com/design/human-interface-guidelines/app-icons]App icons[/url].
+ </member>
+ <member name="icons/icon_front_layer_1024x1024" type="String" setter="" getter="">
+ Front layer of the visionOS app icon. Should be a 1024x1024 image. Falls back to [member icons/icon_1024x1024], then [member ProjectSettings.application/config/icon] when empty. See [url=https://developer.apple.com/design/human-interface-guidelines/app-icons]App icons[/url].
+ </member>
+ <member name="icons/icon_middle_layer_1024x1024" type="String" setter="" getter="">
+ Middle layer of the visionOS app icon. Should be a 1024x1024 image. See [url=https://developer.apple.com/design/human-interface-guidelines/app-icons]App icons[/url].
+ </member>
<member name="modules/camera" type="bool" setter="" getter="">
If [code]true[/code], [CameraServer] module is added to the exported project.
</member>
diff --git a/platform/visionos/export/export_plugin.cpp b/platform/visionos/export/export_plugin.cpp
index 12482b8c69b..eca8b9c4d66 100644
--- a/platform/visionos/export/export_plugin.cpp
+++ b/platform/visionos/export/export_plugin.cpp
@@ -59,12 +59,134 @@ void EditorExportPlatformVisionOS::get_export_options(List<ExportOption> *r_opti
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/app_role", PROPERTY_HINT_ENUM, "Window,Immersive"), 0));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/immersion_style", PROPERTY_HINT_ENUM, "Full,Mixed"), 1));
+
+ // Front layer falls back to the project icon; middle/back use a black placeholder when unset.
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_front_layer_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_middle_layer_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_back_layer_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
}
Vector<EditorExportPlatformAppleEmbedded::IconInfo> EditorExportPlatformVisionOS::get_icon_infos() const {
+ // Layered icons don't fit IconInfo; _export_icons emits them directly.
return Vector<EditorExportPlatformAppleEmbedded::IconInfo>();
}
+Error EditorExportPlatformVisionOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
+ // AppIcon.solidimagestack/<Layer>.solidimagestacklayer/Content.imageset/<layer>.png
+
+ struct LayerInfo {
+ const char *name;
+ const char *preset_key;
+ bool fallback_to_project_icon;
+ };
+ const LayerInfo layers[] = {
+ { "Front", "icons/icon_front_layer_1024x1024", true },
+ { "Middle", "icons/icon_middle_layer_1024x1024", false },
+ { "Back", "icons/icon_back_layer_1024x1024", false },
+ };
+ constexpr int LAYER_SIDE = 1024;
+
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ if (da.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), TTR("Could not access the filesystem."));
+ return ERR_CANT_CREATE;
+ }
+
+ String stack_json = "{\"info\":{\"author\":\"xcode\",\"version\":1},\"layers\":[";
+ for (int i = 0; i < 3; i++) {
+ if (i > 0) {
+ stack_json += ",";
+ }
+ stack_json += String("{\"filename\":\"") + layers[i].name + ".solidimagestacklayer\"}";
+ }
+ stack_json += "]}";
+
+ {
+ Ref<FileAccess> f = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
+ if (f.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json"));
+ return ERR_CANT_CREATE;
+ }
+ CharString utf8 = stack_json.utf8();
+ f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length());
+ }
+
+ const String layer_metadata_json = "{\"info\":{\"author\":\"xcode\",\"version\":1}}";
+ const Image::Interpolation interpolation = (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int());
+
+ for (int i = 0; i < 3; i++) {
+ const String layer_dir = p_iconset_dir + layers[i].name + ".solidimagestacklayer/";
+ const String imageset_dir = layer_dir + "Content.imageset/";
+ const String png_name = String(layers[i].name).to_lower() + ".png";
+
+ Error err = da->make_dir_recursive(imageset_dir);
+ if (err != OK) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not create a directory at path \"%s\"."), imageset_dir));
+ return err;
+ }
+
+ // Front layer falls back to the iOS or project icon if missing.
+ String icon_path = p_preset->get(layers[i].preset_key);
+ bool warn_on_resize = true;
+ if (icon_path.is_empty() && layers[i].fallback_to_project_icon) {
+ icon_path = p_preset->get("icons/icon_1024x1024");
+ warn_on_resize = false;
+ }
+ if (icon_path.is_empty() && layers[i].fallback_to_project_icon) {
+ icon_path = get_project_setting(p_preset, "application/config/icon");
+ warn_on_resize = false;
+ }
+
+ Ref<Image> img;
+ if (icon_path.is_empty()) {
+ // All layers fall back to a full-size opaque-black placeholder if missing.
+ img = Image::create_empty(LAYER_SIDE, LAYER_SIDE, false, Image::FORMAT_RGBA8);
+ img->fill(Color(0, 0, 0, 1));
+ } else {
+ img = _load_icon_or_splash_image(icon_path, &err);
+ if (err != OK || img.is_null() || img->is_empty()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", layers[i].preset_key, icon_path));
+ return ERR_UNCONFIGURED;
+ }
+ if (img->get_width() != LAYER_SIDE || img->get_height() != LAYER_SIDE) {
+ if (warn_on_resize) {
+ add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s): '%s' has incorrect size %s and was automatically resized to %s.", layers[i].preset_key, icon_path, img->get_size(), Vector2i(LAYER_SIDE, LAYER_SIDE)));
+ }
+ img->resize(LAYER_SIDE, LAYER_SIDE, interpolation);
+ }
+ }
+
+ err = img->save_png(imageset_dir + png_name);
+ if (err != OK) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", layers[i].preset_key, icon_path));
+ return err;
+ }
+
+ {
+ Ref<FileAccess> f = FileAccess::open(layer_dir + "Contents.json", FileAccess::WRITE);
+ if (f.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), layer_dir + "Contents.json"));
+ return ERR_CANT_CREATE;
+ }
+ CharString utf8 = layer_metadata_json.utf8();
+ f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length());
+ }
+
+ {
+ String imageset_json = "{\"images\":[{\"filename\":\"" + png_name + "\",\"idiom\":\"vision\",\"scale\":\"2x\"}],\"info\":{\"author\":\"xcode\",\"version\":1}}";
+ Ref<FileAccess> f = FileAccess::open(imageset_dir + "Contents.json", FileAccess::WRITE);
+ if (f.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), imageset_dir + "Contents.json"));
+ return ERR_CANT_CREATE;
+ }
+ CharString utf8 = imageset_json.utf8();
+ f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length());
+ }
+ }
+
+ return OK;
+}
+
String EditorExportPlatformVisionOS::_process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing) {
// Do visionOS specific processing first, and call super implementation if there are no matches
diff --git a/platform/visionos/export/export_plugin.h b/platform/visionos/export/export_plugin.h
index 7535710089c..91da9e8a5af 100644
--- a/platform/visionos/export/export_plugin.h
+++ b/platform/visionos/export/export_plugin.h
@@ -45,6 +45,10 @@ class EditorExportPlatformVisionOS : public EditorExportPlatformAppleEmbedded {
virtual Vector<EditorExportPlatformAppleEmbedded::IconInfo> get_icon_infos() const override;
+ // visionOS uses a layered .solidimagestack with three .solidimagestacklayer dirs.
+ virtual String _get_iconset_dir_name() const override { return "AppIcon.solidimagestack"; }
+ virtual Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) override;
+
virtual void get_export_options(List<ExportOption> *r_options) const override;
virtual String _process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing) override;