一、程序效果:

 

二、程序代码(您需创建两个文件)

【文件1】(MyApp):

import SwiftUI
@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            Reality()
        }
    }
}

【文件2】(Reality):

import SwiftUI
import RealityKit
struct Reality: View {
    var body: some View {
        ARViewContainer().edgesIgnoringSafeArea(.all)
    }
}
struct ARViewContainer: UIViewRepresentable {
    func makeUIView(context: Context) -> ARView {
        let arView = ARView(frame: .zero, cameraMode: .ar, automaticallyConfigureSession: true)
        let anchorEntity = AnchorEntity(plane: .horizontal)//水平类场景
        guard let ARentity = try? ModelEntity.load(named: "U3aQM13") else {
            fatalError("U3aQM13 model is not!")
        }//导入reality/usdz文件
        anchorEntity.addChild(ARentity)//锚点
        arView.scene.anchors.append(anchorEntity)//场景
        return arView
    }
    func updateUIView(_ uiView: ARView, context: Context) {
    }
}

备注:制作一个 reality 或 usdz 文件,将文件导入程序。

目录:https://docs.qq.com/mind/DTE5ScEFsRW5yQklw

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐