티스토리 뷰

반응형

 

RealityKit의 4가지 기본 개념을 알아봅시다. 

 

- ARView

- Scene

- Anchor

- Entity

 

https://developer.apple.com/documentation/realitykit/arview

 

 

 

 

 

[1] ARView 

 

ARView는 augmented reality experience를 display 해주는 뷰입니다.

 

 

 

[2] Scene

 

Scene은 문서에서 'entity 모음을 들고 있는 container' 라고 표현하고 있습니다.

사전적 의미 그대로 장면이라고 이해하면 쉽습니다. 

 

Reality Composer를 보면 Scene을 추가할 수 있습니다. 

 

 

이것은 Watermelon Scene 

 

 

이것은 Bread Scene 

 

 

 

[3] Anchor 

 

Entity들이 위치하는 기준 바닥(?) 이라고 생각하면 됩니다. 

모든 Entity들은 anchored 되어야합니다.

 

 

 

Reality Composer를 보면 

앵커 종류는 이런 것들이 있습니다. 

 

 

 

예를들어 이미지를 앵커로 선택했다!! 하면

기준 바닥(?)이 이미지니까

이미지가 이동할 때 그 위의 entity도 이미지를 기준으로 함께 이동하는 것을 볼 수 있습니다.

 

 

 

그리고 Anchor는 Entity의 한 종류 랍니다.

정확히 말하면 AnchorEntity라고 해야하겠네요!

 

 

 

[4] Entity 

 

AR Object 입니다. (WWDC에서도 entity랑 object라는 단어를 혼용해서 쓰시더라구요)

parent-child 계층구조를 가질 수 있습니다. 

그래서 만약 virtual table 위에 virtual cup 이 있다면

cup entity의 parent는 table entity이므로 두개를 같이 이동시킬 수 있습니다. 

 

 

[4.1] Entity > Component 

 

Entity에는 여러 Component를 붙일 수 있습니다.

 

 

예를들어 Ball, Lamp, Camera Entity가 있다고 해봅시다. 

 

 

Ball, Lamp, Camera 는 일단 모두 Anchor component 를 가져야합니다. 

 

그리고 Ball, Lamp는 시각적으로 표현되어야하니까 Model component를 더합니다. 

반면 카메라는 안보이니까 안가집니다. 

 

그리고 오브젝트들 끼리 충돌할 수 있어야하니까 

Ball, Lamp 에 collision component를 붙입니다. 

 

이런 식으로 각 entity가 가져야하는 component들을 붙일 수 있습니다. 

 

이것을 코드로 표현하면 이렇게 되겠네요

(참고로 local position은 parent entity안에서의 포지션을 말합니다) 

 

 

그리고 RealityKit은 이미 필요한 Components들이 구성되어있는 여러 종류의 Entity들을 제공합니다.

 

예를들어 위의 코드처럼 Entity에 SpotLightComponent를 직접 더할 수 도 있겠지만

이미 이 Component가 더해져있는 SpotLight 라는 Entity를 바로 사용해도 되는 것입니다! 

 

 

그리고 이 중에서 가장 많이 쓰이는 Anchor Entity랑 Model Entity 도 좀 더 살펴봅시다. 

우선 Entity 의 서브 클래스니까 Entity가 가지고 있는 기본 component들을 다 가지고 있습니다. 

 

AnchorEntityAnchoringComponent 를 가지고 있는 entity 이고

ModelEntity 는 Collision, Physics Component를 가지고 있는 entity 입니다. 

 

https://developer.apple.com/documentation/realitykit/entity

 

[4.1.1] Anchor Entity 

 

 

 

한 씬에 여러 anchor를 둘 수 도 있네요

 

 

 

[4.1.2] Model Entity

 

 


ModelComponent 는 entity의 visual appearance를 만드는 리소스 모음입니다. 

Model Entity는 USDZ 또는 Reality file을 바로 로드해서 만들어질 수 있습니다. 

 

 

 

#  Mesh Resource

 

그리고 모든 Model Entity는 Mesh Resource를 가지고 있습니다. 

Mesh Resource는 모델의  geometric representation을 해주게 됩니다.  

(geometric representation이란 Object의 형체가 어떻게 되는 지 표현해준다는 뜻) 

 

 

만약 USDZ 파일에서 MeshResource를 로드해오지 않는다면 

RealityKit에서 제공하는 기본 MeshResource를 쓸 수 도 있습니다. 

 

 

https://developer.apple.com/documentation/realitykit/meshresource

 

 

 

# Material 

 

그리고 여기에 Material 을 더하여서 

형체에 색이나 이미지랑 입히는 렌더링을 하게 되는 것입니다. 

 

 

Material은 Model Entity를 USDZ 파일로 부터 로드할 때 이미 정의되어있기도 하고 

너가 직접 Material을 만들 수 도 있습니다. 

 

다양한 Material을 제공합니다. 

 

Simple Material 

 

 

 

UnlitMaterial

 

 

OcclusionMaterial

 

 

 

PhysicallyBasedMaterial

 

- iOS 15에 추가되었어요! 

 

 

 

 

위에서 말한 것들을 코드로 작성해보면 이런 식으로 되겠습니다

 

 

 

[4.2] Entity > Animation

 

그리고 Entity에 Animation을 추가할 수 도 있습니다.  (참고: https://developer.apple.com/documentation/realitykit/entity/3244105-playanimation)

 

 

 

 

 

 

[ Referece ]

 

https://developer.apple.com/videos/play/wwdc2019/603/

 

Introducing RealityKit and Reality Composer - WWDC19 - Videos - Apple Developer

Architected for AR, RealityKit provides developers access to world-class capabilities for rendering, animation, physics, and spatial...

developer.apple.com

 

반응형
댓글