-
Notifications
You must be signed in to change notification settings - Fork 53
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
visionOS sample code: add view model, get Mesh construction off the main thread #116
base: main
Are you sure you want to change the base?
Conversation
…l platforms", for on-device Vision Pro build. (nicklockwood#114)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #116 +/- ##
=======================================
Coverage 77.36% 77.36%
=======================================
Files 32 32
Lines 8218 8218
=======================================
Hits 6358 6358
Misses 1860 1860 ☔ View full report in Codecov by Sentry. |
ExampleVisionOS/VolumetricView.swift
Outdated
// for gesture targeting | ||
demoBoxEntity.components.set(InputTargetComponent()) | ||
var body: some View { | ||
let _ = Self._printChanges() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave this in the sample code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It shows the view's redraw/update
as it reacts to the model changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, it's a distraction. Removed.
ExampleVisionOS/MeshViewModel.swift
Outdated
entity = demoBoxEntity | ||
contentReady = true | ||
} catch { | ||
print("nope") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend removing this, leaving an empty catch for clarity, or adding a more explicit logging message that reports that nothing was updated in the background.
func prepareContent() { | ||
Task.init { | ||
do { | ||
let demoBoxEntity = try await ModelEntity(euclidMesh.scaled(by: 0.5)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a huge deal, but what about moving euclidMesh
into this class? (I always look askance at global functions.)
As I get more experience on visionOS, I’m having second thoughts about this PR. The RealityView initialization is already async. I was seeing the placeholder view and thinking it was the equivalent of a beach ball. But nothing’s blocked, and I think I’ve made this example needlessly complex. I’m working on something different at the moment, will take another crack next week. If someone else wants to run with it you have my blessing. |
ab73495
to
5f6ffe2
Compare
c92a7a4
to
f5f0a69
Compare
ExampleVisionOS
now has a view model, and creates theMesh
andEntity
instances on a separate thread. I've added somesleep()
time to simulate a long-runningMesh
creation. The sample code now reflects typical SwiftUI patterns used in visionOS and in iOS 17+. No changes made to theEuclid
codebase, just to the sample app.