SwiftUI & Scenekit hit testing example.

Related tags

Testing HitTestApp
Overview

HitTestApp

SwiftUI & Scenekit hit testing example.

This example application is written for macOS, though with minor changes it should be able to be changed to an iOS app fairly quickly.

Many people have run into the issue that the SwiftUI SceneView doesn't appear to have any hit testing ability.
After much searching and working on this problem, I have discovered how to get the hit testing working. It involves using a small NSViewRepresentable (or UIViewRepresentable if on iOS) to get an SCNView which does conform to the SCNSceneRenderer protocol.

The ScenekitView class in this repo creates an SCNView for use by SwiftUI, replacing SceneView.

There are a number of other things in the contentView that are used as well. Such as using a DragGesture(minimumDistance: 0.0, coordinateSpace: .local).onEnded() in order to get the location of a tap, since a TapGesture() does not provide a location value, which is needed for feeding to the hitTest().

An example of using the DragGesture() to rotate the view is given.

I've also included a TapGesture() to double click on an object for centering the view on it. The camera system uses a camera node attached as the child of a camera orbit node in order to get the entire view to rotate around. the selected object.

Finally, there is a SwiftUI overlay on top of the Scene.

You might also like...
Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems

Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems. It combines machine learning and reinforcement learning techniques to assist discovery in a more intelligent way.

Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5 and iOS 15.
Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5 and iOS 15.

StoreHelper Demo Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5, iOS 15. See also In-App Purchases with Xcode 12 and

Genything is a framework for random testing of a program properties.

Genything is a framework for random testing of a program properties. It provides way to random data based on simple and complex types.

For Testing APIs of NYTimes

NYTimes-APIs For Testing APIs of NYTimes Mark Dennis Diwa 👓 To run the app: Open terminal first then run pod install. Open workspace. Run the app on

A Mac and iOS Playgrounds Unit Testing library based on Nimble.
A Mac and iOS Playgrounds Unit Testing library based on Nimble.

Spry Spry is a Swift Playgrounds Unit Testing library based on Nimble. The best thing about Spry is that the API matches Nimble perfectly. Which means

Multivariate & A/B Testing for iOS and Mac

This library is no longer being maintained. You can continue to use SkyLab in your projects, but we recommend switching another solution whenever you

Remote configuration and A/B Testing framework for iOS

MSActiveConfig v1.0.1 Remote configuration and A/B Testing framework for iOS. Documentation available online. MSActiveConfig at a glance One of the bi

AB testing framework for iOS

ABKit Split Testing for Swift. ABKit is a library for implementing a simple Split Test that: Doesn't require an HTTP client written in Pure Swift Inst

AppiumLibrary is an appium testing library for RobotFramework

Appium library for RobotFramework Introduction AppiumLibrary is an appium testing library for Robot Framework. Library can be downloaded from PyPI. It

Comments
  • hit test is unreliable

    hit test is unreliable

    first off, thank you for this example, it's incredible and well organized and documented! Would've taken forever to figure this out on my own.

    One issue though, the raycasting doesn't seem to be reliable. Tried a bit of debugging and strangely, even if you're tapping on one of the circles, but you were previously rotating the camera, it doesn't always return any hits, resulting in no changing of the camera view.

    Any ideas? Maybe it's due to some change in the latest xcode or something?

    opened by edwonedwon 2
Owner
Eric Freitas
Eric Freitas
Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

Keepsafe 287 Nov 19, 2022
Testing the UI without UI Testing, a Swift experiment.

UI tests without UI Testing experiment This repo is a small experiment to see if there's an "in-between" for testing iOS applications. More feature-le

Joe Masilotti 20 Sep 26, 2022
Runtime introspection and unit testing of SwiftUI views

ViewInspector ??️‍♂️ for SwiftUI ViewInspector is a library for unit testing SwiftUI views. It allows for traversing a view hierarchy at runtime provi

Alexey Naumov 1.5k Jan 8, 2023
Sample project for testing out focus in SwiftUI and iOS 15

This project was to test out different ways of enabling focus in a SwiftUI app.

null 3 Dec 21, 2021
Network testing for Swift

DVR DVR is a simple Swift framework for making fake NSURLSession requests for iOS, watchOS, and OS X based on VCR. Easy dependency injection is the ma

Venmo 650 Nov 3, 2022
The Swift (and Objective-C) testing framework.

Quick is a behavior-driven development framework for Swift and Objective-C. Inspired by RSpec, Specta, and Ginkgo. // Swift import Quick import Nimbl

Quick 9.6k Dec 31, 2022
Snapshot testing tool for iOS and tvOS

SnapshotTest is a simple view testing tool written completely in Swift to aid with development for Apple platforms. It's like unit testing for views.

Pär Strindevall 44 Sep 29, 2022
UI Testing Cheat Sheet and Examples.

UI Testing Cheat Sheet This repository is complementary code for my post, UI Testing Cheat Sheet and Examples. The post goes into more detail with exa

Joe Masilotti 2.1k Dec 25, 2022
Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS

Mockingbird Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop

FARFETCH 183 Dec 24, 2022
Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running in minutes. @buildasaur

Buildasaur Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running

Buildasaurs 774 Dec 11, 2022