🎯
RealityComposerProの基本的な使い方
元ネタ
WWDC23: Meet Reality Composer Pro | Apple
プロジェクトの設定
Xcode > OpenDeveloperTool > RealityComposerProで起動する

もしくは、プロジェクトヒエラルキーのPackages > Packageを選択
Open in Reality Composer Pro で開くことができる

下記のようなProjectWindowが開ければOK.

操作
ほぼUnity3Dである。
Entity = GameObject
Component = Component と読み替えると、Unityユーザはすぐに理解できるだろう.
モデルの追加
ProjectBrowserの中から、 Scene.usdaをDrag&DropするとSphereがシーンビューに配置できる.

[ProjectRoot] > Packages > RealityKitContent > Sources > RealityKitContent > RealityKitContent.rkassets 以下のモデルが一覧に表示されている。
Blenderで Cube.usdz を書き出してみた。MaterialもセットでProjectBrowserに表示できている.

編集した結果は、Immersive.usdaとして保存されている.
Swiftでの読み込み
ImmsersiveView.swiftに下記のようなEntity.loadの読み出し処理を記述すると、
先ほど定義したrealityKitContentBundle内のImmersive.usdaがEntityとしてロードできる。
ImmersiveView.swift
import SwiftUI
import RealityKit
import RealityKitContent
struct ImmersiveView: View {
var body: some View {
RealityView { content in
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
}
}
}
}
#Preview(immersionStyle: .mixed) {
ImmersiveView()
.environment(AppModel())
}

Entity内部のEntityへアクセス
Entity.findEntityを利用することでアクセスできる.
ImmersiveView.swift
struct ImmersiveView: View {
var body: some View {
RealityView { content in
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
// cubeを探して位置とスケールを変更
let cube = immersiveContentEntity.findEntity(named: "Cube")
cube?.position = SIMD3<Float>(x: 0, y: 1, z: -1.5)
cube?.transform.scale = SIMD3<Float>(x: 0.1, y: 1, z: 0.1)
}
}
}
}
#Preview(immersionStyle: .mixed) {
ImmersiveView()
.environment(AppModel())
}

Discussion