RealityKit 採用 ECS 架構,將「個體」(Entity)的屬性分散到各個元件(Component)中,需要時再動態載入。好處之一是讓「個體」保持輕盈,另一個好處是可自行定義元件,無限擴充,可說兼顧效率與彈性。
從另一個角度看,元件也是「個體」能發揮作用的關鍵,個體想要什麼功能,就須具備相關元件。因此,了解有哪些可用元件,對初學者來說非常重要。
有趣的是,RealityKit 從2019年發表,到2023年之間,內建元件只有寥寥十幾個,很多功能還不如 SceneKit (如缺乏粒子系統、臉部動畫等),2023年推出 Vision Pro 之後,Apple 才大舉投入空間運算,2024年 RealityKit 一口氣新增36個元件,總算彌平差距。
在可預期的未來,Apple 必然持續開發空間運算相關產品,不論是低價版的 Vision Pro、AR眼鏡或其他穿戴裝置,空間運算的應用可結合AR、AI、元宇宙、網路服務…,將越來越重要。
可以說,現在是學習 RealityKit 的好時機!
以下是目前 RealityKit 內建元件列表,共計56個元件,本單元課程大約會用到其中三分之一基礎元件,其餘三分之二以及未來發布的新元件有賴讀者自行探索。
# | 物件名稱 | 中文名稱 | 功能說明 |
---|---|---|---|
【預設元件】 | |||
1 | SynchronizationComponent | 網路同步元件 | 小範圍多人AR遊戲的同步機制 |
2 | Transform | 座標變換元件 | 虛擬空間中的位移、旋轉、縮放 |
【模型元件】 | |||
3 | ModelComponent | 模型元件 | 模型網格(Mesh)與材質(Materials) |
4 | ModelDebugOptionsComponent | 模型偵錯元件 | 視覺化法線、UV座標、材質等資料 |
5 | ModelSortGroupComponent | 模型排序元件 | 調整模型階層的渲染次序 |
【一般用途元件】 | |||
6 | AdaptiveResolutionComponent | 解析度元件 | 對遠離的物件降低解析度,以減少計算量 |
7 | AnimationLibraryComponent | 動畫庫元件 | 將動畫加入動畫庫,以便存檔或複製 |
8 | BillboardComponent | 告示板元件 | 讓模型永遠面對鏡頭視角 |
9 | OpacityComponent | 透明度元件 | 調整整個模型(而非材質)的透明度 |
10 | TextComponent | 2D文字元件 | 在虛擬空間中加入2D文字 |
【UI互動元件】 | |||
11 | AccessibilityComponent | 輔助元件 | 提供視障、聽障輔助功能 |
12 | HoverEffectComponent | 懸浮效果元件 | (macOS)滑鼠游標移到該物件時會稍亮 |
13 | InputTargetComponent | 輸入標定元件 | 用手指觸控或滑鼠點選3D物件 |
【鏡頭相關元件】 | |||
14 | OrthographicCameraComponent | 正投影鏡頭元件 | 非透視鏡頭,尺寸固定,不會隨深度縮小 |
15 | PerspectiveCameraComponent | 透視鏡頭元件 | 物體會隨深度縮小(近大遠小) |
16 | ProjectiveTransformCameraComponent | 座標投影鏡頭元件 | 非透視鏡頭,物體邊緣會扭曲 |
【音效相關元件】 | |||
17 | AmbientAudioComponent | 環境音效元件 | 加入環境音效 |
18 | AudioLibraryComponent | 音效庫元件 | 將音效加入音效庫,以便存檔或複製 |
19 | AudioMixGroupsComponent | 混音元件 | 混音群組 |
20 | ChannelAudioComponent | 多聲道元件 | 單聲道或多聲道 |
21 | ReverbComponent | 殘響音效元件 | 提供多種殘響音效 |
22 | SpatialAudioComponent | 空間音效元件 | 播放空間音效 |
23 | VideoPlayerComponent | 影片播放元件 | 在虛擬空間中播放影片 |
【燈光相關元件】 | |||
24 | DirectionalLightComponent | 定向光元件 | 在虛擬空間中提供某個方向的光源 |
25 | DirectionalLightComponent.Shadow | 定向光陰影元件 | 讓定向光源產生陰影 |
26 | DynamicLightShadowComponent | 動態陰影元件 | 虛擬空間中動態計算陰影 |
27 | GroundingShadowComponent | 地面陰影元件 | 對平面或地面產生陰影(實體或虛擬空間) |
28 | PointLightComponent | 點光源元件 | 對虛擬空間任意方向產生光照 |
29 | SpotLightComponent | 聚光燈元件 | 對某方向圓錐狀的光照 |
30 | SpotLightComponent.Shadow | 聚光燈陰影元件 | 對聚光燈源產生陰影效果 |
31 | EnvironmentLightingConfigurationComponent | 環境光照元件 | 調整環境光照(即天空盒)效果 |
32 | ImageBasedLightComponent | 圖像光照元件 | 產生環境光照(即天空盒)效果 |
33 | ImageBasedLightReceiverComponent | 圖像光照接收元件 | 接收環境光照,產生反光或動態陰影 |
34 | VirtualEnvironmentProbeComponent | 虛擬環境探測元件 | 計算環境光照的偵測元件 |
【門戶相關元件】 | |||
35 | PortalComponent | 門戶元件 | 產生門戶材質(PortalMaterial),以展示另一個虛擬場景,就像3D版的畫中畫 |
36 | PortalCrossingComponent | 門戶穿越元件 | 穿過門戶後是否隱藏 |
37 | WorldComponent | 門戶世界元件 | 產生門戶材質(PortalMaterial) |
【物理模擬相關元件】 | |||
38 | CollisionComponent | 碰撞偵測元件 | 偵測兩個物理模擬本體是否接觸 |
39 | PhysicsBodyComponent | 物理本體元件 | 要加入物理模擬的個體 |
40 | PhysicsMotionComponent | 物理運動元件 | 用程式手動控制運動與旋轉速度 |
41 | ForceEffectComponent | 力場元件 | 提供物理力場模擬效果 |
42 | ParticleEmitterComponent | 粒子噴射元件 | 產生粒子系統特效 |
43 | PhysicsJointsComponent | 物理關節元件 | 加入關節模擬 |
44 | PhysicsSimulationComponent | 客製化物理模擬元件 | 調整物理系統的參數(如重力加速度) |
【AR擴增實境元件】 | |||
45 | AnchoringComponent | 錨定元件 | 錨定虛擬空間與實體空間的座標點 |
46 | ReferenceComponent | 參考個體元件 | AR應用的參考個體(以便錨定) |
47 | SceneUnderstandingComponent | 場境分析元件 | 自動場景分析(需LiDAR鏡頭) |
48 | BlendShapeWeightsComponent | 臉部動畫元件 | 臉部網格分析(需NPU神經網路晶片) |
49 | BodyTrackingComponent | 人體追蹤元件 | 人體辨識並且實時追蹤錨定 |
50 | CharacterControllerComponent | 角色控制元件 | 模擬虛擬角色(虛擬人物) |
51 | CharacterControllerStateComponent | 角色狀態元件 | 虛擬角色狀態 |
52 | GeometricPinsComponent | 幾何關節元件 | 模擬關節位置 |
53 | IKComponent | 肢體控制元件 | 用反向推導關節控制的肢體動作 |
54 | SkeletalPosesComponent | 骨骼姿態元件 | 調整骨骼姿態 |
【visionOS專用元件】 | |||
55 | DockingRegionComponent | 場景投射元件 | 投射虛擬場景的範圍 |
56 | ViewAttachmentComponent | 視圖附件元件 | 在擴增實境中顯示2D視圖 |
<aside> 💡
註解