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

visionOS sample code: add view model, get Mesh construction off the main thread #116

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

halmueller
Copy link
Contributor

ExampleVisionOS now has a view model, and creates the Mesh and Entity instances on a separate thread. I've added some sleep() time to simulate a long-running Mesh creation. The sample code now reflects typical SwiftUI patterns used in visionOS and in iOS 17+. No changes made to the Euclid codebase, just to the sample app.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.36%. Comparing base (1399eec) to head (ae3e6a8).

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.
📢 Have feedback on the report? Share it here.

// for gesture targeting
demoBoxEntity.components.set(InputTargetComponent())
var body: some View {
let _ = Self._printChanges()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

entity = demoBoxEntity
contentReady = true
} catch {
print("nope")
Copy link
Contributor

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))
Copy link

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.)

@halmueller halmueller marked this pull request as draft March 22, 2024 07:21
@halmueller
Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

3 participants