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

Add SwiftUI visionOS example. #115

Merged
merged 7 commits into from
Mar 9, 2024
Merged

Conversation

halmueller
Copy link
Contributor

@halmueller halmueller commented Mar 7, 2024

This PR adds a standalone SwiftUI sample (ExampleVisionOS) that creates a volumetric window on visionOS.

Of note:

  • Vision Pro (native) run destination has been removed from the existing Example app. The RealityKit view does not display anything in native mode. Vision Pro (Designed for iPad) works fine, and remains as a destination.
  • EuclidMesh.swift in ExampleVisionOS is virtually identical to the one in Example. UIKit dependency has been replaced by CoreGraphics, and the solid UIKit color has been replaced by a solid Euclid-defined color.
  • This sample only displays a volumetric window. It's cut down from the Xcode 15.3 template to be as simple and short as possible.
  • I removed the bones of the Apple template relating to the unimplemented immersive experience, because that added a top-level Packages folder to the Euclid project file. I thought that was potentially confusing and distracting. The best way to provide an immersive example would be as a freestanding .xcodeproj that imports Euclid and doesn't mess with the Euclid library project structure.
  • If you want to see the distracting modification that I rejected, add a visionOS target to the project file, specifying an immersive app. Note the Packages folder that appears at top level.

Simulator Screenshot - Apple Vision Pro - 2024-03-06 at 18 34 06

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.46%. Comparing base (d3afbeb) to head (afaec04).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
+ Coverage   77.36%   77.46%   +0.09%     
==========================================
  Files          32       32              
  Lines        8218     8218              
==========================================
+ Hits         6358     6366       +8     
+ Misses       1860     1852       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@halmueller halmueller marked this pull request as draft March 7, 2024 06:51
@halmueller halmueller marked this pull request as ready for review March 8, 2024 00:07
@halmueller halmueller marked this pull request as draft March 8, 2024 05:03
@halmueller halmueller marked this pull request as ready for review March 8, 2024 07:02
@nicklockwood nicklockwood merged commit 1399eec into nicklockwood:main Mar 9, 2024
7 checks passed
@halmueller halmueller deleted the vpExample branch March 9, 2024 12:57
// create some geometry using Euclid
let cube = Mesh.cube(size: 0.8, material: Color.red)
let sphere = Mesh.sphere(slices: 120, material: CGImage.checkerboard())
let mesh = cube.subtracting(sphere).makeWatertight()
Copy link

Choose a reason for hiding this comment

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

I know this PR is closed, but (and maybe this is the wrong place to ask this question), I'm curious how important makeWatertight() is here.

When running this on device as/is, the print of Time: was ~4.5 seconds. If I remove the call to makeWatertight() and bump the sphere slices parameter down to 60, it runs in around .5 seconds, and there doesn't seem (to me) to be a discernible difference.

Copy link
Owner

Choose a reason for hiding this comment

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

@mgrider Are you sure it wasn't reducing the slices that had the main impact, not removing makeWatertight()? The latter is usually negligible.

In any case, the answer is that non-watertight shapes can cause weird artifacts when performing CSG operations, but in this case since it's the last step you can skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A better improvement might be to get the construction off the main thread with a Task.

Copy link
Owner

Choose a reason for hiding this comment

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

I almost forgot, if you are running in debug mode, switching to release mode (or just enabling optimized builds for the Euclid module in debug mode, which will still let you debug the example app) should yield a significant speedup.

Copy link

Choose a reason for hiding this comment

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

You're totally right. Adding makeWatertight() back yields: Time: 0.6943490505218506.

Copy link

Choose a reason for hiding this comment

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

And it's just my opinion, but I think a 4.5 second delay in the example project feels broken (or at least not especially great), whereas .5 gets a 🤷‍♂️. Of course there will be ways to optimize, but this is going to be what people see when they're evaluating Euclid as a dependency.

Copy link

Choose a reason for hiding this comment

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

Love that this got made/merged, BTW. Definitely aiming for (hopefully helpful) constructive criticism!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's still a problem with blocking the main thread. What I had missed earlier is that Apple's RK samples all use the try! await Entity(named: "MyEntity") idiom, calling the async method to load from a file. There is no async version of init(_ mesh:...), so we should be calling that in a task and adding the content when it's ready. A real-world user of the framework may have very complicated/expensive meshes to build. Let me poke at that a bit and I'll post a new PR/branch.

Copy link
Owner

Choose a reason for hiding this comment

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

Everything in Euclid should be safe to run on a background thread. Distinct meshes should be safe to create in parallel on multiple threads/tasks as there's no global shared state.

Euclid already makes some use of multithreading internally which may not play nicely with async/await but is probably OK. Search for "batch" in the codebase if you're curious.

I plan to add async interfaces at some point, but it's complicated for various reasons. You're more than welcome to take a stab at it if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See what we think about #116. And let's continue conversation on that PR, close out this thread.

nicklockwood pushed a commit that referenced this pull request Jul 24, 2024
nicklockwood pushed a commit that referenced this pull request Jul 24, 2024
nicklockwood pushed a commit that referenced this pull request Oct 9, 2024
nicklockwood pushed a commit that referenced this pull request Oct 9, 2024
nicklockwood pushed a commit that referenced this pull request Oct 9, 2024
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