LoginSignup
0
1

More than 3 years have passed since last update.

ARKit : Reality Composerでオブジェクトに名前をつける、Swiftで名前を得る

Last updated at Posted at 2020-10-18

Reality Composerで名前をつける

表示するオブジェクトをダブルクリックして設定画面を表示し名前をつける。下図の場合「hako」という名前をつけている。
スクリーンショット 2020-10-18 20.37.29.png

Swiftで名前を得る

オブジェクトをタップするとデバッグ画面に「hako」と表示される。


import UIKit
import RealityKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience.loadBox()
        boxAnchor.actions.tapped.onAction=clickEvent(_:)
        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
    }

    func clickEvent(_ entity: Entity?) {
        guard let entity = entity else { return }

        print(entity.name)
    }
}

「tapped」はReality Composerで付けたビヘイビア。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1