Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARKit for Godot 3.2 #24227

Merged
merged 1 commit into from Jun 30, 2019
Merged

ARKit for Godot 3.2 #24227

merged 1 commit into from Jun 30, 2019

Conversation

BastiaanOlij
Copy link
Contributor

@BastiaanOlij BastiaanOlij commented Dec 8, 2018

This PR sees the introduction of our ARKit interface on iOS. All the basic functionality now works. There is some polish needed most likely but....

Anyway this does need a proper example project, there is a simple test project that you can find here: https://github.com/BastiaanOlij/godot3_test_projects/tree/ARKit/ARKit

Since the class is only available on iOS its also not part of the documentation, I need to have a look into working around that. I might just include the class but strip out the code when not compiling for iOS

Todos:

  • make a proper solution for dealing with the dependency on iOS 11 (or make that the minimum iOS for Godot?)
  • implement a reflection probe implementation that uses the interface added to ARKit 2.0 to get real world reflections in materials (possibly for later)

Note that this PR includes the Camera server PR and BzztBombs PR. They should probably be merged first before merging this.

@BastiaanOlij
Copy link
Contributor Author

I'm not sure why Github decided to auto request all the reviews btw :)

@groud
Copy link
Member

groud commented Dec 8, 2018

We use Github's file owners feature. It automatically asks review for PR that changes a of "owned" files.

@akien-mga akien-mga added this to the 3.2 milestone Dec 9, 2018
@BastiaanOlij
Copy link
Contributor Author

Loads of thanks to Arjen van Staalduinen who's been testing this on an iPad and emailing me patches to apply. I've not been able to test it out myself due to some hardware issues but this is really starting to work well by the looks of what Arjen has been doing.

@BastiaanOlij
Copy link
Contributor Author

Todos that are left:

  • pretty up some code, there are a few shortcuts in there.
  • add code that prevents iOS 11.0 code running on older devices
  • look into ARKit 2.0 enhancements.

@BastiaanOlij
Copy link
Contributor Author

Ok, important bit of information we'll eventually need to add into the docs :)

Godot has the ability to fix the orientation for mobile apps with the default set to landscape:
project settings

ArKit does work best with a fixed orientation so this default works best but you can change it to sensor to have the 2D part of the UI match the orientation of the iPhone/iPad.

Whichever you chose, you have to make sure that your xcode setting match else Godot will fix the orientation but ArKit will keep adjusting its orientation with some really funky results. So if you stick to the landscape default make sure your xcode project settings are as follows:
xcode settings

@BastiaanOlij BastiaanOlij requested a review from a team as a code owner January 27, 2019 12:32
Copy link
Member

@cbscribe cbscribe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting & style changes.

doc/classes/CameraServer.xml Outdated Show resolved Hide resolved
doc/classes/CameraServer.xml Outdated Show resolved Hide resolved
doc/classes/CameraServer.xml Outdated Show resolved Hide resolved
doc/classes/Environment.xml Outdated Show resolved Hide resolved
doc/classes/Environment.xml Outdated Show resolved Hide resolved
@BastiaanOlij
Copy link
Contributor Author

@cbscribe forgot to do the fixups sorry, need to do those as part of #10643

@BastiaanOlij
Copy link
Contributor Author

Ok, I'm moving ARKit into a module, easier to turn it on/off. Haven't finished moving it completely yet. Still WIP :)

// Note, this also contains a scale factor which gives us an idea of the size of the anchor
// We may extract that in our ARVRAnchor class
Basis b;
matrix_float4x4 m44 = anchor.transform;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are begging for a static inline helper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, yeah it can be cleaned up a bit, I'll be doing that at the end when everything is working fine. I have a feeling there will be more changes here :)

@BastiaanOlij
Copy link
Contributor Author

Just rebased this and made a few small changes. I'm trying to make the focus in/focus out logic for pausing ARKit go through _notification as the notification system is being called for this but unsuccessfully so far. I'm guessing because ARVR Interfaces aren't nodes but more basic objects. Could use some help with solving this better (also impacts ARCore). @reduz any suggestions here?

Copy link
Contributor

@samgreen samgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the relevant iOS portions. Everything looks good, but I can't quite understand the camera session stuff. It seems like we're duplicating some work that already exists in a more optimized fashion. Would love your input on this as I probably missed something.

drivers/gles3/rasterizer_storage_gles3.cpp Outdated Show resolved Hide resolved
drivers/gles3/shaders/ycbcr.glsl Outdated Show resolved Hide resolved
modules/arkit/arkit_interface.mm Outdated Show resolved Hide resolved
modules/arkit/arkit_interface.mm Outdated Show resolved Hide resolved
if (plane_detection_is_enabled != p_enable) {
plane_detection_is_enabled = p_enable;

// Restart our session (this will be ignore if we're not initialised)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says initalised but the code reads session_was_started. Which is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me come back to you on that one once I have a moment to catch up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so this is some weirdness around how phones work, it doesn't work fully yet because I haven't got notifications to work properly just yet.

Anyway, the problem lies around an app becoming dormant when you switch away from it. Basically ARKit needs to be doing its thing when you've initialized it AND we have focus.

So if ARKit is initialized before we obtain focus, we initialize ARKit but we don't start the session. Then when we obtain focus start_session is called and we start our ARKit session.
If we obtain focus before ARKit is initialized start_session is called but initialize is false so we don't do anything more, the session_was_started ensures that once we initialize we also setup the ARKit session.

If at any time after this has all been setup we loose focus stop_session is called and we simply pause our ARKit session and unpause it in start_session once focus is regained (the unpauze is actually a reinitialize as settings on the phone may have changed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should either hook the appDidResignActive and appDidBecomeActive events from iOS, or if we should hoist them up to Godot and provide other notifications for the window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are now hooked up, these result in FOCUS IN and FOCUS OUT notifications and after I managed to get notifications to work with the ARVRServer the other day and that change was merged in, should now work with ARKit :)

b.elements[1].z = m44.columns[2][1];
b.elements[2].z = m44.columns[2][2];
tracker->set_orientation(b);
tracker->set_rw_position(Vector3(m44.columns[3][0], m44.columns[3][1], m44.columns[3][2]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're missing the scale in the transform here, Won't that prevent ARKit from resizing the generated surface to match the environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is why we have set_rw_position (rw as in real world), the scale is applied later. This so that if the position of an anchor doesn't change, but you change the scale, we still get everything positioned correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, now that I think of it, we do need to apply our scale to the mesh somehow or it will have the wrong size, need to think that one through... That might need to be solved in the anchor.tscn

modules/arkit/arkit_interface.mm Show resolved Hide resolved
modules/arkit/arkit_session_delegate.h Show resolved Hide resolved
platform/iphone/camera_ios.mm Outdated Show resolved Hide resolved
platform/iphone/detect.py Outdated Show resolved Hide resolved
@BastiaanOlij
Copy link
Contributor Author

BastiaanOlij commented Apr 18, 2019 via email

@akien-mga akien-mga removed the request for review from reduz April 30, 2019 13:00
@BastiaanOlij BastiaanOlij changed the title [WIP] ARKit for Godot 3.1 ARKit for Godot 3.1 May 17, 2019
@BastiaanOlij
Copy link
Contributor Author

Forgot my dongle to attach my phone so I can't test this latest rebase but it compiles fine. Will test on Monday or hear back from one of the other if it still works.

I've removed WIP from this because I feel this is pretty much done but bug fixing and polish.

Before we can merge this however we do need to first approve and merge PR #10643
This also includes BzztBomb PR but we can remove that if it holds back merging as BzztBomb was going to do some more changes.

The only real question mark for this PR is around iOS versions, ARKit has a minimum of iOS 11 and a few of the newer functions in ARKit 2.0 need an even more up to date version of iOS.

The other thing that needs to improve but which we might want to handle separately is including the ARKit framework automatically on export.

@BastiaanOlij BastiaanOlij changed the title ARKit for Godot 3.1 ARKit for Godot 3.2 May 17, 2019
@BastiaanOlij
Copy link
Contributor Author

Just rebased this, things run on my phone but having some issues still with the shadow thing, not sure why yet, still looking into it

@BastiaanOlij
Copy link
Contributor Author

Just rebased, need to spend a few more hours cleaning stuff up and fixing the export so the arkit framework is added into the build settings.

@form-follows-function
Copy link

This compiled successfully for me, but I can't export to iOS as Godot is reporting damaged export templates. How to fix that?

@BastiaanOlij
Copy link
Contributor Author

@form-follows-function I did a video on the process: https://www.youtube.com/watch?v=6NEonfH1ME0
you need to create your own template using the files in misc/dist/ios_xcode and the binary you compiled.

That said, I had reports from someone else it does currently crash, I may have damaged something in the camera server while rebasing this but I haven't had time to investigate yet.

@BastiaanOlij
Copy link
Contributor Author

Ok, this morning I spend a bit of time making sure this compiles and runs again. Somehow I messed something up when it doesn't find any cameras because we weren't looking for all types.

It should also export ARKit projects properly when the ARKit tick is ticked. What I don't know is how well things behave if you're not using ARkit and not including it. That said if ARKit is unwanted to be included you can always turn off the module when compiling.

I vote we start working towards merging this. There are plenty of improvements to be made but I think this is better served if its merged and more people can start picking things up.

@akien-mga
Copy link
Member

Same comment as for #10643 (comment), could you make the commit log a bit more descriptive so that it's ready to merge? Also it probably shouldn't refer to Godot 3.1 :)

This PR introduces support for ARKit to the iOS version of Godot.
ARKit is Apples Augmented Reality platform.
This PR brings in support for ARKit 1.0 and implements a few ARKit 2.0 features.
It requires iOS 11 to run but should not prevent Godot from running on older versions as long as ARKit remains unused.
@akien-mga akien-mga merged commit 96d3270 into godotengine:master Jun 30, 2019
@akien-mga
Copy link
Member

Thanks a ton!

@juangea
Copy link

juangea commented Jan 14, 2024

What is the status on this?

I saw there is a plugin that is kind of compatible with Godot 4, but this seems to be a native implementation, is this already inside Godot 4?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants