有没有办法在 RealityKit 中对同一场景使用多个相机(.ar 和 .nonAR)?
Is there a way to use multiple cameras (.ar and .nonAR) for the same scene in RealityKit?
我想在 RealityKit 中从正交视图创建一个主 AR 相机(cameraMode:.ar)和第二个画中画虚拟相机(cameraMode:.nonAR)。第二个摄像头的目标是在没有摄像头馈送的情况下从同一场景中的不同视角可视化模型实体。
虽然我没有使用 SceneKit 的经验,但在非 AR 场景中,这似乎可以通过更改第二个相机的 pointOfView 属性 使用两个不同的相机来完成。
我在 RealityKit 中找不到类似的 属性。这在 RealityKit 中可能吗?有人试过使用 SceneKit 作为渲染器而不是 RealityKit 吗?
在不改变非 AR 相机位置的情况下,我尝试在 SwiftUI 中创建上述两个视图,但收到多个错误:
-[MTLTextureDescriptorInternal validateWithDevice:]:1248: 断言`纹理描述符验证失败
MTLTextureDescriptor 的宽度 (4294967295) 大于允许的最大尺寸 16384。
MTLTextureDescriptor 的高度 (4294967295) 大于允许的最大尺寸 16384。
MTLTextureDescriptor 具有无效的像素格式 (0)。
示例代码如下:
import SwiftUI
import RealityKit
let arViewOne: ARView = ARView(frame: .zero, cameraMode: .ar, automaticallyConfigureSession: true)
let arViewTwo: ARView = ARView(frame: .zero, cameraMode: .nonAR, automaticallyConfigureSession: true)
let boxAnchor = try! Experience.loadBox()
struct ContentView : View {
var body: some View {
HStack {
ARViewContainerOne().edgesIgnoringSafeArea(.all)
ARViewContainerTwo().edgesIgnoringSafeArea(.all)
}
}
}
struct ARViewContainerOne: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
arViewOne.scene.anchors.append(boxAnchor)
return arViewOne
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
struct ARViewContainerTwo: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
return arViewTwo
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
我无法让它在 RealityKit 中运行。需要注意的是,我已经能够使用 SceneKit 产生所需的效果。但是,我运行陷入了一个问题。第二台摄像机始终显示摄像机提要。当我尝试更改场景背景颜色时,它不会改变。我需要 AR 摄像头来回馈摄像头和非 AR 摄像头
在查找如何解决这个问题时,我发现另一个开发人员也在寻找解决同样问题的方法。该开发人员使用了一种不太理想的不太方便的解决方法。 Creating two camera views, one AR and on nonAR in SceneKit.
理想情况下,我想让它在 RealityKit 中工作。但这是一个不错的解决方法。
我认为是 Andy Fedoroff 提供了为 RealityKit 视图提供不同背景不透明度的答案,这对我在不同的项目中很有用。我无法在 SceneKit 中找到相同的解决方案。
arView.environment.background = .cameraFeed(exposureCompensation: -4.0) // -4 is partial
我想在 RealityKit 中从正交视图创建一个主 AR 相机(cameraMode:.ar)和第二个画中画虚拟相机(cameraMode:.nonAR)。第二个摄像头的目标是在没有摄像头馈送的情况下从同一场景中的不同视角可视化模型实体。
虽然我没有使用 SceneKit 的经验,但在非 AR 场景中,这似乎可以通过更改第二个相机的 pointOfView 属性 使用两个不同的相机来完成。
我在 RealityKit 中找不到类似的 属性。这在 RealityKit 中可能吗?有人试过使用 SceneKit 作为渲染器而不是 RealityKit 吗?
在不改变非 AR 相机位置的情况下,我尝试在 SwiftUI 中创建上述两个视图,但收到多个错误:
-[MTLTextureDescriptorInternal validateWithDevice:]:1248: 断言`纹理描述符验证失败 MTLTextureDescriptor 的宽度 (4294967295) 大于允许的最大尺寸 16384。 MTLTextureDescriptor 的高度 (4294967295) 大于允许的最大尺寸 16384。 MTLTextureDescriptor 具有无效的像素格式 (0)。
示例代码如下:
import SwiftUI
import RealityKit
let arViewOne: ARView = ARView(frame: .zero, cameraMode: .ar, automaticallyConfigureSession: true)
let arViewTwo: ARView = ARView(frame: .zero, cameraMode: .nonAR, automaticallyConfigureSession: true)
let boxAnchor = try! Experience.loadBox()
struct ContentView : View {
var body: some View {
HStack {
ARViewContainerOne().edgesIgnoringSafeArea(.all)
ARViewContainerTwo().edgesIgnoringSafeArea(.all)
}
}
}
struct ARViewContainerOne: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
arViewOne.scene.anchors.append(boxAnchor)
return arViewOne
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
struct ARViewContainerTwo: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
return arViewTwo
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
我无法让它在 RealityKit 中运行。需要注意的是,我已经能够使用 SceneKit 产生所需的效果。但是,我运行陷入了一个问题。第二台摄像机始终显示摄像机提要。当我尝试更改场景背景颜色时,它不会改变。我需要 AR 摄像头来回馈摄像头和非 AR 摄像头
在查找如何解决这个问题时,我发现另一个开发人员也在寻找解决同样问题的方法。该开发人员使用了一种不太理想的不太方便的解决方法。 Creating two camera views, one AR and on nonAR in SceneKit.
理想情况下,我想让它在 RealityKit 中工作。但这是一个不错的解决方法。
我认为是 Andy Fedoroff 提供了为 RealityKit 视图提供不同背景不透明度的答案,这对我在不同的项目中很有用。我无法在 SceneKit 中找到相同的解决方案。
arView.environment.background = .cameraFeed(exposureCompensation: -4.0) // -4 is partial