How to Add Material to ModelEntity programatically in RealityKit?

Updated: January 26, 2023 RealityKit materials There are 6 types of materials in RealityKit 2.0 and RealityFoundation at the moment: SimpleMaterial UnlitMaterial OcclusionMaterial (read this post to find out how to setup SceneKit occlusion shader) VideoMaterial (look at this post to find out how to setup it) PhysicallyBasedMaterial CustomMaterial (Medium story) SwiftUI version Here I … Read more

How do I programmatically move an ARAnchor?

You don’t need to move anchors. (hand wave) That’s not the API you’re looking for… Adding ARAnchor objects to a session is effectively about “labeling” a point in real-world space so that you can refer to it later. The point (1,1,1) (for example) is always the point (1,1,1) — you can’t move it someplace else … Read more

Adding 3D object to ARGeoAnchor

At first you have to check if ARGeoTrackingConfiguration is supported on your device. Requirements: You need a device with A12+ chip and cellular (GPS) support. import ARKit @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if !ARGeoTrackingConfiguration.isSupported { let sb = UIStoryboard(name: “Main”, … Read more

What is the real benefit of using Raycast in ARKit and RealityKit?

Simple Ray-Casting, the same way as Hit-Testing, helps to locate a 3D point on a real-world surface by projecting an imaginary ray from a screen 2D point onto a detected plane. In Apple documentation (2019) there was the following definition of a raycasting: Ray-casting is the preferred method for finding positions on surfaces in the … Read more

Projecting the ARKit face tracking 3D mesh to 2D image coordinates

Maybe you can use the projectPoint function of the SCNSceneRenderer. extension ARFaceAnchor{ // struct to store the 3d vertex and the 2d projection point struct VerticesAndProjection { var vertex: SIMD3<Float> var projected: CGPoint } // return a struct with vertices and projection func verticeAndProjection(to view: ARSCNView) -> [VerticesAndProjection]{ let points = geometry.vertices.compactMap({ (vertex) -> VerticesAndProjection? … Read more

What’s the difference between using ARAnchor to insert a node and directly insert a node?

Update: As of iOS 11.3 (aka “ARKit 1.5”), there is a difference between adding an ARAnchor to the session (and then associating SceneKit content with it through ARSCNViewDelegate callbacks) and just placing content in SceneKit space. When you add an anchor to the session, you’re telling ARKit that a certain point in world space is … Read more

RealityKit vs SceneKit vs Metal – High-Quality Rendering

Updated: October 08, 2022. TL;DR This post is not only about RealityKit, SceneKit & Metal, but also about related APIs and USD files. RealityKit 2.0 RealityKit (and RealityFoundation) is the youngest SDK in Apple family of rendering technologies. This high-level framework was released in 2019. RealityKit is made for AR / VR projects, has simplified … Read more