Skip to content

Commit

Permalink
ARCore iOS SDK 1.45.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fine committed Aug 15, 2024
1 parent fe41a4d commit 686fe38
Show file tree
Hide file tree
Showing 103 changed files with 3,900 additions and 66,505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*/

import ARCore
import SceneKit

import ARCore

/// Contains all objects needed to hold a face mesh. Used for multi-buffering.
private class FaceMesh {
/// Metal buffer containing vertex positions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

import ARCore
import AVFoundation
import CoreMedia
import CoreMotion
import SceneKit
import UIKit

import ARCore

/// Demonstrates how to use ARCore Augmented Faces with SceneKit.
public final class FacesViewController: UIViewController {

Expand Down
2 changes: 1 addition & 1 deletion Examples/AugmentedFacesExample/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target 'AugmentedFacesExample'
use_frameworks!
platform :ios, '12.0'
pod 'ARCore/AugmentedFaces', '~> 1.44.0'
pod 'ARCore/AugmentedFaces', '~> 1.45.0'
278 changes: 147 additions & 131 deletions Examples/CloudAnchorExample/CloudAnchorExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions Examples/CloudAnchorExample/CloudAnchorExample/ARViewContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//
// Copyright 2024 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import ARCore
import ARKit
import Foundation
import RealityKit
import SwiftUI
import UIKit
import simd

/// SwiftUI wrapper for an `ARView` and all rendering code.
struct ARViewContainer: UIViewRepresentable {
let manager: CloudAnchorManager

/// Coordinator to act as `ARSessionDelegate` for `ARView`.
class Coordinator: NSObject, ARSessionDelegate {
private enum Constants {
/// Name of USDZ file to load Android model from.
static let andyName = "andy"
/// Material for rendered planes.
static let planeMaterial = UnlitMaterial(
color: UIColor(red: 0, green: 0, blue: 1, alpha: 0.7))
}

private let manager: CloudAnchorManager
private var hostedAnchorModel: Entity?
private var resolvedAnchorModel: Entity?
private var planeModels: [UUID: ModelEntity] = [:]

init(manager: CloudAnchorManager) {
self.manager = manager
super.init()
manager.arView.session.delegate = self
}

private static func createAndyNode() -> Entity? {
return try? Entity.load(named: Constants.andyName)
}

private static func createPlaneMesh(plane: ARPlaneAnchor) -> MeshResource? {
var descriptor = MeshDescriptor()
descriptor.positions = MeshBuffers.Positions(plane.geometry.vertices)
descriptor.primitives = .triangles(plane.geometry.triangleIndices.map { UInt32($0) })
return try? MeshResource.generate(from: [descriptor])
}

private static func createPlaneModel(plane: ARPlaneAnchor) -> ModelEntity? {
guard let mesh = createPlaneMesh(plane: plane) else {
return nil
}
return ModelEntity(mesh: mesh, materials: [Constants.planeMaterial])
}

private static func updatePlaneModel(model: ModelEntity, plane: ARPlaneAnchor) {
guard let planeMesh = createPlaneMesh(plane: plane) else {
return
}
model.model?.mesh = planeMesh
}

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
for anchor in anchors {
if anchor is AREnvironmentProbeAnchor { continue }
if let plane = (anchor as? ARPlaneAnchor) {
guard let model = Coordinator.createPlaneModel(plane: plane) else { continue }
planeModels[plane.identifier] = model
let anchorEntity = AnchorEntity(.anchor(identifier: anchor.identifier))
anchorEntity.addChild(model)
manager.arView.scene.addAnchor(anchorEntity)
continue
}
guard let model = Coordinator.createAndyNode() else { continue }
hostedAnchorModel = model
let anchorEntity = AnchorEntity(.anchor(identifier: anchor.identifier))
anchorEntity.addChild(model)
manager.arView.scene.addAnchor(anchorEntity)
}
}

func session(_ session: ARSession, didRemove anchors: [ARAnchor]) {
for anchor in anchors {
if anchor is AREnvironmentProbeAnchor { continue }
if let plane = (anchor as? ARPlaneAnchor) {
guard let model = planeModels.removeValue(forKey: plane.identifier) else { continue }
model.parent?.removeFromParent()
continue
}
hostedAnchorModel?.parent?.removeFromParent()
hostedAnchorModel = nil
}
}

func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
for anchor in anchors {
guard let plane = (anchor as? ARPlaneAnchor) else { continue }
guard let model = planeModels[plane.identifier] else { continue }
Coordinator.updatePlaneModel(model: model, plane: plane)
}
}

func session(_ session: ARSession, didUpdate frame: ARFrame) {
guard let garFrame = try? manager.garSession?.update(frame) else { return }
guard let garAnchor = garFrame.anchors.first else {
resolvedAnchorModel?.parent?.removeFromParent()
resolvedAnchorModel = nil
return
}
if resolvedAnchorModel == nil {
guard let model = Coordinator.createAndyNode() else { return }
resolvedAnchorModel = model
let anchorEntity = AnchorEntity(world: matrix_identity_float4x4)
anchorEntity.addChild(model)
manager.arView.scene.addAnchor(anchorEntity)
}
guard let resolvedAnchorModel else { return }
resolvedAnchorModel.transform = Transform(matrix: garAnchor.transform)
resolvedAnchorModel.isEnabled = (garAnchor.trackingState == .tracking)
}
}

func makeUIView(context: Context) -> some UIView {
return manager.arView
}

func updateUIView(_ uiView: UIViewType, context: Context) {}

func makeCoordinator() -> Coordinator {
Coordinator(manager: manager)
}
}
23 changes: 0 additions & 23 deletions Examples/CloudAnchorExample/CloudAnchorExample/AppDelegate.h

This file was deleted.

54 changes: 0 additions & 54 deletions Examples/CloudAnchorExample/CloudAnchorExample/AppDelegate.m

This file was deleted.

31 changes: 31 additions & 0 deletions Examples/CloudAnchorExample/CloudAnchorExample/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2024 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import FirebaseCore
import UIKit

/// Application delegate needed for Firebase integration with SwiftUI. See
/// https://firebase.google.com/docs/database/ios/start#set_up.
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
FirebaseApp.configure()
return true
}
}

This file was deleted.

Loading

0 comments on commit 686fe38

Please sign in to comment.