Machineboy空

Reality Composer Pro Animations, 애니메이션 있는 usdz파일 넣기 본문

언어/swift

Reality Composer Pro Animations, 애니메이션 있는 usdz파일 넣기

안녕도라 2024. 10. 1. 14:54

오늘의 목표

Reality Composer Pro에 Animation이 실행되는 usdz파일을 넣고, 이를 ARView에 띄워보겠다.


찾아본 것들..

https://www.youtube.com/watch?v=pJ3D20zNd18

 

예전 튜토리얼들을 살펴보면 Reality Composer Pro UI가 달라서

Action Sequence 창을 도무지 어떻게 띄우는지를 모르겠다..

**저건 Reality Composer였다..

 

https://developer.apple.com/documentation/visionos/diorama

 

Diorama | Apple Developer Documentation

Design scenes for your visionOS app using Reality Composer Pro.

developer.apple.com

가장 유명한 Diorama 예제인데 visionOS 빌드 전용의 RealityView이다..

iOS에 띄울 ARView에서는 realitykitcontent 라이브러리를 import하여 사용할 수가 없고,

RealityView를 컨테이너에 담아 ARView에 띄우기란 스택오버플로우 답변상 아마 불가능한 것 같다.

 

Diorama 예제 속 독수리는 이미 animation이 들어있는 채로 import되어 사용되고 있다..

animation이 포함된 usdz파일은 어떻게 만드는 거고,

Reality Composer Pro에서 animation을 넣는 거라면 어떻게 하는 건지 방법을 찾아보겠음.


Solution: 애초에 animation 들어있는 모델 구해서 스크립트 제어

Diorama 관련 WWDC 봐도, 이미 animation이 있는 모델을 import했다고 나온다.

https://sketchfab.com/3d-models/quirky-series-free-animals-pack-19e91ef86cd0448f9cbb5d6c538dade2#download

 

Quirky Series - FREE Animals Pack - Download Free 3D model by Omabuarts Studio - Sketchfab

DOWNLOAD: Get all files from omabuarts.com/product/quirky-series-free-animals/ Quirky Packs Quirky Singles – Email : omabuarts@gmail.com - Features: ✅ Eight (8) animals pack ✅ Tiny 16x4 px texture ✅ Rigged/Skeleton ✅ 18 animations ✅ 29 blendsha

sketchfab.com

 

import SwiftUI
import RealityKit
import ARKit

struct ContentView : View {
    var body: some View {
        ARViewContainer().edgesIgnoringSafeArea(.all)
    }
}

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        arView.addCoaching()

        // Load the model with embedded animation
        let model = try! ModelEntity.loadModel(named: "Camelon")
        model.scale = SIMD3(x: 2.5, y: 2.5, z: 2.5)
        model.generateCollisionShapes(recursive: true)
        
        // Play the embedded animation in a loop
        if let animation = model.availableAnimations.first {
            model.playAnimation(animation.repeat(), transitionDuration: 0.5, startsPaused: false)
        }
        
        // Create horizontal plane anchor for the content
        let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2)))
        anchor.children.append(model)

        // Add the horizontal plane anchor to the scene
        arView.scene.anchors.append(anchor)

        return arView
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {}
    
}

extension ARView: ARCoachingOverlayViewDelegate {
    func addCoaching(){
        let coachingOverlay = ARCoachingOverlayView()
        
        coachingOverlay.goal = .horizontalPlane
        coachingOverlay.session = self.session
        coachingOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.addSubview(coachingOverlay)
    }
}

#Preview {
    ContentView()
}
// Animation 재생 함수 숙지
        let model = try! ModelEntity.loadModel(named: "Camelon")
        model.scale = SIMD3(x: 2.5, y: 2.5, z: 2.5)
        model.generateCollisionShapes(recursive: true)
        
        if let animation = model.availableAnimations.first {
            model.playAnimation(animation.repeat(), transitionDuration: 0.5, startsPaused: false)
        }

 

어찌저찌 성공!


이제 Reality Composer Pro 상에서 animation에 접근하는 방법을 찾아보자..

우선 이것저것 다 눌러보니 Statistics안에 Animation이 있긴 한데 이건 정말 수치를 보여주는 창인듯 하다.

 

WWDC의 Animation관련 내용은.. 2024부터 적용된 건지 창이 나랑 다르다..

이건 2024버전인지... 나랑 같지 않은데

 

https://medium.com/daily-monster/wwdc23-meet-reality-composer-pro-082bb13635b8

 

[WWDC23] Meet Reality Composer Pro

안녕하세요 월요괴물 inu입니다. 오늘은 Reality Composer Pro에 대한 세션을 정리해왔어요.

medium.com

 

또 다른 튜토리얼들을 보면 iOS나 iPad에서만 지원된다는 Reality Composer 을 사용해서 Animation을 제어하고 있다..

대체 mac 지원은 왜 안되는 것이고.. 사람들은 왜 손 터치로 3D를 만지고 있는거지.. 이해가 안가는 애플 AR 생태계

 

https://apps.apple.com/kr/app/reality-composer/id1462358802

 

‎Reality Composer

‎이전에 3D 제작 경험이 없어도 AR에서 직접 증강 현실 경험을 쉽게 프로토타입하고 제작할 수 있습니다. • 드래그 앤 드롭으로 가상 오브젝트를 배치 및 회전하여 캔버스 또는 AR에서 직접 장

apps.apple.com

 

여튼 2024 리뉴얼된 Reality Composer Pro에서 기존 내장된 Animation API도 사용이 가능하고, Animation을 배열로 저장하고서 State 관리도 가능하다는 것을 확인했으나.. 그 리뉴얼된 리얼리티 컴포저 프로 대체 어디서 다운받는지 모르겠음..

일단 고급기능은 차차 알아가보는 걸로!