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
2 changes: 1 addition & 1 deletion doc/classes/CameraServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>
The [CameraServer] keeps track of different cameras accessible in Godot. These are external cameras such as webcams or the cameras on your phone.
It is notably used to provide AR modules with a video feed from the camera.
[b]Note:[/b] This class is currently only implemented on Linux, Android, macOS, and iOS. On other platforms no [CameraFeed]s will be available. To get a [CameraFeed] on iOS, the camera plugin from [url=https://github.com/godotengine/godot-ios-plugins]godot-ios-plugins[/url] is required.
[b]Note:[/b] This class is currently only implemented on Linux, Android, macOS, and iOS. On other platforms no [CameraFeed]s will be available. To get a [CameraFeed] on iOS, enable [member EditorExportPlatformIOS.modules/camera].
</description>
<tutorials>
</tutorials>
Expand Down
71 changes: 59 additions & 12 deletions editor/export/editor_export_platform_apple_embedded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ void EditorExportPlatformAppleEmbedded::get_export_options(List<ExportOption> *r
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/export_project_only"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/delete_old_export_files_unconditionally"), false));

r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "modules/camera"), false));

Vector<PluginConfigAppleEmbedded> found_plugins = get_plugins(get_platform_name());
for (int i = 0; i < found_plugins.size(); i++) {
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
Expand Down Expand Up @@ -1422,7 +1424,7 @@ Vector<String> EditorExportPlatformAppleEmbedded::_get_preset_architectures(cons
return enabled_archs;
}

Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &dest_dir, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug) {
Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &p_dest_dir, const Vector<String> &p_module_libs, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug) {
String plugin_definition_cpp_code;
String plugin_initialization_cpp_code;
String plugin_deinitialization_cpp_code;
Expand All @@ -1449,7 +1451,7 @@ Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Re
String plugin_binary_result_file = plugin.binary.get_file();
// We shouldn't embed .xcframework that contains static libraries.
// Static libraries are not embedded anyway.
err = _copy_asset(p_preset, dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
err = _copy_asset(p_preset, p_dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
ERR_FAIL_COND_V(err != OK, err);

// Adding dependencies.
Expand Down Expand Up @@ -1553,6 +1555,23 @@ Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Re
plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
}

for (const String &lib_name : p_module_libs) {
String definition_comment = "// Module: " + lib_name + "\n";
String initialization_method = "register_" + lib_name + "_external_module();\n";
String deinitialization_method = "unregister_" + lib_name + "_external_module();\n";

plugin_definition_cpp_code += definition_comment +
"extern void " + initialization_method +
"extern void " + deinitialization_method + "\n";

plugin_initialization_cpp_code += "\t" + initialization_method;
plugin_deinitialization_cpp_code += "\t" + deinitialization_method;

String binary_name = p_dest_dir.get_file().get_basename();
AppleEmbeddedExportAsset exported_asset = { binary_name + "_" + lib_name + ".xcframework", true, false };
r_exported_assets.push_back(exported_asset);
}

// Updating `Info.plist`
{
for (const KeyValue<String, String> &E : plist_values) {
Expand All @@ -1570,15 +1589,15 @@ Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Re
// Export files
{
// Export linked plugin dependency
err = _export_additional_assets(p_preset, dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
err = _export_additional_assets(p_preset, p_dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
ERR_FAIL_COND_V(err != OK, err);

// Export embedded plugin dependency
err = _export_additional_assets(p_preset, dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
err = _export_additional_assets(p_preset, p_dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
ERR_FAIL_COND_V(err != OK, err);

// Export plugin files
err = _export_additional_assets(p_preset, dest_dir, plugin_files, false, false, r_exported_assets);
err = _export_additional_assets(p_preset, p_dest_dir, plugin_files, false, false, r_exported_assets);
ERR_FAIL_COND_V(err != OK, err);
}

Expand Down Expand Up @@ -1765,6 +1784,10 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
}

String library_to_use = "libgodot." + get_platform_name() + "." + String(p_debug ? "debug" : "release") + ".xcframework";
Vector<String> module_libs;
if (p_preset->get("modules/camera").operator bool()) {
module_libs.push_back("camera");
}

print_line("Static framework: " + library_to_use);
String pkg_name;
Expand All @@ -1774,7 +1797,7 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
pkg_name = "Unnamed";
}

bool found_library = false;
int found_libraries = 0;

HashSet<String> files_to_parse;
const String project_file = "godot_apple_embedded.xcodeproj/project.pbxproj";
Expand Down Expand Up @@ -1821,7 +1844,7 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
return ERR_CANT_OPEN;
}

err = _export_apple_embedded_plugins(p_preset, config_data, binary_dir, assets, p_debug);
err = _export_apple_embedded_plugins(p_preset, config_data, binary_dir, module_libs, assets, p_debug);
if (err != OK) {
// TODO: Improve error reporting by using `add_message` throughout all methods called via `_export_apple_embedded_plugins`.
// For now a generic top level message would be fine, but we're ought to use proper reporting here instead of
Expand Down Expand Up @@ -1861,16 +1884,32 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor

if (files_to_parse.has(file)) {
_fix_config_file(p_preset, data, config_data, p_debug);
} else if (file.begins_with("libgodot." + get_platform_name())) {
if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
} else if (file.begins_with("libgodot") && file.contains(get_platform_name())) {
String prefix_lib = library_to_use;
String suffix_lib = binary_name;
bool is_lib = file.begins_with(library_to_use);
if (!is_lib) {
for (const String &lib_name : module_libs) {
String prefix = "libgodot_" + lib_name + "." + get_platform_name() + "." + String(p_debug ? "debug" : "release") + ".xcframework";
if (file.begins_with(prefix)) {
is_lib = true;
prefix_lib = prefix;
suffix_lib = binary_name + "_" + lib_name;
break;
}
}
}
if (!is_lib || file.ends_with(String("/empty"))) {
ret = unzGoToNextFile(src_pkg_zip);
continue; //ignore!
}
found_library = true;
if (file.ends_with("Info.plist")) {
found_libraries++;
}
#if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
is_execute = true;
#endif
file = file.replace(library_to_use, binary_name + ".xcframework");
file = file.replace(prefix_lib, suffix_lib + ".xcframework");
}

if (file == project_file) {
Expand Down Expand Up @@ -1924,7 +1963,7 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
// We're done with our source zip.
unzClose(src_pkg_zip);

if (!found_library) {
if (found_libraries < module_libs.size() + 1) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template library '%s' not found. It might be missing from your template archive."), library_to_use));
return ERR_FILE_NOT_FOUND;
}
Expand Down Expand Up @@ -2194,6 +2233,14 @@ bool EditorExportPlatformAppleEmbedded::has_valid_export_configuration(const Ref
valid = dvalid || rvalid;
r_missing_templates = !valid;

if (p_preset->get("modules/camera").operator bool()) {
String description = p_preset->get("privacy/camera_usage_description");
if (description.is_empty()) {
valid = false;
err += TTR("Camera module enabled, but camera usage description is not set.") + "\n";
}
}

const String &additional_plist_content = p_preset->get("application/additional_plist_content");
if (!additional_plist_content.is_empty()) {
const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Expand Down
2 changes: 1 addition & 1 deletion editor/export/editor_export_platform_apple_embedded.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class EditorExportPlatformAppleEmbedded : public EditorExportPlatform {
Error _export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets);
Error _copy_asset(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets);
Error _export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<AppleEmbeddedExportAsset> &r_exported_assets);
Error _export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &dest_dir, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug);
Error _export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &p_dest_dir, const Vector<String> &p_module_libs, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug);

Error _export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags, bool p_oneclick);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>xros-arm64</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>xros-arm64-simulator</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>xros-arm64</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>xros-arm64-simulator</string>
<key>LibraryPath</key>
<string>libgodot_camera.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file to make dylibs folder exported
10 changes: 8 additions & 2 deletions modules/camera/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ Import("env_modules")

env_camera = env_modules.Clone()

if env["platform"] in ["windows", "macos", "linuxbsd", "android"]:
if env["platform"] in ["windows", "macos", "linuxbsd", "android", "ios", "visionos"]:
env_camera.add_source_files(env.modules_sources, "register_types.cpp")

if env["platform"] == "windows":
env_camera.add_source_files(env.modules_sources, "camera_win.cpp")

elif env["platform"] == "macos":
env_camera.add_source_files(env.modules_sources, "camera_macos.mm")
env_camera.add_source_files(env.modules_sources, "camera_apple.mm")

elif env["platform"] == "android":
env_camera.add_source_files(env.modules_sources, "camera_android.cpp")
env.Append(LIBS=["camera2ndk", "mediandk"])

elif env["platform"] in ["ios", "visionos"]:
ext_module_source = ["camera_apple.mm"]
ext_camera_lib = env_camera.add_library("#bin/libgodot_camera", ext_module_source)
env.Append(LIBS_EXTERNAL=[ext_camera_lib])
env.Append(MODULES_EXTERNAL=["_camera"])

elif env["platform"] == "linuxbsd":
env_camera.add_source_files(env.modules_sources, "camera_linux.cpp")
env_camera.add_source_files(env.modules_sources, "camera_feed_linux.cpp")
Expand Down
Loading
Loading