diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-30 12:14:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-30 12:14:23 +0200 |
commit | 96d3270c344c7fe9a463b87006b0c56004128f6d (patch) | |
tree | 3479aa293c44f92cb3ead64f38e5b4b4885bfe7f /platform/iphone | |
parent | b4aba3ae7c89b7d236d3efab459fb89b33c91a3c (diff) | |
parent | d9cefb34c1dd825fcceb76d430ee7410349b6a12 (diff) |
Merge pull request #24227 from BastiaanOlij/arkit31
ARKit for Godot 3.2
Diffstat (limited to 'platform/iphone')
-rw-r--r-- | platform/iphone/camera_ios.h | 4 | ||||
-rw-r--r-- | platform/iphone/camera_ios.mm | 63 | ||||
-rw-r--r-- | platform/iphone/detect.py | 1 | ||||
-rw-r--r-- | platform/iphone/export/export.cpp | 29 | ||||
-rw-r--r-- | platform/iphone/gl_view.mm | 2 |
5 files changed, 55 insertions, 44 deletions
diff --git a/platform/iphone/camera_ios.h b/platform/iphone/camera_ios.h index cf747283e1..ceabdba6a3 100644 --- a/platform/iphone/camera_ios.h +++ b/platform/iphone/camera_ios.h @@ -31,12 +31,10 @@ #ifndef CAMERAIOS_H #define CAMERAIOS_H -///@TODO this is a near duplicate of CameraOSX, we should find a way to combine those to minimise code duplication!!!! -// If you fix something here, make sure you fix it there as wel! - #include "servers/camera_server.h" class CameraIOS : public CameraServer { +private: public: CameraIOS(); ~CameraIOS(); diff --git a/platform/iphone/camera_ios.mm b/platform/iphone/camera_ios.mm index 4c11701fdd..5a54eaee9b 100644 --- a/platform/iphone/camera_ios.mm +++ b/platform/iphone/camera_ios.mm @@ -241,7 +241,6 @@ class CameraFeedIOS : public CameraFeed { private: - bool is_arkit; // if true this feed is updated through ARKit (should only have one and not yet implemented) AVCaptureDevice *device; MyCaptureSession *capture_session; @@ -258,10 +257,6 @@ public: void deactivate_feed(); }; -bool CameraFeedIOS::get_is_arkit() const { - return is_arkit; -}; - AVCaptureDevice *CameraFeedIOS::get_device() const { return device; }; @@ -274,24 +269,16 @@ CameraFeedIOS::CameraFeedIOS() { void CameraFeedIOS::set_device(AVCaptureDevice *p_device) { device = p_device; - if (device == NULL) { - ///@TODO finish this! - is_arkit = true; - name = "ARKit"; + [device retain]; + + // get some info + NSString *device_name = p_device.localizedName; + name = device_name.UTF8String; + position = CameraFeed::FEED_UNSPECIFIED; + if ([p_device position] == AVCaptureDevicePositionBack) { position = CameraFeed::FEED_BACK; - } else { - is_arkit = false; - [device retain]; - - // get some info - NSString *device_name = p_device.localizedName; - name = device_name.UTF8String; - position = CameraFeed::FEED_UNSPECIFIED; - if ([p_device position] == AVCaptureDevicePositionBack) { - position = CameraFeed::FEED_BACK; - } else if ([p_device position] == AVCaptureDevicePositionFront) { - position = CameraFeed::FEED_FRONT; - }; + } else if ([p_device position] == AVCaptureDevicePositionFront) { + position = CameraFeed::FEED_FRONT; }; }; @@ -308,15 +295,11 @@ CameraFeedIOS::~CameraFeedIOS() { }; bool CameraFeedIOS::activate_feed() { - if (is_arkit) { - ///@TODO to implement; + if (capture_session) { + // already recording! } else { - if (capture_session) { - // already recording! - } else { - // start camera capture - capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device]; - }; + // start camera capture + capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device]; }; return true; @@ -376,14 +359,14 @@ void CameraIOS::update_feeds() { // this way of doing things is deprecated but still works, // rewrite to using AVCaptureDeviceDiscoverySession - AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeBuiltInTelephotoCamera, AVCaptureDeviceTypeBuiltInDualCamera, AVCaptureDeviceTypeBuiltInTrueDepthCamera] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; + AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeBuiltInTelephotoCamera, AVCaptureDeviceTypeBuiltInDualCamera, AVCaptureDeviceTypeBuiltInTrueDepthCamera, AVCaptureDeviceTypeBuiltInWideAngleCamera] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; // remove devices that are gone.. for (int i = feeds.size() - 1; i >= 0; i--) { - Ref<CameraFeedIOS> feed = (Ref<CameraFeedIOS>)feeds[i]; + Ref<CameraFeedIOS> feed(feeds[i]); - if (feed->get_is_arkit()) { - // ignore, this is our arkit entry + if (feed.is_null()) { + // feed not managed by us } else if (![session.devices containsObject:feed->get_device()]) { // remove it from our array, this will also destroy it ;) remove_feed(feed); @@ -393,9 +376,13 @@ void CameraIOS::update_feeds() { // add new devices.. for (AVCaptureDevice *device in session.devices) { bool found = false; + for (int i = 0; i < feeds.size() && !found; i++) { - Ref<CameraFeedIOS> feed = (Ref<CameraFeedIOS>)feeds[i]; - if (feed->get_device() == device) { + Ref<CameraFeedIOS> feed(feeds[i]); + + if (feed.is_null()) { + // feed not managed by us + } else if (feed->get_device() == device) { found = true; }; }; @@ -410,9 +397,13 @@ void CameraIOS::update_feeds() { }; CameraIOS::CameraIOS() { + print_line("Requesting Camera permissions"); + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if (granted) { + print_line("Access to cameras granted!"); + // Find available cameras we have at this time update_feeds(); diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py index daf4f405fd..b448cbe097 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -154,6 +154,7 @@ def configure(env): '-framework', 'Security', '-framework', 'SystemConfiguration', '-framework', 'UIKit', + '-framework', 'ARKit', ]) # Feature options diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index b2064472e4..a9daa6ea5f 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -95,7 +95,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { Vector<ExportArchitecture> _get_supported_architectures(); Vector<String> _get_preset_architectures(const Ref<EditorExportPreset> &p_preset); - void _add_assets_to_project(Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets); + void _add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets); Error _export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, Vector<IOSExportAsset> &r_exported_assets); Error _export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets); @@ -656,7 +656,7 @@ struct ExportLibsData { String dest_dir; }; -void EditorExportPlatformIOS::_add_assets_to_project(Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) { +void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) { Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins(); Vector<String> frameworks; for (int i = 0; i < export_plugins.size(); ++i) { @@ -714,7 +714,28 @@ void EditorExportPlatformIOS::_add_assets_to_project(Vector<uint8_t> &p_project_ // Note, frameworks like gamekit are always included in our project.pbxprof file // even if turned off in capabilities. - // Frameworks that are used by modules (like arkit) we may need to optionally add here. + + // We do need our ARKit framework + if ((bool)p_preset->get("capabilities/arkit")) { + String build_id = (++current_id).str(); + String ref_id = (++current_id).str(); + + if (pbx_frameworks_build.length() > 0) { + pbx_frameworks_build += ",\n"; + pbx_frameworks_refs += ",\n"; + } + + pbx_frameworks_build += build_id; + pbx_frameworks_refs += ref_id; + + Dictionary format_dict; + format_dict["build_id"] = build_id; + format_dict["ref_id"] = ref_id; + format_dict["name"] = "ARKit.framework"; + format_dict["file_path"] = "System/Library/Frameworks/ARKit.framework"; + format_dict["file_type"] = "wrapper.framework"; + pbx_files += file_info_format.format(format_dict, "$_"); + } String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size()); str = str.replace("$additional_pbx_files", pbx_files); @@ -1045,7 +1066,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p print_line("Exporting additional assets"); Vector<IOSExportAsset> assets; _export_additional_assets(dest_dir + binary_name, libraries, assets); - _add_assets_to_project(project_file_data, assets); + _add_assets_to_project(p_preset, project_file_data, assets); String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj"; FileAccess *f = FileAccess::open(project_file_name, FileAccess::WRITE); if (!f) { diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 1cb8d0e44e..4641b2c4ac 100644 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -494,7 +494,7 @@ static void clear_touches() { #ifdef DEBUG_ENABLED GLenum err = glGetError(); if (err) - NSLog(@"%x error", err); + NSLog(@"DrawView: %x error", err); #endif } |