标签: realitykit

RealityKit – 以编程方式设置 Reality Composer 实体的文本

在我的 iOS 应用程序中,我想使用新的 Reality Composer 引入 AR 的一部分。

在我的项目中,我使用以下代码加载场景:

let arView = ARView.init(frame: frame)

// Configure the AR session for horizontal plane tracking.

let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arView.session.run(arConfiguration)
arView.session.delegate = self

self.view.addSubview(arView)

Experience.loadSceneAsync{ [weak self] scene, error in

print("Error \(String(describing: error))")

guard let scene = scene else { return }

arView.scene.addAnchor(scene)

// THIS IS THE entity that i want to edit programmatically
scene.Label
Run Code Online (Sandbox Code Playgroud)

“scene.label”在我的场景中的文本对象,我想设置文本编程。

我怎样才能做到这一点?这是可能的?

提前致谢

augmented-reality swift arkit realitykit reality-composer

5
推荐指数
1
解决办法
2225
查看次数

RealityKit 和 ARKit 的挑战

我想在 ARKit 中构建一个演示应用程序,并且我对 Beta 版当前可能实现的功能有一些疑问(Apple 一直将其称为 RealityKit 或 ARKit 3.0)。


我正在尝试构建的演示应用程序应执行以下操作:

  1. 识别真实环境中的物体或图像,并在那里创建一个锚点

  2. 渲染附加到锚点的虚拟模型

  3. 让虚拟模型呈现遮挡

  4. 让虚拟模型与锚图像/对象一起移动


我尝试改编早期版本(利用 SceneKit 的 ARKit 2.0)中的一些代码,但某些功能(如人物遮挡)不是 ARKit 2.0 的一部分。

由于 Apple 一直在迭代他们的测试版,因此在他们的网站上和 WWDC 2019 上宣传的许多功能似乎已经从 RealityKit 的文档中消失了(人物遮挡、身体跟踪、世界跟踪)。

根据我的理解,ARKit 2.0 可以实现第 (1) 和 (2) 项。第 (3) 项尽可能与测试版一起宣传,但我几乎看不到任何文档。

在最新的测试版中可以这样做吗?如果是这样,最好的方法是什么?如果没有,是否有任何解决方法,例如混合新旧 API 之类的?

augmented-reality scenekit swift arkit realitykit

5
推荐指数
1
解决办法
2144
查看次数

如何将视频素材添加到 ModelEntity?

我使用代码在 RealityKit 中添加图片纹理,效果很好。

var material = SimpleMaterial()

material.baseColor = try! .texture(.load(named: "image.jpg"))
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码添加视频文件作为纹理,但它崩溃了!

guard let url = Bundle.main.url(forResource: "data", withExtension: "mp4") else {
    return
}
material.baseColor = try! .texture(.load(contentsOf: url))
Run Code Online (Sandbox Code Playgroud)

如何添加视频文件?

scenekit swift arkit swiftui realitykit

5
推荐指数
2
解决办法
2132
查看次数

使用 RealityKit 跟踪相机位置

如何使用 RealityKit 跟踪相机的位置?有几个例子在使用 SceneKit,但我发现没有一个使用 RealityKit。我需要一个功能,例如:

func session(_ session: ARSession, didUpdate frame: ARFrame) {
    // Do something with the new transform
    let currentTransform = frame.camera.transform
    doSomething(with: currentTransform)
}
Run Code Online (Sandbox Code Playgroud)

augmented-reality ios swift arkit realitykit

5
推荐指数
1
解决办法
1620
查看次数

在 RealityKit 中将 UIImage 作为纹理添加到平面

我正在 swift 中尝试新的 RealityKit 框架,我想在 ARAnchor 上放置一个 2D 图像。我设法创建了一个网格平面,并尝试将图像作为纹理添加到该平面。我发现我可以为材料提供局部图像。我该如何使用 UIImage 代替?

let resource = try? TextureResource.load(named: "restart")
var material = UnlitMaterial()
material.baseColor = MaterialColorParameter.texture(resource!)
material.tintColor = UIColor.white.withAlphaComponent(0.99)

let imagePlane = ModelEntity(mesh: MeshResource.generatePlane(width: 0.25, height: 0.25), materials: [SimpleMaterial(color: color, isMetallic: true)])
Run Code Online (Sandbox Code Playgroud)

augmented-reality swift arkit realitykit

5
推荐指数
1
解决办法
885
查看次数

RealityKit – 从 Web URL 资源加载 ModelEntity

我想知道是否有人知道是否可以加载 AR 对象(例如,从 Web url 加载 .usdz 并将其放置在 AR 视图中)。我尝试过这个:

let fileUrl = NSURL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")
cancellable = Entity.loadModelAsync(contentsOf: fileUrl! as URL)
                .sink(receiveCompletion: { completion in
                    self.cancellable?.cancel()
                }, receiveValue: { [self] (model: Entity) in
                    if let model = model as? ModelEntity {
                        let anchorEntity = AnchorEntity(anchor: anchor)
                        anchorEntity.addChild(model)

                        arView.scene.addAnchor(anchorEntity)
                        loadingView.isHidden = true
                    }
                })
Run Code Online (Sandbox Code Playgroud)

但它不起作用并抛出错误Failed to open scene 'https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz'.

如果可能的话你会吗?

quicklook augmented-reality swift usdz realitykit

5
推荐指数
1
解决办法
1574
查看次数

在 Xcode 中运行 AR 应用模板时出现错误

在 MacOS 12 beta 上运行 Xcode 13 beta,部署到运行 iOS 15 beta 的 iPad Pro 第四代。

在 Xcode 中,我使用增强现实应用程序创建一个应用程序,选择默认的 SwiftUI 界面、Swift 语言和 RealityKit 内容技术。

创建后,我绝对不会对代码进行任何更改,只需在我的 iPad 上运行即可。除了下面显示的其他错误/消息之外,我还收到许多弃用和类型不存在的错误/消息。

我对 Apple 开发环境有点陌生,所以也许我错过了一些非常基本的东西,但为什么我会在模板代码上收到这么多警告/错误?这是苹果测试版产品的典型情况吗?

2021-06-15 09:37:13.272034-0700 Test[47081:3536556] Metal GPU Frame Capture Enabled
2021-06-15 09:37:13.272264-0700 Test[47081:3536556] Metal API Validation Enabled
2021-06-15 09:37:15.828657-0700 Test[47081:3536556] [AssetTypes] Registering library (/System/Library/PrivateFrameworks/CoreRE.framework/default.metallib) that already exists in shader manager. Library will be overwritten.
2021-06-15 09:37:16.003778-0700 Test[47081:3536556] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/suFeatheringCreateMergedOcclusionMask.rematerial' as an asset path -- this usage is deprecated; instead provide …
Run Code Online (Sandbox Code Playgroud)

beta xcode augmented-reality realitykit

5
推荐指数
1
解决办法
1640
查看次数

ARKit,AnchorEntity,缺少初始化程序

了解ARKit,我正在观看所有AR WWDC内容。在ARKit 3 介绍中,第一次使用RealityKit ,有一个使用AnchorEntity和下面第一个屏幕截图中的第三个便利初始化器的示例。 Xcode12.5iOS13当在Xcode 13 Beta中使用 iOS15 目标 创建项目时,这些初始化程序中的很少一部分会消失,如下面的屏幕截图所示:Xcode13iOS15 我查阅了文档,没有发现与此相关的额外信息。初始化程序可用,但没有有关计划弃用的信息。我觉得很奇怪。 https://developer.apple.com/documentation/realitykit/anchorentity/3255326-init 可能是什么原因?这可能是与 beta xcode 相关的某种错误吗?

ios swift arkit realitykit

5
推荐指数
1
解决办法
611
查看次数

如何在 RealityKit 中显示图库中的图像?

我想显示图库中的图像。我正在使用 imagePicker 加载图像。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let image = info[.originalImage] as? UIImage else { return }
  
    if let imgUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL{            
        self.photoEntity = createPhotoEntity(fileUrl: imgUrl, fileName: imgName)
    }
    dismiss(animated: true)
}
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个像这样的 modelEntity 。

private func createPhotoEntity(fileUrl: URL, fileName: String) -> ModelEntity? {
    // Create a TextureResource by loading the contents of the file URL.
    do {
        let texture = try TextureResource.load(contentsOf: fileUrl)
        let planeMesh = MeshResource.generatePlane(width: 0.5, depth: 0.5) …
Run Code Online (Sandbox Code Playgroud)

augmented-reality swift arkit realitykit

5
推荐指数
1
解决办法
949
查看次数

如何使用 RealityKit 渲染规范面网格?

I\xe2\x80\x99m 尝试使用 RealityKit 渲染面部网格,但尚未成功。因此,当 ARKit 检测到人脸时,ARSession 会生成一个 ARFaceAnchor,其中包含人脸几何网格。

\n

但它不能生成为模型实体。

\n

有人可以帮忙吗?

\n

swift arkit swiftui realitykit

5
推荐指数
1
解决办法
814
查看次数